diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-07-18 12:59:42 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-07-18 12:59:42 +0000 |
commit | 73d5425879a7329ba6be5b1c2ff8a45c60d8dfa9 (patch) | |
tree | da82dced48259c076098cb92ef16a4a3bd1cbc2e /usr.sbin/ntpd/ntp.c | |
parent | 6c018fb721847e86bbfbbb3b93be011eadd837e6 (diff) |
query interval scaling, episode II
1) base the interval calculation on the offset from the last reply, not
from the last peer update.
Allows us to send more queries again faster when the local clock
diverges too much
2) every time we form a peer update (for which we need 8 replies)
check wether we have a ready peer update for all peers that are
currently trusted, and if so, calculate the total offset and call
adjtime().
that means that adjtime is no longer called in fixed intervals
but whenever we have enough data to reliably calculate the local
clock offset.
In practice, that means we call adjtime() less often, but with
probably better data.
3) invalidate peer updates after beeing used. no point in re-using them
- this resulted in calling adjtime() multiple times with the same
offset, which doesn't make sense
tested by many
Diffstat (limited to 'usr.sbin/ntpd/ntp.c')
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index efeddd56a18..5326c28f5e5 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.24 2004/07/14 20:16:31 henning Exp $ */ +/* $OpenBSD: ntp.c,v 1.25 2004/07/18 12:59:41 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -34,10 +34,10 @@ volatile sig_atomic_t ntp_quit = 0; struct imsgbuf ibuf_main; struct l_fixedpt ref_ts; +struct ntpd_conf *conf; void ntp_sighdlr(int); int ntp_dispatch_imsg(void); -void ntp_adjtime(struct ntpd_conf *); void ntp_sighdlr(int sig) @@ -51,7 +51,7 @@ ntp_sighdlr(int sig) } pid_t -ntp_main(int pipe_prnt[2], struct ntpd_conf *conf) +ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) { int nfds, i, j, idx_peers, timeout; u_int pfd_elms = 0, idx2peer_elms = 0; @@ -63,7 +63,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *conf) struct listen_addr *la; struct ntp_peer *p; struct ntp_peer **idx2peer = NULL; - time_t nextaction, next_adjtime; + time_t nextaction; void *newp; switch (pid = fork()) { @@ -88,6 +88,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *conf) setproctitle("ntp engine"); + conf = nconf; setup_listeners(se, conf, &listener_cnt); if (setgroups(1, &pw->pw_gid) || @@ -118,8 +119,6 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *conf) TAILQ_FOREACH(p, &conf->ntp_peers, entry) peer_cnt++; - next_adjtime = time(NULL) + INTERVAL_ADJTIME; - while (ntp_quit == 0) { if (peer_cnt > idx2peer_elms || peer_cnt + IDX2PEER_RESERVE < idx2peer_elms) { @@ -152,7 +151,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *conf) bzero(pfd, sizeof(struct pollfd) * pfd_elms); bzero(idx2peer, sizeof(void *) * idx2peer_elms); - nextaction = next_adjtime; + nextaction = time(NULL) + 3600; pfd[PFD_PIPE_MAIN].fd = ibuf_main.fd; pfd[PFD_PIPE_MAIN].events = POLLIN; @@ -193,11 +192,6 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *conf) } } - if (next_adjtime <= time(NULL)) { - next_adjtime = time(NULL) + INTERVAL_ADJTIME; - ntp_adjtime(conf); - } - if (ibuf_main.w.queued > 0) pfd[PFD_PIPE_MAIN].events |= POLLOUT; @@ -277,24 +271,19 @@ ntp_dispatch_imsg(void) } void -ntp_adjtime(struct ntpd_conf *conf) +ntp_adjtime(void) { struct ntp_peer *p; double offset_median = 0; int offset_cnt = 0; TAILQ_FOREACH(p, &conf->ntp_peers, entry) { - if (!p->update.good) - continue; - - if (p->update.rcvd + REPLY_MAXAGE < time(NULL)) { - p->update.good = 0; - continue; - } - if (p->trustlevel < TRUSTLEVEL_BADPEER) continue; + if (!p->update.good) + return; + offset_median += p->update.offset; offset_cnt++; } @@ -307,4 +296,7 @@ ntp_adjtime(struct ntpd_conf *conf) conf->status.reftime = gettime(); conf->status.leap = LI_NOWARNING; /* XXX */ } + + TAILQ_FOREACH(p, &conf->ntp_peers, entry) + p->update.good = 0; } |