]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sourcestats: add function to correct accumulated offsets
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Nov 2021 14:34:26 +0000 (15:34 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 16 Nov 2021 09:23:20 +0000 (10:23 +0100)
This will be needed to follow server time corrections in order to
better estimate frequency.

sourcestats.c
sourcestats.h

index 7dfc9dbcbeb713ddf7be0ba9ccdfcb488c8b311f..900dc607fb65d5f2ad7ca5e587bec24eb729dcea 100644 (file)
@@ -779,6 +779,22 @@ SST_SlewSamples(SST_Stats inst, struct timespec *when, double dfreq, double doff
 
 /* ================================================== */
 
+void
+SST_CorrectOffset(SST_Stats inst, double doffset)
+{
+  int i;
+
+  if (!inst->n_samples)
+    return;
+
+  for (i = -inst->runs_samples; i < inst->n_samples; i++)
+    inst->offsets[get_runsbuf_index(inst, i)] += doffset;
+
+  inst->estimated_offset += doffset;
+}
+
+/* ================================================== */
+
 void 
 SST_AddDispersion(SST_Stats inst, double dispersion)
 {
index bb5fb714e952928849e6c2aef6b79f9d056d3349..7a551e6b0dcd167b449940302b2e364bd8dff904 100644 (file)
@@ -102,6 +102,10 @@ SST_GetTrackingData(SST_Stats inst, struct timespec *ref_time,
 
 extern void SST_SlewSamples(SST_Stats inst, struct timespec *when, double dfreq, double doffset);
 
+/* This routine corrects already accumulated samples to improve the
+   frequency estimate when a new sample is accumulated */
+extern void SST_CorrectOffset(SST_Stats inst, double doffset);
+
 /* This routine is called when an indeterminate offset is introduced
    into the local time. */
 extern void SST_AddDispersion(SST_Stats inst, double dispersion);