[Git][NTPsec/ntpsec][master] 3 commits: 1e6 -> US_PER_S, remove more magic numbers.
Gary E. Miller
gitlab at mg.gitlab.com
Thu Mar 16 02:07:40 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
80d1c441 by Gary E. Miller at 2017-03-15T18:30:10-07:00
1e6 -> US_PER_S, remove more magic numbers.
No functional changes.
- - - - -
dc2e190a by Gary E. Miller at 2017-03-15T18:40:24-07:00
"/ 1e9" becomes "* NS_PER_S"
No functional change. Added some include timespecops.h
- - - - -
d66a8fe2 by Gary E. Miller at 2017-03-15T18:52:12-07:00
More use of S_PER*S.
No functional change.
- - - - -
10 changed files:
- libntp/pymodule.c
- ntpd/ntp_packetstamp.c
- ntpd/ntp_proto.c
- ntpd/ntp_refclock.c
- ntpd/ntp_util.c
- ntpd/refclock_arbiter.c
- ntpd/refclock_generic.c
- ntpd/refclock_jupiter.c
- ntpfrob/jitter.c
- ntpfrob/pps-api.c
Changes:
=====================================
libntp/pymodule.c
=====================================
--- a/libntp/pymodule.c
+++ b/libntp/pymodule.c
@@ -100,7 +100,7 @@ ntpc_lfptofloat(PyObject *self, PyObject *args)
return NULL;
}
tt = lfp_stamp_to_tspec(ts, NULL);
- return Py_BuildValue("d", tt.tv_sec + tt.tv_nsec * 1e-9);
+ return Py_BuildValue("d", tt.tv_sec + tt.tv_nsec * S_PER_NS);
}
static PyObject *
=====================================
ntpd/ntp_packetstamp.c
=====================================
--- a/ntpd/ntp_packetstamp.c
+++ b/ntpd/ntp_packetstamp.c
@@ -156,7 +156,7 @@ fetch_packetstamp(
setlfpuint(nts, btp->sec + JAN_1970);
setlfpfrac(nts, (uint32_t)(btp->frac >> 32));
if (sys_tick > measured_tick &&
- sys_tick > 1e-9) {
+ sys_tick > S_PER_NS) {
ticks = (unsigned long)(lfpfrac(nts) / (unsigned long)(sys_tick * FRAC));
setlfpfrac(nts, (unsigned long)(ticks * (unsigned long)(sys_tick * FRAC)));
}
@@ -168,10 +168,11 @@ fetch_packetstamp(
case SCM_TIMESTAMPNS:
tsp = (struct timespec *)CMSG_DATA(cmsghdr);
if (sys_tick > measured_tick &&
- sys_tick > 1e-9) {
- ticks = (unsigned long)((tsp->tv_nsec * 1e-9) /
+ sys_tick > S_PER_NS) {
+ ticks = (unsigned long)
+ ((tsp->tv_nsec * S_PER_NS) /
sys_tick);
- tsp->tv_nsec = (long)(ticks * 1e9 *
+ tsp->tv_nsec = (long)(ticks * S_PER_NS *
sys_tick);
}
DPRINTF(4, ("fetch_timestamp: system nsec network time stamp: %ld.%09ld\n",
@@ -186,7 +187,7 @@ fetch_packetstamp(
sys_tick > 1e-6) {
ticks = (unsigned long)((tvp->tv_usec * 1e-6) /
sys_tick);
- tvp->tv_usec = (long)(ticks * 1e6 *
+ tvp->tv_usec = (long)(ticks * US_PER_S *
sys_tick);
}
DPRINTF(4, ("fetch_timestamp: system usec network time stamp: %jd.%06ld\n",
=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -9,6 +9,7 @@
#include "ntp_stdlib.h"
#include "ntp_leapsec.h"
#include "refidsmear.h"
+#include "timespecops.h"
#include <string.h>
#include <stdio.h>
@@ -2664,10 +2665,10 @@ measure_precision(const bool verbose)
set_sys_tick_precision(measured_tick);
if (verbose) {
msyslog(LOG_INFO, "proto: precision = %.3f usec (%d)",
- sys_tick * 1e6, sys_precision);
+ sys_tick * US_PER_S, sys_precision);
if (sys_fuzz < sys_tick) {
msyslog(LOG_NOTICE, "proto: fuzz beneath %.3f usec",
- sys_fuzz * 1e6);
+ sys_fuzz * US_PER_S);
}
}
}
=====================================
ntpd/ntp_refclock.c
=====================================
--- a/ntpd/ntp_refclock.c
+++ b/ntpd/ntp_refclock.c
@@ -11,6 +11,7 @@
#include "ntp_assert.h"
#include "lib_strbuf.h"
#include "ntp_calendar.h"
+#include "timespecops.h"
#include <stdio.h>
@@ -414,7 +415,7 @@ refclock_process_f(
setlfpuint(offset, sec);
setlfpfrac(offset, 0);
- ltemp = dtolfp(pp->nsec / 1e9);
+ ltemp = dtolfp(pp->nsec * S_PER_NS);
offset += ltemp;
refclock_process_offset(pp, offset, pp->lastrec, fudge);
return true;
@@ -1093,7 +1094,7 @@ refclock_catcher(
* Convert to signed fraction offset and stuff in median filter.
*/
setlfpuint(pp->lastrec, (uint32_t)ap->ts.tv_sec + JAN_1970);
- dtemp = ap->ts.tv_nsec / 1e9;
+ dtemp = ap->ts.tv_nsec * S_PER_NS;
setlfpfrac(pp->lastrec, (uint32_t)(dtemp * FRAC));
if (dtemp > .5)
dtemp -= 1.;
=====================================
ntpd/ntp_util.c
=====================================
--- a/ntpd/ntp_util.c
+++ b/ntpd/ntp_util.c
@@ -11,6 +11,7 @@
#include "ntp_leapsec.h"
#include "ntp_stdlib.h"
#include "ntpd.h"
+#include "timespecops.h"
#include <stdio.h>
#include <libgen.h>
@@ -187,8 +188,8 @@ write_stats(void)
#ifdef DEBUG
if (debug)
printf("write_stats: frequency %.6lf thresh %.6lf, freq %.6lf\n",
- (prev_drift_comp - drift_comp) * 1e6, wander_resid *
- 1e6, drift_comp * 1e6);
+ (prev_drift_comp - drift_comp) * US_PER_S,
+ wander_resid * US_PER_S, drift_comp * US_PER_S);
#endif
if (fabs(prev_drift_comp - drift_comp) < wander_resid) {
wander_resid *= 0.5;
@@ -196,7 +197,7 @@ write_stats(void)
}
prev_drift_comp = drift_comp;
wander_resid = wander_threshold;
- drift_write(stats_drift_file, drift_comp * 1e6);
+ drift_write(stats_drift_file, drift_comp * US_PER_S);
}
}
@@ -428,8 +429,8 @@ record_loop_stats(
setlfpuint(now, lfpuint(now) % 86400);
if (loopstats.fp != NULL) {
fprintf(loopstats.fp, "%lu %s %.9f %.6f %.9f %.6f %d\n",
- day, ulfptoa(now, 3), offset, freq * 1e6, jitter,
- wander * 1e6, spoll);
+ day, ulfptoa(now, 3), offset, freq * US_PER_S, jitter,
+ wander * US_PER_S, spoll);
fflush(loopstats.fp);
}
}
=====================================
ntpd/refclock_arbiter.c
=====================================
--- a/ntpd/refclock_arbiter.c
+++ b/ntpd/refclock_arbiter.c
@@ -8,6 +8,7 @@
#include "ntp_io.h"
#include "ntp_refclock.h"
#include "ntp_stdlib.h"
+#include "timespecops.h"
#include <stdio.h>
#include <ctype.h>
@@ -357,7 +358,7 @@ arb_receive(
break;
case '4': /* unlock accuracy < 1 us */
- pp->disp = 1e-6;
+ pp->disp = S_PER_US;
break;
case '5': /* unlock accuracy < 10 us */
@@ -369,7 +370,7 @@ arb_receive(
break;
case '7': /* unlock accuracy < 1 ms */
- pp->disp = .001;
+ pp->disp = S_PER_MS;
break;
case '8': /* unlock accuracy < 10 ms */
=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -19,6 +19,7 @@
#include "config.h"
#include "ntp_types.h"
+#include "timespecops.h"
/*
* This driver currently provides the support for
@@ -1855,7 +1856,7 @@ local_input(
setlfpuint(parse->parseio.parse_dtime.parse_ptime, (uint32_t) (pts.tv_sec + JAN_1970));
- dtemp = (double) pts.tv_nsec / 1e9;
+ dtemp = (double) pts.tv_nsec * S_PER_NS;
if (dtemp < 0.) {
dtemp += 1;
bumplfpuint(parse->parseio.parse_dtime.parse_ptime, -1);
=====================================
ntpd/refclock_jupiter.c
=====================================
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -12,6 +12,7 @@
#include "ntp_refclock.h"
#include "ntp_stdlib.h"
#include "ntp_calendar.h"
+#include "timespecops.h"
#include <stdio.h>
#include <ctype.h>
@@ -643,7 +644,7 @@ jupiter_pps(struct instance *instance)
instance->ts = ts;
setlfpuint(tstmp, (uint32_t)ts.tv_sec + JAN_1970);
- dtemp = ts.tv_nsec * FRAC / 1e9;
+ dtemp = ts.tv_nsec * FRAC * S_PER_NS;
setlfpfrac(tstmp, (uint32_t)dtemp);
instance->peer->procptr->lastrec = tstmp;
return false;
=====================================
ntpfrob/jitter.c
=====================================
--- a/ntpfrob/jitter.c
+++ b/ntpfrob/jitter.c
@@ -21,6 +21,7 @@
#include "ntp_fp.h"
#include "ntp_calendar.h"
+#include "timespecops.h"
#define NBUF 800002
#define NSAMPLES 10
@@ -45,7 +46,7 @@ get_clocktime(
*/
clock_gettime(CLOCK_REALTIME, &ts);
setlfpsint(*now, ts.tv_sec + JAN_1970);
- dtemp = ts.tv_nsec / 1e9;
+ dtemp = ts.tv_nsec * S_PER_NS;
/*
* Renormalize to seconds past 1900 and fraction.
=====================================
ntpfrob/pps-api.c
=====================================
--- a/ntpfrob/pps-api.c
+++ b/ntpfrob/pps-api.c
@@ -18,6 +18,8 @@
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
+#include "timespecops.h"
+
#ifdef HAVE_SYS_TIMEPPS_H
#include <sys/timepps.h>
@@ -31,7 +33,7 @@
(vvp)->tv_nsec -= (uvp)->tv_nsec; \
if ((vvp)->tv_nsec < 0) { \
(vvp)->tv_sec--; \
- (vvp)->tv_nsec += 1000000000; \
+ (vvp)->tv_nsec += NS_PER_S; \
} \
} while (0)
@@ -47,7 +49,7 @@ Chew(struct timespec *tsa, struct timespec *tsc, unsigned sa, unsigned sc)
ts = *tsc;
timespecsub(&ts,tsa);
- printf("%.9f ", ts.tv_sec + ts.tv_nsec / 1e9);
+ printf("%.9f ", ts.tv_sec + ts.tv_nsec * S_PER_NS);
printf("\n");
fflush(stdout);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/3357c0c23a96dfe1786d24499d0c79eac464ab8d...d66a8fe29e7025b47a065cc073c510b81b00cf23
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170316/6b363b7c/attachment.html>
More information about the vc
mailing list