[PATCH 6/6] pps: Round to closest integer in pps_event()

From: Sebastian Huber <sebastian.huber_at_embedded-brains.de>
Date: Thu, 07 Jul 2022 15:25:06 UTC
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 nsec value is a time difference and not a timestamp.  So, rounding
to the closest integer is probably slightly better.
---
 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 f29dd9b8e7f2..8db5911a4c0e 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 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;
 		nsec = 1000000000;
 		nsec *= tcount;
-		nsec /= captc->tc_frequency;
+		freq = captc->tc_frequency;
+		nsec = (nesc + freq / 2) / freq;
 		hardpps(tsp, (long)nsec);
 	}
 #endif
-- 
2.35.3