]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Reselect source also according to distance
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 27 Oct 2009 13:28:19 +0000 (14:28 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 27 Oct 2009 13:28:19 +0000 (14:28 +0100)
Reselect when a source with the same stratum is available and has
significantly better distance than the current source.

sources.c

index b77a5b72534cd62d78d0bf7c8f0f73141de43845..1a2c84d1712b38c1380d1e8eae53d08c28a9e05d 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -656,29 +656,32 @@ SRC_SelectSource(unsigned long match_addr)
           if (stratum < min_stratum) min_stratum = stratum;
         }
 
+        /* Find the best source with minimum stratum */
+        min_distance_index = INVALID_SOURCE;
+        for (i=0; i<n_sel_sources; i++) {
+          index = sel_sources[i];
+          if (sources[index]->sel_info.stratum == min_stratum) {
+            if ((min_distance_index == INVALID_SOURCE) ||
+                (sources[index]->sel_info.root_distance < min_distance)) {
+              min_distance = sources[index]->sel_info.root_distance;
+              min_distance_index = index;
+            }
+          }
+        }
+
 #if 0
         LOG(LOGS_INFO, LOGF_Sources, "min_stratum=%d", min_stratum);
 #endif
 
-        /* Does the current source have this stratum and is it still a
-           survivor? */
+        /* Does the current source have this stratum, doesn't have distance
+           much worse than the best source and is it still a survivor? */
 
         if ((selected_source_index == INVALID_SOURCE) ||
             (sources[selected_source_index]->status != SRC_SELECTABLE) ||
-            (sources[selected_source_index]->sel_info.stratum > min_stratum)) {
+            (sources[selected_source_index]->sel_info.stratum > min_stratum) ||
+            (sources[selected_source_index]->sel_info.root_distance > 10 * min_distance)) {
           
           /* We have to elect a new synchronisation source */
-          min_distance_index = INVALID_SOURCE;
-          for (i=0; i<n_sel_sources; i++) {
-            index = sel_sources[i];
-            if (sources[index]->sel_info.stratum == min_stratum) {
-              if ((min_distance_index == INVALID_SOURCE) ||
-                  (sources[index]->sel_info.root_distance < min_distance)) {
-                min_distance = sources[index]->sel_info.root_distance;
-                min_distance_index = index;
-              }
-            }
-          }
 
           selected_source_index = min_distance_index;
           LOG(LOGS_INFO, LOGF_Sources, "Selected source %s",