[PATCH] time: Use CLOCK_REALTIME for time (BZ #30200)

Florian Weimer fweimer@redhat.com
Tue Mar 7 11:11:01 GMT 2023


* Adhemerval Zanella:

> Different than gettimeofday and timespec_get, time uses
> CLOCK_REALTIME_COARSE instead of CLOCK_REALTIME on Linux.  The
> coarse time is used mostly as optimization, but it may show
> divergence progression due the clock resolution.
>
> For x86_64 and powerpc64, it should add slight more latency since
> it would call now clock_gettime internally.

It seems really significant on x86-64.

Before:

min:        14 ns
25%:        16 ns
50%:        17 ns
75%:        17 ns
95%:        18 ns
99%:        18 ns
max:     18722 ns
avg:   16.6606 ns

After:

min:        29 ns
25%:        31 ns
50%:        31 ns
75%:        32 ns
95%:        32 ns
99%:        33 ns
max:     12161 ns
avg:   31.2205 ns

And of those original 17 ns, quite a bit is overhead from the
benchmarking loop.  I guess applications could work around it by having
a background timer thread that increments a global variable and use that
instead of the time function call, but that seems not a great approach.

Based on previous feedback, I expect we'd have to carry a downstream
revert of this patch indefinitely, so I'm rather strongly against
applying it upstrean.

Thanks,
Florian



More information about the Libc-alpha mailing list