]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp+hwclock: add margin to estimated delay quantiles
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 18 Nov 2024 15:18:40 +0000 (16:18 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 21 Nov 2024 14:59:47 +0000 (15:59 +0100)
Extend the interval of accepted delays by half of the quantile minimum
step in both directions to make room for floating-point errors in the
quantile calculation and an error that will be intentionally added in
the next commit.

hwclock.c
ntp_core.c

index c662dae3d0f6de67bd9b91af92d5f20ba1c868a4..e2f72e7aeba99b76ec36945f05a2714cf73060a6 100644 (file)
--- a/hwclock.c
+++ b/hwclock.c
@@ -199,8 +199,10 @@ HCL_ProcessReadings(HCL_Instance clock, int n_readings, struct timespec tss[][3]
 
   local_prec = LCL_GetSysPrecisionAsQuantum();
 
-  low_delay = QNT_GetQuantile(clock->delay_quants, QNT_GetMinK(clock->delay_quants));
-  high_delay = QNT_GetQuantile(clock->delay_quants, QNT_GetMaxK(clock->delay_quants));
+  low_delay = QNT_GetQuantile(clock->delay_quants, QNT_GetMinK(clock->delay_quants)) -
+              QNT_GetMinStep(clock->delay_quants) / 2.0;
+  high_delay = QNT_GetQuantile(clock->delay_quants, QNT_GetMaxK(clock->delay_quants)) +
+               QNT_GetMinStep(clock->delay_quants) / 2.0;
   low_delay = MIN(low_delay, high_delay);
   high_delay = MAX(high_delay, low_delay + local_prec);
 
index 296541382f7a27e3ee806eaa1d87df8172feb500..e802e1832379a30c9fda350688d769123c7ac0ab 100644 (file)
@@ -1742,7 +1742,7 @@ check_delay_quant(NCR_Instance inst, double delay)
 
   quant = QNT_GetQuantile(inst->delay_quant, QNT_GetMinK(inst->delay_quant));
 
-  if (delay <= quant)
+  if (delay <= quant + QNT_GetMinStep(inst->delay_quant) / 2.0)
     return 1;
 
   DEBUG_LOG("maxdelayquant: delay=%e quant=%e", delay, quant);