]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Delay selecting source on start
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 16 Dec 2010 17:27:38 +0000 (18:27 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 17 Dec 2010 12:22:57 +0000 (13:22 +0100)
On start, when servers are reachable and use the same polling interval,
wait for them to have the same reachability register (which corresponds
to the number of samples in sourcestats) before selecting one.

sources.c

index af90aecf675dd8d6db68ed5d7eeebebd3ecbcce9..170710e34ed17ca4f8c7c0473a46a071e8caf291 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -423,6 +423,8 @@ SRC_SelectSource(unsigned long match_addr)
   int min_distance_index;
   struct SelectInfo *si;
   double total_root_dispersion;
+  int n_badstats_sources;
+  int max_sel_reach, max_badstat_reach;
 
   NTP_Leap leap_status = LEAP_Normal;
   old_selected_index = selected_source_index;
@@ -442,6 +444,8 @@ SRC_SelectSource(unsigned long match_addr)
   /* Step 1 - build intervals about each source */
   n_endpoints = 0;
   n_sel_sources = 0;
+  n_badstats_sources = 0;
+  max_sel_reach = max_badstat_reach = 0;
   for (i=0; i<n_sources; i++) {
 
     if (sources[i]->selectable && sources[i]->reachability &&
@@ -487,8 +491,16 @@ SRC_SelectSource(unsigned long match_addr)
 
         n_endpoints += 2;
 
+        if (max_sel_reach < sources[i]->reachability) {
+          max_sel_reach = sources[i]->reachability;
+        }
       } else {
+        ++n_badstats_sources;
         sources[i]->status = SRC_BAD_STATS;
+
+        if (max_badstat_reach < sources[i]->reachability) {
+          max_badstat_reach = sources[i]->reachability;
+        }
       }
     } else {
       /* If the source is not reachable, there is no way we will pick
@@ -497,6 +509,23 @@ SRC_SelectSource(unsigned long match_addr)
     }
   }
 
+#if 0
+  LOG(LOGS_INFO, LOGF_Sources, "badstat_sources=%d sel_sources=%d badstat_reach=%x sel_reach=%x",
+      n_badstats_sources, n_sel_sources, max_badstat_reach, max_sel_reach);
+#endif
+
+  /* Wait for the next call if we have no source selected and there is
+     a source with bad stats (has less than 3 samples) with reachability
+     equal to shifted maximum reachability of sources with valid stats.
+     This delays selecting source on start with servers using the same
+     polling interval until they all have valid stats. */
+
+  if (n_badstats_sources && n_sel_sources &&
+      selected_source_index == INVALID_SOURCE && 
+      max_sel_reach >> 1 == max_badstat_reach) {
+    return;
+  }
+
 #if 0
   LOG(LOGS_INFO, LOGF_Sources, "n_endpoints=%d", n_endpoints);
 #endif