From 55717c1ccdf75aaa7b30570ac3478237a66a89f1 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 24 Feb 2022 08:45:10 +0100 Subject: [PATCH] refclock: trim offset in local mode With the local option, trim offset larger than 1 second to not lose precision after large steps of the clock. --- refclock.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/refclock.c b/refclock.c index cfa958ca..42acd53c 100644 --- a/refclock.c +++ b/refclock.c @@ -757,6 +757,12 @@ follow_local(RCL_Instance inst, struct timespec *prev_ref_time, double prev_freq LCL_ReadCookedTime(&now, NULL); SST_SlewSamples(stats, &now, dfreq, doffset); SPF_SlewSamples(inst->filter, &now, dfreq, doffset); + + /* Keep the offset close to zero to not lose precision */ + if (fabs(offset) >= 1.0) { + SST_CorrectOffset(stats, -round(offset)); + SPF_CorrectOffset(inst->filter, -round(offset)); + } } static void -- 2.47.2