aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-02-21 09:05:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-02-21 09:05:48 +0100
commit423c4c25d8496a6e784b4ebbbaf1a6f4ae490f9b (patch)
tree980cd641ec7e0b65089b683794eb19090b741a24
parent5024d862551a762f8e95d887830710cd32c03fb8 (diff)
downloadbusybox-w32-423c4c25d8496a6e784b4ebbbaf1a6f4ae490f9b.tar.gz
busybox-w32-423c4c25d8496a6e784b4ebbbaf1a6f4ae490f9b.tar.bz2
busybox-w32-423c4c25d8496a6e784b4ebbbaf1a6f4ae490f9b.zip
ntpd: remove unused USING_INITIAL_FREQ_ESTIMATION code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ntpd.c184
1 files changed, 2 insertions, 182 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 8c9e59de1..62543ad2f 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -373,8 +373,7 @@ typedef struct {
373} peer_t; 373} peer_t;
374 374
375 375
376#define USING_KERNEL_PLL_LOOP 1 376#define USING_KERNEL_PLL_LOOP 1
377#define USING_INITIAL_FREQ_ESTIMATION 0
378 377
379enum { 378enum {
380 OPT_n = (1 << 0), 379 OPT_n = (1 << 0),
@@ -657,104 +656,11 @@ filter_datapoints(peer_t *p)
657 double sum, wavg; 656 double sum, wavg;
658 datapoint_t *fdp; 657 datapoint_t *fdp;
659 658
660#if 0
661/* Simulations have shown that use of *averaged* offset for p->filter_offset 659/* Simulations have shown that use of *averaged* offset for p->filter_offset
662 * is in fact worse than simply using last received one: with large poll intervals 660 * is in fact worse than simply using last received one: with large poll intervals
663 * (>= 2048) averaging code uses offset values which are outdated by hours, 661 * (>= 2048) averaging code uses offset values which are outdated by hours,
664 * and time/frequency correction goes totally wrong when fed essentially bogus offsets. 662 * and time/frequency correction goes totally wrong when fed essentially bogus offsets.
665 */ 663 */
666 int got_newest;
667 double minoff, maxoff, w;
668 double x = x; /* for compiler */
669 double oldest_off = oldest_off;
670 double oldest_age = oldest_age;
671 double newest_off = newest_off;
672 double newest_age = newest_age;
673
674 fdp = p->filter_datapoint;
675
676 minoff = maxoff = fdp[0].d_offset;
677 for (i = 1; i < NUM_DATAPOINTS; i++) {
678 if (minoff > fdp[i].d_offset)
679 minoff = fdp[i].d_offset;
680 if (maxoff < fdp[i].d_offset)
681 maxoff = fdp[i].d_offset;
682 }
683
684 idx = p->datapoint_idx; /* most recent datapoint's index */
685 /* Average offset:
686 * Drop two outliers and take weighted average of the rest:
687 * most_recent/2 + older1/4 + older2/8 ... + older5/32 + older6/32
688 * we use older6/32, not older6/64 since sum of weights should be 1:
689 * 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/32 = 1
690 */
691 wavg = 0;
692 w = 0.5;
693 /* n-1
694 * --- dispersion(i)
695 * filter_dispersion = \ -------------
696 * / (i+1)
697 * --- 2
698 * i=0
699 */
700 got_newest = 0;
701 sum = 0;
702 for (i = 0; i < NUM_DATAPOINTS; i++) {
703 VERB5 {
704 bb_error_msg("datapoint[%d]: off:%f disp:%f(%f) age:%f%s",
705 i,
706 fdp[idx].d_offset,
707 fdp[idx].d_dispersion, dispersion(&fdp[idx]),
708 G.cur_time - fdp[idx].d_recv_time,
709 (minoff == fdp[idx].d_offset || maxoff == fdp[idx].d_offset)
710 ? " (outlier by offset)" : ""
711 );
712 }
713
714 sum += dispersion(&fdp[idx]) / (2 << i);
715
716 if (minoff == fdp[idx].d_offset) {
717 minoff -= 1; /* so that we don't match it ever again */
718 } else
719 if (maxoff == fdp[idx].d_offset) {
720 maxoff += 1;
721 } else {
722 oldest_off = fdp[idx].d_offset;
723 oldest_age = G.cur_time - fdp[idx].d_recv_time;
724 if (!got_newest) {
725 got_newest = 1;
726 newest_off = oldest_off;
727 newest_age = oldest_age;
728 }
729 x = oldest_off * w;
730 wavg += x;
731 w /= 2;
732 }
733
734 idx = (idx - 1) & (NUM_DATAPOINTS - 1);
735 }
736 p->filter_dispersion = sum;
737 wavg += x; /* add another older6/64 to form older6/32 */
738 /* Fix systematic underestimation with large poll intervals.
739 * Imagine that we still have a bit of uncorrected drift,
740 * and poll interval is big (say, 100 sec). Offsets form a progression:
741 * 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 - 0.7 is most recent.
742 * The algorithm above drops 0.0 and 0.7 as outliers,
743 * and then we have this estimation, ~25% off from 0.7:
744 * 0.1/32 + 0.2/32 + 0.3/16 + 0.4/8 + 0.5/4 + 0.6/2 = 0.503125
745 */
746 x = oldest_age - newest_age;
747 if (x != 0) {
748 x = newest_age / x; /* in above example, 100 / (600 - 100) */
749 if (x < 1) { /* paranoia check */
750 x = (newest_off - oldest_off) * x; /* 0.5 * 100/500 = 0.1 */
751 wavg += x;
752 }
753 }
754 p->filter_offset = wavg;
755
756#else
757
758 fdp = p->filter_datapoint; 664 fdp = p->filter_datapoint;
759 idx = p->datapoint_idx; /* most recent datapoint's index */ 665 idx = p->datapoint_idx; /* most recent datapoint's index */
760 666
@@ -777,7 +683,6 @@ filter_datapoints(peer_t *p)
777 } 683 }
778 wavg /= NUM_DATAPOINTS; 684 wavg /= NUM_DATAPOINTS;
779 p->filter_dispersion = sum; 685 p->filter_dispersion = sum;
780#endif
781 686
782 /* +----- -----+ ^ 1/2 687 /* +----- -----+ ^ 1/2
783 * | n-1 | 688 * | n-1 |
@@ -1572,8 +1477,6 @@ update_local_clock(peer_t *p)
1572 double abs_offset; 1477 double abs_offset;
1573#if !USING_KERNEL_PLL_LOOP 1478#if !USING_KERNEL_PLL_LOOP
1574 double freq_drift; 1479 double freq_drift;
1575#endif
1576#if !USING_KERNEL_PLL_LOOP || USING_INITIAL_FREQ_ESTIMATION
1577 double since_last_update; 1480 double since_last_update;
1578#endif 1481#endif
1579 double etemp, dtemp; 1482 double etemp, dtemp;
@@ -1603,63 +1506,15 @@ update_local_clock(peer_t *p)
1603 * action is and defines how the system reacts to large time 1506 * action is and defines how the system reacts to large time
1604 * and frequency errors. 1507 * and frequency errors.
1605 */ 1508 */
1606#if !USING_KERNEL_PLL_LOOP || USING_INITIAL_FREQ_ESTIMATION
1607 since_last_update = recv_time - G.reftime;
1608#endif
1609#if !USING_KERNEL_PLL_LOOP 1509#if !USING_KERNEL_PLL_LOOP
1510 since_last_update = recv_time - G.reftime;
1610 freq_drift = 0; 1511 freq_drift = 0;
1611#endif 1512#endif
1612#if USING_INITIAL_FREQ_ESTIMATION
1613 if (G.discipline_state == STATE_FREQ) {
1614 /* Ignore updates until the stepout threshold */
1615 if (since_last_update < WATCH_THRESHOLD) {
1616 VERB4 bb_error_msg("measuring drift, datapoint ignored, %f sec remains",
1617 WATCH_THRESHOLD - since_last_update);
1618 return 0; /* "leave poll interval as is" */
1619 }
1620# if !USING_KERNEL_PLL_LOOP
1621 freq_drift = (offset - G.last_update_offset) / since_last_update;
1622# endif
1623 }
1624#endif
1625 1513
1626 /* There are two main regimes: when the 1514 /* There are two main regimes: when the
1627 * offset exceeds the step threshold and when it does not. 1515 * offset exceeds the step threshold and when it does not.
1628 */ 1516 */
1629 if (abs_offset > STEP_THRESHOLD) { 1517 if (abs_offset > STEP_THRESHOLD) {
1630#if 0
1631 double remains;
1632
1633// This "spike state" seems to be useless, peer selection already drops
1634// occassional "bad" datapoints. If we are here, there were _many_
1635// large offsets. When a few first large offsets are seen,
1636// we end up in "no valid datapoints, no peer selected" state.
1637// Only when enough of them are seen (which means it's not a fluke),
1638// we end up here. Looks like _our_ clock is off.
1639 switch (G.discipline_state) {
1640 case STATE_SYNC:
1641 /* The first outlyer: ignore it, switch to SPIK state */
1642 VERB3 bb_error_msg("update from %s: offset:%+f, spike%s",
1643 p->p_dotted, offset,
1644 "");
1645 G.discipline_state = STATE_SPIK;
1646 return -1; /* "decrease poll interval" */
1647
1648 case STATE_SPIK:
1649 /* Ignore succeeding outlyers until either an inlyer
1650 * is found or the stepout threshold is exceeded.
1651 */
1652 remains = WATCH_THRESHOLD - since_last_update;
1653 if (remains > 0) {
1654 VERB3 bb_error_msg("update from %s: offset:%+f, spike%s",
1655 p->p_dotted, offset,
1656 ", datapoint ignored");
1657 return -1; /* "decrease poll interval" */
1658 }
1659 /* fall through: we need to step */
1660 } /* switch */
1661#endif
1662
1663 /* Step the time and clamp down the poll interval. 1518 /* Step the time and clamp down the poll interval.
1664 * 1519 *
1665 * In NSET state an initial frequency correction is 1520 * In NSET state an initial frequency correction is
@@ -1694,12 +1549,6 @@ update_local_clock(peer_t *p)
1694 1549
1695 recv_time += offset; 1550 recv_time += offset;
1696 1551
1697#if USING_INITIAL_FREQ_ESTIMATION
1698 if (G.discipline_state == STATE_NSET) {
1699 set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time);
1700 return 1; /* "ok to increase poll interval" */
1701 }
1702#endif
1703 abs_offset = offset = 0; 1552 abs_offset = offset = 0;
1704 set_new_values(STATE_SYNC, offset, recv_time); 1553 set_new_values(STATE_SYNC, offset, recv_time);
1705 } else { /* abs_offset <= STEP_THRESHOLD */ 1554 } else { /* abs_offset <= STEP_THRESHOLD */
@@ -1726,39 +1575,10 @@ update_local_clock(peer_t *p)
1726 */ 1575 */
1727 exit(0); 1576 exit(0);
1728 } 1577 }
1729#if USING_INITIAL_FREQ_ESTIMATION
1730 /* This is the first update received and the frequency
1731 * has not been initialized. The first thing to do
1732 * is directly measure the oscillator frequency.
1733 */
1734 set_new_values(STATE_FREQ, offset, recv_time);
1735#else
1736 set_new_values(STATE_SYNC, offset, recv_time); 1578 set_new_values(STATE_SYNC, offset, recv_time);
1737#endif
1738 VERB4 bb_simple_error_msg("transitioning to FREQ, datapoint ignored"); 1579 VERB4 bb_simple_error_msg("transitioning to FREQ, datapoint ignored");
1739 return 0; /* "leave poll interval as is" */ 1580 return 0; /* "leave poll interval as is" */
1740 1581
1741#if 0 /* this is dead code for now */
1742 case STATE_FSET:
1743 /* This is the first update and the frequency
1744 * has been initialized. Adjust the phase, but
1745 * don't adjust the frequency until the next update.
1746 */
1747 set_new_values(STATE_SYNC, offset, recv_time);
1748 /* freq_drift remains 0 */
1749 break;
1750#endif
1751
1752#if USING_INITIAL_FREQ_ESTIMATION
1753 case STATE_FREQ:
1754 /* since_last_update >= WATCH_THRESHOLD, we waited enough.
1755 * Correct the phase and frequency and switch to SYNC state.
1756 * freq_drift was already estimated (see code above)
1757 */
1758 set_new_values(STATE_SYNC, offset, recv_time);
1759 break;
1760#endif
1761
1762 default: 1582 default:
1763#if !USING_KERNEL_PLL_LOOP 1583#if !USING_KERNEL_PLL_LOOP
1764 /* Compute freq_drift due to PLL and FLL contributions. 1584 /* Compute freq_drift due to PLL and FLL contributions.