diff options
-rw-r--r-- | networking/ntpd.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index e86f72f83..938c7f040 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -107,7 +107,10 @@ | |||
107 | #define FREQ_TOLERANCE 0.000015 /* frequency tolerance (15 PPM) */ | 107 | #define FREQ_TOLERANCE 0.000015 /* frequency tolerance (15 PPM) */ |
108 | #define BURSTPOLL 0 /* initial poll */ | 108 | #define BURSTPOLL 0 /* initial poll */ |
109 | #define MINPOLL 5 /* minimum poll interval. std ntpd uses 6 (6: 64 sec) */ | 109 | #define MINPOLL 5 /* minimum poll interval. std ntpd uses 6 (6: 64 sec) */ |
110 | #define BIGPOLL 10 /* drop to lower poll at any trouble (10: 17 min) */ | 110 | /* If offset > discipline_jitter * POLLADJ_GATE, and poll interval is >= 2^BIGPOLL, |
111 | * then it is decreased _at once_. (If < 2^BIGPOLL, it will be decreased _eventually_). | ||
112 | */ | ||
113 | #define BIGPOLL 10 /* 2^10 sec ~= 17 min */ | ||
111 | #define MAXPOLL 12 /* maximum poll interval (12: 1.1h, 17: 36.4h). std ntpd uses 17 */ | 114 | #define MAXPOLL 12 /* maximum poll interval (12: 1.1h, 17: 36.4h). std ntpd uses 17 */ |
112 | /* Actively lower poll when we see such big offsets. | 115 | /* Actively lower poll when we see such big offsets. |
113 | * With STEP_THRESHOLD = 0.125, it means we try to sync more aggressively | 116 | * With STEP_THRESHOLD = 0.125, it means we try to sync more aggressively |
@@ -124,13 +127,13 @@ | |||
124 | 127 | ||
125 | /* Poll-adjust threshold. | 128 | /* Poll-adjust threshold. |
126 | * When we see that offset is small enough compared to discipline jitter, | 129 | * When we see that offset is small enough compared to discipline jitter, |
127 | * we grow a counter: += MINPOLL. When it goes over POLLADJ_LIMIT, | 130 | * we grow a counter: += MINPOLL. When counter goes over POLLADJ_LIMIT, |
128 | * we poll_exp++. If offset isn't small, counter -= poll_exp*2, | 131 | * we poll_exp++. If offset isn't small, counter -= poll_exp*2, |
129 | * and when it goes below -POLLADJ_LIMIT, we poll_exp-- | 132 | * and when it goes below -POLLADJ_LIMIT, we poll_exp--. |
130 | * (bumped from 30 to 40 since otherwise I often see poll_exp going *2* steps down) | 133 | * (Bumped from 30 to 40 since otherwise I often see poll_exp going *2* steps down) |
131 | */ | 134 | */ |
132 | #define POLLADJ_LIMIT 40 | 135 | #define POLLADJ_LIMIT 40 |
133 | /* If offset < POLLADJ_GATE * discipline_jitter, then we can increase | 136 | /* If offset < discipline_jitter * POLLADJ_GATE, then we decide to increase |
134 | * poll interval (we think we can't improve timekeeping | 137 | * poll interval (we think we can't improve timekeeping |
135 | * by staying at smaller poll). | 138 | * by staying at smaller poll). |
136 | */ | 139 | */ |
@@ -732,6 +735,12 @@ send_query_to_peer(peer_t *p) | |||
732 | free(local_lsa); | 735 | free(local_lsa); |
733 | } | 736 | } |
734 | 737 | ||
738 | /* Emit message _before_ attempted send. Think of a very short | ||
739 | * roundtrip networks: we need to go back to recv loop ASAP, | ||
740 | * to reduce delay. Printing messages after send works against that. | ||
741 | */ | ||
742 | VERB1 bb_error_msg("sending query to %s", p->p_dotted); | ||
743 | |||
735 | /* | 744 | /* |
736 | * Send out a random 64-bit number as our transmit time. The NTP | 745 | * Send out a random 64-bit number as our transmit time. The NTP |
737 | * server will copy said number into the originate field on the | 746 | * server will copy said number into the originate field on the |
@@ -759,7 +768,6 @@ send_query_to_peer(peer_t *p) | |||
759 | } | 768 | } |
760 | 769 | ||
761 | p->reachable_bits <<= 1; | 770 | p->reachable_bits <<= 1; |
762 | VERB1 bb_error_msg("sent query to %s", p->p_dotted); | ||
763 | set_next(p, RESPONSE_INTERVAL); | 771 | set_next(p, RESPONSE_INTERVAL); |
764 | } | 772 | } |
765 | 773 | ||
@@ -2077,8 +2085,23 @@ int ntpd_main(int argc UNUSED_PARAM, char **argv) | |||
2077 | timeout++; /* (nextaction - G.cur_time) rounds down, compensating */ | 2085 | timeout++; /* (nextaction - G.cur_time) rounds down, compensating */ |
2078 | 2086 | ||
2079 | /* Here we may block */ | 2087 | /* Here we may block */ |
2080 | VERB2 bb_error_msg("poll %us, sockets:%u, poll interval:%us", timeout, i, 1 << G.poll_exp); | 2088 | VERB2 { |
2089 | if (i > ENABLE_FEATURE_NTPD_SERVER) { | ||
2090 | /* We wait for at least one reply. | ||
2091 | * Poll for it, without wasting time for message. | ||
2092 | * Since replies often come under 1 second, this also | ||
2093 | * reduces clutter in logs. | ||
2094 | */ | ||
2095 | nfds = poll(pfd, i, 1000); | ||
2096 | if (nfds != 0) | ||
2097 | goto did_poll; | ||
2098 | if (--timeout <= 0) | ||
2099 | goto did_poll; | ||
2100 | } | ||
2101 | bb_error_msg("poll %us, sockets:%u, poll interval:%us", timeout, i, 1 << G.poll_exp); | ||
2102 | } | ||
2081 | nfds = poll(pfd, i, timeout * 1000); | 2103 | nfds = poll(pfd, i, timeout * 1000); |
2104 | did_poll: | ||
2082 | gettime1900d(); /* sets G.cur_time */ | 2105 | gettime1900d(); /* sets G.cur_time */ |
2083 | if (nfds <= 0) { | 2106 | if (nfds <= 0) { |
2084 | if (G.script_name && G.cur_time - G.last_script_run > 11*60) { | 2107 | if (G.script_name && G.cur_time - G.last_script_run > 11*60) { |