]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sourcestats: move stratum to sources
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 3 Feb 2021 11:54:08 +0000 (12:54 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Feb 2021 16:43:29 +0000 (17:43 +0100)
The stratum value is not needed in sourcestats. Keep it in the source
itself.

sources.c
sourcestats.c
sourcestats.h

index 63647d26bd3b7c2e83962ae32840798c372a622c..9345055c20380866c321f352a010c01c8e2f32be 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -54,7 +54,6 @@ static int initialised = 0;
 /* ================================================== */
 /* Structure used to hold info for selecting between sources */
 struct SelectInfo {
-  int stratum;
   int select_ok;
   double std_dev;
   double root_distance;
@@ -132,7 +131,10 @@ struct SRC_Instance_Record {
 
   struct SelectInfo sel_info;
 
-  /* Latest leap status */
+  /* Current stratum */
+  int stratum;
+
+  /* Current leap status */
   NTP_Leap leap;
 
   /* Flag indicating the source has a leap second vote */
@@ -313,6 +315,7 @@ SRC_ResetInstance(SRC_Instance instance)
   instance->distant = 0;
   instance->status = SRC_BAD_STATS;
   instance->sel_score = 1.0;
+  instance->stratum = 0;
   instance->leap = LEAP_Unsynchronised;
   instance->leap_vote = 0;
 
@@ -407,6 +410,8 @@ SRC_AccumulateSample(SRC_Instance inst, NTP_Sample *sample)
     return;
   }
 
+  inst->stratum = sample->stratum;
+
   SST_AccumulateSample(inst->stats, sample);
   SST_DoNewRegression(inst->stats);
 }
@@ -808,7 +813,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
     }
 
     si = &sources[i]->sel_info;
-    SST_GetSelectionData(sources[i]->stats, &now, &si->stratum,
+    SST_GetSelectionData(sources[i]->stats, &now,
                          &si->lo_limit, &si->hi_limit, &si->root_distance,
                          &si->std_dev, &first_sample_ago,
                          &si->last_sample_ago, &si->select_ok);
@@ -890,10 +895,10 @@ SRC_SelectSource(SRC_Instance updated_inst)
        source can settle down to a state where only one server is serving its
        local unsychronised time and others are synchronised to it. */
 
-    if (si->stratum >= orphan_stratum && sources[i]->type == SRC_NTP) {
+    if (sources[i]->stratum >= orphan_stratum && sources[i]->type == SRC_NTP) {
       mark_source(sources[i], SRC_ORPHAN);
 
-      if (si->stratum == orphan_stratum && sources[i]->reachability &&
+      if (sources[i]->stratum == orphan_stratum && sources[i]->reachability &&
           (orphan_source == INVALID_SOURCE ||
            sources[i]->ref_id < sources[orphan_source]->ref_id))
         orphan_source = i;
@@ -1131,10 +1136,10 @@ SRC_SelectSource(SRC_Instance updated_inst)
   /* Find minimum stratum */
 
   index = sel_sources[0];
-  min_stratum = sources[index]->sel_info.stratum;
+  min_stratum = sources[index]->stratum;
   for (i = 1; i < n_sel_sources; i++) {
     index = sel_sources[i];
-    stratum = sources[index]->sel_info.stratum;
+    stratum = sources[index]->stratum;
     if (stratum < min_stratum)
       min_stratum = stratum;
   }
@@ -1147,7 +1152,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
 
   if (selected_source_index != INVALID_SOURCE)
     sel_src_distance = sources[selected_source_index]->sel_info.root_distance +
-      (sources[selected_source_index]->sel_info.stratum - min_stratum) * stratum_weight;
+      (sources[selected_source_index]->stratum - min_stratum) * stratum_weight;
 
   for (i = 0; i < n_sources; i++) {
     /* Reset score for non-selectable sources */
@@ -1159,7 +1164,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
     }
 
     distance = sources[i]->sel_info.root_distance +
-      (sources[i]->sel_info.stratum - min_stratum) * stratum_weight;
+      (sources[i]->stratum - min_stratum) * stratum_weight;
     if (sources[i]->type == SRC_NTP)
       distance += reselect_distance;
 
@@ -1247,7 +1252,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
   combined = combine_sources(n_sel_sources, &ref_time, &src_offset, &src_offset_sd,
                              &src_frequency, &src_frequency_sd, &src_skew);
 
-  REF_SetReference(sources[selected_source_index]->sel_info.stratum,
+  REF_SetReference(sources[selected_source_index]->stratum,
                    leap_status, combined,
                    sources[selected_source_index]->ref_id,
                    sources[selected_source_index]->ip_addr,
@@ -1492,6 +1497,8 @@ SRC_ReportSource(int index, RPT_SourceReport *report, struct timespec *now)
       report->ip_addr.family = IPADDR_INET4;
     }
 
+    report->stratum = src->stratum;
+
     switch (src->status) {
       case SRC_FALSETICKER:
         report->state = RPT_FALSETICKER;
index c93b5e4c8e042ef13afb575649a997c69b993e66..f35ba841b7660defa31b7b592c4c69fd38147594 100644 (file)
@@ -177,9 +177,6 @@ struct SST_Stats_Record {
   /* This array contains the root dispersions of each sample at the
      time of the measurements */
   double root_dispersions[MAX_SAMPLES];
-
-  /* The stratum from the last accumulated sample */
-  int stratum;
 };
 
 /* ================================================== */
@@ -321,7 +318,6 @@ SST_AccumulateSample(SST_Stats inst, NTP_Sample *sample)
   inst->peer_dispersions[m] = sample->peer_dispersion;
   inst->root_delays[m] = sample->root_delay;
   inst->root_dispersions[m] = sample->root_dispersion;
-  inst->stratum = sample->stratum;
  
   if (inst->peer_delays[n] < inst->fixed_min_delay)
     inst->peer_delays[n] = 2.0 * inst->fixed_min_delay - inst->peer_delays[n];
@@ -650,7 +646,6 @@ SST_GetFrequencyRange(SST_Stats inst,
 
 void
 SST_GetSelectionData(SST_Stats inst, struct timespec *now,
-                     int *stratum,
                      double *offset_lo_limit,
                      double *offset_hi_limit,
                      double *root_distance,
@@ -670,7 +665,6 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now,
   i = get_runsbuf_index(inst, inst->best_single_sample);
   j = get_buf_index(inst, inst->best_single_sample);
 
-  *stratum = inst->stratum;
   *std_dev = inst->std_dev;
 
   sample_elapsed = fabs(UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]));
@@ -885,7 +879,7 @@ SST_SaveToFile(SST_Stats inst, FILE *out)
             inst->root_delays[j],
             inst->root_dispersions[j],
             1.0, /* used to be inst->weights[i] */
-            inst->stratum /* used to be an array */);
+            0 /* used to be an array of strata */);
 
   }
 
@@ -907,6 +901,7 @@ SST_LoadFromFile(SST_Stats inst, FILE *in)
   int i;
   char line[1024];
   double weight;
+  int stratum;
 
   SST_ResetInstance(inst);
 
@@ -930,7 +925,7 @@ SST_LoadFromFile(SST_Stats inst, FILE *in)
                   &(inst->root_delays[i]),
                   &(inst->root_dispersions[i]),
                   &weight, /* not used anymore */
-                  &inst->stratum) != 10)) {
+                  &stratum /* not used anymore */) != 10)) {
 
         /* This is the branch taken if the read FAILED */
 
@@ -978,7 +973,6 @@ SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timespec *no
     report->orig_latest_meas = inst->orig_offsets[j];
     report->latest_meas = inst->offsets[i];
     report->latest_meas_err = 0.5*inst->root_delays[j] + inst->root_dispersions[j];
-    report->stratum = inst->stratum;
 
     /* Align the sample time to reduce the leak of the receive timestamp */
     last_sample_time = inst->sample_times[i];
index 72fd54688e607195c1938c7bc4232ce73ba75267..a0f6af968cb229dd15bd715bdcbc6bb3402008c2 100644 (file)
@@ -69,7 +69,6 @@ extern void SST_GetFrequencyRange(SST_Stats inst, double *lo, double *hi);
 /* Get data needed for selection */
 extern void
 SST_GetSelectionData(SST_Stats inst, struct timespec *now,
-                     int *stratum,
                      double *offset_lo_limit,
                      double *offset_hi_limit,
                      double *root_distance,