From: Tjalling Hattink Date: Thu, 22 May 2014 09:25:00 +0000 (+0200) Subject: refclock: honour leap second flag in the PPS refclock X-Git-Tag: 1.30-pre1~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8210be0f17429f8e396d09a5e92c9e0f8f8e751e;p=thirdparty%2Fchrony.git refclock: honour leap second flag in the PPS refclock 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 --- diff --git a/refclock.c b/refclock.c index c9618aa2..ae8134e9 100644 --- a/refclock.c +++ b/refclock.c @@ -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);