diff options
author | Miroslav Lichvar <mlichvar@redhat.com> | 2014-09-18 16:19:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-09-24 15:37:17 +0200 |
commit | 590a22cf8d100edc968aa5d691c1ca3000654350 (patch) | |
tree | e69adfbbd74930d107d1adeb8b16bf2acf3cc3d5 | |
parent | fb143f783da8a3b13ae7a35f6750c2d0c86081e6 (diff) | |
download | busybox-590a22cf8d100edc968aa5d691c1ca3000654350.tar.gz |
ntpd: split out poll adjusting code
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ntpd.c | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 3c708c1c5..2d1ad69a0 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -1679,6 +1679,41 @@ poll_interval(int exponent) return interval; } static NOINLINE void +adjust_poll(int count) +{ + G.polladj_count += count; + if (G.polladj_count > POLLADJ_LIMIT) { + G.polladj_count = 0; + if (G.poll_exp < MAXPOLL) { + G.poll_exp++; + VERB4 bb_error_msg("polladj: discipline_jitter:%f ++poll_exp=%d", + G.discipline_jitter, G.poll_exp); + } + } else if (G.polladj_count < -POLLADJ_LIMIT || (count < 0 && G.poll_exp >= BIGPOLL)) { + G.polladj_count = 0; + if (G.poll_exp > MINPOLL) { + llist_t *item; + + G.poll_exp--; + /* Correct p->next_action_time in each peer + * which waits for sending, so that they send earlier. + * Old pp->next_action_time are on the order + * of t + (1 << old_poll_exp) + small_random, + * we simply need to subtract ~half of that. + */ + for (item = G.ntp_peers; item != NULL; item = item->link) { + peer_t *pp = (peer_t *) item->data; + if (pp->p_fd < 0) + pp->next_action_time -= (1 << G.poll_exp); + } + VERB4 bb_error_msg("polladj: discipline_jitter:%f --poll_exp=%d", + G.discipline_jitter, G.poll_exp); + } + } else { + VERB4 bb_error_msg("polladj: count:%d", G.polladj_count); + } +} +static NOINLINE void recv_and_process_peer_pkt(peer_t *p) { int rc; @@ -1837,7 +1872,8 @@ recv_and_process_peer_pkt(peer_t *p) */ if (fabs(q->filter_offset) >= POLLDOWN_OFFSET) { VERB4 bb_error_msg("offset:%+f > POLLDOWN_OFFSET", q->filter_offset); - goto poll_down; + adjust_poll(-POLLADJ_LIMIT * 3); + rc = 0; } } } @@ -1853,43 +1889,9 @@ recv_and_process_peer_pkt(peer_t *p) if (rc > 0 && G.offset_to_jitter_ratio <= POLLADJ_GATE) { /* was += G.poll_exp but it is a bit * too optimistic for my taste at high poll_exp's */ - G.polladj_count += MINPOLL; - if (G.polladj_count > POLLADJ_LIMIT) { - G.polladj_count = 0; - if (G.poll_exp < MAXPOLL) { - G.poll_exp++; - VERB4 bb_error_msg("polladj: discipline_jitter:%f ++poll_exp=%d", - G.discipline_jitter, G.poll_exp); - } - } else { - VERB4 bb_error_msg("polladj: incr:%d", G.polladj_count); - } + adjust_poll(MINPOLL); } else { - G.polladj_count -= G.poll_exp * 2; - if (G.polladj_count < -POLLADJ_LIMIT || G.poll_exp >= BIGPOLL) { - poll_down: - G.polladj_count = 0; - if (G.poll_exp > MINPOLL) { - llist_t *item; - - G.poll_exp--; - /* Correct p->next_action_time in each peer - * which waits for sending, so that they send earlier. - * Old pp->next_action_time are on the order - * of t + (1 << old_poll_exp) + small_random, - * we simply need to subtract ~half of that. - */ - for (item = G.ntp_peers; item != NULL; item = item->link) { - peer_t *pp = (peer_t *) item->data; - if (pp->p_fd < 0) - pp->next_action_time -= (1 << G.poll_exp); - } - VERB4 bb_error_msg("polladj: discipline_jitter:%f --poll_exp=%d", - G.discipline_jitter, G.poll_exp); - } - } else { - VERB4 bb_error_msg("polladj: decr:%d", G.polladj_count); - } + adjust_poll(-G.poll_exp * 2); } } |