From 18de587b8e6b0d86c0070fac4aa4dcf137bdf119 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 14 Apr 2005 10:31:27 +0000 Subject: [PATCH] Use corrected system time internally, adjust old offsets after doing a relative adjust of kern.ntp.delta. Change the default scaling interval to 0.005 and 0.010, which means that offsets smaller than 5ms double to probe interval, anything greater than 10ms uses the default. The value of QSCALE_OFF_MIN can be decreases even more, once frequency correction is implemented. --- usr.sbin/ntpd/patches/ntp.c.patch | 23 +++++++++++++++++ usr.sbin/ntpd/patches/ntpd.c.patch | 37 +++++++++++++++++++++++++--- usr.sbin/ntpd/patches/ntpd.h.patch | 22 ++++++++++++++++- usr.sbin/ntpd/patches/server.c.patch | 25 ++++++++++++++++--- usr.sbin/ntpd/patches/util.c.patch | 35 ++++++++++++++++++++++++++ 5 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 usr.sbin/ntpd/patches/ntp.c.patch create mode 100644 usr.sbin/ntpd/patches/util.c.patch diff --git a/usr.sbin/ntpd/patches/ntp.c.patch b/usr.sbin/ntpd/patches/ntp.c.patch new file mode 100644 index 0000000000..1f8dea145b --- /dev/null +++ b/usr.sbin/ntpd/patches/ntp.c.patch @@ -0,0 +1,23 @@ +$DragonFly: src/usr.sbin/ntpd/patches/Attic/ntp.c.patch,v 1.3 2005/04/14 10:31:27 joerg Exp $ + +--- ntp.c 25 Feb 2005 16:43:19 -0000 1.6 ++++ ntp.c 12 Apr 2005 20:13:45 -0000 +@@ -422,12 +422,15 @@ + if (peers[offset_cnt / 2]->addr->ss.ss_family == AF_INET) + conf->status.refid = ((struct sockaddr_in *) + &peers[offset_cnt / 2]->addr->ss)->sin_addr.s_addr; ++ ++ TAILQ_FOREACH(p, &conf->ntp_peers, entry) { ++ for (i = 0; i < OFFSET_ARRAY_SIZE; i++) ++ p->reply[i].offset -= offset_median; ++ p->update.good = 0; ++ } + } + + free(peers); +- +- TAILQ_FOREACH(p, &conf->ntp_peers, entry) +- p->update.good = 0; + } + + int diff --git a/usr.sbin/ntpd/patches/ntpd.c.patch b/usr.sbin/ntpd/patches/ntpd.c.patch index e577361fca..cce11bc494 100644 --- a/usr.sbin/ntpd/patches/ntpd.c.patch +++ b/usr.sbin/ntpd/patches/ntpd.c.patch @@ -1,8 +1,16 @@ -$DragonFly: src/usr.sbin/ntpd/patches/Attic/ntpd.c.patch,v 1.5 2005/02/25 16:43:20 joerg Exp $ +$DragonFly: src/usr.sbin/ntpd/patches/Attic/ntpd.c.patch,v 1.6 2005/04/14 10:31:27 joerg Exp $ --- ntpd.c.orig 2004-11-09 20:39:54.000000000 +0100 +++ ntpd.c 2004-11-09 20:40:48.000000000 +0100 -@@ -34,7 +34,7 @@ +@@ -18,6 +18,7 @@ + + #include + #include ++#include + #include + #include + #include +@@ -34,7 +35,7 @@ #include "ntpd.h" void sighdlr(int); @@ -11,7 +19,7 @@ $DragonFly: src/usr.sbin/ntpd/patches/Attic/ntpd.c.patch,v 1.5 2005/02/25 16:43: int main(int, char *[]); int check_child(pid_t, const char *); int dispatch_imsg(struct ntpd_conf *); -@@ -63,12 +63,10 @@ +@@ -63,12 +64,10 @@ } } @@ -26,3 +34,26 @@ $DragonFly: src/usr.sbin/ntpd/patches/Attic/ntpd.c.patch,v 1.5 2005/02/25 16:43: exit(1); } +@@ -307,16 +306,18 @@ + void + ntpd_adjtime(double d) + { +- struct timeval tv; ++ int64_t adjust; + + if (d >= (double)LOG_NEGLIGEE / 1000 || + d <= -1 * (double)LOG_NEGLIGEE / 1000) + log_info("adjusting local clock by %fs", d); + else + log_debug("adjusting local clock by %fs", d); +- d_to_tv(d, &tv); +- if (adjtime(&tv, NULL) == -1) +- log_warn("adjtime failed"); ++ adjust = d * 1e9; ++ ++ if (sysctlbyname("kern.ntp.adjust", NULL, NULL, &adjust, ++ sizeof(adjust))) ++ log_info("adjtime failed"); + } + + void diff --git a/usr.sbin/ntpd/patches/ntpd.h.patch b/usr.sbin/ntpd/patches/ntpd.h.patch index aa9f6c77cc..0c8ca87a0b 100644 --- a/usr.sbin/ntpd/patches/ntpd.h.patch +++ b/usr.sbin/ntpd/patches/ntpd.h.patch @@ -1,4 +1,4 @@ -$DragonFly: src/usr.sbin/ntpd/patches/Attic/ntpd.h.patch,v 1.4 2005/02/28 21:40:49 joerg Exp $ +$DragonFly: src/usr.sbin/ntpd/patches/Attic/ntpd.h.patch,v 1.5 2005/04/14 10:31:27 joerg Exp $ Index: ntpd.h =================================================================== @@ -16,3 +16,23 @@ diff -u -r1.6 ntpd.h #define NTPD_USER "_ntp" #define CONFFILE "/etc/ntpd.conf" +@@ -49,8 +51,8 @@ + + #define MAX_SERVERS_DNS 8 + +-#define QSCALE_OFF_MIN 0.05 +-#define QSCALE_OFF_MAX 0.50 ++#define QSCALE_OFF_MIN 0.005 ++#define QSCALE_OFF_MAX 0.010 + + #define QUERYTIME_MAX 15 /* single query might take n secs max */ + #define OFFSET_ARRAY_SIZE 8 +@@ -247,6 +249,8 @@ + + /* util.c */ + double gettime(void); ++double gettime_corrected(void); ++double getoffset(void); + void d_to_tv(double, struct timeval *); + double lfp_to_d(struct l_fixedpt); + struct l_fixedpt d_to_lfp(double); diff --git a/usr.sbin/ntpd/patches/server.c.patch b/usr.sbin/ntpd/patches/server.c.patch index 0189c15582..5f3a9eecbf 100644 --- a/usr.sbin/ntpd/patches/server.c.patch +++ b/usr.sbin/ntpd/patches/server.c.patch @@ -1,5 +1,22 @@ -$DragonFly: src/usr.sbin/ntpd/patches/Attic/server.c.patch,v 1.2 2005/02/28 21:40:49 joerg Exp $ +$DragonFly: src/usr.sbin/ntpd/patches/Attic/server.c.patch,v 1.3 2005/04/14 10:31:27 joerg Exp $ ---- server.c.orig 2004-11-09 20:34:55.000000000 +0100 -+++ server.c 2004-11-09 20:38:09.000000000 +0100 -@@ -0,0 +0,0 @@ +--- server.c 25 Feb 2005 16:43:19 -0000 1.4 ++++ server.c 12 Apr 2005 20:13:45 -0000 +@@ -120,7 +120,7 @@ + fatal("recvfrom"); + } + +- rectime = gettime(); ++ rectime = gettime_corrected(); + + if (ntp_getmsg(buf, size, &query) == -1) + return (0); +@@ -139,7 +139,7 @@ + reply.precision = conf->status.precision; + reply.rectime = d_to_lfp(rectime); + reply.reftime = d_to_lfp(conf->status.reftime); +- reply.xmttime = d_to_lfp(gettime()); ++ reply.xmttime = d_to_lfp(gettime_corrected()); + reply.orgtime = query.xmttime; + reply.rootdelay = d_to_sfp(conf->status.rootdelay); + diff --git a/usr.sbin/ntpd/patches/util.c.patch b/usr.sbin/ntpd/patches/util.c.patch new file mode 100644 index 0000000000..a5371ed1f8 --- /dev/null +++ b/usr.sbin/ntpd/patches/util.c.patch @@ -0,0 +1,35 @@ +$DragonFly: src/usr.sbin/ntpd/patches/Attic/util.c.patch,v 1.3 2005/04/14 10:31:27 joerg Exp $ + +--- util.c 25 Feb 2005 16:43:19 -0000 1.5 ++++ util.c 12 Apr 2005 20:13:45 -0000 +@@ -16,6 +16,8 @@ + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + ++#include ++#include + #include + #include + +@@ -32,6 +34,21 @@ + return (tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec); + } + ++double ++gettime_corrected(void) ++{ ++ return (gettime() + getoffset()); ++} ++ ++double ++getoffset(void) ++{ ++ int64_t offset; ++ size_t len = sizeof(offset); ++ if (sysctlbyname("kern.ntp.delta", &offset, &len, NULL, 0)) ++ return (0.0); ++ return (offset * 1e-9); ++} + + void + d_to_tv(double d, struct timeval *tv) -- 2.35.2