[PATCH v6] time: Add TIME_MONOTONIC, TIME_ACTIVE, and TIME_THREAD_ACTIVE
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Thu Dec 4 16:52:43 GMT 2025
On 04/12/25 10:56, 罗勇刚(Yonggang Luo) wrote:
> On Wed, Dec 3, 2025 at 2:51 AM Adhemerval Zanella
> <adhemerval.zanella@linaro.org> wrote:
>>
>> The TIME_MONOTONIC maps to POSIX's CLOCK_MONOTONIC, TIME_ACTIVE to
>> CLOCK_PROCESS_CPUTIME_ID, and TIME_THREAD_ACTIVE to
>> CLOCK_THREAD_CPUTIME_ID.
>>
>> No Linux specific timer are added as extension.
>>
>> Co-authored-by: Yonggang Luo <luoyonggang@gmail.com>
>> --
>> Change from v5:
>> * Changed _Static_assert to use verify.
>> * Added Paul Eggert manual suggestions.
>>
>> Changes from v4:
>> * Fixed _Static_assert naming in clock_from_timebase (hopefully
>> this time).
>>
>> Changes from v3:
>> * Fixed _Static_assert naming in clock_from_timebase.
>>
>> Changes from v2:
>> * Added manual entries for the new symbols.
>> * Optimized C TIME to POSIX clockid_t mapping.
>>
>> Changes from v1:
>> * Fixed new timers on ABIs with 32 bit time_t support.
>> * Dropped support for the Linux specific timers.
>> ---
>> NEWS | 3 ++
>> include/time.h | 12 +++++++
>> manual/time.texi | 13 ++++++++
>> sysdeps/unix/sysv/linux/timespec_get.c | 9 ++---
>> sysdeps/unix/sysv/linux/timespec_getres.c | 10 ++----
>> time/time.h | 5 +++
>> time/timespec_get.c | 7 +---
>> time/timespec_getres.c | 7 +---
>> time/tst-timespec_get.c | 24 +++++++-------
>> time/tst-timespec_getres.c | 40 ++++++++++++++---------
>> 10 files changed, 76 insertions(+), 54 deletions(-)
>>
>> diff --git a/NEWS b/NEWS
>> index 81c7e04293..c420b67676 100644
>> --- a/NEWS
>> +++ b/NEWS
>> @@ -46,6 +46,9 @@ Major new features:
>> lgammaf/lgammaf_r, log10f, sinhf, sqrtf, tgammaf, y0/j0, y1/j1, and yn/jn
>> were moved to compat symbols, allowing improvements in performance.
>>
>> +* The ISO C23 optional time base TIME_MONOTONIC, TIME_ACTIVE, and
>> + TIME_THREAD_ACTIVE have been added.
>> +
>> Deprecated and removed features, and other changes affecting compatibility:
>>
>> * Support for dumped heaps has been removed - malloc_set_state() now always
>> diff --git a/include/time.h b/include/time.h
>> index f599eeed4e..518215a2f9 100644
>> --- a/include/time.h
>> +++ b/include/time.h
>> @@ -12,6 +12,7 @@
>> # include <time-clockid.h>
>> # include <sys/time.h>
>> # include <stdint.h>
>> +# include <verify.h>
>>
>> extern __typeof (strftime_l) __strftime_l;
>> libc_hidden_proto (__strftime_l)
>> @@ -536,6 +537,17 @@ time64_now (void)
>> return ts.tv_sec;
>> }
>>
>> +/* Helper that converts from C timebase to POSIX clockid_t. */
>> +static inline clockid_t
>> +clock_from_timebase (int timebase)
>
> Please rename clock_from_timebase to __clock_from_timebase
> or __glibc_clock_from_timebase, as this function is in header that
> be used by so much code, use __glibc_clock_from_timebase will reduce
> potential conflict
This is an internal-only header and the function is marked as inline,
so there is no need to use a double underscore to avoid namespace
polution in staitc linking, neither to prepend to with a __glibc
namespace.
More information about the Libc-alpha
mailing list