[Git][NTPsec/ntpsec][master] Do more arithmetic at nanosecond scale.

Eric S. Raymond gitlab at mg.gitlab.com
Fri Sep 30 14:16:57 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
222e7558 by Eric S. Raymond at 2016-09-30T10:15:52-04:00
Do more arithmetic at nanosecond scale.

- - - - -


4 changed files:

- include/timespecops.h
- include/timevalops.h
- ntpd/ntp_io.c
- tests/libntp/timevalops.c


Changes:

=====================================
include/timespecops.h
=====================================
--- a/include/timespecops.h
+++ b/include/timespecops.h
@@ -383,4 +383,15 @@ lfp_stamp_to_tspec(
 	return out;
 }
 
+static inline struct timespec
+tval_to_tspec(
+    struct timeval x
+    )
+{
+    struct timespec y;
+    y.tv_sec = x.tv_sec;
+    y.tv_nsec = x.tv_usec * 1000;
+    return y;
+}
+
 #endif	/* GUARD_TIMESPECOPS_H */


=====================================
include/timevalops.h
=====================================
--- a/include/timevalops.h
+++ b/include/timevalops.h
@@ -177,36 +177,6 @@ abs_tval(
 	return c;
 }
 
-/* convert from timeval duration to l_fp duration */
-static inline l_fp
-tval_intv_to_lfp(
-	struct timeval	x
-	)
-{
-	struct timeval	v;
-	l_fp		y;
-	
-	v = normalize_tval(x);
-	TVUTOTSF(v.tv_usec, y.l_uf);
-	y.l_i = (int32_t)v.tv_sec;
-
-	return y;
-}
-
-/* x must be UN*X epoch, output *y will be in NTP epoch */
-static inline l_fp
-tval_stamp_to_lfp(
-	struct timeval	x
-	)
-{
-	l_fp		y;
-
-	y = tval_intv_to_lfp(x);
-	y.l_ui += JAN_1970;
-
-	return y;
-}
-
 /* convert to l_fp type, relative signed/unsigned and absolute */
 static inline struct timeval
 lfp_intv_to_tval(


=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -27,7 +27,6 @@
 #include "ntp_stdlib.h"
 #include "ntp_worker.h"
 #include "ntp_assert.h"
-#include "timevalops.h"
 #include "timespecops.h"
 
 #include <isc/mem.h>
@@ -3238,7 +3237,7 @@ fetch_timestamp(
 				}
 				DPRINTF(4, ("fetch_timestamp: system usec network time stamp: %jd.%06ld\n",
 					    (intmax_t)tvp->tv_sec, (long)tvp->tv_usec));
-				nts = tval_stamp_to_lfp(*tvp);
+				nts = tspec_stamp_to_lfp(tval_to_tspec(*tvp));
 				break;
 #endif  /* USE_SCM_TIMESTAMP */
 			}


=====================================
tests/libntp/timevalops.c
=====================================
--- a/tests/libntp/timevalops.c
+++ b/tests/libntp/timevalops.c
@@ -469,6 +469,22 @@ TEST(timevalops, Helpers2) {
 // conversion to l_fp
 //----------------------------------------------------------------------
 
+/* convert from timeval duration to l_fp duration */
+static inline l_fp
+tval_intv_to_lfp(
+	struct timeval	x
+	)
+{
+	struct timeval	v;
+	l_fp		y;
+
+	v = normalize_tval(x);
+	TVUTOTSF(v.tv_usec, y.l_uf);
+	y.l_i = (int32_t)v.tv_sec;
+
+	return y;
+}
+
 TEST(timevalops, ToLFPbittest) {
 	l_fp lfpClose =  l_fp_init(0, 1);
 
@@ -520,22 +536,6 @@ TEST(timevalops, ToLFPrelNeg) {
 }
 
 
-TEST(timevalops, ToLFPabs) {
-	l_fp lfpClose =  l_fp_init(0, 1);
-	int i = 0;
-
-	for (i = 0; i < (int)COUNTOF(fdata); ++i) {
-		struct timeval a = timeval_init(1, fdata[i].usec);
-		l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac);
-		l_fp    r;
-
-		r = tval_stamp_to_lfp(a);
-		TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
-	}
-
-	return;
-}
-
 //----------------------------------------------------------------------
 // conversion from l_fp
 //----------------------------------------------------------------------
@@ -631,7 +631,6 @@ TEST_GROUP_RUNNER(timevalops) {
 	RUN_TEST_CASE(timevalops, ToLFPbittest);
 	RUN_TEST_CASE(timevalops, ToLFPrelPos);
 	RUN_TEST_CASE(timevalops, ToLFPrelNeg);
-	RUN_TEST_CASE(timevalops, ToLFPabs);
 	RUN_TEST_CASE(timevalops, FromLFPbittest);
 	RUN_TEST_CASE(timevalops, FromLFPrelPos);
 	RUN_TEST_CASE(timevalops, FromLFPrelNeg);



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/222e7558d055b572d73d39a4f60628ef6f296bd5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160930/fa343a14/attachment.html>


More information about the vc mailing list