From: Alan T. DeKok Date: Mon, 23 Jan 2023 19:35:07 +0000 (-0500) Subject: use CLOCK_MONOTONIC_RAW if it exists X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36548e2162f4f48f83d818892343ec9fc58d980d;p=thirdparty%2Ffreeradius-server.git use CLOCK_MONOTONIC_RAW if it exists otherwise use CLOCK_MONOTONIC. The RAW version is unaffected by frequency or time adjustments --- diff --git a/src/lib/util/time.c b/src/lib/util/time.c index 6f0a8de67be..567810bb38d 100644 --- a/src/lib/util/time.c +++ b/src/lib/util/time.c @@ -115,7 +115,7 @@ int fr_time_sync(void) * Call these consecutively to minimise drift... */ if (clock_gettime(CLOCK_REALTIME, &ts_realtime) < 0) return -1; - if (clock_gettime(CLOCK_MONOTONIC, &ts_monotime) < 0) return -1; + if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts_monotime) < 0) return -1; atomic_store_explicit(&our_realtime, fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts_realtime)) - @@ -151,7 +151,7 @@ int fr_time_start(void) tzset(); /* Populate timezone, daylight and tzname globals */ struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) return -1; + if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts) < 0) return -1; our_epoch = fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts)); return fr_time_sync(); diff --git a/src/lib/util/time.h b/src/lib/util/time.h index 34383d3ded5..fc76144c573 100644 --- a/src/lib/util/time.h +++ b/src/lib/util/time.h @@ -950,6 +950,10 @@ static inline int8_t fr_unix_time_cmp(fr_unix_time_t a, fr_unix_time_t b) return CMP(fr_unix_time_unwrap(a), fr_unix_time_unwrap(b)); } +#ifndef CLOCK_MONOTONIC_RAW +#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC +#endif + /** Return a relative time since the server our_epoch * * This time is useful for doing time comparisons, deltas, etc. @@ -962,7 +966,7 @@ static inline int8_t fr_unix_time_cmp(fr_unix_time_t a, fr_unix_time_t b) static inline fr_time_t fr_time(void) { struct timespec ts; - (void) clock_gettime(CLOCK_MONOTONIC, &ts); + (void) clock_gettime(CLOCK_MONOTONIC_RAW, &ts); return fr_time_wrap(fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts)) - our_epoch); }