diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-02-21 09:13:05 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-02-21 09:13:05 +0100 |
| commit | 2620d387141c16bdce74dd9d91043ee3869febc4 (patch) | |
| tree | 8fb73e78307e888155e1c9fa25690cb4bef93118 | |
| parent | 423c4c25d8496a6e784b4ebbbaf1a6f4ae490f9b (diff) | |
| download | busybox-w32-2620d387141c16bdce74dd9d91043ee3869febc4.tar.gz busybox-w32-2620d387141c16bdce74dd9d91043ee3869febc4.tar.bz2 busybox-w32-2620d387141c16bdce74dd9d91043ee3869febc4.zip | |
ntpd: without INITIAL_FREQ_ESTIMATION code, state variable is not needed too
function old new delta
update_local_clock 917 872 -45
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/ntpd.c | 88 |
1 files changed, 36 insertions, 52 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 62543ad2f..ede993078 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
| @@ -461,12 +461,7 @@ struct globals { | |||
| 461 | #define G_precision_sec 0.002 | 461 | #define G_precision_sec 0.002 |
| 462 | uint8_t stratum; | 462 | uint8_t stratum; |
| 463 | 463 | ||
| 464 | #define STATE_NSET 0 /* initial state, "nothing is set" */ | 464 | //uint8_t discipline_state; // doc calls it c.state |
| 465 | //#define STATE_FSET 1 /* frequency set from file */ | ||
| 466 | //#define STATE_SPIK 2 /* spike detected */ | ||
| 467 | //#define STATE_FREQ 3 /* initial frequency */ | ||
| 468 | #define STATE_SYNC 4 /* clock synchronized (normal operation) */ | ||
| 469 | uint8_t discipline_state; // doc calls it c.state | ||
| 470 | uint8_t poll_exp; // s.poll | 465 | uint8_t poll_exp; // s.poll |
| 471 | int polladj_count; // c.count | 466 | int polladj_count; // c.count |
| 472 | int FREQHOLD_cnt; | 467 | int FREQHOLD_cnt; |
| @@ -1453,15 +1448,14 @@ select_and_cluster(void) | |||
| 1453 | * Local clock discipline and its helpers | 1448 | * Local clock discipline and its helpers |
| 1454 | */ | 1449 | */ |
| 1455 | static void | 1450 | static void |
| 1456 | set_new_values(int disc_state, double offset, double recv_time) | 1451 | set_new_values(double offset, double recv_time) |
| 1457 | { | 1452 | { |
| 1458 | /* Enter new state and set state variables. Note we use the time | 1453 | /* Enter new state and set state variables. Note we use the time |
| 1459 | * of the last clock filter sample, which must be earlier than | 1454 | * of the last clock filter sample, which must be earlier than |
| 1460 | * the current time. | 1455 | * the current time. |
| 1461 | */ | 1456 | */ |
| 1462 | VERB4 bb_error_msg("disc_state=%d last update offset=%f recv_time=%f", | 1457 | VERB4 bb_error_msg("last update offset=%f recv_time=%f", |
| 1463 | disc_state, offset, recv_time); | 1458 | offset, recv_time); |
| 1464 | G.discipline_state = disc_state; | ||
| 1465 | G.last_update_offset = offset; | 1459 | G.last_update_offset = offset; |
| 1466 | G.last_update_recv_time = recv_time; | 1460 | G.last_update_recv_time = recv_time; |
| 1467 | } | 1461 | } |
| @@ -1550,9 +1544,16 @@ update_local_clock(peer_t *p) | |||
| 1550 | recv_time += offset; | 1544 | recv_time += offset; |
| 1551 | 1545 | ||
| 1552 | abs_offset = offset = 0; | 1546 | abs_offset = offset = 0; |
| 1553 | set_new_values(STATE_SYNC, offset, recv_time); | 1547 | set_new_values(offset, recv_time); |
| 1554 | } else { /* abs_offset <= STEP_THRESHOLD */ | 1548 | } else { /* abs_offset <= STEP_THRESHOLD */ |
| 1555 | 1549 | ||
| 1550 | if (option_mask32 & OPT_q) { | ||
| 1551 | /* We were only asked to set time once. | ||
| 1552 | * The clock is precise enough, no need to step. | ||
| 1553 | */ | ||
| 1554 | exit(0); | ||
| 1555 | } | ||
| 1556 | |||
| 1556 | /* The ratio is calculated before jitter is updated to make | 1557 | /* The ratio is calculated before jitter is updated to make |
| 1557 | * poll adjust code more sensitive to large offsets. | 1558 | * poll adjust code more sensitive to large offsets. |
| 1558 | */ | 1559 | */ |
| @@ -1567,46 +1568,31 @@ update_local_clock(peer_t *p) | |||
| 1567 | if (G.discipline_jitter < G_precision_sec) | 1568 | if (G.discipline_jitter < G_precision_sec) |
| 1568 | G.discipline_jitter = G_precision_sec; | 1569 | G.discipline_jitter = G_precision_sec; |
| 1569 | 1570 | ||
| 1570 | switch (G.discipline_state) { | ||
| 1571 | case STATE_NSET: | ||
| 1572 | if (option_mask32 & OPT_q) { | ||
| 1573 | /* We were only asked to set time once. | ||
| 1574 | * The clock is precise enough, no need to step. | ||
| 1575 | */ | ||
| 1576 | exit(0); | ||
| 1577 | } | ||
| 1578 | set_new_values(STATE_SYNC, offset, recv_time); | ||
| 1579 | VERB4 bb_simple_error_msg("transitioning to FREQ, datapoint ignored"); | ||
| 1580 | return 0; /* "leave poll interval as is" */ | ||
| 1581 | |||
| 1582 | default: | ||
| 1583 | #if !USING_KERNEL_PLL_LOOP | 1571 | #if !USING_KERNEL_PLL_LOOP |
| 1584 | /* Compute freq_drift due to PLL and FLL contributions. | 1572 | /* Compute freq_drift due to PLL and FLL contributions. |
| 1585 | * | 1573 | * |
| 1586 | * The FLL and PLL frequency gain constants | 1574 | * The FLL and PLL frequency gain constants |
| 1587 | * depend on the poll interval and Allan | 1575 | * depend on the poll interval and Allan |
| 1588 | * intercept. The FLL is not used below one-half | 1576 | * intercept. The FLL is not used below one-half |
| 1589 | * the Allan intercept. Above that the loop gain | 1577 | * the Allan intercept. Above that the loop gain |
| 1590 | * increases in steps to 1 / AVG. | 1578 | * increases in steps to 1 / AVG. |
| 1591 | */ | 1579 | */ |
| 1592 | if ((1 << G.poll_exp) > ALLAN / 2) { | 1580 | if ((1 << G.poll_exp) > ALLAN / 2) { |
| 1593 | etemp = FLL - G.poll_exp; | 1581 | etemp = FLL - G.poll_exp; |
| 1594 | if (etemp < AVG) | 1582 | if (etemp < AVG) |
| 1595 | etemp = AVG; | 1583 | etemp = AVG; |
| 1596 | freq_drift += (offset - G.last_update_offset) / (MAXD(since_last_update, ALLAN) * etemp); | 1584 | freq_drift += (offset - G.last_update_offset) / (MAXD(since_last_update, ALLAN) * etemp); |
| 1597 | } | ||
| 1598 | /* For the PLL the integration interval | ||
| 1599 | * (numerator) is the minimum of the update | ||
| 1600 | * interval and poll interval. This allows | ||
| 1601 | * oversampling, but not undersampling. | ||
| 1602 | */ | ||
| 1603 | etemp = MIND(since_last_update, (1 << G.poll_exp)); | ||
| 1604 | dtemp = (4 * PLL) << G.poll_exp; | ||
| 1605 | freq_drift += offset * etemp / SQUARE(dtemp); | ||
| 1606 | #endif | ||
| 1607 | set_new_values(STATE_SYNC, offset, recv_time); | ||
| 1608 | break; | ||
| 1609 | } | 1585 | } |
| 1586 | /* For the PLL the integration interval | ||
| 1587 | * (numerator) is the minimum of the update | ||
| 1588 | * interval and poll interval. This allows | ||
| 1589 | * oversampling, but not undersampling. | ||
| 1590 | */ | ||
| 1591 | etemp = MIND(since_last_update, (1 << G.poll_exp)); | ||
| 1592 | dtemp = (4 * PLL) << G.poll_exp; | ||
| 1593 | freq_drift += offset * etemp / SQUARE(dtemp); | ||
| 1594 | #endif | ||
| 1595 | set_new_values(offset, recv_time); | ||
| 1610 | if (G.stratum != p->lastpkt_stratum + 1) { | 1596 | if (G.stratum != p->lastpkt_stratum + 1) { |
| 1611 | G.stratum = p->lastpkt_stratum + 1; | 1597 | G.stratum = p->lastpkt_stratum + 1; |
| 1612 | run_script("stratum", offset); | 1598 | run_script("stratum", offset); |
| @@ -1625,9 +1611,7 @@ update_local_clock(peer_t *p) | |||
| 1625 | G.rootdisp = p->lastpkt_rootdisp + dtemp; | 1611 | G.rootdisp = p->lastpkt_rootdisp + dtemp; |
| 1626 | VERB4 bb_error_msg("updating leap/refid/reftime/rootdisp from peer %s", p->p_dotted); | 1612 | VERB4 bb_error_msg("updating leap/refid/reftime/rootdisp from peer %s", p->p_dotted); |
| 1627 | 1613 | ||
| 1628 | /* We are in STATE_SYNC now, but did not do adjtimex yet. | 1614 | /* By this time, freq_drift and offset are set |
| 1629 | * (Any other state does not reach this, they all return earlier) | ||
| 1630 | * By this time, freq_drift and offset are set | ||
| 1631 | * to values suitable for adjtimex. | 1615 | * to values suitable for adjtimex. |
| 1632 | */ | 1616 | */ |
| 1633 | #if !USING_KERNEL_PLL_LOOP | 1617 | #if !USING_KERNEL_PLL_LOOP |
