Date: Mon, 27 Feb 2023 22:12:23 GMT From: Warner Losh <imp@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 28ed159f2669 - main - pps: Round to closest integer in pps_event() Message-ID: <202302272212.31RMCNGU028875@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=28ed159f2669b8d401ca95bf5c6e9ff06a997ef9 commit 28ed159f2669b8d401ca95bf5c6e9ff06a997ef9 Author: Sebastian Huber <sebastian.huber@embedded-brains.de> AuthorDate: 2023-02-27 21:49:10 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2023-02-27 22:10:55 +0000 pps: Round to closest integer in pps_event() The comment above bintime2timespec() says: When converting between timestamps on parallel timescales of differing resolutions it is historical and scientific practice to round down. However, the delta_nsec value is a time difference and not a timestamp. Also the rounding errors accumulate in the frequency accumulator, see hardpps(). So, rounding to the closest integer is probably slightly better. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/604 --- sys/kern/kern_tc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index 0dc233896baa..e4b3d5e80529 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -1882,6 +1882,7 @@ pps_event(struct pps_state *pps, int event) #ifdef PPS_SYNC if (fhard) { uint64_t delta_nsec; + uint64_t freq; /* * Feed the NTP PLL/FLL. @@ -1893,7 +1894,8 @@ pps_event(struct pps_state *pps, int event) tcount &= captc->tc_counter_mask; delta_nsec = 1000000000; delta_nsec *= tcount; - delta_nsec /= captc->tc_frequency; + freq = captc->tc_frequency; + delta_nsec = (delta_nsec + freq / 2) / freq; hardpps(tsp, (long)delta_nsec); } #endif
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302272212.31RMCNGU028875>