[chrony-dev] Patch for adding leap seconds in the PPS refclock

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


Hi,

I've pasted a patch below that 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.

Kind regards,

Tjalling Hattink


--- a/refclock.c
+++ b/refclock.c
@@ -378,7 +378,9 @@ RCL_AddPulse(RCL_Instance instance, stru
   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);
@@ -421,6 +423,8 @@ RCL_AddPulse(RCL_Instance instance, stru
     if (fabs(ref_offset - offset) + ref_dispersion + dispersion >= 0.2
/ rate)
       return 0;
 
+    leap = refclocks[instance->lock_ref].leap_status;
+
 #if 0
     LOG(LOGS_INFO, LOGF_Refclock, "refclock pulse second=%.9f
offset=%.9f offdiff=%.9f samplediff=%.9f",
         second, offset, ref_offset - offset, sample_diff);
@@ -429,7 +433,6 @@ RCL_AddPulse(RCL_Instance instance, stru
     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 */
@@ -450,7 +453,7 @@ RCL_AddPulse(RCL_Instance instance, stru
   }
 
   filter_add_sample(&instance->filter, &cooked_time, offset,
dispersion);
-  instance->leap_status = LEAP_Normal;
+  instance->leap_status = leap;
 
   log_sample(instance, &cooked_time, 0, 1, offset + correction -
instance->offset, offset, dispersion);


--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/