]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: replace beginning flag with size of reachability register
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 7 Apr 2014 13:33:01 +0000 (15:33 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 8 Apr 2014 15:00:47 +0000 (17:00 +0200)
This will allow to detect sources that are not reachable on start.

sources.c

index 62bce833856c67eccc1b3a338b075122a48cce0f..e95fa8ae53599f595bd507aa5ab82bad7bf32ce9 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -93,8 +93,8 @@ struct SRC_Instance_Record {
   /* Reachability register */
   int reachability;
 
-  /* Flag indicating that only few samples were accumulated so far */
-  int beginning;
+  /* Number of set bits in the reachability register */
+  int reachability_size;
 
   /* Updates left before allowing combining */
   int outlier;
@@ -219,7 +219,7 @@ SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, SRC_SelectOpt
   result->ip_addr = addr;
   result->selectable = 0;
   result->reachability = 0;
-  result->beginning = 1;
+  result->reachability_size = 0;
   result->outlier = 0;
   result->status = SRC_BAD_STATS;
   result->type = type;
@@ -356,9 +356,8 @@ SRC_UpdateReachability(SRC_Instance inst, int reachable)
   inst->reachability |= !!reachable;
   inst->reachability &= ~(-1 << REACH_BITS);
 
-  /* The beginning is over when the first sample is at the end of the register */
-  if (inst->reachability & (1 << (REACH_BITS - 1)))
-      inst->beginning = 0;
+  if (inst->reachability_size < REACH_BITS)
+      inst->reachability_size++;
 
   if (!reachable && inst->index == selected_source_index) {
     /* Try to select a better source */
@@ -375,6 +374,7 @@ SRC_ResetReachability(SRC_Instance inst)
      a peer selected even when not reachable */
 #if 0
   inst->reachability = 0;
+  inst->reachability_size = 0;
   SRC_UpdateReachability(inst, 0);
 #endif
 }
@@ -451,7 +451,9 @@ combine_sources(int n_sel_sources, struct timeval *ref_time, double *offset,
            (reselect_distance + sources[selected_source_index]->sel_info.root_distance) ||
          fabs(*frequency - src_frequency) >
            combine_limit * (*skew + src_skew + LCL_GetMaxClockError()))) {
-      sources[index]->outlier = !sources[index]->beginning ? OUTLIER_PENALTY : 1;
+      /* Use a smaller penalty in first few updates */
+      sources[index]->outlier = sources[index]->reachability_size >= REACH_BITS ?
+                                OUTLIER_PENALTY : 1;
     } else if (sources[index]->outlier) {
       sources[index]->outlier--;
     }