[Git][NTPsec/ntpsec][master] 4 commits: MICROSECONDS -> US_PER_S, to avoid confusion.
Gary E. Miller
gitlab at mg.gitlab.com
Wed Mar 15 22:25:55 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
b2222356 by Gary E. Miller at 2017-03-15T15:04:01-07:00
MICROSECONDS -> US_PER_S, to avoid confusion.
A slightly shorter line allowed some style fixups. No functional
changes.
- - - - -
fd0a5bea by Gary E. Miller at 2017-03-15T15:08:25-07:00
MICROSECOND -> S_PER_US for clarity
No functional changes.
- - - - -
f8260f36 by Gary E. Miller at 2017-03-15T15:09:58-07:00
MILLISECOND -> S_PER_MS, not currently useda.
- - - - -
3357c0c2 by Gary E. Miller at 2017-03-15T15:17:05-07:00
remove duplicates of MS_PER_S and US_PER_S.
No functional change, just add an include, remove dupes.
- - - - -
6 changed files:
- include/timespecops.h
- libntp/systime.c
- libparse/clk_rawdcf.c
- ntpd/ntp_control.c
- ntpd/ntp_loopfilter.c
- ntptime/ntptime.c
Changes:
=====================================
include/timespecops.h
=====================================
--- a/include/timespecops.h
+++ b/include/timespecops.h
@@ -51,13 +51,13 @@
/* milliseconds per second */
#define MS_PER_S 1000
-/* sconds per microsecond */
-#define MILLISECOND 1.0e-3
+/* seconds per microsecond */
+#define S_PER_MS 1.0e-3
/* microseconds per second */
-#define MICROSECONDS 1000000
-/* sconds per microsecond */
-#define MICROSECOND 1.0e-6
+#define US_PER_S 1000000
+/* seconds per microsecond */
+#define S_PER_US 1.0e-6
/* nanoseconds per second */
#define NS_PER_S 1000000000
=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -270,20 +270,20 @@ adj_systime(
if (sys_tick > sys_fuzz)
quant = sys_tick;
else
- quant = MICROSECOND;
+ quant = S_PER_US;
ticks = (long)(dtemp / quant + .5);
- adjtv.tv_usec = (long)(ticks * quant * MICROSECONDS + .5);
+ adjtv.tv_usec = (long)(ticks * quant * US_PER_S + .5);
/* The rounding in the conversions could push us over the
* limits: make sure the result is properly normalised!
* note: sign comes later, all numbers non-negative here.
*/
- if (adjtv.tv_usec >= MICROSECONDS) {
+ if (adjtv.tv_usec >= US_PER_S) {
adjtv.tv_sec += 1;
- adjtv.tv_usec -= MICROSECONDS;
+ adjtv.tv_usec -= US_PER_S;
dtemp -= 1.;
}
/* set the new residual with leftover from correction */
- sys_residual = dtemp - adjtv.tv_usec * MICROSECOND;
+ sys_residual = dtemp - adjtv.tv_usec * S_PER_US;
/*
* Convert to signed seconds and microseconds for the Unix
=====================================
libparse/clk_rawdcf.c
=====================================
--- a/libparse/clk_rawdcf.c
+++ b/libparse/clk_rawdcf.c
@@ -513,7 +513,7 @@ calc_usecdiff(
delt -= *base;
delta = lfp_uintv_to_tspec(delt);
- delta_usec = MICROSECONDS*(int32_t)delta.tv_sec + delta.tv_nsec/1000;
+ delta_usec = US_PER_S * (int32_t)delta.tv_sec + delta.tv_nsec / 1000;
return delta_usec;
}
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -660,8 +660,6 @@ static char *reqend;
#define MIN(a, b) (((a) <= (b)) ? (a) : (b))
#endif
-#define MS_PER_S 1000 /* milliseconds per second -magic numbers suck */
-
/*
* init_control - initialize request data
*/
@@ -1511,7 +1509,7 @@ ctl_putsys(
case CS_DRIFT:
/* a.k.a frequency. (s/s), reported as us/s a.k.a. ppm */
- ctl_putdbl6(sys_var[CS_DRIFT].text, drift_comp * MICROSECONDS);
+ ctl_putdbl6(sys_var[CS_DRIFT].text, drift_comp * US_PER_S);
break;
case CS_JITTER:
@@ -1546,8 +1544,7 @@ ctl_putsys(
case CS_STABIL:
/* a.k.a clk_wander (s/s), output as us/s */
- ctl_putdbl6(sys_var[CS_STABIL].text, clock_stability *
- MICROSECONDS);
+ ctl_putdbl6(sys_var[CS_STABIL].text, clock_stability * US_PER_S);
break;
case CS_VARLIST:
@@ -2028,7 +2025,7 @@ ctl_putsys(
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);
+ ctl_putdbl(sys_var[varid].text, wander_threshold * US_PER_S);
break;
case CS_TICK:
/* a.k.a. sys_tick (s), output in ms */
=====================================
ntpd/ntp_loopfilter.c
=====================================
--- a/ntpd/ntp_loopfilter.c
+++ b/ntpd/ntp_loopfilter.c
@@ -18,15 +18,14 @@
#include "ntp_calendar.h"
#include "ntp_stdlib.h"
#include "ntp_syscall.h"
+#include "timespecops.h"
#define NTP_MAXFREQ 500e-6
#ifdef HAVE_KERNEL_PLL
-# define NS_PER_S 1000000
# define FREQTOD(x) ((x) / 65536e6) /* NTP to double */
# define DTOFREQ(x) ((int32_t)((x) * 65536e6)) /* double to NTP */
#endif
-#define MICROSECONDS 1e6
/*
* This is an implementation of the clock discipline algorithm described
@@ -788,9 +787,9 @@ local_clock(
if (ntv.constant < 0)
ntv.constant = 0;
- ntv.esterror = (long)(clock_jitter * MICROSECONDS);
+ ntv.esterror = (long)(clock_jitter * US_PER_S);
ntv.maxerror = (long)((sys_rootdelay / 2 +
- sys_rootdisp) * MICROSECONDS);
+ sys_rootdisp) * US_PER_S);
ntv.status = STA_PLL;
/*
@@ -861,7 +860,7 @@ local_clock(
if (fabs(clock_frequency) > NTP_MAXFREQ)
msyslog(LOG_NOTICE,
"frequency error %.0f PPM exceeds tolerance %.0f PPM",
- clock_frequency * MICROSECONDS, NTP_MAXFREQ * MICROSECONDS);
+ clock_frequency * US_PER_S, NTP_MAXFREQ * US_PER_S);
dtemp = SQUARE(clock_frequency - drift_comp);
if (clock_frequency > NTP_MAXFREQ)
drift_comp = NTP_MAXFREQ;
@@ -923,8 +922,8 @@ local_clock(
if (debug)
printf(
"local_clock: offset %.9f jit %.9f freq %.6f stab %.3f poll %d\n",
- clock_offset, clock_jitter, drift_comp * MICROSECONDS,
- clock_stability * MICROSECONDS, sys_poll);
+ clock_offset, clock_jitter, drift_comp * US_PER_S,
+ clock_stability * US_PER_S, sys_poll);
#endif /* DEBUG */
return (rval);
#endif /* ENABLE_LOCKCLOCK */
@@ -1098,7 +1097,7 @@ set_freq(
}
#endif /* HAVE_KERNEL_PLL */
mprintf_event(EVNT_FSET, NULL, "%s %.6f PPM", loop_desc,
- drift_comp * MICROSECONDS);
+ drift_comp * US_PER_S);
}
#endif /* HAVE_LOCKCLOCK */
@@ -1267,7 +1266,7 @@ loop_config(
* calibration phase.
*/
{
- double ftemp = init_drift_comp / MICROSECONDS;
+ double ftemp = init_drift_comp / US_PER_S;
if (ftemp > NTP_MAXFREQ)
ftemp = NTP_MAXFREQ;
else if (ftemp < -NTP_MAXFREQ)
@@ -1310,7 +1309,7 @@ loop_config(
break;
case LOOP_PHI: /* dispersion threshold (dispersion) */
- clock_phi = freq / MICROSECONDS;
+ clock_phi = freq / US_PER_S;
break;
case LOOP_FREQ: /* initial frequency (freq) */
=====================================
ntptime/ntptime.c
=====================================
--- a/ntptime/ntptime.c
+++ b/ntptime/ntptime.c
@@ -30,7 +30,7 @@
* Convert usec to a time stamp fraction.
*/
# define TVUTOTSF(tvu) \
- (uint32_t)((((uint64_t)(tvu) << 32) + MICROSECONDS / 2) / MICROSECONDS)
+ (uint32_t)((((uint64_t)(tvu) << 32) + US_PER_S / 2) / US_PER_S)
#define NS_PER_MS_FLOAT 1000.0
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/120c479b395a22994290ca91b40fe7128ba90b92...3357c0c23a96dfe1786d24499d0c79eac464ab8d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170315/d9488956/attachment.html>
More information about the vc
mailing list