Skip site navigation (1)Skip section navigation (2)
Date:      Thu,  7 Jul 2022 17:25:06 +0200
From:      Sebastian Huber <sebastian.huber@embedded-brains.de>
To:        freebsd-hackers@freebsd.org
Subject:   [PATCH 6/6] pps: Round to closest integer in pps_event()
Message-ID:  <20220707152506.55626-7-sebastian.huber@embedded-brains.de>
In-Reply-To: <20220707152506.55626-1-sebastian.huber@embedded-brains.de>
References:  <20220707152506.55626-1-sebastian.huber@embedded-brains.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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, ro=
unding
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;
=20
 		/*
 		 * Feed the NTP PLL/FLL.
@@ -1893,7 +1894,8 @@ pps_event(struct pps_state *pps, int event)
 		tcount &=3D captc->tc_counter_mask;
 		nsec =3D 1000000000;
 		nsec *=3D tcount;
-		nsec /=3D captc->tc_frequency;
+		freq =3D captc->tc_frequency;
+		nsec =3D (nesc + freq / 2) / freq;
 		hardpps(tsp, (long)nsec);
 	}
 #endif
--=20
2.35.3




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20220707152506.55626-7-sebastian.huber>