]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sys_linux: don't drop PHC samples with zero delay
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 19 Apr 2017 10:20:14 +0000 (12:20 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 19 Apr 2017 11:03:10 +0000 (13:03 +0200)
When processing data from the PTP_SYS_OFFSET ioctl, the sample is
dropped when an interval between two consecutive readings of the system
clock is negative or zero, assuming the clock has been stepped between
the two readings.

With a real PHC the interval is normally expected to be at least a
microsecond, but with a virtual PHC and a low-resolution system clock
it's possible to get two readings with the same system time. Modify the
check to drop only samples with a negative delay.

sys_linux.c

index c06112a2aaa5a70e435f5e67fa98bf541cd8afa8..649afb0e80069e013c236e2fc378008ee69e79e6 100644 (file)
@@ -705,9 +705,11 @@ get_phc_sample(int phc_fd, double precision, struct timespec *phc_ts,
     phc_tss[i] = ts2;
     delays[i] = UTI_DiffTimespecsToDouble(&ts3, &ts1);
 
-    if (delays[i] <= 0.0)
+    if (delays[i] < 0.0) {
       /* Step in the middle of a PHC reading? */
+      DEBUG_LOG("Bad PTP_SYS_OFFSET sample delay=%e", delays[i]);
       return 0;
+    }
 
     if (!i || delays[i] < min_delay)
       min_delay = delays[i];