From: Miroslav Lichvar Date: Tue, 6 Jun 2023 08:40:51 +0000 (+0200) Subject: ntp: use monotonic time for replacement interval X-Git-Tag: 4.4-pre2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab8da7ecb9c1680ec0cf46aba1bc34e1d27d4b14;p=thirdparty%2Fchrony.git ntp: use monotonic time for replacement interval Avoid errors in the measured interval due to clock steps. --- diff --git a/ntp_sources.c b/ntp_sources.c index f10b3302..2f20299e 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -1006,11 +1006,10 @@ resolve_source_replacement(SourceRecord *record, int refreshment) void NSR_HandleBadSource(IPAddr *address) { - static struct timespec last_replacement; - struct timespec now; + static double last_replacement = -1e6; SourceRecord *record; IPAddr ip_addr; - double diff; + double now; int slot; if (!find_slot(address, &slot)) @@ -1025,9 +1024,9 @@ NSR_HandleBadSource(IPAddr *address) return; /* Don't resolve names too frequently */ - SCH_GetLastEventTime(NULL, NULL, &now); - diff = UTI_DiffTimespecsToDouble(&now, &last_replacement); - if (fabs(diff) < RESOLVE_INTERVAL_UNIT * (1 << MIN_REPLACEMENT_INTERVAL)) { + now = SCH_GetLastEventMonoTime(); + if (now - last_replacement < + RESOLVE_INTERVAL_UNIT * (1 << MIN_REPLACEMENT_INTERVAL)) { DEBUG_LOG("replacement postponed"); return; }