From 4534db84c4001779a1550de66136a357855ba4e9 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 4 Aug 2017 15:08:40 +0200 Subject: [PATCH] hwclock: fix conversion of HW timestamps Fix a sign error in conversion of HW time to local time, which caused the jitter to be amplified instead of reduced. NTP with HW timestamping should now be more stable and able to ignore occasionally delayed readings of PHC. --- hwclock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hwclock.c b/hwclock.c index b816127..84a130d 100644 --- a/hwclock.c +++ b/hwclock.c @@ -198,7 +198,7 @@ HCL_CookTime(HCL_Instance clock, struct timespec *raw, struct timespec *cooked, return 0; elapsed = UTI_DiffTimespecsToDouble(raw, &clock->hw_ref); - offset = clock->offset + elapsed / clock->frequency; + offset = elapsed / clock->frequency - clock->offset; UTI_AddDoubleToTimespec(&clock->local_ref, offset, cooked); /* Fow now, just return the error of the last sample */