]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Set reference time to last sample instead of time on update
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 11 Apr 2011 15:52:04 +0000 (17:52 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 11 Apr 2011 15:52:04 +0000 (17:52 +0200)
This is done mainly to fix reported root dispersion to include max clock
error after selecting another source without new sample.

reference.c
sources.c
sourcestats.c
sourcestats.h

index d12e439f80a740a5f9bd6622a71424761f1ce84d..14f61991b0516197f4e3cd95d3906e6ca06fde8e 100644 (file)
@@ -530,10 +530,10 @@ REF_SetReference(int stratum,
   double delta_freq1, delta_freq2;
   double skew1, skew2;
   double our_frequency;
-
   double abs_freq_ppm;
-
   double update_interval;
+  double elapsed;
+  struct timeval now;
 
   assert(initialised);
 
@@ -570,10 +570,13 @@ REF_SetReference(int stratum,
   else
     our_ref_ip.family = IPADDR_UNSPEC;
   our_ref_time = *ref_time;
-  our_offset = offset;
   our_root_delay = root_delay;
   our_root_dispersion = root_dispersion;
 
+  LCL_ReadCookedTime(&now, NULL);
+  UTI_DiffTimevalsToDouble(&elapsed, &now, ref_time);
+  our_offset = offset + elapsed * frequency;
+
   update_leap_status(leap);
 
   /* Eliminate updates that are based on totally unreliable frequency
@@ -627,14 +630,14 @@ REF_SetReference(int stratum,
 
   abs_freq_ppm = LCL_ReadAbsoluteFrequency();
 
-  write_log(ref_time,
+  write_log(&now,
             our_ref_ip.family != IPADDR_UNSPEC ? UTI_IPToString(&our_ref_ip) : UTI_RefidToString(our_ref_id),
             our_stratum,
             abs_freq_ppm,
             1.0e6*our_skew,
             our_offset);
 
-  UTI_DiffTimevalsToDouble(&update_interval, ref_time, &last_ref_update);
+  UTI_DiffTimevalsToDouble(&update_interval, &now, &last_ref_update);
 
   if (drift_file) {
     /* Update drift file at most once per hour */
@@ -650,7 +653,7 @@ REF_SetReference(int stratum,
     update_fb_drifts(abs_freq_ppm, update_interval);
   }
 
-  last_ref_update = *ref_time;
+  last_ref_update = now;
   last_ref_update_interval = update_interval;
 
   /* And now set the freq and offset to zero */
index b596ed9716f7a94cfc7c6d0da0f0a674d614b81e..bc515e97c1546d1d1016cbd1fea89d6a89b11c13 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -424,9 +424,9 @@ void
 SRC_SelectSource(unsigned long match_addr)
 {
   int i, j, index, old_selected_index;
-  struct timeval now;
+  struct timeval now, ref_time;
   double src_offset, src_offset_sd, src_frequency, src_skew;
-  double src_accrued_dispersion;
+  double src_root_delay, src_root_dispersion;
   int n_endpoints, j1, j2;
   double best_lo, best_hi;
   int depth, best_depth;
@@ -434,7 +434,6 @@ SRC_SelectSource(unsigned long match_addr)
   double distance, sel_src_distance;
   int stratum, min_stratum;
   struct SelectInfo *si;
-  double total_root_dispersion;
   int n_badstats_sources;
   int max_sel_reach, max_badstat_reach;
   int max_score_index;
@@ -846,25 +845,20 @@ SRC_SelectSource(unsigned long match_addr)
           /* Now just use the statistics of the selected source for
              trimming the local clock */
 
-          LCL_ReadCookedTime(&now, NULL);
-
-          SST_GetTrackingData(sources[selected_source_index]->stats, &now,
+          SST_GetTrackingData(sources[selected_source_index]->stats, &ref_time,
                               &src_offset, &src_offset_sd,
-                              &src_accrued_dispersion,
-                              &src_frequency, &src_skew);
-
-          total_root_dispersion = (src_accrued_dispersion +
-              sources[selected_source_index]->sel_info.root_dispersion);
+                              &src_frequency, &src_skew,
+                              &src_root_delay, &src_root_dispersion);
 
           REF_SetReference(min_stratum, leap_status,
                            sources[selected_source_index]->ref_id,
                            sources[selected_source_index]->ip_addr,
-                           &now,
+                           &ref_time,
                            src_offset,
                            src_frequency,
                            src_skew,
-                           sources[selected_source_index]->sel_info.root_delay,
-                           total_root_dispersion);
+                           src_root_delay,
+                           src_root_dispersion);
         }
 
       } else {
index ec34b8db3ca5503a742b41573f1f717fc028ca90..9560eac413eb90e6c42c23f10a291f9e74549f8e 100644 (file)
@@ -582,29 +582,30 @@ SST_GetSelectionData(SST_Stats inst, struct timeval *now,
 /* ================================================== */
 
 void
-SST_GetTrackingData(SST_Stats inst, struct timeval *now,
+SST_GetTrackingData(SST_Stats inst, struct timeval *ref_time,
                     double *average_offset, double *offset_sd,
-                    double *accrued_dispersion,
-                    double *frequency, double *skew)
+                    double *frequency, double *skew,
+                    double *root_delay, double *root_dispersion)
 {
-  int i;
-  double elapsed_offset, elapsed_sample;
+  int i, j;
+  double elapsed_sample;
 
   i = get_runsbuf_index(inst, inst->best_single_sample);
+  j = get_buf_index(inst, inst->best_single_sample);
 
+  *ref_time = inst->offset_time;
+  *average_offset = inst->estimated_offset;
+  *offset_sd = inst->estimated_offset_sd;
   *frequency = inst->estimated_frequency;
   *skew = inst->skew;
+  *root_delay = inst->root_delays[j];
 
-  UTI_DiffTimevalsToDouble(&elapsed_offset, now, &(inst->offset_time));
-  *average_offset = inst->estimated_offset + inst->estimated_frequency * elapsed_offset;
-  *offset_sd = inst->estimated_offset_sd + elapsed_offset * inst->skew;
-
-  UTI_DiffTimevalsToDouble(&elapsed_sample, now, &inst->sample_times[i]);
-  *accrued_dispersion = inst->skew * elapsed_sample;
+  UTI_DiffTimevalsToDouble(&elapsed_sample, &inst->offset_time, &inst->sample_times[i]);
+  *root_dispersion = inst->root_dispersions[j] + inst->skew * elapsed_sample;
 
 #ifdef TRACEON
-  LOG(LOGS_INFO, LOGF_SourceStats, "n=%d freq=%f (%.3fppm) skew=%f (%.3fppm) avoff=%f offsd=%f accrdis=%f",
-      inst->n_samples, *frequency, 1.0e6* *frequency, *skew, 1.0e6* *skew, *average_offset, *offset_sd, *accrued_dispersion);
+  LOG(LOGS_INFO, LOGF_SourceStats, "n=%d freq=%f (%.3fppm) skew=%f (%.3fppm) avoff=%f offsd=%f disp=%f",
+      inst->n_samples, *frequency, 1.0e6* *frequency, *skew, 1.0e6* *skew, *average_offset, *offset_sd, *root_dispersion);
 #endif
 
 }
index 2a20d8e1ad77646b85f1dd7f1d87e156a374cdda..740a3c1c8188bfbb5964d9697122e361bb29ffd3 100644 (file)
@@ -89,10 +89,10 @@ SST_GetSelectionData(SST_Stats inst, struct timeval *now,
 
 /* Get data needed when setting up tracking on this source */
 extern void
-SST_GetTrackingData(SST_Stats inst, struct timeval *now,
+SST_GetTrackingData(SST_Stats inst, struct timeval *ref_time,
                     double *average_offset, double *offset_sd,
-                    double *accrued_dispersion,
-                    double *frequency, double *skew);
+                    double *frequency, double *skew,
+                    double *root_delay, double *root_dispersion);
 
 /* Get parameters for using this source as the reference */
 extern void