[v2,2/4] time: Implement c23 timespec_get base
Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
fail
|
Testing failed
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
fail
|
Testing failed
|
Commit Message
These are implemented https://gustedt.gitlabpages.inria.fr/c23-library/#time_monotonic-time_active-time_thread_active
with:
# define TIME_MONOTONIC 2
# define TIME_ACTIVE 3
# define TIME_THREAD_ACTIVE 4
# define TIME_MONOTONIC_RAW 5
# define TIME_UTC_COARSE 6
# define TIME_MONOTONIC_COARSE 7
# define TIME_BOOTTIME 8
# define TIME_UTC_ALARM 9
# define TIME_BOOTTIME_ALARM 10
# define TIME_SGI_CYCLE 11
# define TIME_TAI 12
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
time/time.h | 13 +++++++++++-
time/timespec_get.c | 51 +++++++++++++++++++++++++++++++++++++++++----
2 files changed, 59 insertions(+), 5 deletions(-)
Comments
On Wed, 21 Jun 2023, Yonggang Luo via Libc-alpha wrote:
> #ifdef __USE_ISOC11
> /* Time base values for timespec_get. */
> -# define TIME_UTC 1
> +# define TIME_UTC 1
> +# define TIME_MONOTONIC 2
> +# define TIME_ACTIVE 3
> +# define TIME_THREAD_ACTIVE 4
These should be conditional on C2x.
> +# define TIME_MONOTONIC_RAW 5
> +# define TIME_UTC_COARSE 6
> +# define TIME_MONOTONIC_COARSE 7
> +# define TIME_BOOTTIME 8
> +# define TIME_UTC_ALARM 9
> +# define TIME_BOOTTIME_ALARM 10
> +# define TIME_SGI_CYCLE 11
> +# define TIME_TAI 12
And adding these is questionable; certainly any extension to these
interfaces would need properly documenting (i.e. with what glibc defines
the semantics to be, *not* what the Linux kernel defines some CLOCK_*
semantics to be), and if added, it would be appropriate for them to be
conditional on __USE_GNU.
> + case TIME_BOOTTIME:
> + clockid = CLOCK_BOOTTIME;
> + break;
> + case TIME_UTC_ALARM:
> + clockid = CLOCK_REALTIME_ALARM;
> + break;
> + case TIME_BOOTTIME_ALARM:
> + clockid = CLOCK_BOOTTIME_ALARM;
> + break;
These don't exist in bits/time.h; try building for Hurd with
build-many-glibcs.py.
> + case TIME_SGI_CYCLE:
> + clockid = CLOCK_SGI_CYCLE;
> + break;
And this doesn't exist in glibc at all. Is a Linux kernel uapi header
included somehow?
> + case TIME_TAI:
> + clockid = CLOCK_TAI;
> + break;
Again, I'd expect this to break the build for Hurd.
On Wed, Jun 21, 2023 at 4:37 AM Joseph Myers <joseph@codesourcery.com>
wrote:
>
> On Wed, 21 Jun 2023, Yonggang Luo via Libc-alpha wrote:
>
> > #ifdef __USE_ISOC11
> > /* Time base values for timespec_get. */
> > -# define TIME_UTC 1
> > +# define TIME_UTC 1
>
> > +# define TIME_MONOTONIC 2
> > +# define TIME_ACTIVE 3
> > +# define TIME_THREAD_ACTIVE 4
>
> These should be conditional on C2x.
>
> > +# define TIME_MONOTONIC_RAW 5
> > +# define TIME_UTC_COARSE 6
> > +# define TIME_MONOTONIC_COARSE 7
> > +# define TIME_BOOTTIME 8
> > +# define TIME_UTC_ALARM 9
> > +# define TIME_BOOTTIME_ALARM 10
> > +# define TIME_SGI_CYCLE 11
> > +# define TIME_TAI 12
>
> And adding these is questionable; certainly any extension to these
> interfaces would need properly documenting (i.e. with what glibc defines
> the semantics to be, *not* what the Linux kernel defines some CLOCK_*
> semantics to be), and if added, it would be appropriate for them to be
> conditional on __USE_GNU.
Defining it without __USE_GNU is my intention, as TIME_* is not GNU
specified.
my intention is defines these TIME_* macros in a cross-platform manner, so
that
We can always accessed to these enums and have no need concern which
os/platform we are on,
and if the platform doesn't support that, we can use timespec_get(ts,
TIME_TAI) != TIME_TAI
to do that. This is also why c11 introduced timespec_get.
>
> > + case TIME_BOOTTIME:
> > + clockid = CLOCK_BOOTTIME;
> > + break;
> > + case TIME_UTC_ALARM:
> > + clockid = CLOCK_REALTIME_ALARM;
> > + break;
> > + case TIME_BOOTTIME_ALARM:
> > + clockid = CLOCK_BOOTTIME_ALARM;
> > + break;
>
> These don't exist in bits/time.h; try building for Hurd with
> build-many-glibcs.py.
>
> > + case TIME_SGI_CYCLE:
> > + clockid = CLOCK_SGI_CYCLE;
> > + break;
>
> And this doesn't exist in glibc at all. Is a Linux kernel uapi header
> included somehow?
>
> > + case TIME_TAI:
> > + clockid = CLOCK_TAI;
> > + break;
>
> Again, I'd expect this to break the build for Hurd.
>
How about change the code to the form like this:
clockid_t clockid = -1;
switch (base)
{
default:
break;
case TIME_UTC:
clockid = CLOCK_REALTIME;
break;
case TIME_MONOTONIC:
clockid = CLOCK_MONOTONIC;
break;
case TIME_ACTIVE:
clockid = CLOCK_PROCESS_CPUTIME_ID;
break;
case TIME_THREAD_ACTIVE:
clockid = CLOCK_THREAD_CPUTIME_ID;
break;
case TIME_MONOTONIC_RAW:
clockid = CLOCK_MONOTONIC_RAW;
break;
case TIME_UTC_COARSE:
clockid = CLOCK_REALTIME_COARSE;
break;
case TIME_MONOTONIC_COARSE:
clockid = CLOCK_MONOTONIC_COARSE;
break;
#ifdef CLOCK_BOOTTIME
case TIME_BOOTTIME:
clockid = CLOCK_BOOTTIME;
break;
#endif
#ifdef CLOCK_REALTIME_ALARM
case TIME_UTC_ALARM:
clockid = CLOCK_REALTIME_ALARM;
break;
#endif
#ifdef CLOCK_BOOTTIME_ALARM
case TIME_BOOTTIME_ALARM:
clockid = CLOCK_BOOTTIME_ALARM;
break;
#endif
#ifdef CLOCK_SGI_CYCLE
case TIME_SGI_CYCLE:
clockid = CLOCK_SGI_CYCLE;
break;
#endif
#ifdef CLOCK_TAI
case TIME_TAI:
clockid = CLOCK_TAI;
break;
#endif
}
> --
> Joseph S. Myers
> joseph@codesourcery.com
--
此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo
@@ -62,7 +62,18 @@ typedef __pid_t pid_t;
#ifdef __USE_ISOC11
/* Time base values for timespec_get. */
-# define TIME_UTC 1
+# define TIME_UTC 1
+# define TIME_MONOTONIC 2
+# define TIME_ACTIVE 3
+# define TIME_THREAD_ACTIVE 4
+# define TIME_MONOTONIC_RAW 5
+# define TIME_UTC_COARSE 6
+# define TIME_MONOTONIC_COARSE 7
+# define TIME_BOOTTIME 8
+# define TIME_UTC_ALARM 9
+# define TIME_BOOTTIME_ALARM 10
+# define TIME_SGI_CYCLE 11
+# define TIME_TAI 12
#endif
__BEGIN_DECLS
@@ -17,15 +17,58 @@
#include <time.h>
-
/* Set TS to calendar time based in time base BASE. */
int
timespec_get (struct timespec *ts, int base)
{
- if (base == TIME_UTC)
+ clockid_t clockid = -1;
+ switch (base)
+ {
+ default:
+ break;
+ case TIME_UTC:
+ clockid = CLOCK_REALTIME;
+ break;
+ case TIME_MONOTONIC:
+ clockid = CLOCK_MONOTONIC;
+ break;
+ case TIME_ACTIVE:
+ clockid = CLOCK_PROCESS_CPUTIME_ID;
+ break;
+ case TIME_THREAD_ACTIVE:
+ clockid = CLOCK_THREAD_CPUTIME_ID;
+ break;
+ case TIME_MONOTONIC_RAW:
+ clockid = CLOCK_MONOTONIC_RAW;
+ break;
+ case TIME_UTC_COARSE:
+ clockid = CLOCK_REALTIME_COARSE;
+ break;
+ case TIME_MONOTONIC_COARSE:
+ clockid = CLOCK_MONOTONIC_COARSE;
+ break;
+ case TIME_BOOTTIME:
+ clockid = CLOCK_BOOTTIME;
+ break;
+ case TIME_UTC_ALARM:
+ clockid = CLOCK_REALTIME_ALARM;
+ break;
+ case TIME_BOOTTIME_ALARM:
+ clockid = CLOCK_BOOTTIME_ALARM;
+ break;
+ case TIME_SGI_CYCLE:
+ clockid = CLOCK_SGI_CYCLE;
+ break;
+ case TIME_TAI:
+ clockid = CLOCK_TAI;
+ break;
+ }
+ if (clockid >= 0)
{
- __clock_gettime (CLOCK_REALTIME, ts);
- return base;
+ if (__clock_gettime (clockid, ts) >= 0)
+ {
+ return base;
+ }
}
return 0;
}