[Git][NTPsec/ntpsec][saw6-fix] 3 commits: Restore cross-era interoperability via pivoting timestamps on build data.
Eric S. Raymond
gitlab at mg.gitlab.com
Mon Apr 17 23:48:37 UTC 2017
Eric S. Raymond pushed to branch saw6-fix at NTPsec / ntpsec
Commits:
c0973bb2 by Eric S. Raymond at 2017-04-17T12:15:02-04:00
Restore cross-era interoperability via pivoting timestamps on build data.
This repairs an error first introduced some weeks ago during an l_fp cleanup
pass and compounded by later changes. It was insidious because the effects
would not have shown until 2036, at which point interoperability between
ntpd instances built before and after the era 1 epoch would have broken.
- - - - -
91cad2a4 by James Browning at 2017-04-17T13:41:15-07:00
New systemd units to run NTPviz data gathering and graphing.
The units run data acquisition every five minutes, daily stats
graphing every hour and weekly stats graphing every 12 hours.
Signed-off-by: Gary E. Miller <gem at rellim.com>
- - - - -
190844c0 by Ian Bruene at 2017-04-17T23:48:08+00:00
Fixed lack of 4th digit in unitless display.
- - - - -
12 changed files:
- + etc/ntploggps.service
- + etc/ntploggps.timer
- + etc/ntplogtemp.service
- + etc/ntplogtemp.timer
- + etc/ntpviz-daily.service
- + etc/ntpviz-daily.timer
- + etc/ntpviz-weekly.service
- + etc/ntpviz-weekly.timer
- include/ntp_calendar.h
- libntp/ntp_calendar.c
- libntp/systime.c
- pylib/util.py
Changes:
=====================================
etc/ntploggps.service
=====================================
--- /dev/null
+++ b/etc/ntploggps.service
@@ -0,0 +1,8 @@
+[Unit]
+Documentation=man:ntploggps(1)
+Description=GPS information logger for ntpviz
+Requires=gpsd.service
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/ntploggps -o -l /var/log/ntpstats/gpsd
=====================================
etc/ntploggps.timer
=====================================
--- /dev/null
+++ b/etc/ntploggps.timer
@@ -0,0 +1,10 @@
+[Unit]
+Description=Run ntploggps every five minutes
+
+[Timer]
+OnBootSec=5min
+OnUnitActiveSec=5min
+Persistent=true
+
+[Install]
+WantedBy=timers.target
=====================================
etc/ntplogtemp.service
=====================================
--- /dev/null
+++ b/etc/ntplogtemp.service
@@ -0,0 +1,7 @@
+[Unit]
+Documentation=man:ntplogtemp(1)
+Description=Temperature information logger for ntpviz
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/ntplogtemp -o -l /var/log/ntpstats/temp
=====================================
etc/ntplogtemp.timer
=====================================
--- /dev/null
+++ b/etc/ntplogtemp.timer
@@ -0,0 +1,10 @@
+[Unit]
+Description=Run ntplogtemp every five minutes
+
+[Timer]
+OnBootSec=5min
+OnUnitActiveSec=5min
+Persistent=true
+
+[Install]
+WantedBy=timers.target
=====================================
etc/ntpviz-daily.service
=====================================
--- /dev/null
+++ b/etc/ntpviz-daily.service
@@ -0,0 +1,8 @@
+[Unit]
+Documentation=man:ntpviz(1)
+Description=Graph daily information for NTP
+Requires=ntpd.service
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/ntpviz -w l -p 1 -o /var/www/localhost/htdocs/day
=====================================
etc/ntpviz-daily.timer
=====================================
--- /dev/null
+++ b/etc/ntpviz-daily.timer
@@ -0,0 +1,9 @@
+[Unit]
+Description=Run ntpviz for daily data graphing once an hour
+
+[Timer]
+OnCalendar=*:53:00
+Persistent=true
+
+[Install]
+WantedBy=timers.target
=====================================
etc/ntpviz-weekly.service
=====================================
--- /dev/null
+++ b/etc/ntpviz-weekly.service
@@ -0,0 +1,8 @@
+[Unit]
+Documentation=man:ntpviz(1)
+Description=Graph weekly information for NTP
+Requires=ntpd.service
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/ntpviz -w l -p 7 -o /var/www/localhost/htdocs/week
=====================================
etc/ntpviz-weekly.timer
=====================================
--- /dev/null
+++ b/etc/ntpviz-weekly.timer
@@ -0,0 +1,9 @@
+[Unit]
+Description=Run ntpviz for daily weekly graphing twice a day
+
+[Timer]
+OnCalendar=11,23:45:00
+Persistent=true
+
+[Install]
+WantedBy=timers.target
=====================================
include/ntp_calendar.h
=====================================
--- a/include/ntp_calendar.h
+++ b/include/ntp_calendar.h
@@ -195,23 +195,23 @@ ntpcal_daysec_to_date(struct calendar * /* jt */, int32_t /* secs */);
extern int32_t
ntpcal_date_to_daysec(const struct calendar *);
-/* used by ntpd/refclock_gpsd.c */
-extern int32_t
-ntpcal_tm_to_daysec(const struct tm * /* utm */);
-
-
/*
- * convert a RataDie to the RataDie of start of the calendar month.
+ * Take a value of seconds since midnight and split it into hhmmss in
+ * a 'struct tm'. Return excessive days.
*/
extern int32_t
-ntpcal_rd_to_mstart(int32_t /* year */);
+ntpcal_daysec_to_tm(struct tm * /* utm */, int32_t /* secs */);
+extern int32_t
+ntpcal_tm_to_daysec(const struct tm * /* utm */);
+extern int
+ntpcal_daysplit_to_date(struct calendar * /* jt */,
+ const ntpcal_split * /* ds */, int32_t /* dof */);
extern int
ntpcal_time_to_date(struct calendar * /* jd */, const time64_t /* ts */);
-/* used by ntpd/refclock_nmea.c */
extern int32_t
ntpcal_periodic_extend(int32_t /* pivot */, int32_t /* value */,
int32_t /* cycle */) __attribute__((const));
@@ -219,11 +219,12 @@ ntpcal_periodic_extend(int32_t /* pivot */, int32_t /* value */,
extern int
ntpcal_ntp64_to_date(struct calendar * /* jd */, const time64_t /* ntp */);
-/* used by ntpd/refclock_nmea.c */
extern int
ntpcal_ntp_to_date(struct calendar * /* jd */, uint32_t /* ntp */,
const time_t * /* pivot */);
+extern time_t
+ntpcal_date_to_time(const struct calendar * /* jd */);
/*
=====================================
libntp/ntp_calendar.c
=====================================
--- a/libntp/ntp_calendar.c
+++ b/libntp/ntp_calendar.c
@@ -582,7 +582,6 @@ ntpcal_rd_to_date(
return retv ? retv : leaps;
}
-
/*
*---------------------------------------------------------------------
* Take a value of seconds since midnight and split it into hhmmss in a
@@ -606,7 +605,49 @@ ntpcal_daysec_to_date(
return days;
}
+/*
+ *---------------------------------------------------------------------
+ * Take a value of seconds since midnight and split it into hhmmss in a
+ * 'struct tm'.
+ *---------------------------------------------------------------------
+ */
+int32_t
+ntpcal_daysec_to_tm(
+ struct tm *utm,
+ int32_t sec
+ )
+{
+ int32_t days;
+ int32_t ts[3];
+
+ days = priv_timesplit(ts, sec);
+ utm->tm_hour = ts[0];
+ utm->tm_min = ts[1];
+ utm->tm_sec = ts[2];
+
+ return days;
+}
+/*
+ *---------------------------------------------------------------------
+ * take a split representation for day/second-of-day and day offset
+ * and convert it to a 'struct calendar'. The seconds will be normalised
+ * into the range of a day, and the day will be adjusted accordingly.
+ *
+ * returns >0 if the result is in a leap year, 0 if in a regular
+ * year and <0 if the result did not fit into the calendar struct.
+ *---------------------------------------------------------------------
+ */
+int
+ntpcal_daysplit_to_date(
+ struct calendar *jd,
+ const ntpcal_split *ds,
+ int32_t dof
+ )
+{
+ dof += ntpcal_daysec_to_date(jd, ds->lo);
+ return ntpcal_rd_to_date(jd, ds->hi + dof);
+}
/*
*---------------------------------------------------------------------
@@ -863,25 +904,6 @@ ntpcal_date_to_rd(
/*
*---------------------------------------------------------------------
- * For a given RD, get the RD of the associated month start.
- *---------------------------------------------------------------------
- */
-int32_t
-ntpcal_rd_to_mstart(
- int32_t rd
- )
-{
- ntpcal_split split;
- int32_t leaps;
-
- split = ntpcal_split_eradays(rd - 1, &leaps);
- split = ntpcal_split_yeardays(split.lo, leaps);
-
- return rd - split.lo;
-}
-
-/*
- *---------------------------------------------------------------------
* take a 'struct calendar' and get the seconds-of-day from it.
*---------------------------------------------------------------------
*/
@@ -908,6 +930,27 @@ ntpcal_tm_to_daysec(
utm->tm_sec);
}
+/*
+ *---------------------------------------------------------------------
+ * take a 'struct calendar' and convert it to a 'time_t'
+ *---------------------------------------------------------------------
+ */
+time_t
+ntpcal_date_to_time(
+ const struct calendar *jd
+ )
+{
+ time64_t join;
+ int32_t days, secs;
+
+ days = ntpcal_date_to_rd(jd) - DAY_UNIX_STARTS;
+ secs = ntpcal_date_to_daysec(jd);
+ join = ntpcal_dayjoin(days, secs);
+
+ /* might truncate if time_t is 32 bits */
+ return (time_t)join;
+}
+
int
ntpcal_ntp64_to_date(
@@ -941,5 +984,4 @@ ntpcal_ntp_to_date(
return ntpcal_ntp64_to_date(jd, ntp64);
}
-
/* -*-EOF-*- */
=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -317,22 +317,71 @@ step_systime(
int (*settime)(struct timespec *)
)
{
+ time_t pivot; /* for ntp era unfolding */
struct timespec timets, tslast, tsdiff;
- struct timespec ofs_ts; /* desired offset as teimspec */
+ struct calendar jd;
+ l_fp fp_ofs, fp_sys; /* offset and target system time in FP */
- /* get the complete jump distance as timespec */
- ofs_ts = d_to_tspec(step + sys_residual);
+ /*
+ * Get pivot time for NTP era unfolding. Since we don't step
+ * very often, we can afford to do the whole calculation from
+ * scratch. And we're not in the time-critical path yet.
+ */
+#if NTP_SIZEOF_TIME_T > 4
+ /*
+ * This code makes sure the resulting time stamp for the new
+ * system time is in the 2^32 seconds starting at 1970-01-01,
+ * 00:00:00 UTC.
+ */
+ pivot = 0x80000000;
+#if USE_COMPILETIME_PIVOT
+ /*
+ * Add the compile time minus 10 years to get a possible target
+ * area of (compile time - 10 years) to (compile time + 126
+ * years). This should be sufficient for a given binary of
+ * NTPD.
+ */
+ if (ntpcal_get_build_date(&jd)) {
+ jd.year -= 10;
+ pivot += ntpcal_date_to_time(&jd);
+ } else {
+ msyslog(LOG_ERR,
+ "step_systime: assume 1970-01-01 as build date");
+ }
+#else
+ UNUSED_LOCAL(jd);
+#endif /* USE_COMPILETIME_PIVOT */
+#else
+ UNUSED_LOCAL(jd);
+ /* This makes sure the resulting time stamp is on or after
+ * 1969-12-31/23:59:59 UTC and gives us additional two years,
+ * from the change of NTP era in 2036 to the UNIX rollover in
+ * 2038. (Minus one second, but that won't hurt.) We *really*
+ * need a longer 'time_t' after that! Or a different baseline,
+ * but that would cause other serious trouble, too.
+ */
+ pivot = 0x7FFFFFFF;
+#endif
+
+ /* get the complete jump distance as l_fp */
+ fp_sys = dtolfp(sys_residual);
+ fp_ofs = dtolfp(step);
+ fp_ofs += fp_sys;
/* ---> time-critical path starts ---> */
- /* get the current time as, without fuzz, as struct timespec */
+ /* get the current time as l_fp (without fuzz) and as struct timespec */
get_ostime(&timets);
+ fp_sys = tspec_stamp_to_lfp(timets);
+
+ /* get the target time as l_fp */
+ fp_sys += fp_ofs;
- /* add offset */
- tslast = add_tspec(timets, ofs_ts);
+ /* unfold the new system time */
+ timets = lfp_stamp_to_tspec(fp_sys, &pivot);
/* now set new system time */
- if (settime(&tslast) != 0) {
+ if (settime(&timets) != 0) {
msyslog(LOG_ERR, "step_systime: %m");
return false;
}
@@ -340,6 +389,8 @@ step_systime(
/* <--- time-critical path ended with call to the settime hook <--- */
/* only used for utmp/wtmpx time-step recording */
+ tslast.tv_sec = timets.tv_sec;
+ tslast.tv_nsec = timets.tv_nsec;
sys_residual = 0;
lamport_violated = (step < 0);
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -756,8 +756,7 @@ class PeerSummary:
reach = value
elif name == "delay":
estdelay = rawvalue if self.showunits else value
- elif name == "delay-s":
- if len(value) > 6 and value[-7] == ".":
+ if len(rawvalue) > 6 and rawvalue[-7] == ".":
saw6 = True
elif name == "offset":
estoffset = rawvalue if self.showunits else value
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/42efe98db36351a2427e9af4632c173fbc850896...190844c08953cab8a3b8d5d86b1678270d16d13d
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/42efe98db36351a2427e9af4632c173fbc850896...190844c08953cab8a3b8d5d86b1678270d16d13d
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170417/26cd124d/attachment.html>
More information about the vc
mailing list