diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-02-27 21:49:10 +0000 |
---|---|---|
committer | Warner Losh <imp@FreeBSD.org> | 2023-02-27 22:10:55 +0000 |
commit | 28ed159f2669b8d401ca95bf5c6e9ff06a997ef9 (patch) | |
tree | d6cfea3b40bcf29891a5b252d4a2e0b849c0fa7c | |
parent | 1e48d9d336c042a44edc0f66d35b72655f68f258 (diff) | |
download | src-28ed159f2669b8d401ca95bf5c6e9ff06a997ef9.tar.gz src-28ed159f2669b8d401ca95bf5c6e9ff06a997ef9.zip |
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
-rw-r--r-- | sys/kern/kern_tc.c | 4 |
1 files changed, 3 insertions, 1 deletions
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 |