]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sourcestats: reset SST instance thoroughly when dropping samples
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 2 Jun 2014 14:30:12 +0000 (16:30 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 2 Jun 2014 14:46:53 +0000 (16:46 +0200)
sourcestats.c
sourcestats.h

index ffc22ea431f578e9c99496bca88a63046a777c0d..53fb83462a9490ffaafbc0b306c350038fddcbf5 100644 (file)
@@ -188,6 +188,26 @@ SST_CreateInstance(uint32_t refid, IPAddr *addr)
   inst = MallocNew(struct SST_Stats_Record);
   inst->refid = refid;
   inst->ip_addr = addr;
+
+  SST_ResetInstance(inst);
+
+  return inst;
+}
+
+/* ================================================== */
+/* This function deletes an instance of the statistics handler. */
+
+void
+SST_DeleteInstance(SST_Stats inst)
+{
+  Free(inst);
+}
+
+/* ================================================== */
+
+void
+SST_ResetInstance(SST_Stats inst)
+{
   inst->n_samples = 0;
   inst->runs_samples = 0;
   inst->last_sample = 0;
@@ -203,16 +223,6 @@ SST_CreateInstance(uint32_t refid, IPAddr *addr)
   inst->offset_time.tv_usec = 0;
   inst->variance = 16.0;
   inst->nruns = 0;
-  return inst;
-}
-
-/* ================================================== */
-/* This function deletes an instance of the statistics handler. */
-
-void
-SST_DeleteInstance(SST_Stats inst)
-{
-  Free(inst);
 }
 
 /* ================================================== */
@@ -258,7 +268,7 @@ SST_AccumulateSample(SST_Stats inst, struct timeval *sample_time,
       UTI_CompareTimevals(&inst->sample_times[inst->last_sample], sample_time) >= 0) {
     LOG(LOGS_WARN, LOGF_SourceStats, "Out of order sample detected, discarding history for %s",
         inst->ip_addr ? UTI_IPToString(inst->ip_addr) : UTI_RefidToString(inst->refid));
-    prune_register(inst, inst->n_samples);
+    SST_ResetInstance(inst);
   }
 
   n = inst->last_sample = (inst->last_sample + 1) %
@@ -584,6 +594,8 @@ SST_GetTrackingData(SST_Stats inst, struct timeval *ref_time,
   int i, j;
   double elapsed_sample;
 
+  assert(inst->n_samples > 0);
+
   i = get_runsbuf_index(inst, inst->best_single_sample);
   j = get_buf_index(inst, inst->best_single_sample);
 
index ff0f0c2ae532a0d83bb1519e92b61fa16de4580d..33005c96e8186f04aca508d36ac0c16069886bdd 100644 (file)
@@ -43,6 +43,9 @@ extern SST_Stats SST_CreateInstance(uint32_t refid, IPAddr *addr);
 /* This function deletes an instance of the statistics handler. */
 extern void SST_DeleteInstance(SST_Stats inst);
 
+/* This function resets an instance */
+extern void SST_ResetInstance(SST_Stats inst);
+
 /* This function accumulates a single sample into the statistics handler
 
    sample_time is the epoch at which the sample is to be considered to