]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
refclock: honour leap second flag in the PPS refclock
authorTjalling Hattink <t.hattink@fugro.nl>
Thu, 22 May 2014 09:25:00 +0000 (11:25 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 22 May 2014 11:28:46 +0000 (13:28 +0200)
This patch fixes leap second handling for the PPS refclock. Without the
patch the PPS refclock will always report LEAP_normal. But if a locked
refclock (the SHM clock in my case) does report a leap state it should
also be taken over by the PPS refclock, otherwise chrony will still use
LEAP_normal when the PPS clock is used as reference source.

The patch will copy the leap state from the refclock. In case the PPS
clock is not specifically locked to another refclock it will take over
the leap state from the local clock.

I've tested this patch by simulating a leap second through the samples
for the SHM clock, and with the patch you will see chrony properly jump
forward or backward on the leap second. Without the patch it will not do
this and the clock becomes desynchronized and no leap state is reported
upstream to other NTP clients.

Signed-off-by: Tjalling Hattink <t.hattink@fugro.nl>
refclock.c

index c9618aa2c006994353d288c05a574bac4a5c30b9..ae8134e9120000d7674fd9e25c5704e273e9b948 100644 (file)
@@ -385,7 +385,9 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
   double correction, dispersion, offset;
   struct timeval cooked_time;
   int rate;
+  NTP_Leap leap;
 
+  leap = LEAP_Normal;
   LCL_GetOffsetCorrection(pulse_time, &correction, &dispersion);
   UTI_AddDoubleToTimeval(pulse_time, correction, &cooked_time);
   dispersion += instance->precision + filter_get_avg_sample_dispersion(&instance->filter);
@@ -436,13 +438,14 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
       return 0;
     }
 
+    leap = refclocks[instance->lock_ref].leap_status;
+
     DEBUG_LOG(LOGF_Refclock, "refclock pulse second=%.9f offset=%.9f offdiff=%.9f samplediff=%.9f",
         second, offset, ref_offset - offset, sample_diff);
   } else {
     struct timeval ref_time;
     int is_synchronised, stratum;
     double root_delay, root_dispersion, distance;
-    NTP_Leap leap;
     uint32_t ref_id;
 
     /* Ignore the pulse if we are not well synchronized */
@@ -461,7 +464,7 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
   }
 
   filter_add_sample(&instance->filter, &cooked_time, offset, dispersion);
-  instance->leap_status = LEAP_Normal;
+  instance->leap_status = leap;
   instance->pps_active = 1;
 
   log_sample(instance, &cooked_time, 0, 1, offset + correction - instance->offset, offset, dispersion);