From 2582be8754ab9603c64ee96a8d371dbb1e6f1b2a Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 11 Mar 2020 15:48:00 +0100 Subject: [PATCH] sources: separate update of leap status Remove leap status from the NTP sample and set it independently from the sample accumulation in order to accept a leap second sooner when samples are filtered. --- ntp.h | 1 - ntp_core.c | 2 +- refclock.c | 2 +- samplefilt.c | 1 - sources.c | 12 +++++++++++- sources.h | 6 ++++-- test/unit/samplefilt.c | 5 +++-- test/unit/sources.c | 1 - 8 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ntp.h b/ntp.h index 90f24c2..8044918 100644 --- a/ntp.h +++ b/ntp.h @@ -152,7 +152,6 @@ typedef struct { double root_delay; double root_dispersion; int stratum; - NTP_Leap leap; } NTP_Sample; #endif /* GOT_NTP_H */ diff --git a/ntp_core.c b/ntp_core.c index 68b86e1..c4da33d 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1682,7 +1682,6 @@ process_response(NCR_Instance inst, NTP_Local_Address *local_addr, sample.root_delay = pkt_root_delay + sample.peer_delay; sample.root_dispersion = pkt_root_dispersion + sample.peer_dispersion; sample.stratum = MAX(message->stratum, inst->min_stratum); - sample.leap = (NTP_Leap)pkt_leap; /* Update the NTP timestamps. If it's a valid packet from a synchronised source, the timestamps may be used later when processing a packet in the @@ -1772,6 +1771,7 @@ process_response(NCR_Instance inst, NTP_Local_Address *local_addr, inst->tx_count = 0; SRC_UpdateReachability(inst->source, synced_packet); + SRC_SetLeapStatus(inst->source, pkt_leap); if (good_packet) { /* Adjust the polling interval, accumulate the sample, etc. */ diff --git a/refclock.c b/refclock.c index 561df45..1a78bfe 100644 --- a/refclock.c +++ b/refclock.c @@ -415,7 +415,6 @@ accumulate_sample(RCL_Instance instance, struct timespec *sample_time, double of sample.root_delay = instance->delay; sample.peer_dispersion = dispersion; sample.root_dispersion = dispersion; - sample.leap = instance->leap_status; /* Handle special case when PPS is used with the local reference */ if (instance->pps_active && instance->lock_ref == -1) @@ -704,6 +703,7 @@ poll_timeout(void *arg) if (SPF_GetFilteredSample(inst->filter, &sample)) { SRC_UpdateReachability(inst->source, 1); + SRC_SetLeapStatus(inst->source, inst->leap_status); SRC_AccumulateSample(inst->source, &sample); SRC_SelectSource(inst->source); diff --git a/samplefilt.c b/samplefilt.c index 2b737e9..f320fc9 100644 --- a/samplefilt.c +++ b/samplefilt.c @@ -387,7 +387,6 @@ combine_selected_samples(SPF_Instance filter, int n, NTP_Sample *result) result->peer_delay = mean_peer_delay; result->root_delay = mean_root_delay; result->stratum = last_sample->stratum; - result->leap = last_sample->leap; return 1; } diff --git a/sources.c b/sources.c index 58cc4f2..6294bbd 100644 --- a/sources.c +++ b/sources.c @@ -326,6 +326,17 @@ SRC_GetSourcestats(SRC_Instance instance) /* ================================================== */ +void +SRC_SetLeapStatus(SRC_Instance inst, NTP_Leap leap) +{ + if (REF_IsLeapSecondClose()) + return; + + inst->leap = leap; +} + +/* ================================================== */ + /* This function is called by one of the source drivers when it has a new sample that is to be accumulated. @@ -351,7 +362,6 @@ SRC_AccumulateSample(SRC_Instance inst, NTP_Sample *sample) SST_AccumulateSample(inst->stats, sample); SST_DoNewRegression(inst->stats); - inst->leap = sample->leap; } /* ================================================== */ diff --git a/sources.h b/sources.h index 75f0f23..6d97ee4 100644 --- a/sources.h +++ b/sources.h @@ -79,8 +79,10 @@ extern void SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr); /* Function to get access to the sourcestats instance */ extern SST_Stats SRC_GetSourcestats(SRC_Instance instance); -/* This function is called by one of the source drivers when it has - a new sample that is to be accumulated */ +/* Function to set the current leap status according to the source */ +extern void SRC_SetLeapStatus(SRC_Instance instance, NTP_Leap leap); + +/* Function to accumulate a new sample from the source */ extern void SRC_AccumulateSample(SRC_Instance instance, NTP_Sample *sample); /* This routine sets the source as receiving reachability updates */ diff --git a/test/unit/samplefilt.c b/test/unit/samplefilt.c index a371b3a..d8d2975 100644 --- a/test/unit/samplefilt.c +++ b/test/unit/samplefilt.c @@ -35,6 +35,9 @@ test_unit(void) LCL_Initialise(); + memset(&sample_in, 0, sizeof (sample_in)); + memset(&sample_out, 0, sizeof (sample_out)); + for (i = 0; i <= 100; i++) { max_samples = random() % 20 + 1; min_samples = random() % (max_samples) + 1; @@ -57,7 +60,6 @@ test_unit(void) sample_in.peer_delay = TST_GetRandomDouble(1.0e-2, 2.0e-2); sample_in.root_delay = TST_GetRandomDouble(1.0e-1, 2.0e-1); sample_in.stratum = random() % 16; - sample_in.leap = random() % 4; TEST_CHECK(SPF_AccumulateSample(filter, &sample_in)); TEST_CHECK(!SPF_AccumulateSample(filter, &sample_in)); @@ -95,7 +97,6 @@ test_unit(void) sample_out.peer_delay <= 2.0e-2); TEST_CHECK(sample_out.root_delay >= 1.0e-1 && sample_out.root_delay <= 2.0e-1); - TEST_CHECK(sample_out.leap >= 0 && sample_out.leap <= 3); TEST_CHECK(sample_out.stratum >= 0 && sample_out.stratum <= 15); if (max_samples == 1) diff --git a/test/unit/sources.c b/test/unit/sources.c index 83f7060..ce7dc00 100644 --- a/test/unit/sources.c +++ b/test/unit/sources.c @@ -71,7 +71,6 @@ test_unit(void) sample.root_delay = sample.peer_delay; sample.root_dispersion = sample.peer_dispersion; sample.stratum = 1; - sample.leap = LEAP_Normal; DEBUG_LOG("source %d sample %d offset %f delay %f disp %f", j, k, sample.offset, sample.peer_delay, sample.peer_dispersion);