]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Allow selecting source only when last regression was successful
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 15 Dec 2010 16:48:30 +0000 (17:48 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 15 Dec 2010 16:48:30 +0000 (17:48 +0100)
sources.c
sourcestats.c
sourcestats.h

index 346eace78231149f8917c8ea4889959946e335a0..473eeeeb9575744623b3d820a5a91c8cbdbdb156 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -385,7 +385,6 @@ SRC_SelectSource(unsigned long match_addr)
 {
   int i, j, index;
   struct timeval now;
-  int src_select_ok;
   double src_offset, src_offset_sd, src_frequency, src_skew;
   double src_accrued_dispersion;
   int n_endpoints, j1, j2;
@@ -397,7 +396,6 @@ SRC_SelectSource(unsigned long match_addr)
   int min_distance_index;
   struct SelectInfo *si;
   double total_root_dispersion;
-  int n_reachable_sources;
 
   NTP_Leap leap_status = LEAP_Normal;
 
@@ -415,13 +413,11 @@ SRC_SelectSource(unsigned long match_addr)
 
   /* Step 1 - build intervals about each source */
   n_endpoints = 0;
-  n_reachable_sources = 0;
+  n_sel_sources = 0;
   for (i=0; i<n_sources; i++) {
 
     if (sources[i]->reachable && sources[i]->sel_option != SRC_SelectNoselect) {
 
-      ++n_reachable_sources;
-
       si = &(sources[i]->sel_info);
       SST_GetSelectionData(sources[i]->stats, &now,
                            &(si->stratum),
@@ -431,10 +427,6 @@ SRC_SelectSource(unsigned long match_addr)
                            &(si->variance),
                            &(si->select_ok));
 
-      /* Eventually this might be a flag indicating whether the get
-         selection data call was successful.  For now it always is. */
-      src_select_ok = 1;
-
       si->root_distance = si->root_dispersion + 0.5 * fabs(si->root_delay);
       si->lo_limit = si->best_offset - si->root_distance;
       si->hi_limit = si->best_offset + si->root_distance;
@@ -446,7 +438,8 @@ SRC_SelectSource(unsigned long match_addr)
           si->lo_limit, si->hi_limit);
 #endif
       
-      if (src_select_ok) {
+      if (si->select_ok) {
+        ++n_sel_sources;
 
         sources[i]->status = SRC_OK; /* For now */
 
@@ -544,7 +537,7 @@ SRC_SelectSource(unsigned long match_addr)
         best_depth, best_lo, best_hi);
 #endif
 
-    if (best_depth <= n_reachable_sources/2) {
+    if (best_depth <= n_sel_sources/2) {
       /* Could not even get half the reachable sources to agree -
          clearly we can't synchronise.
 
index 4ea43a060c580861fce5001116a5ccabbb6d42b8..5ac46dad7fa6ec2feba472186c408efaddc81669 100644 (file)
@@ -73,6 +73,9 @@ struct SST_Stats_Record {
   /* The index of the newest sample */
   int last_sample;
 
+  /* Flag indicating whether last regression was successful */
+  int regression_ok;
+
   /* The best individual sample that we are holding, in terms of the minimum
      root distance at the present time */
   int best_single_sample;
@@ -180,6 +183,7 @@ SST_CreateInstance(unsigned long refid, IPAddr *addr)
   inst->n_samples = 0;
   inst->runs_samples = 0;
   inst->last_sample = 0;
+  inst->regression_ok = 0;
   inst->best_single_sample = 0;
   inst->min_delay_sample = 0;
   inst->estimated_frequency = 0;
@@ -387,8 +391,6 @@ SST_DoNewRegression(SST_Stats inst)
   double sd_weight, sd;
   double old_skew, old_freq, stress;
 
-  int regression_ok;
-
   convert_to_intervals(inst, times_back + inst->runs_samples);
 
   if (inst->n_samples > 0) {
@@ -416,14 +418,14 @@ SST_DoNewRegression(SST_Stats inst)
     }
   }
 
-  regression_ok = RGR_FindBestRegression(times_back + inst->runs_samples,
+  inst->regression_ok = RGR_FindBestRegression(times_back + inst->runs_samples,
                                          offsets + inst->runs_samples, weights,
                                          inst->n_samples, inst->runs_samples,
                                          &est_intercept, &est_slope, &est_var,
                                          &est_intercept_sd, &est_slope_sd,
                                          &best_start, &nruns, &degrees_of_freedom);
 
-  if (regression_ok) {
+  if (inst->regression_ok) {
 
     old_skew = inst->skew;
     old_freq = inst->estimated_frequency;
@@ -536,12 +538,13 @@ SST_GetSelectionData(SST_Stats inst, struct timeval *now,
                      int *stratum,
                      double *best_offset, double *best_root_delay,
                      double *best_root_dispersion,
-                     double *variance, int *average_ok)
+                     double *variance, int *select_ok)
 {
   double average_offset;
   double sample_elapsed;
   double elapsed;
   int i, j;
+  int average_ok;
   double peer_distance;
   
   i = get_runsbuf_index(inst, inst->best_single_sample);
@@ -558,17 +561,20 @@ SST_GetSelectionData(SST_Stats inst, struct timeval *now,
   *best_root_delay = inst->root_delays[j];
   *best_root_dispersion = inst->root_dispersions[j] + sample_elapsed * inst->skew;
 
+  /* average_ok ignored for now */
   average_offset = inst->estimated_offset + inst->estimated_frequency * elapsed;
   if (fabs(average_offset - *best_offset) <= peer_distance) {
-    *average_ok = 1;
+    average_ok = 1;
   } else {
-    *average_ok = 0;
+    average_ok = 0;
   }
 
+  *select_ok = inst->regression_ok;
+
 #ifdef TRACEON
-  LOG(LOGS_INFO, LOGF_SourceStats, "n=%d off=%f del=%f dis=%f var=%f pdist=%f avoff=%f avok=%d",
+  LOG(LOGS_INFO, LOGF_SourceStats, "n=%d off=%f del=%f dis=%f var=%f pdist=%f avoff=%f avok=%d selok=%d",
       inst->n_samples, *best_offset, *best_root_delay, *best_root_dispersion, *variance,
-      peer_distance, average_offset, *average_ok);
+      peer_distance, average_offset, average_ok, *select_ok);
 #endif
 
   return;
index 27908c89ab590c0aee0aa1741d26801e6088b821..cdbff9ad6888693c38e4789a27b49262bf14b043 100644 (file)
@@ -89,7 +89,7 @@ SST_GetSelectionData(SST_Stats inst, struct timeval *now,
                      double *best_offset, double *best_root_delay,
                      double *best_root_dispersion,
                      double *variance,
-                     int *average_ok);
+                     int *select_ok);
 
 /* Get data needed when setting up tracking on this source */
 extern void