From nobody Thu Aug 24 21:51:14 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RWxc23kbYz4rcxS; Thu, 24 Aug 2023 21:51:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RWxc23H2kz3XGL; Thu, 24 Aug 2023 21:51:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692913874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=l9DDv7qNK0gmUv5d+C9kbJiTZwQNRoBelFOQNSCm6K4=; b=Rn3ZVoKLdedPSisEgLoeCATgqm7OennXYNT2ozsAbY+6tixLqqI+WKlK/sH41BrB5fWzMG DPWD6QZIBdOs/g94fLuhEtHifnwniZCyqeuaZBp9ltDffmiSv8kNENGdrj+cAFEAF1J4FC 0pDNp9J5PS/Sdm6JzitmEsnlHfeqB6eTReMslkWwkXIUvaz1Op7HSClfSDOR3HhZgur1Mc fljNrbVovG7Ezk5go6TjKNG+xGw6V3wR+W9gl3dgGLr/xsgHMkGJLTerBU9NpaHGWEaW0A 6+maoFmzYtmk5+gp3bdooZONLSoUztK0omG/apjattmfZ/mdaQD4Nh3ziPSc9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692913874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=l9DDv7qNK0gmUv5d+C9kbJiTZwQNRoBelFOQNSCm6K4=; b=fmJrDd3ANDl44nkxj/VkwN9FC/RKwi/NQCxMEKdbOWyEUteGBAxIb4Umw1/L9mYwCnjSz3 13CtGqMBMnmE2MLXAFmBOYEehNWYXis+4Cg76vgrxhB89poY0bptlX9lBJD7c+z/AgrWTA Mnq3llit4ymAfH2rXFluAC2wuFHZCBI22/7Q/Y/PUp0ycy0GKCixef/ZD+UUB/5cxV6HPL X0CWSUWqh1sGHsx3S0Ohvsc0h3jhGbd3pMWsdNrftbGdU3m6QPeSG0mW1RmhCfLkU10KHv T321ngXX0CDcivmtwSCkUgQCHvD21K7lreT144/Cyb13+6Wo1vDliJcL2BNX7Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692913874; a=rsa-sha256; cv=none; b=HB69Km/uxLnti+Oi21OAghmEiqRs/gH7S3yDb+aD5zca1I+m7K2P94kNzKZXlw9KBNh2/6 LIrcfAAn75Z/4fSZOCXJyqiEuVv2uzqqoT0d3iy1roin82NRBaQphKTpuG5fS6u51UuNRa 5aoAx9U+OPPQnJ4nAEv9uuRoyPBMuJF8VBZKvPK/OlskDLLZknJLtpTK5heajoIsJwZQpJ lJ0xupwPaWFGM3mYZyd5nLOt37cytLS3GX5/HNmmOFEEgrL5gK83L16dSrthdPKbCDp3wt +w8hKsbCfZKOHHzRKtdoxvYYE4xvD6HsSkhsHZ4J2tB6m8u9gUxE67N+u3ilkA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RWxc22LwLzk0Y; Thu, 24 Aug 2023 21:51:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37OLpEno037440; Thu, 24 Aug 2023 21:51:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37OLpEW0037437; Thu, 24 Aug 2023 21:51:14 GMT (envelope-from git) Date: Thu, 24 Aug 2023 21:51:14 GMT Message-Id: <202308242151.37OLpEW0037437@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 9b5d724cad10 - main - libc: Add timespec_getres(3) as per C23. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9b5d724cad10087e34165199e55f15f2df744ed5 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=9b5d724cad10087e34165199e55f15f2df744ed5 commit 9b5d724cad10087e34165199e55f15f2df744ed5 Author: Dag-Erling Smørgrav AuthorDate: 2023-08-24 21:31:11 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-08-24 21:31:54 +0000 libc: Add timespec_getres(3) as per C23. This also adds support for TIME_MONOTONIC to timespec_get(3). Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D41524 --- include/time.h | 8 ++++++- lib/libc/gen/Makefile.inc | 2 ++ lib/libc/gen/timespec_get.3 | 17 ++++++++++++-- lib/libc/gen/timespec_get.c | 4 ++++ lib/libc/gen/timespec_getres.3 | 51 ++++++++++++++++++++++++++++++++++++++++++ lib/libc/gen/timespec_getres.c | 24 ++++++++++++++++++++ 6 files changed, 103 insertions(+), 3 deletions(-) diff --git a/include/time.h b/include/time.h index c6c083316423..ef55577a2f84 100644 --- a/include/time.h +++ b/include/time.h @@ -182,9 +182,15 @@ time_t posix2time(time_t t); #if defined(__BSD_VISIBLE) || __ISO_C_VISIBLE >= 2011 || \ (defined(__cplusplus) && __cplusplus >= 201703) #include -/* ISO/IEC 9899:201x 7.27.2.5 The timespec_get function */ +/* ISO/IEC 9899:2011 7.27.2.5 The timespec_get function */ #define TIME_UTC 1 /* time elapsed since epoch */ int timespec_get(struct timespec *ts, int base); +#if defined (__BSD_VISIBLE) || __ISO_C_VISIBLE >= 2023 +/* ISO/IEC 9899:2024 7.29.1 Components of time */ +#define TIME_MONOTONIC 2 /* monotonic time */ +/* ISO/IEC 9899:2024 7.29.2.7 The timespec_getres function */ +int timespec_getres(struct timespec *, int); +#endif #endif __END_DECLS diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 34de0e9ddeb0..655843f03715 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -156,6 +156,7 @@ SRCS+= __getosreldate.c \ time.c \ times.c \ timespec_get.c \ + timespec_getres.c \ timezone.c \ tls.c \ ttyname.c \ @@ -319,6 +320,7 @@ MAN+= alarm.3 \ time.3 \ times.3 \ timespec_get.3 \ + timespec_getres.3 \ timezone.3 \ ttyname.3 \ tzset.3 \ diff --git a/lib/libc/gen/timespec_get.3 b/lib/libc/gen/timespec_get.3 index 00d1a7c684c4..7edf4fe17c30 100644 --- a/lib/libc/gen/timespec_get.3 +++ b/lib/libc/gen/timespec_get.3 @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd August 10, 2018 +.Dd August 21, 2023 .Dt TIMESPEC_GET 3 .Os .Sh NAME @@ -55,6 +55,14 @@ In .Fx , this corresponds to .Dv CLOCK_REALTIME . +.Pp +The base +.Dv TIME_MONOTONIC +returns a monotonically-increasing time since an unspecified point in the past. +In +.Fx , +this corresponds to +.Dv CLOCK_MONOTONIC . .Sh RETURN VALUES The .Nm @@ -66,7 +74,8 @@ on failure. .Sh SEE ALSO .Xr clock_gettime 2 , .Xr gettimeofday 2 , -.Xr time 3 +.Xr time 3 , +.Xr timespec_getres 3 .Sh STANDARDS The .Nm @@ -76,6 +85,10 @@ of .Dv TIME_UTC conforms to .St -isoC-2011 . +.\" The +.\" .Dv TIME_MONOTONIC +.\" base conforms to +.\" -isoC-2023 . .Sh HISTORY This interface first appeared in .Fx 12 . diff --git a/lib/libc/gen/timespec_get.c b/lib/libc/gen/timespec_get.c index bcf392cbfa44..96845d545048 100644 --- a/lib/libc/gen/timespec_get.c +++ b/lib/libc/gen/timespec_get.c @@ -44,6 +44,10 @@ timespec_get(struct timespec *ts, int base) if (clock_gettime(CLOCK_REALTIME, ts) == -1) return 0; break; + case TIME_MONOTONIC: + if (clock_gettime(CLOCK_MONOTONIC, ts) == -1) + return 0; + break; default: return 0; } diff --git a/lib/libc/gen/timespec_getres.3 b/lib/libc/gen/timespec_getres.3 new file mode 100644 index 000000000000..e00af6758f1a --- /dev/null +++ b/lib/libc/gen/timespec_getres.3 @@ -0,0 +1,51 @@ +.\"- +.\" Copyright (c) 2023 Dag-Erling Smørgrav +.\" +.\" SPDX-License-Identifier: BSD-2-Clause +.\" +.Dd August 21, 2023 +.Dt TIMESPEC_GETRES 3 +.Os +.Sh NAME +.Nm timespec_getres +.Nd get clock resolution +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Ft int +.Fn timespec_getres "struct timespec *ts" "int base" +.Sh DESCRIPTION +If +.Fa ts +is non-null and +.Fa base +refers to a supported time base as described in +.Xr timespec_get 3 , +the +.Nm +function fills in the structure pointed to by +.Fa ts +to reflect the resolution of that time base. +.Sh RETURN VALUES +The +.Nm +function returns the value of +.Fa base +if successful and zero otherwise. +.Sh SEE ALSO +.Xr clock_getres 2 , +.Xr timespec_get 3 +.\" .Sh STANDARDS +.\" The +.\" .Nm +.\" function conforms to +.\" .St -isoC-2023 . +.Sh HISTORY +This interface first appeared in +.Fx 14 . +.Sh AUTHORS +The +.Nm +function and this manual page were written by +.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org . diff --git a/lib/libc/gen/timespec_getres.c b/lib/libc/gen/timespec_getres.c new file mode 100644 index 000000000000..4977d22cf910 --- /dev/null +++ b/lib/libc/gen/timespec_getres.c @@ -0,0 +1,24 @@ +/*- + * Copyright (c) 2023 Dag-Erling Smørgrav + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +int +timespec_getres(struct timespec *ts, int base) +{ + + switch (base) { + case TIME_UTC: + if (clock_getres(CLOCK_REALTIME, ts) == 0) + return (base); + break; + case TIME_MONOTONIC: + if (clock_getres(CLOCK_MONOTONIC, ts) == 0) + return (base); + break; + } + return (0); +}