[Git][NTPsec/ntpsec][master] 4 commits: NANOSECONDS -> NS_PER_S, more readable define.
Gary E. Miller
gitlab at mg.gitlab.com
Wed Mar 15 21:59:48 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
6167b909 by Gary E. Miller at 2017-03-15T14:58:41-07:00
NANOSECONDS -> NS_PER_S, more readable define.
Avoid conflicting definitions of NANOSECONDS.
- - - - -
4b379a6e by Gary E. Miller at 2017-03-15T14:58:51-07:00
NANOSECOND -> S_PER_NS, to avoid confusion.
*BSD defines NANOSECOND backwards as 1e9, not 1e-9. This is to
avoid that confusion.
No functional changes, just the name of the define.
- - - - -
b03fb5d9 by Gary E. Miller at 2017-03-15T14:59:00-07:00
style cleanups, NS_PER_S is shorter so some lines can be improved.
- - - - -
120c479b by Gary E. Miller at 2017-03-15T14:59:10-07:00
MILLISECONDS -> MS_PER_S, avoid ambiguity.
No functional changes, a tad bit of restyling.
- - - - -
7 changed files:
- include/timespecops.h
- libntp/systime.c
- libparse/clk_rawdcf.c
- ntpd/ntp_control.c
- ntpd/ntp_loopfilter.c
- ntpfrob/bumpclock.c
- tests/libntp/timespecops.c
Changes:
=====================================
include/timespecops.h
=====================================
--- a/include/timespecops.h
+++ b/include/timespecops.h
@@ -50,7 +50,7 @@
/* milliseconds per second */
-#define MILLISECONDS 1000
+#define MS_PER_S 1000
/* sconds per microsecond */
#define MILLISECOND 1.0e-3
@@ -60,26 +60,21 @@
#define MICROSECOND 1.0e-6
/* nanoseconds per second */
-#define NANOSECONDS 1000000000
+#define NS_PER_S 1000000000
/* seconds per nanosecond */
-#define NANOSECOND 1.0e-9
+#define S_PER_NS 1.0e-9
/* predicate: returns true if the nanoseconds are in nominal range */
-#define timespec_isnormal(x) \
- ((x)->tv_nsec >= 0 && (x)->tv_nsec < NANOSECONDS)
+#define timespec_isnormal(x) ((x)->tv_nsec >= 0 && (x)->tv_nsec < NS_PER_S)
/* predicate: returns true if the nanoseconds are out-of-bounds */
#define timespec_isdenormal(x) (!timespec_isnormal(x))
/* conversion between l_fp fractions and nanoseconds */
-# define FTOTVN(tsf) \
- ((int32_t) \
- (((uint64_t)(tsf) * NANOSECONDS + 0x80000000) >> 32))
-# define TVNTOF(tvu) \
- ((uint32_t) \
- ((((uint64_t)(tvu) << 32) + NANOSECONDS / 2) / \
- NANOSECONDS))
-
+#define FTOTVN(tsf) \
+ ((int32_t)(((uint64_t)(tsf) * NS_PER_S + 0x80000000) >> 32))
+#define TVNTOF(tvu) \
+ ((uint32_t) ((((uint64_t)(tvu) << 32) + NS_PER_S / 2) / NS_PER_S))
/* make sure nanoseconds are in nominal range */
@@ -89,18 +84,18 @@ normalize_tspec(
)
{
#if NTP_SIZEOF_LONG > 4
- /*
+ /*
* tv_nsec is of type 'long', and on a 64-bit machine using only
* loops becomes prohibitive once the upper 32 bits get
* involved. On the other hand, division by constant should be
* fast enough; so we do a division of the nanoseconds in that
* case.
*/
- if (x.tv_nsec < 0 || x.tv_nsec >= NANOSECONDS) {
- ldiv_t z = ldiv( x.tv_nsec, NANOSECONDS);
+ if (x.tv_nsec < 0 || x.tv_nsec >= NS_PER_S) {
+ ldiv_t z = ldiv( x.tv_nsec, NS_PER_S);
if (z.rem < 0) {
z.quot--;
- z.rem += NANOSECONDS;
+ z.rem += NS_PER_S;
}
x.tv_sec += z.quot;
x.tv_nsec = z.rem;
@@ -112,14 +107,14 @@ normalize_tspec(
* employed. */
if (x.tv_nsec < 0)
do {
- x.tv_nsec += NANOSECONDS;
+ x.tv_nsec += NS_PER_S;
x.tv_sec--;
} while (x.tv_nsec < 0);
- else if (x.tv_nsec >= NANOSECONDS)
+ else if (x.tv_nsec >= NS_PER_S)
do {
- x.tv_nsec -= NANOSECONDS;
+ x.tv_nsec -= NS_PER_S;
x.tv_sec++;
- } while (x.tv_nsec >= NANOSECONDS);
+ } while (x.tv_nsec >= NS_PER_S);
#endif
return x;
@@ -135,7 +130,7 @@ d_to_tspec(
double s = floor(d);
x.tv_sec = (time_t) s;
- x.tv_nsec = (long) (((d - s) * NANOSECONDS) + 0.5);
+ x.tv_nsec = (long) (((d - s) * NS_PER_S) + 0.5);
return x;
}
@@ -227,7 +222,7 @@ abs_tspec(
if (c.tv_sec < 0) {
if (c.tv_nsec != 0) {
c.tv_sec = -c.tv_sec - 1;
- c.tv_nsec = NANOSECONDS - c.tv_nsec;
+ c.tv_nsec = NS_PER_S - c.tv_nsec;
} else {
c.tv_sec = -c.tv_sec;
}
=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -84,7 +84,7 @@ set_sys_fuzz(
sys_fuzz = fuzz_val;
//INSIST(sys_fuzz >= 0);
//INSIST(sys_fuzz <= 1.0);
- sys_fuzz_nsec = (long)(sys_fuzz * NANOSECONDS + 0.5);
+ sys_fuzz_nsec = (long)(sys_fuzz * NS_PER_S + 0.5);
}
@@ -106,8 +106,8 @@ get_ostime(
}
if (trunc_os_clock) {
- ticks = (long)((tsp->tv_nsec * NANOSECOND) / sys_tick);
- tsp->tv_nsec = (long)(ticks * NANOSECONDS * sys_tick);
+ ticks = (long)((tsp->tv_nsec * S_PER_NS) / sys_tick);
+ tsp->tv_nsec = (long)(ticks * NS_PER_S * sys_tick);
}
}
@@ -157,11 +157,10 @@ normalize_time(
if (cmp_tspec(ts, ts_min) < 0) {
ts_lam = sub_tspec(ts_min, ts);
if (ts_lam.tv_sec > 0 && !lamport_violated) {
- msyslog(LOG_ERR,
- "get_systime Lamport advance exceeds one second (%.9f)",
- ts_lam.tv_sec +
- NANOSECOND * ts_lam.tv_nsec);
- exit(1);
+ msyslog(LOG_ERR,
+ "get_systime Lamport advance exceeds one second (%.9f)",
+ ts_lam.tv_sec + S_PER_NS * ts_lam.tv_nsec);
+ exit(1);
}
if (!lamport_violated)
ts = ts_min;
=====================================
libparse/clk_rawdcf.c
=====================================
--- a/libparse/clk_rawdcf.c
+++ b/libparse/clk_rawdcf.c
@@ -553,8 +553,9 @@ snt_rawdcf(
parseio->parse_index - 1, delta_usec));
if (((parseio->parse_dtime.parse_status & CVT_MASK) == CVT_OK) &&
- (delta_usec < (NANOSECONDS/2000) && delta_usec >= 0)) /* only if minute marker is available */
+ (delta_usec < (NS_PER_S/2000) && delta_usec >= 0))
{
+ /* only if minute marker is available */
parseio->parse_dtime.parse_stime = *ptime;
bumplfpuint(parseio->parse_dtime.parse_time, 1);
@@ -578,9 +579,11 @@ inp_rawdcf(
timestamp_t *tstamp
)
{
- static struct timespec timeout = { 1, (NANOSECONDS/2) }; /* 1.5 seconds denote second #60 */
+ /* 1.5 seconds denote second #60 */
+ static struct timespec timeout = { 1, (NS_PER_S/2) };
- parseprintf(DD_PARSE, ("inp_rawdcf(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_rawdcf(0x%lx, 0x%x, ...)\n",
+ (long)parseio, ch));
parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */
@@ -618,7 +621,7 @@ inp_rawdcf(
delta_usec = -1;
}
- if (delta_usec < (NANOSECONDS/2000) && delta_usec >= 0)
+ if (delta_usec < (NS_PER_S/2000) && delta_usec >= 0)
{
parseprintf(DD_RAWDCF, ("inp_rawdcf: timeout time difference %ld usec - minute marker set\n", delta_usec));
/* collect minute markers only if spaced by 60 seconds */
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -660,7 +660,7 @@ static char *reqend;
#define MIN(a, b) (((a) <= (b)) ? (a) : (b))
#endif
-#define MILLISECONDS 1000 /* milliseconds per second -magic numbers suck */
+#define MS_PER_S 1000 /* milliseconds per second -magic numbers suck */
/*
* init_control - initialize request data
@@ -1406,7 +1406,7 @@ ctl_putarray(
i--;
NTP_INSIST((cp - buffer) < (int)sizeof(buffer));
snprintf(cp, sizeof(buffer) - (size_t)(cp - buffer),
- " %.2f", arr[i] * MILLISECONDS);
+ " %.2f", arr[i] * MS_PER_S);
cp += strlen(cp);
} while (i != start);
ctl_putdata(buffer, (unsigned)(cp - buffer), false);
@@ -1459,13 +1459,12 @@ ctl_putsys(
break;
case CS_ROOTDELAY:
- ctl_putdbl(sys_var[CS_ROOTDELAY].text, sys_rootdelay *
- MILLISECONDS);
+ ctl_putdbl(sys_var[CS_ROOTDELAY].text, sys_rootdelay * MS_PER_S);
break;
case CS_ROOTDISPERSION:
ctl_putdbl(sys_var[CS_ROOTDISPERSION].text,
- sys_rootdisp * MILLISECONDS);
+ sys_rootdisp * MS_PER_S);
break;
case CS_REFID:
@@ -1507,7 +1506,7 @@ ctl_putsys(
break;
case CS_OFFSET:
- ctl_putdbl6(sys_var[CS_OFFSET].text, last_offset * MILLISECONDS);
+ ctl_putdbl6(sys_var[CS_OFFSET].text, last_offset * MS_PER_S);
break;
case CS_DRIFT:
@@ -1516,12 +1515,12 @@ ctl_putsys(
break;
case CS_JITTER:
- ctl_putdbl6(sys_var[CS_JITTER].text, sys_jitter * MILLISECONDS);
+ ctl_putdbl6(sys_var[CS_JITTER].text, sys_jitter * MS_PER_S);
break;
case CS_ERROR:
/* a.k.a clk_jitter (s). output as ms */
- ctl_putdbl6(sys_var[CS_ERROR].text, clock_jitter * MILLISECONDS);
+ ctl_putdbl6(sys_var[CS_ERROR].text, clock_jitter * MS_PER_S);
break;
case CS_CLOCK:
@@ -1644,7 +1643,7 @@ ctl_putsys(
case CS_LEAPSMEAROFFS:
if (leap_smear_intv > 0)
ctl_putdbl(sys_var[CS_LEAPSMEAROFFS].text,
- leap_smear.doffset * MILLISECONDS);
+ leap_smear.doffset * MS_PER_S);
break;
#endif /* ENABLE_LEAP_SMEAR */
@@ -1774,7 +1773,7 @@ ctl_putsys(
case CS_AUTHDELAY:
dtemp = lfptod(sys_authdelay);
- ctl_putdbl(sys_var[varid].text, dtemp * MILLISECONDS);
+ ctl_putdbl(sys_var[varid].text, dtemp * MS_PER_S);
break;
case CS_AUTHKEYS:
@@ -1847,7 +1846,7 @@ ctl_putsys(
CTL_IF_KERNLOOP(
ctl_putdblf,
(sys_var[varid].text, 0, -1,
- ntp_error_in_seconds(ntx.offset)*MILLISECONDS)
+ ntp_error_in_seconds(ntx.offset) * MS_PER_S)
);
break;
@@ -1862,7 +1861,7 @@ ctl_putsys(
CTL_IF_KERNLOOP(
ctl_putdblf,
(sys_var[varid].text, 0, 6,
- ntp_error_in_seconds(ntx.maxerror)*MILLISECONDS)
+ ntp_error_in_seconds(ntx.maxerror) * MS_PER_S)
);
break;
@@ -1870,7 +1869,7 @@ ctl_putsys(
CTL_IF_KERNLOOP(
ctl_putdblf,
(sys_var[varid].text, 0, 6,
- ntp_error_in_seconds(ntx.esterror)*MILLISECONDS)
+ ntp_error_in_seconds(ntx.esterror) * MS_PER_S)
);
break;
@@ -1894,7 +1893,7 @@ ctl_putsys(
CTL_IF_KERNLOOP(
ctl_putdblf,
(sys_var[varid].text, 0, 6,
- ntp_error_in_seconds(ntx.precision)*MILLISECONDS)
+ ntp_error_in_seconds(ntx.precision) * MS_PER_S)
);
break;
@@ -1923,7 +1922,7 @@ ctl_putsys(
CTL_IF_KERNPPS(
ctl_putdbl,
(sys_var[varid].text,
- ntp_error_in_seconds(ntx.jitter)*MILLISECONDS)
+ ntp_error_in_seconds(ntx.jitter) * MS_PER_S)
);
break;
@@ -2026,14 +2025,14 @@ ctl_putsys(
case CS_FUZZ:
/* a.k.a. fuzz (s), output in ms */
- ctl_putdbl6(sys_var[varid].text, sys_fuzz * MILLISECONDS);
+ ctl_putdbl6(sys_var[varid].text, sys_fuzz * MS_PER_S);
break;
case CS_WANDER_THRESH:
ctl_putdbl(sys_var[varid].text, wander_threshold * MICROSECONDS);
break;
case CS_TICK:
/* a.k.a. sys_tick (s), output in ms */
- ctl_putdbl6(sys_var[varid].text, sys_tick * MILLISECONDS);
+ ctl_putdbl6(sys_var[varid].text, sys_tick * MS_PER_S);
break;
}
}
@@ -2108,12 +2107,12 @@ ctl_putpeer(
case CP_IN:
if (p->r21 > 0.)
- ctl_putdbl(peer_var[id].text, p->r21 / MILLISECONDS);
+ ctl_putdbl(peer_var[id].text, p->r21 / MS_PER_S);
break;
case CP_OUT:
if (p->r34 > 0.)
- ctl_putdbl(peer_var[id].text, p->r34 / MILLISECONDS);
+ ctl_putdbl(peer_var[id].text, p->r34 / MS_PER_S);
break;
case CP_RATE:
@@ -2145,11 +2144,11 @@ ctl_putpeer(
break;
case CP_ROOTDELAY:
- ctl_putdbl(peer_var[id].text, p->rootdelay * MILLISECONDS);
+ ctl_putdbl(peer_var[id].text, p->rootdelay * MS_PER_S);
break;
case CP_ROOTDISPERSION:
- ctl_putdbl(peer_var[id].text, p->rootdisp * MILLISECONDS);
+ ctl_putdbl(peer_var[id].text, p->rootdisp * MS_PER_S);
break;
case CP_REFID:
@@ -2180,7 +2179,7 @@ ctl_putpeer(
case CP_BIAS:
if (p->bias != 0.)
- ctl_putdbl(peer_var[id].text, p->bias * MILLISECONDS);
+ ctl_putdbl(peer_var[id].text, p->bias * MS_PER_S);
break;
case CP_REACH:
@@ -2210,19 +2209,19 @@ ctl_putpeer(
break;
case CP_DELAY:
- ctl_putdbl6(peer_var[id].text, p->delay * MILLISECONDS);
+ ctl_putdbl6(peer_var[id].text, p->delay * MS_PER_S);
break;
case CP_OFFSET:
- ctl_putdbl6(peer_var[id].text, p->offset * MILLISECONDS);
+ ctl_putdbl6(peer_var[id].text, p->offset * MS_PER_S);
break;
case CP_JITTER:
- ctl_putdbl6(peer_var[id].text, p->jitter * MILLISECONDS);
+ ctl_putdbl6(peer_var[id].text, p->jitter * MS_PER_S);
break;
case CP_DISPERSION:
- ctl_putdbl6(peer_var[id].text, p->disp * MILLISECONDS);
+ ctl_putdbl6(peer_var[id].text, p->disp * MS_PER_S);
break;
case CP_KEYID:
@@ -2385,13 +2384,13 @@ ctl_putclock(
case CC_FUDGETIME1:
if (mustput || (pcs->haveflags & CLK_HAVETIME1))
ctl_putdbl(clock_var[id].text,
- pcs->fudgetime1 * MILLISECONDS);
+ pcs->fudgetime1 * MS_PER_S);
break;
case CC_FUDGETIME2:
if (mustput || (pcs->haveflags & CLK_HAVETIME2))
ctl_putdbl(clock_var[id].text,
- pcs->fudgetime2 * MILLISECONDS);
+ pcs->fudgetime2 * MS_PER_S);
break;
case CC_FUDGEVAL1:
=====================================
ntpd/ntp_loopfilter.c
=====================================
--- a/ntpd/ntp_loopfilter.c
+++ b/ntpd/ntp_loopfilter.c
@@ -22,7 +22,7 @@
#define NTP_MAXFREQ 500e-6
#ifdef HAVE_KERNEL_PLL
-# define NANOSECONDS 1e9
+# define NS_PER_S 1000000
# define FREQTOD(x) ((x) / 65536e6) /* NTP to double */
# define DTOFREQ(x) ((int32_t)((x) * 65536e6)) /* double to NTP */
#endif
@@ -779,7 +779,7 @@ local_clock(
dtemp = -.5;
else
dtemp = .5;
- ntv.offset = (long)(clock_offset * NANOSECONDS + dtemp);
+ ntv.offset = (long)(clock_offset * NS_PER_S + dtemp);
#ifdef STA_NANO
ntv.constant = sys_poll;
#else /* STA_NANO */
@@ -828,14 +828,14 @@ local_clock(
ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, hardpps_enable, false, __LINE__ - 1);
}
pll_status = ntv.status;
- clock_offset = ntv.offset / NANOSECONDS;
+ clock_offset = ntv.offset / NS_PER_S;
clock_frequency = FREQTOD(ntv.freq);
/*
* If the kernel PPS is lit, monitor its performance.
*/
if (ntv.status & STA_PPSTIME) {
- clock_jitter = ntv.jitter / NANOSECONDS;
+ clock_jitter = ntv.jitter / NS_PER_S;
}
#if defined(STA_NANO) && NTP_API == 4
=====================================
ntpfrob/bumpclock.c
=====================================
--- a/ntpfrob/bumpclock.c
+++ b/ntpfrob/bumpclock.c
@@ -10,7 +10,7 @@
#include <string.h>
#include <time.h>
-#define NANOSECONDS 1000000000
+#define NS_PER_S 1000000000
void bumpclock(int bump)
{
@@ -27,12 +27,12 @@ void bumpclock(int bump)
bump *= 1000;
/* coverity[tainted_data] */
set.tv_nsec += bump;
- while (set.tv_nsec >= NANOSECONDS ) {
- set.tv_nsec -= NANOSECONDS;
+ while (set.tv_nsec >= NS_PER_S ) {
+ set.tv_nsec -= NS_PER_S;
set.tv_sec +=1;
}
while (set.tv_nsec <= 0 ) {
- set.tv_nsec += NANOSECONDS;
+ set.tv_nsec += NS_PER_S;
set.tv_sec -=1;
}
rc2 = clock_settime(CLOCK_REALTIME, &set);
=====================================
tests/libntp/timespecops.c
=====================================
--- a/tests/libntp/timespecops.c
+++ b/tests/libntp/timespecops.c
@@ -319,7 +319,7 @@ TEST(timespecops, AddNsecOflow1) {
struct timespec E = timespec_init(i + 1, 100);
struct timespec c;
- c = add_tspec_ns(a, NANOSECONDS - 100);
+ c = add_tspec_ns(a, NS_PER_S - 100);
TEST_ASSERT_EQUAL_timespec(E, c);
}
@@ -390,7 +390,7 @@ TEST(timespecops, SubNsecOflow) {
struct timespec E = timespec_init(i-1, 200);
struct timespec c;
- c = sub_tspec_ns(a, NANOSECONDS - 100);
+ c = sub_tspec_ns(a, NS_PER_S - 100);
TEST_ASSERT_EQUAL_timespec(E, c);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c0c821419297bc789323f6ec699d7b202e0109d2...120c479b395a22994290ca91b40fe7128ba90b92
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170315/160fe63e/attachment.html>
More information about the vc
mailing list