[rtems commit] pps: Round to closest integer in pps_event()

Sebastian Huber sebh at rtems.org
Thu Mar 9 06:54:14 UTC 2023


Module:    rtems
Branch:    master
Commit:    d5c386ff99933c2e71e2119b395cd0470a772a0b
Changeset: http://git.rtems.org/rtems/commit/?id=d5c386ff99933c2e71e2119b395cd0470a772a0b

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Feb 27 14:49:10 2023 -0700

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

---

 cpukit/score/src/kern_tc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index 0aa0fdd393..95ae01b5b4 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -2266,6 +2266,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.
@@ -2277,7 +2278,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



More information about the vc mailing list