aboutsummaryrefslogtreecommitdiff
path: root/networking/ntpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-17 01:05:58 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-17 01:05:58 +0100
commit5b9a910749176cabcd6e822ca46af66a9947d032 (patch)
treee6a4397422f5c0a3f2773c95856cc1574d66b731 /networking/ntpd.c
parente208279722a7dc874b02e7ebf456667f26d6c8e2 (diff)
downloadbusybox-w32-5b9a910749176cabcd6e822ca46af66a9947d032.tar.gz
busybox-w32-5b9a910749176cabcd6e822ca46af66a9947d032.tar.bz2
busybox-w32-5b9a910749176cabcd6e822ca46af66a9947d032.zip
ntpd: disable frequency estimation code
function old new delta reset_peer_stats 164 168 +4 ntp_init 371 368 -3 recv_and_process_peer_pkt 869 852 -17 update_local_clock 823 759 -64 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 4/-84) Total: -80 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r--networking/ntpd.c69
1 files changed, 45 insertions, 24 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index e52d20c01..b2cd0a3c0 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -57,6 +57,10 @@
57 * seconds. After WATCH_THRESHOLD seconds we look at accumulated 57 * seconds. After WATCH_THRESHOLD seconds we look at accumulated
58 * offset and estimate frequency drift. 58 * offset and estimate frequency drift.
59 * 59 *
60 * (frequency measurement step seems to not be strictly needed,
61 * it is conditionally disabled with USING_INITIAL_FREQ_ESTIMATION
62 * define set to 0)
63 *
60 * After this, we enter "steady state": we collect a datapoint, 64 * After this, we enter "steady state": we collect a datapoint,
61 * we select the best peer, if this datapoint is not a new one 65 * we select the best peer, if this datapoint is not a new one
62 * (IOW: if this datapoint isn't for selected peer), sleep 66 * (IOW: if this datapoint isn't for selected peer), sleep
@@ -76,21 +80,27 @@
76#define INITIAL_SAMLPES 4 /* how many samples do we want for init */ 80#define INITIAL_SAMLPES 4 /* how many samples do we want for init */
77 81
78/* Clock discipline parameters and constants */ 82/* Clock discipline parameters and constants */
79#define STEP_THRESHOLD 0.128 /* step threshold (s) */ 83
80#define WATCH_THRESHOLD 150 /* stepout threshold (s). std ntpd uses 900 (11 mins (!)) */ 84/* Step threshold (sec). std ntpd uses 0.128.
85 * Using exact power of 2 (1/8) results in smaller code */
86#define STEP_THRESHOLD 0.125
87#define WATCH_THRESHOLD 128 /* stepout threshold (sec). std ntpd uses 900 (11 mins (!)) */
81/* NB: set WATCH_THRESHOLD to ~60 when debugging to save time) */ 88/* NB: set WATCH_THRESHOLD to ~60 when debugging to save time) */
82//UNUSED: #define PANIC_THRESHOLD 1000 /* panic threshold (s) */ 89//UNUSED: #define PANIC_THRESHOLD 1000 /* panic threshold (sec) */
83 90
84#define FREQ_TOLERANCE 0.000015 /* frequency tolerance (15 PPM) */ 91#define FREQ_TOLERANCE 0.000015 /* frequency tolerance (15 PPM) */
85#define BURSTPOLL 0 /* initial poll */ 92#define BURSTPOLL 0 /* initial poll */
86#define MINPOLL 4 /* minimum poll interval (6: 64 s) */ 93#define MINPOLL 5 /* minimum poll interval. std ntpd uses 6 (6: 64 sec) */
87#define BIGPOLL 10 /* drop to lower poll at any trouble (10: 17 min) */ 94#define BIGPOLL 10 /* drop to lower poll at any trouble (10: 17 min) */
88#define MAXPOLL 12 /* maximum poll interval (12: 1.1h, 17: 36.4h) (was 17) */ 95#define MAXPOLL 12 /* maximum poll interval (12: 1.1h, 17: 36.4h). std ntpd uses 17 */
89#define POLLDOWN_OFFSET (STEP_THRESHOLD / 3) /* actively lower poll when we see such big offsets */ 96/* Actively lower poll when we see such big offsets.
90#define MINDISP 0.01 /* minimum dispersion (s) */ 97 * With STEP_THRESHOLD = 0.125, it means we try to sync more aggressively
91#define MAXDISP 16 /* maximum dispersion (s) */ 98 * if offset increases over 0.03 sec */
99#define POLLDOWN_OFFSET (STEP_THRESHOLD / 4)
100#define MINDISP 0.01 /* minimum dispersion (sec) */
101#define MAXDISP 16 /* maximum dispersion (sec) */
92#define MAXSTRAT 16 /* maximum stratum (infinity metric) */ 102#define MAXSTRAT 16 /* maximum stratum (infinity metric) */
93#define MAXDIST 1 /* distance threshold (s) */ 103#define MAXDIST 1 /* distance threshold (sec) */
94#define MIN_SELECTED 1 /* minimum intersection survivors */ 104#define MIN_SELECTED 1 /* minimum intersection survivors */
95#define MIN_CLUSTERED 3 /* minimum cluster survivors */ 105#define MIN_CLUSTERED 3 /* minimum cluster survivors */
96 106
@@ -109,7 +119,7 @@
109 * by staying at smaller poll). 119 * by staying at smaller poll).
110 */ 120 */
111#define POLLADJ_GATE 4 121#define POLLADJ_GATE 4
112/* Compromise Allan intercept (s). doc uses 1500, std ntpd uses 512 */ 122/* Compromise Allan intercept (sec). doc uses 1500, std ntpd uses 512 */
113#define ALLAN 512 123#define ALLAN 512
114/* PLL loop gain */ 124/* PLL loop gain */
115#define PLL 65536 125#define PLL 65536
@@ -214,6 +224,9 @@ typedef struct {
214} peer_t; 224} peer_t;
215 225
216 226
227#define USING_KERNEL_PLL_LOOP 1
228#define USING_INITIAL_FREQ_ESTIMATION 0
229
217enum { 230enum {
218 OPT_n = (1 << 0), 231 OPT_n = (1 << 0),
219 OPT_q = (1 << 1), 232 OPT_q = (1 << 1),
@@ -284,6 +297,11 @@ struct globals {
284 smallint adjtimex_was_done; 297 smallint adjtimex_was_done;
285 smallint initial_poll_complete; 298 smallint initial_poll_complete;
286 299
300#define STATE_NSET 0 /* initial state, "nothing is set" */
301//#define STATE_FSET 1 /* frequency set from file */
302#define STATE_SPIK 2 /* spike detected */
303//#define STATE_FREQ 3 /* initial frequency */
304#define STATE_SYNC 4 /* clock synchronized (normal operation) */
287 uint8_t discipline_state; // doc calls it c.state 305 uint8_t discipline_state; // doc calls it c.state
288 uint8_t poll_exp; // s.poll 306 uint8_t poll_exp; // s.poll
289 int polladj_count; // c.count 307 int polladj_count; // c.count
@@ -292,7 +310,6 @@ struct globals {
292 double last_update_recv_time; // s.t 310 double last_update_recv_time; // s.t
293 double discipline_jitter; // c.jitter 311 double discipline_jitter; // c.jitter
294//TODO: add s.jitter - grep for it here and see clock_combine() in doc 312//TODO: add s.jitter - grep for it here and see clock_combine() in doc
295#define USING_KERNEL_PLL_LOOP 1
296#if !USING_KERNEL_PLL_LOOP 313#if !USING_KERNEL_PLL_LOOP
297 double discipline_freq_drift; // c.freq 314 double discipline_freq_drift; // c.freq
298//TODO: conditionally calculate wander? it's used only for logging 315//TODO: conditionally calculate wander? it's used only for logging
@@ -581,8 +598,10 @@ static void
581reset_peer_stats(peer_t *p, double offset) 598reset_peer_stats(peer_t *p, double offset)
582{ 599{
583 int i; 600 int i;
601 bool small_ofs = fabs(offset) < 16 * STEP_THRESHOLD;
602
584 for (i = 0; i < NUM_DATAPOINTS; i++) { 603 for (i = 0; i < NUM_DATAPOINTS; i++) {
585 if (offset < 16 * STEP_THRESHOLD) { 604 if (small_ofs) {
586 p->filter_datapoint[i].d_recv_time -= offset; 605 p->filter_datapoint[i].d_recv_time -= offset;
587 if (p->filter_datapoint[i].d_offset != 0) { 606 if (p->filter_datapoint[i].d_offset != 0) {
588 p->filter_datapoint[i].d_offset -= offset; 607 p->filter_datapoint[i].d_offset -= offset;
@@ -593,7 +612,7 @@ reset_peer_stats(peer_t *p, double offset)
593 p->filter_datapoint[i].d_dispersion = MAXDISP; 612 p->filter_datapoint[i].d_dispersion = MAXDISP;
594 } 613 }
595 } 614 }
596 if (offset < 16 * STEP_THRESHOLD) { 615 if (small_ofs) {
597 p->lastpkt_recv_time -= offset; 616 p->lastpkt_recv_time -= offset;
598 } else { 617 } else {
599 p->reachable_bits = 0; 618 p->reachable_bits = 0;
@@ -1105,12 +1124,6 @@ set_new_values(int disc_state, double offset, double recv_time)
1105 G.last_update_offset = offset; 1124 G.last_update_offset = offset;
1106 G.last_update_recv_time = recv_time; 1125 G.last_update_recv_time = recv_time;
1107} 1126}
1108/* Clock state definitions */
1109#define STATE_NSET 0 /* initial state, "nothing is set" */
1110#define STATE_FSET 1 /* frequency set from file */
1111#define STATE_SPIK 2 /* spike detected */
1112#define STATE_FREQ 3 /* initial frequency */
1113#define STATE_SYNC 4 /* clock synchronized (normal operation) */
1114/* Return: -1: decrease poll interval, 0: leave as is, 1: increase */ 1127/* Return: -1: decrease poll interval, 0: leave as is, 1: increase */
1115static NOINLINE int 1128static NOINLINE int
1116update_local_clock(peer_t *p) 1129update_local_clock(peer_t *p)
@@ -1156,6 +1169,7 @@ update_local_clock(peer_t *p)
1156#if !USING_KERNEL_PLL_LOOP 1169#if !USING_KERNEL_PLL_LOOP
1157 freq_drift = 0; 1170 freq_drift = 0;
1158#endif 1171#endif
1172#if USING_INITIAL_FREQ_ESTIMATION
1159 if (G.discipline_state == STATE_FREQ) { 1173 if (G.discipline_state == STATE_FREQ) {
1160 /* Ignore updates until the stepout threshold */ 1174 /* Ignore updates until the stepout threshold */
1161 if (since_last_update < WATCH_THRESHOLD) { 1175 if (since_last_update < WATCH_THRESHOLD) {
@@ -1163,10 +1177,11 @@ update_local_clock(peer_t *p)
1163 WATCH_THRESHOLD - since_last_update); 1177 WATCH_THRESHOLD - since_last_update);
1164 return 0; /* "leave poll interval as is" */ 1178 return 0; /* "leave poll interval as is" */
1165 } 1179 }
1166#if !USING_KERNEL_PLL_LOOP 1180# if !USING_KERNEL_PLL_LOOP
1167 freq_drift = (offset - G.last_update_offset) / since_last_update; 1181 freq_drift = (offset - G.last_update_offset) / since_last_update;
1168#endif 1182# endif
1169 } 1183 }
1184#endif
1170 1185
1171 /* There are two main regimes: when the 1186 /* There are two main regimes: when the
1172 * offset exceeds the step threshold and when it does not. 1187 * offset exceeds the step threshold and when it does not.
@@ -1225,10 +1240,12 @@ update_local_clock(peer_t *p)
1225 1240
1226 run_script("step", offset); 1241 run_script("step", offset);
1227 1242
1243#if USING_INITIAL_FREQ_ESTIMATION
1228 if (G.discipline_state == STATE_NSET) { 1244 if (G.discipline_state == STATE_NSET) {
1229 set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time); 1245 set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time);
1230 return 1; /* "ok to increase poll interval" */ 1246 return 1; /* "ok to increase poll interval" */
1231 } 1247 }
1248#endif
1232 set_new_values(STATE_SYNC, /*offset:*/ 0, recv_time); 1249 set_new_values(STATE_SYNC, /*offset:*/ 0, recv_time);
1233 1250
1234 } else { /* abs_offset <= STEP_THRESHOLD */ 1251 } else { /* abs_offset <= STEP_THRESHOLD */
@@ -1255,11 +1272,15 @@ update_local_clock(peer_t *p)
1255 */ 1272 */
1256 exit(0); 1273 exit(0);
1257 } 1274 }
1275#if USING_INITIAL_FREQ_ESTIMATION
1258 /* This is the first update received and the frequency 1276 /* This is the first update received and the frequency
1259 * has not been initialized. The first thing to do 1277 * has not been initialized. The first thing to do
1260 * is directly measure the oscillator frequency. 1278 * is directly measure the oscillator frequency.
1261 */ 1279 */
1262 set_new_values(STATE_FREQ, offset, recv_time); 1280 set_new_values(STATE_FREQ, offset, recv_time);
1281#else
1282 set_new_values(STATE_SYNC, offset, recv_time);
1283#endif
1263 VERB3 bb_error_msg("transitioning to FREQ, datapoint ignored"); 1284 VERB3 bb_error_msg("transitioning to FREQ, datapoint ignored");
1264 return 0; /* "leave poll interval as is" */ 1285 return 0; /* "leave poll interval as is" */
1265 1286
@@ -1274,6 +1295,7 @@ update_local_clock(peer_t *p)
1274 break; 1295 break;
1275#endif 1296#endif
1276 1297
1298#if USING_INITIAL_FREQ_ESTIMATION
1277 case STATE_FREQ: 1299 case STATE_FREQ:
1278 /* since_last_update >= WATCH_THRESHOLD, we waited enough. 1300 /* since_last_update >= WATCH_THRESHOLD, we waited enough.
1279 * Correct the phase and frequency and switch to SYNC state. 1301 * Correct the phase and frequency and switch to SYNC state.
@@ -1281,6 +1303,7 @@ update_local_clock(peer_t *p)
1281 */ 1303 */
1282 set_new_values(STATE_SYNC, offset, recv_time); 1304 set_new_values(STATE_SYNC, offset, recv_time);
1283 break; 1305 break;
1306#endif
1284 1307
1285 default: 1308 default:
1286#if !USING_KERNEL_PLL_LOOP 1309#if !USING_KERNEL_PLL_LOOP
@@ -1579,9 +1602,7 @@ recv_and_process_peer_pkt(peer_t *p)
1579 /* If drift is dangerously large, immediately 1602 /* If drift is dangerously large, immediately
1580 * drop poll interval one step down. 1603 * drop poll interval one step down.
1581 */ 1604 */
1582 if (q->filter_offset < -POLLDOWN_OFFSET 1605 if (fabs(q->filter_offset) >= POLLDOWN_OFFSET) {
1583 || q->filter_offset > POLLDOWN_OFFSET
1584 ) {
1585 VERB3 bb_error_msg("offset:%f > POLLDOWN_OFFSET", q->filter_offset); 1606 VERB3 bb_error_msg("offset:%f > POLLDOWN_OFFSET", q->filter_offset);
1586 goto poll_down; 1607 goto poll_down;
1587 } 1608 }