]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: use monotonic time to measure how long setting time takes
authorSami Kerola <kerolasa@iki.fi>
Mon, 7 Jan 2019 21:34:11 +0000 (21:34 +0000)
committerSami Kerola <kerolasa@iki.fi>
Sat, 12 Jan 2019 08:46:54 +0000 (08:46 +0000)
Earlier gettimeofday() was affected by discontinuous jumps.  Measuring how
long time it takes to set time using function that effected by the very
thing being measured makes head spin.  Lets make this less confusing with
monotonic clock that ticks on without jumps.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/Makemodule.am
sys-utils/hwclock-rtc.c

index 825a7335bf7d28195660988f57ee92b190a43104..fdecbfac4ae35bb2b7973bdc791e604fcca4f26b 100644 (file)
@@ -454,7 +454,9 @@ hwclock_SOURCES = \
        sys-utils/hwclock.h \
        sys-utils/hwclock-cmos.c
 if LINUX
-hwclock_SOURCES += sys-utils/hwclock-rtc.c
+hwclock_SOURCES += \
+       sys-utils/hwclock-rtc.c \
+       lib/monotonic.c
 endif
 hwclock_LDADD = $(LDADD) libcommon.la -lm
 if HAVE_AUDIT
index 32feb3504e88131797d2cb1f7722683cbaa6a27c..a0d28f89e740804efa3f9c92e19cda809645362d 100644 (file)
@@ -12,6 +12,7 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "monotonic.h"
 #include "nls.h"
 
 #include "hwclock.h"
@@ -223,12 +224,12 @@ static int busywait_for_rtc_clock_tick(const struct hwclock_control *ctl,
         * something weird happens, we have a time limit (1.5s) on this loop
         * to reduce the impact of this failure.
         */
-       gettimeofday(&begin, NULL);
+       gettime_monotonic(&begin);
        do {
                rc = do_rtc_read_ioctl(rtc_fd, &nowtime);
                if (rc || start_time.tm_sec != nowtime.tm_sec)
                        break;
-               gettimeofday(&now, NULL);
+               gettime_monotonic(&now);
                if (time_diff(now, begin) > 1.5) {
                        warnx(_("Timed out waiting for time change."));
                        return 1;