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 <[email protected]> --- refclock.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/refclock.c b/refclock.c index c9618aa..ae8134e 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); -- 1.9.1 -- To unsubscribe email [email protected] with "unsubscribe" in the subject. For help email [email protected] with "help" in the subject. Trouble? Email [email protected].
