Commit 44adb31b authored by Daniel Stone's avatar Daniel Stone Committed by Keith Packard
Browse files

GetTimeInMillis: Use CLOCK_MONOTONIC_COARSE where available



On some systems, using CLOCK_MONOTONIC forces a readback of HPET or some
similarly expensive timer.  CLOCK_MONOTONIC_COARSE can alleviate this,
at the cost of negligibly-reduced resolution, so prefer that where we
can.
Signed-off-by: Daniel Stone's avatarDaniel Stone <daniel@fooishbar.org>
Reviewed-by: Julien Cristau's avatarJulien Cristau <jcristau@debian.org>
Reviewed-by: default avatarTiago Vignatti <tiago.vignatti@nokia.com>
parent e06fa804
......@@ -427,7 +427,21 @@ GetTimeInMillis(void)
#ifdef MONOTONIC_CLOCK
struct timespec tp;
static clockid_t clockid;
if (!clockid) {
#ifdef CLOCK_MONOTONIC_COARSE
if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
(tp.tv_nsec / 1000) <= 1000 &&
clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
clockid = CLOCK_MONOTONIC_COARSE;
else
#endif
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
clockid = CLOCK_MONOTONIC;
else
clockid = ~0L;
}
if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment