]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: separate update of leap status
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 11 Mar 2020 14:48:00 +0000 (15:48 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 12 Mar 2020 13:07:12 +0000 (14:07 +0100)
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
ntp_core.c
refclock.c
samplefilt.c
sources.c
sources.h
test/unit/samplefilt.c
test/unit/sources.c

diff --git a/ntp.h b/ntp.h
index 90f24c29ed4b967d790e23fb6fedb7b189d3b8d0..804491837891646106d07f5ee186a66b640a5bb1 100644 (file)
--- 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 */
index 68b86e18d0cc7764ec0d81ecc5f56dade05d0926..c4da33d0beca0e9d354052771fcf122b6a8a94fc 100644 (file)
@@ -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. */
index 561df4537c77ce5b58c898ad7bf9db7716f97b89..1a78bfe8055bf9aa46b311b7c95ee708d69d21ef 100644 (file)
@@ -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);
 
index 2b737e9c5777015358e2d54a4d2b4d529cdb4235..f320fc9d5b7c22fbf09e38d9d892b747baf4acae 100644 (file)
@@ -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;
 }
index 58cc4f2b85fa3a425434807b749ced64f385c716..6294bbd3c6070a08f75f9c09161826fc3af2d503 100644 (file)
--- 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;
 }
 
 /* ================================================== */
index 75f0f232c8f3fc46cf0b03618dfc78d1e3485198..6d97ee49a4ddceb6ad8bafd8f6eb565059cb3e7f 100644 (file)
--- 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 */
index a371b3a7eff53649e328d1bb7a3df540a189c53b..d8d29756c756a450a774844729bd5232adf683eb 100644 (file)
@@ -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)
index 83f70603856f2a4020941798d8c5fbe0059b6e8a..ce7dc008a2c758b4a653b46594a48c0128060eec 100644 (file)
@@ -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);