]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: split source selection from sample accumulation
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 3 Apr 2014 16:11:37 +0000 (18:11 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 8 Apr 2014 15:00:47 +0000 (17:00 +0200)
This will allow postponing source selection and reference update, which
could be useful in burst modes.

ntp_core.c
refclock.c
sources.c
sources.h

index 87944d0d6a2357193c45f2f8cd6095eb1a907597..719172bb32e589196391292084789c7a133035b0 100644 (file)
@@ -1179,6 +1179,8 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
                            root_delay, root_dispersion,
                            message->stratum, (NTP_Leap) pkt_leap);
 
+      SRC_SelectSource(inst->source);
+
       /* Now examine the registers.  First though, if the prediction is
          not even within +/- the peer distance of the peer, we are clearly
          not tracking the peer at all well, so we back off the sampling
index 15fe9d63cb23b0349deb43e44da4a9715add64d5..ddece9f7a7580e8d9da74928ae91e861b5b75896 100644 (file)
@@ -549,6 +549,7 @@ poll_timeout(void *arg)
       SRC_UpdateReachability(inst->source, 1);
       SRC_AccumulateSample(inst->source, &sample_time, offset,
           inst->delay, dispersion, inst->delay, dispersion, stratum, inst->leap_status);
+      SRC_SelectSource(inst->source);
 
       log_sample(inst, &sample_time, 1, 0, 0.0, offset, dispersion);
     } else {
index de07bd3a86b71058356b9a60fc65801dae178596..62bce833856c67eccc1b3a338b075122a48cce0f 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -314,8 +314,6 @@ void SRC_AccumulateSample
      IS FLIPPED */
   SST_AccumulateSample(inst->stats, sample_time, -offset, peer_delay, peer_dispersion, root_delay, root_dispersion, stratum);
   SST_DoNewRegression(inst->stats);
-  /* And redo clock selection */
-  SRC_SelectSource(inst->ref_id);
 }
 
 /* ================================================== */
@@ -344,7 +342,7 @@ SRC_UnsetSelectable(SRC_Instance inst)
   /* If this was the previous reference source, we have to reselect!  */
 
   if (inst->index == selected_source_index) {
-    SRC_SelectSource(0);
+    SRC_SelectSource(NULL);
   }
 
 }
@@ -364,7 +362,7 @@ SRC_UpdateReachability(SRC_Instance inst, int reachable)
 
   if (!reachable && inst->index == selected_source_index) {
     /* Try to select a better source */
-    SRC_SelectSource(0);
+    SRC_SelectSource(NULL);
   }
 }
 
@@ -501,7 +499,7 @@ combine_sources(int n_sel_sources, struct timeval *ref_time, double *offset,
    or match_refid is equal to the selected reference source refid */
 
 void
-SRC_SelectSource(uint32_t match_refid)
+SRC_SelectSource(SRC_Instance updated_inst)
 {
   int i, j, index, old_selected_index, sel_prefer;
   struct timeval now, ref_time;
@@ -862,8 +860,8 @@ SRC_SelectSource(uint32_t match_refid)
 
             /* Update score, but only for source pairs where one source
                has a new sample */
-            if (sources[i]->ref_id == match_refid ||
-                sources[selected_source_index]->ref_id == match_refid) {
+            if (sources[i] == updated_inst ||
+                sources[selected_source_index] == updated_inst) {
 
               sources[i]->sel_score *= sel_src_distance / distance;
 
@@ -881,8 +879,9 @@ SRC_SelectSource(uint32_t match_refid)
           }
 
 #if 0
-          LOG(LOGS_INFO, LOGF_Sources, "select score=%f refid=%lx match_refid=%lx status=%d dist=%f",
-              sources[i]->sel_score, sources[i]->ref_id, match_refid, sources[i]->status, distance);
+          LOG(LOGS_INFO, LOGF_Sources, "select score=%f refid=%x match_refid=%x status=%d dist=%f",
+              sources[i]->sel_score, sources[i]->ref_id, updated_inst ? updated_inst->ref_id : 0,
+              sources[i]->status, distance);
 #endif
         
           if (max_score < sources[i]->sel_score) {
@@ -919,10 +918,10 @@ SRC_SelectSource(uint32_t match_refid)
 
         sources[selected_source_index]->status = SRC_SYNC;
 
-        /* Update local reference only when a new source was selected or a new
-           sample was received (i.e. match_refid is equal to selected refid) */
+        /* Update local reference only when a new source was selected
+           or the selected source has a new sample */
         if (selected_source_index != old_selected_index ||
-            match_refid == sources[selected_source_index]->ref_id) {
+            updated_inst == sources[selected_source_index]) {
 
           /* Now just use the statistics of the selected source combined with
              the other selectable sources for trimming the local clock */
@@ -978,7 +977,7 @@ void
 SRC_ReselectSource(void)
 {
   selected_source_index = INVALID_SOURCE;
-  SRC_SelectSource(0);
+  SRC_SelectSource(NULL);
 }
 
 /* ================================================== */
index e96a9421911494a4e0ff36ed7bb942f47ada3aeb..d06d25d5521ea14f186543ab8668df558c342cca 100644 (file)
--- a/sources.h
+++ b/sources.h
@@ -131,11 +131,11 @@ extern void SRC_ResetReachability(SRC_Instance inst);
 /* This routine is used to select the best source from amongst those
    we currently have valid data on, and use it as the tracking base
    for the local time.  Updates are only made to the local reference
-   if a new source is selected or match_addr is equal to the selected
-   reference source address. (This avoids updating the frequency
+   if a new source is selected or updated_inst is the selected
+   reference source. (This avoids updating the frequency
    tracking for every sample from other sources - only the ones from
    the selected reference make a difference) */
-extern void SRC_SelectSource(uint32_t match_refid);
+extern void SRC_SelectSource(SRC_Instance updated_inst);
 
 /* Force reselecting the best source */
 extern void SRC_ReselectSource(void);