aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-03-05 10:18:00 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2012-03-05 10:18:00 +0100
commit547ee7926e4107d8c37d768959975f0787a66b3d (patch)
tree502d65127aa448378c46eac489edb6f8b667325d
parentb3439d4727b9813ae373d0015720d49d5a0fc72d (diff)
downloadbusybox-w32-547ee7926e4107d8c37d768959975f0787a66b3d.tar.gz
busybox-w32-547ee7926e4107d8c37d768959975f0787a66b3d.tar.bz2
busybox-w32-547ee7926e4107d8c37d768959975f0787a66b3d.zip
ntpd: fix a case when discipline_jitter = 0 if we step
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ntpd.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index b0bfe440f..e9805087c 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -340,7 +340,10 @@ struct globals {
340 double last_update_offset; // c.last 340 double last_update_offset; // c.last
341 double last_update_recv_time; // s.t 341 double last_update_recv_time; // s.t
342 double discipline_jitter; // c.jitter 342 double discipline_jitter; // c.jitter
343 double offset_to_jitter_ratio; 343 /* Since we only compare it with ints, can simplify code
344 * by not making this variable floating point:
345 */
346 unsigned offset_to_jitter_ratio;
344 //double cluster_offset; // s.offset 347 //double cluster_offset; // s.offset
345 //double cluster_jitter; // s.jitter 348 //double cluster_jitter; // s.jitter
346#if !USING_KERNEL_PLL_LOOP 349#if !USING_KERNEL_PLL_LOOP
@@ -1339,7 +1342,7 @@ update_local_clock(peer_t *p)
1339 return 1; /* "ok to increase poll interval" */ 1342 return 1; /* "ok to increase poll interval" */
1340 } 1343 }
1341#endif 1344#endif
1342 offset = 0; 1345 abs_offset = offset = 0;
1343 set_new_values(STATE_SYNC, offset, recv_time); 1346 set_new_values(STATE_SYNC, offset, recv_time);
1344 1347
1345 } else { /* abs_offset <= STEP_THRESHOLD */ 1348 } else { /* abs_offset <= STEP_THRESHOLD */
@@ -1356,10 +1359,6 @@ update_local_clock(peer_t *p)
1356 etemp = SQUARE(G.discipline_jitter); 1359 etemp = SQUARE(G.discipline_jitter);
1357 dtemp = SQUARE(offset - G.last_update_offset); 1360 dtemp = SQUARE(offset - G.last_update_offset);
1358 G.discipline_jitter = SQRT(etemp + (dtemp - etemp) / AVG); 1361 G.discipline_jitter = SQRT(etemp + (dtemp - etemp) / AVG);
1359 if (G.discipline_jitter < G_precision_sec)
1360 G.discipline_jitter = G_precision_sec;
1361 G.offset_to_jitter_ratio = fabs(offset) / G.discipline_jitter;
1362 VERB3 bb_error_msg("discipline jitter=%f", G.discipline_jitter);
1363 1362
1364 switch (G.discipline_state) { 1363 switch (G.discipline_state) {
1365 case STATE_NSET: 1364 case STATE_NSET:
@@ -1436,6 +1435,10 @@ update_local_clock(peer_t *p)
1436 } 1435 }
1437 } 1436 }
1438 1437
1438 if (G.discipline_jitter < G_precision_sec)
1439 G.discipline_jitter = G_precision_sec;
1440 G.offset_to_jitter_ratio = abs_offset / G.discipline_jitter;
1441
1439 G.reftime = G.cur_time; 1442 G.reftime = G.cur_time;
1440 G.ntp_status = p->lastpkt_status; 1443 G.ntp_status = p->lastpkt_status;
1441 G.refid = p->lastpkt_refid; 1444 G.refid = p->lastpkt_refid;
@@ -1473,7 +1476,7 @@ update_local_clock(peer_t *p)
1473 memset(&tmx, 0, sizeof(tmx)); 1476 memset(&tmx, 0, sizeof(tmx));
1474 if (adjtimex(&tmx) < 0) 1477 if (adjtimex(&tmx) < 0)
1475 bb_perror_msg_and_die("adjtimex"); 1478 bb_perror_msg_and_die("adjtimex");
1476 VERB3 bb_error_msg("p adjtimex freq:%ld offset:%+ld constant:%ld status:0x%x", 1479 bb_error_msg("p adjtimex freq:%ld offset:%+ld constant:%ld status:0x%x",
1477 tmx.freq, tmx.offset, tmx.constant, tmx.status); 1480 tmx.freq, tmx.offset, tmx.constant, tmx.status);
1478 } 1481 }
1479 1482
@@ -1506,7 +1509,7 @@ update_local_clock(peer_t *p)
1506 * To be on a safe side, let's do it only if offset is significantly 1509 * To be on a safe side, let's do it only if offset is significantly
1507 * larger than jitter. 1510 * larger than jitter.
1508 */ 1511 */
1509 if (tmx.constant > 0 && G.offset_to_jitter_ratio > TIMECONST_HACK_GATE) 1512 if (tmx.constant > 0 && G.offset_to_jitter_ratio >= TIMECONST_HACK_GATE)
1510 tmx.constant--; 1513 tmx.constant--;
1511 1514
1512 //tmx.esterror = (uint32_t)(clock_jitter * 1e6); 1515 //tmx.esterror = (uint32_t)(clock_jitter * 1e6);
@@ -1520,7 +1523,7 @@ update_local_clock(peer_t *p)
1520 VERB3 bb_error_msg("adjtimex:%d freq:%ld offset:%+ld status:0x%x", 1523 VERB3 bb_error_msg("adjtimex:%d freq:%ld offset:%+ld status:0x%x",
1521 rc, tmx.freq, tmx.offset, tmx.status); 1524 rc, tmx.freq, tmx.offset, tmx.status);
1522 G.kernel_freq_drift = tmx.freq / 65536; 1525 G.kernel_freq_drift = tmx.freq / 65536;
1523 VERB2 bb_error_msg("update peer:%s, offset:%+f, jitter:%f, clock drift:%+.3f ppm, tc:%d", 1526 VERB2 bb_error_msg("update from:%s offset:%+f jitter:%f clock drift:%+.3fppm tc:%d",
1524 p->p_dotted, offset, G.discipline_jitter, (double)tmx.freq / 65536, (int)tmx.constant); 1527 p->p_dotted, offset, G.discipline_jitter, (double)tmx.freq / 65536, (int)tmx.constant);
1525 1528
1526 return 1; /* "ok to increase poll interval" */ 1529 return 1; /* "ok to increase poll interval" */
@@ -1705,14 +1708,7 @@ recv_and_process_peer_pkt(peer_t *p)
1705 * is increased, otherwise it is decreased. A bit of hysteresis 1708 * is increased, otherwise it is decreased. A bit of hysteresis
1706 * helps calm the dance. Works best using burst mode. 1709 * helps calm the dance. Works best using burst mode.
1707 */ 1710 */
1708 VERB4 if (rc > 0) { 1711 if (rc > 0 && G.offset_to_jitter_ratio <= POLLADJ_GATE) {
1709 bb_error_msg("offset:%+f POLLADJ_GATE*discipline_jitter:%f poll:%s",
1710 q->filter_offset, POLLADJ_GATE * G.discipline_jitter,
1711 fabs(q->filter_offset) < POLLADJ_GATE * G.discipline_jitter
1712 ? "grows" : "falls"
1713 );
1714 }
1715 if (rc > 0 && G.offset_to_jitter_ratio < POLLADJ_GATE) {
1716 /* was += G.poll_exp but it is a bit 1712 /* was += G.poll_exp but it is a bit
1717 * too optimistic for my taste at high poll_exp's */ 1713 * too optimistic for my taste at high poll_exp's */
1718 G.polladj_count += MINPOLL; 1714 G.polladj_count += MINPOLL;