[PATCH xserver 2/4] os: Use separate clockid for GetTimeInMicros()

Jeffrey Smith whydoubt at gmail.com
Thu Dec 28 18:16:04 UTC 2017


On Wed, Dec 27, 2017 at 9:38 PM, Keith Packard <keithp at keithp.com> wrote:
> Jeffrey Smith <whydoubt at gmail.com> writes:
>
>> GetTimeInMillis uses the CLOCK_MONOTONIC_COARSE clock if
>> available and the precision is high enough.  That clock is supposed
>> to be more efficient to query than CLOCK_MONOTONIC (at the cost
>> of being less precise).  So implementing GetTimeInMillis by calling
>> GetTimeInMicros could mean spending extra time to get higher
>> precision, just to spend more time (for the division) throwing it
>> away.
>
> Good point. So, we want to use CLOCK_MONOTONIC_COARSE for Millis and
> CLOCK_MONOTONIC for Micros. That seems like a fine plan. I guess what
> I'm getting at is that these two functions should return a value in the
> same universe at least, so we should either be using the two MONOTONIC
> clocks, or we should be using another clock, but we shouldn't be mixing
> MONOTONIC and REALTIME clocks?

Agreed.  With this patch, only these (milli clock , micro clock)
pairings should occur...

if clockid is forced:
    (forced clockid , forced clockid)
else if coarse clock is available (Linux-specific, since 2.6.32) and
has 1ms or finer resolution:
    (CLOCK_MONOTONIC_COARSE , CLOCK_MONOTONIC)
else if monotonic clock is available:
    (CLOCK_MONOTONIC , CLOCK_MONOTONIC)
else:
    (~0L , ~0L)    interpreted to mean use gettimeofday

Also, the next patch changes the final pairing to:
    (CLOCK_REALTIME , CLOCK_REALTIME)

>
> --
> -keith


More information about the xorg-devel mailing list