From b6c201f1e19925207accfaf12cb2dfea0a089fba Mon Sep 17 00:00:00 2001 From: ckuethe <> Date: Thu, 4 Jun 2009 23:39:46 +0000 Subject: [PATCH] After calling adjfreq to correct the clock's rate, measure and fix the clock offset. This avoids future frequency adjustments based on measurements of a clock that was being adjusted. End result: more stable clock and better frequency convergence. Also, fix a mis-ordered structure member while I'm here. ok henning --- src/usr.sbin/ntpd/ntp.c | 8 +++++++- src/usr.sbin/ntpd/ntpd.h | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c index 7e9eff3b..4144bd7a 100644 --- a/src/usr.sbin/ntpd/ntp.c +++ b/src/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.110 2009/01/26 11:51:50 henning Exp $ */ +/* $OpenBSD: ntp.c,v 1.111 2009/06/04 23:39:45 ckuethe Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -530,6 +530,11 @@ priv_adjfreq(double offset) if (!conf->status.synced) return; + if (conf->filters & FILTER_ADJFREQ){ + conf->filters &= ~FILTER_ADJFREQ; + return; + } + conf->freq.samples++; if (conf->freq.samples <= 0) @@ -558,6 +563,7 @@ priv_adjfreq(double offset) freq = -MAX_FREQUENCY_ADJUST; imsg_compose(ibuf_main, IMSG_ADJFREQ, 0, 0, &freq, sizeof(freq)); + conf->filters |= FILTER_ADJFREQ; conf->freq.xy = 0.0; conf->freq.x = 0.0; conf->freq.y = 0.0; diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h index 42bc0734..86829098 100644 --- a/src/usr.sbin/ntpd/ntpd.h +++ b/src/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.100 2009/05/13 15:08:10 stevesk Exp $ */ +/* $OpenBSD: ntpd.h,v 1.101 2009/06/04 23:39:46 ckuethe Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -62,6 +62,7 @@ #define REPORT_INTERVAL (24*60*60) /* interval between status reports */ #define MAX_SEND_ERRORS 3 /* max send errors before reconnect */ +#define FILTER_ADJFREQ 0x01 /* set after doing adjfreq */ #define SENSOR_DATA_MAXAGE (15*60) #define SENSOR_QUERY_INTERVAL 30 @@ -171,11 +172,12 @@ struct ntpd_conf { TAILQ_HEAD(ntp_conf_sensors, ntp_conf_sensor) ntp_conf_sensors; struct ntp_status status; struct ntp_freq freq; + u_int32_t scale; u_int8_t listen_all; u_int8_t settime; u_int8_t debug; - u_int32_t scale; u_int8_t noaction; + u_int8_t filters; }; struct buf {