diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-11 17:08:02 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-11 17:08:02 +0100 |
commit | 448fdcc17df39ac90c59d0588ccaf9ee0400eb7e (patch) | |
tree | a54907435b5d803e20d262c23fb5e163114e9849 | |
parent | 3d306bffc5981b083ebb365c51e93c2231ff9b22 (diff) | |
download | busybox-w32-448fdcc17df39ac90c59d0588ccaf9ee0400eb7e.tar.gz busybox-w32-448fdcc17df39ac90c59d0588ccaf9ee0400eb7e.tar.bz2 busybox-w32-448fdcc17df39ac90c59d0588ccaf9ee0400eb7e.zip |
ntpd: choose initial FREQHOLD_cnt dynamically
function old new delta
update_local_clock 834 858 +24
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ntpd.c | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 2754170c0..8205ab271 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -1715,9 +1715,19 @@ update_local_clock(peer_t *p) | |||
1715 | tmx.freq = G.discipline_freq_drift * 65536e6; | 1715 | tmx.freq = G.discipline_freq_drift * 65536e6; |
1716 | #endif | 1716 | #endif |
1717 | tmx.modes = ADJ_OFFSET | ADJ_STATUS | ADJ_TIMECONST;// | ADJ_MAXERROR | ADJ_ESTERROR; | 1717 | tmx.modes = ADJ_OFFSET | ADJ_STATUS | ADJ_TIMECONST;// | ADJ_MAXERROR | ADJ_ESTERROR; |
1718 | |||
1719 | tmx.offset = (long)(offset * 1000000); /* usec */ | ||
1720 | if (SLEW_THRESHOLD < STEP_THRESHOLD) { | ||
1721 | if (tmx.offset > (long)(SLEW_THRESHOLD * 1000000)) { | ||
1722 | tmx.offset = (long)(SLEW_THRESHOLD * 1000000); | ||
1723 | } | ||
1724 | if (tmx.offset < -(long)(SLEW_THRESHOLD * 1000000)) { | ||
1725 | tmx.offset = -(long)(SLEW_THRESHOLD * 1000000); | ||
1726 | } | ||
1727 | } | ||
1728 | |||
1718 | tmx.status = STA_PLL; | 1729 | tmx.status = STA_PLL; |
1719 | if (G.FREQHOLD_cnt != 0) { | 1730 | if (G.FREQHOLD_cnt != 0) { |
1720 | G.FREQHOLD_cnt--; | ||
1721 | /* man adjtimex on STA_FREQHOLD: | 1731 | /* man adjtimex on STA_FREQHOLD: |
1722 | * "Normally adjustments made via ADJ_OFFSET result in dampened | 1732 | * "Normally adjustments made via ADJ_OFFSET result in dampened |
1723 | * frequency adjustments also being made. | 1733 | * frequency adjustments also being made. |
@@ -1730,6 +1740,48 @@ update_local_clock(peer_t *p) | |||
1730 | * If ntpd was restarted due to e.g. switch to another network, | 1740 | * If ntpd was restarted due to e.g. switch to another network, |
1731 | * this destroys already well-established tmx.freq value. | 1741 | * this destroys already well-established tmx.freq value. |
1732 | */ | 1742 | */ |
1743 | if (G.FREQHOLD_cnt < 0) { | ||
1744 | /* Initialize it */ | ||
1745 | // Example: a laptop whose clock runs slower when hibernated, | ||
1746 | // after wake up it still has good tmx.freq, but accumulated ~0.5 sec offset: | ||
1747 | // Run with code where initial G.FREQHOLD_cnt was always 8: | ||
1748 | //15:17:52.947 no valid datapoints, no peer selected | ||
1749 | //15:17:56.515 update from:<IP> offset:+0.485133 delay:0.157762 jitter:0.209310 clock drift:-1.393ppm tc:4 | ||
1750 | //15:17:57.719 update from:<IP> offset:+0.483825 delay:0.158070 jitter:0.181159 clock drift:-1.393ppm tc:4 | ||
1751 | //15:17:59.925 update from:<IP> offset:+0.479504 delay:0.158147 jitter:0.156657 clock drift:-1.393ppm tc:4 | ||
1752 | //15:18:33.322 update from:<IP> offset:+0.428119 delay:0.158317 jitter:0.138071 clock drift:-1.393ppm tc:4 | ||
1753 | //15:19:06.718 update from:<IP> offset:+0.376932 delay:0.158276 jitter:0.122075 clock drift:-1.393ppm tc:4 | ||
1754 | //15:19:39.114 update from:<IP> offset:+0.327022 delay:0.158384 jitter:0.108538 clock drift:-1.393ppm tc:4 | ||
1755 | //15:20:12.715 update from:<IP> offset:+0.275596 delay:0.158297 jitter:0.097292 clock drift:-1.393ppm tc:4 | ||
1756 | //15:20:45.111 update from:<IP> offset:+0.225715 delay:0.158271 jitter:0.087841 clock drift:-1.393ppm tc:4 | ||
1757 | // If allwed to continue, it would start increasing tmx.freq now. | ||
1758 | // Instead, it was ^Ced, and started anew: | ||
1759 | //15:21:15.043 no valid datapoints, no peer selected | ||
1760 | //15:21:17.408 update from:<IP> offset:+0.175910 delay:0.158314 jitter:0.076683 clock drift:-1.393ppm tc:4 | ||
1761 | //15:21:19.774 update from:<IP> offset:+0.171784 delay:0.158401 jitter:0.066436 clock drift:-1.393ppm tc:4 | ||
1762 | //15:21:22.140 update from:<IP> offset:+0.171660 delay:0.158592 jitter:0.057536 clock drift:-1.393ppm tc:4 | ||
1763 | //15:21:22.140 update from:<IP> offset:+0.167126 delay:0.158507 jitter:0.049792 clock drift:-1.393ppm tc:4 | ||
1764 | //15:21:55.696 update from:<IP> offset:+0.115223 delay:0.158277 jitter:0.050240 clock drift:-1.393ppm tc:4 | ||
1765 | //15:22:29.093 update from:<IP> offset:+0.068051 delay:0.158243 jitter:0.049405 clock drift:-1.393ppm tc:5 | ||
1766 | //15:23:02.490 update from:<IP> offset:+0.051632 delay:0.158215 jitter:0.043545 clock drift:-1.393ppm tc:5 | ||
1767 | //15:23:34.726 update from:<IP> offset:+0.039984 delay:0.158157 jitter:0.038106 clock drift:-1.393ppm tc:5 | ||
1768 | // STA_FREQHOLD no longer set, started increasing tmx.freq now: | ||
1769 | //15:24:06.961 update from:<IP> offset:+0.030968 delay:0.158190 jitter:0.033306 clock drift:+2.387ppm tc:5 | ||
1770 | //15:24:40.357 update from:<IP> offset:+0.023648 delay:0.158211 jitter:0.029072 clock drift:+5.454ppm tc:5 | ||
1771 | //15:25:13.774 update from:<IP> offset:+0.018068 delay:0.157660 jitter:0.025288 clock drift:+7.728ppm tc:5 | ||
1772 | //15:26:19.173 update from:<IP> offset:+0.010057 delay:0.157969 jitter:0.022255 clock drift:+8.361ppm tc:6 | ||
1773 | //15:27:26.602 update from:<IP> offset:+0.006737 delay:0.158103 jitter:0.019316 clock drift:+8.792ppm tc:6 | ||
1774 | //15:28:33.030 update from:<IP> offset:+0.004513 delay:0.158294 jitter:0.016765 clock drift:+9.080ppm tc:6 | ||
1775 | //15:29:40.617 update from:<IP> offset:+0.002787 delay:0.157745 jitter:0.014543 clock drift:+9.258ppm tc:6 | ||
1776 | //15:30:47.045 update from:<IP> offset:+0.001324 delay:0.157709 jitter:0.012594 clock drift:+9.342ppm tc:6 | ||
1777 | //15:31:53.473 update from:<IP> offset:+0.000007 delay:0.158142 jitter:0.010922 clock drift:+9.343ppm tc:6 | ||
1778 | //15:32:58.902 update from:<IP> offset:-0.000728 delay:0.158222 jitter:0.009454 clock drift:+9.298ppm tc:6 | ||
1779 | /* | ||
1780 | * This expression would choose 15 in the above example. | ||
1781 | */ | ||
1782 | G.FREQHOLD_cnt = 8 + ((unsigned)(abs(tmx.offset)) >> 16); | ||
1783 | } | ||
1784 | G.FREQHOLD_cnt--; | ||
1733 | tmx.status |= STA_FREQHOLD; | 1785 | tmx.status |= STA_FREQHOLD; |
1734 | } | 1786 | } |
1735 | if (G.ntp_status & LI_PLUSSEC) | 1787 | if (G.ntp_status & LI_PLUSSEC) |
@@ -1753,16 +1805,6 @@ update_local_clock(peer_t *p) | |||
1753 | if (tmx.constant < 0) | 1805 | if (tmx.constant < 0) |
1754 | tmx.constant = 0; | 1806 | tmx.constant = 0; |
1755 | 1807 | ||
1756 | tmx.offset = (long)(offset * 1000000); /* usec */ | ||
1757 | if (SLEW_THRESHOLD < STEP_THRESHOLD) { | ||
1758 | if (tmx.offset > (long)(SLEW_THRESHOLD * 1000000)) { | ||
1759 | tmx.offset = (long)(SLEW_THRESHOLD * 1000000); | ||
1760 | } | ||
1761 | if (tmx.offset < -(long)(SLEW_THRESHOLD * 1000000)) { | ||
1762 | tmx.offset = -(long)(SLEW_THRESHOLD * 1000000); | ||
1763 | } | ||
1764 | } | ||
1765 | |||
1766 | //tmx.esterror = (uint32_t)(clock_jitter * 1e6); | 1808 | //tmx.esterror = (uint32_t)(clock_jitter * 1e6); |
1767 | //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6); | 1809 | //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6); |
1768 | rc = adjtimex(&tmx); | 1810 | rc = adjtimex(&tmx); |
@@ -2248,7 +2290,7 @@ static NOINLINE void ntp_init(char **argv) | |||
2248 | if (BURSTPOLL != 0) | 2290 | if (BURSTPOLL != 0) |
2249 | G.poll_exp = BURSTPOLL; /* speeds up initial sync */ | 2291 | G.poll_exp = BURSTPOLL; /* speeds up initial sync */ |
2250 | G.last_script_run = G.reftime = G.last_update_recv_time = gettime1900d(); /* sets G.cur_time too */ | 2292 | G.last_script_run = G.reftime = G.last_update_recv_time = gettime1900d(); /* sets G.cur_time too */ |
2251 | G.FREQHOLD_cnt = 8; | 2293 | G.FREQHOLD_cnt = -1; |
2252 | 2294 | ||
2253 | /* Parse options */ | 2295 | /* Parse options */ |
2254 | peers = NULL; | 2296 | peers = NULL; |