]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: update stratum with leap status
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 3 Feb 2021 12:29:14 +0000 (13:29 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Feb 2021 16:43:47 +0000 (17:43 +0100)
Remove stratum from the NTP sample and update it together with the leap
status. This enables a faster update when samples are dropped by the NTP
filters.

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 9a275abb0b7eb98ebf8ed22efff5273442a13cfd..38f3e82cecfdf38a9d066b94e275020e754aa923 100644 (file)
--- a/ntp.h
+++ b/ntp.h
@@ -152,7 +152,6 @@ typedef struct {
   double peer_dispersion;
   double root_delay;
   double root_dispersion;
-  int stratum;
 } NTP_Sample;
 
 #endif /* GOT_NTP_H */
index 43f99959c1a7200cb141e645bf43650bd9daa9a6..50146ef4c770ac36721448b3171aabd26a50b7f3 100644 (file)
@@ -1678,7 +1678,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);
 
   /* 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
@@ -1768,7 +1767,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);
+    SRC_UpdateStatus(inst->source, MAX(message->stratum, inst->min_stratum), pkt_leap);
 
     if (good_packet) {
       /* Adjust the polling interval, accumulate the sample, etc. */
index 70d46ee4fb55d1136a719216eae670e898f2af0d..e1eedffede18d8bf9c71cd958fafacf782216a83 100644 (file)
@@ -415,12 +415,6 @@ accumulate_sample(RCL_Instance instance, struct timespec *sample_time, double of
   sample.peer_dispersion = dispersion;
   sample.root_dispersion = dispersion;
 
-  /* Handle special case when PPS is used with the local reference */
-  if (instance->pps_active && instance->lock_ref == -1)
-    sample.stratum = pps_stratum(instance, &sample.time);
-  else
-    sample.stratum = instance->stratum;
-
   return SPF_AccumulateSample(instance->filter, &sample);
 }
 
@@ -685,7 +679,7 @@ static void
 poll_timeout(void *arg)
 {
   NTP_Sample sample;
-  int poll;
+  int poll, stratum;
 
   RCL_Instance inst = (RCL_Instance)arg;
 
@@ -701,8 +695,14 @@ poll_timeout(void *arg)
     inst->driver_polled = 0;
 
     if (SPF_GetFilteredSample(inst->filter, &sample)) {
+      /* Handle special case when PPS is used with the local reference */
+      if (inst->pps_active && inst->lock_ref == -1)
+        stratum = pps_stratum(inst, &sample.time);
+      else
+        stratum = inst->stratum;
+
       SRC_UpdateReachability(inst->source, 1);
-      SRC_SetLeapStatus(inst->source, inst->leap_status);
+      SRC_UpdateStatus(inst->source, stratum, inst->leap_status);
       SRC_AccumulateSample(inst->source, &sample);
       SRC_SelectSource(inst->source);
 
index f350e40006077b2a97bfa56b9b5635ed53672b1d..fe32b5ce878035078293dd5757e0500cac6f48ff 100644 (file)
@@ -386,7 +386,6 @@ combine_selected_samples(SPF_Instance filter, int n, NTP_Sample *result)
   result->root_dispersion = MAX(disp, mean_root_dispersion);
   result->peer_delay = mean_peer_delay;
   result->root_delay = mean_root_delay;
-  result->stratum = last_sample->stratum;
 
   return 1;
 }
index 9345055c20380866c321f352a010c01c8e2f32be..e2621862e53bf4befc1646abb2a32ba03c71e5f3 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -374,8 +374,10 @@ get_leap_status(void)
 /* ================================================== */
 
 void
-SRC_SetLeapStatus(SRC_Instance inst, NTP_Leap leap)
+SRC_UpdateStatus(SRC_Instance inst, int stratum, NTP_Leap leap)
 {
+  inst->stratum = stratum;
+
   if (REF_IsLeapSecondClose(NULL, 0.0))
     return;
 
@@ -401,17 +403,15 @@ SRC_AccumulateSample(SRC_Instance inst, NTP_Sample *sample)
 
   assert(initialised);
 
-  DEBUG_LOG("src=%s ts=%s offset=%e delay=%e disp=%e stratum=%d",
+  DEBUG_LOG("src=%s ts=%s offset=%e delay=%e disp=%e",
             source_to_string(inst), UTI_TimespecToString(&sample->time), -sample->offset,
-            sample->root_delay, sample->root_dispersion, sample->stratum);
+            sample->root_delay, sample->root_dispersion);
 
   if (REF_IsLeapSecondClose(&sample->time, sample->offset)) {
     LOG(LOGS_INFO, "Dropping sample around leap second");
     return;
   }
 
-  inst->stratum = sample->stratum;
-
   SST_AccumulateSample(inst->stats, sample);
   SST_DoNewRegression(inst->stats);
 }
index a22faab933ac9800fa52eefab69d3f829e1d255f..6c799bb4bcd72059700bdfbbaff6a08c7c2a4b8b 100644 (file)
--- a/sources.h
+++ b/sources.h
@@ -87,8 +87,8 @@ 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);
 
-/* Function to set the current leap status according to the source */
-extern void SRC_SetLeapStatus(SRC_Instance instance, NTP_Leap leap);
+/* Function to update the stratum and leap status of the source */
+extern void SRC_UpdateStatus(SRC_Instance instance, int stratum, NTP_Leap leap);
 
 /* Function to accumulate a new sample from the source */
 extern void SRC_AccumulateSample(SRC_Instance instance, NTP_Sample *sample);
index d8d29756c756a450a774844729bd5232adf683eb..513ff2c465ecd7f7ba29395a98e7258e63bdcf05 100644 (file)
@@ -59,7 +59,6 @@ test_unit(void)
         sample_in.root_dispersion = TST_GetRandomDouble(1.0e-3, 2.0e-3);
         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;
 
         TEST_CHECK(SPF_AccumulateSample(filter, &sample_in));
         TEST_CHECK(!SPF_AccumulateSample(filter, &sample_in));
@@ -97,7 +96,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.stratum >= 0 && sample_out.stratum <= 15);
 
         if (max_samples == 1)
           TEST_CHECK(!memcmp(&sample_in, &sample_out, sizeof (sample_in)));
index 621b79c3b82d3f44d0de374005a1220dce22435a..6d85b8208876473024abc5f5f773e979b9cba1f3 100644 (file)
@@ -79,10 +79,9 @@ test_unit(void)
         sample.peer_dispersion = TST_GetRandomDouble(1.0e-6, 1.0e-1);
         sample.root_delay = sample.peer_delay;
         sample.root_dispersion = sample.peer_dispersion;
-        sample.stratum = 1;
 
         if (random() % 2)
-          SRC_SetLeapStatus(srcs[j], random() % 4);
+          SRC_UpdateStatus(srcs[j], 1, random() % 4);
 
         DEBUG_LOG("source %d sample %d offset %f delay %f disp %f", j, k,
                   sample.offset, sample.peer_delay, sample.peer_dispersion);