]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use CLOCK_MONOTONIC_RAW if it exists
authorAlan T. DeKok <aland@freeradius.org>
Mon, 23 Jan 2023 19:35:07 +0000 (14:35 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 23 Jan 2023 21:34:54 +0000 (16:34 -0500)
otherwise use CLOCK_MONOTONIC.  The RAW version is unaffected
by frequency or time adjustments

src/lib/util/time.c
src/lib/util/time.h

index 6f0a8de67bea302af14d838d385ff937c329589f..567810bb38df32bdb4e4a19c0acec5237a74fa67 100644 (file)
@@ -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();
index 34383d3ded55ba3067409ba0fc6cb5ddc0e31224..fc76144c573b8d9baa3d0d896305e126c5ef026d 100644 (file)
@@ -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);
 }