[PATCH] time: Use CLOCK_REALTIME for time (BZ #30200)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Tue Mar 7 11:45:05 GMT 2023
On 07/03/23 08:11, Florian Weimer wrote:
> * 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.
Yes, this is expected since time call will be route through clock_gettime.
Another fix would be to convince kernels developers to use CLOCK_REALTIME
on vDSO as well.
>
> 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.
To me it really seems like a over-optimization specially because 'time'
has only second resolution.
More information about the Libc-alpha
mailing list