aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-03-10 21:25:53 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-03-10 21:25:53 +0100
commit39dfb4de38fc5b31ca4472dbf45bcde3bb0d6e77 (patch)
treeb1b8065a8a1082c73450e37e09d1f3894b24f6b9
parent3293bc146985c56790033409facc0ad64a471084 (diff)
downloadbusybox-w32-39dfb4de38fc5b31ca4472dbf45bcde3bb0d6e77.tar.gz
busybox-w32-39dfb4de38fc5b31ca4472dbf45bcde3bb0d6e77.tar.bz2
busybox-w32-39dfb4de38fc5b31ca4472dbf45bcde3bb0d6e77.zip
ntpd: suppress in-kernel frequency correction in first 8 adjtimex calls
In other words: try to correct initially existing clock offset first, before assuming that our clock drifts. function old new delta update_local_clock 826 834 +8 ntp_init 550 557 +7 filter_datapoints 179 173 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 15/-6) Total: 9 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ntpd.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 17e5c7da6..2754170c0 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -165,8 +165,12 @@
165 * Using exact power of 2 (1/8) results in smaller code 165 * Using exact power of 2 (1/8) results in smaller code
166 */ 166 */
167#define SLEW_THRESHOLD 0.125 167#define SLEW_THRESHOLD 0.125
168//^^^^^^^^^^^^^^^^^^^^^^^^^^ TODO: man adjtimex about tmx.offset:
169// "Since Linux 2.6.26, the supplied value is clamped to the range (-0.5s, +0.5s)"
170// - can use this larger value instead?
171
168/* Stepout threshold (sec). std ntpd uses 900 (11 mins (!)) */ 172/* Stepout threshold (sec). std ntpd uses 900 (11 mins (!)) */
169#define WATCH_THRESHOLD 128 173//UNUSED: #define WATCH_THRESHOLD 128
170/* NB: set WATCH_THRESHOLD to ~60 when debugging to save time) */ 174/* NB: set WATCH_THRESHOLD to ~60 when debugging to save time) */
171//UNUSED: #define PANIC_THRESHOLD 1000 /* panic threshold (sec) */ 175//UNUSED: #define PANIC_THRESHOLD 1000 /* panic threshold (sec) */
172 176
@@ -419,6 +423,7 @@ struct globals {
419 uint8_t discipline_state; // doc calls it c.state 423 uint8_t discipline_state; // doc calls it c.state
420 uint8_t poll_exp; // s.poll 424 uint8_t poll_exp; // s.poll
421 int polladj_count; // c.count 425 int polladj_count; // c.count
426 int FREQHOLD_cnt;
422 long kernel_freq_drift; 427 long kernel_freq_drift;
423 peer_t *last_update_peer; 428 peer_t *last_update_peer;
424 double last_update_offset; // c.last 429 double last_update_offset; // c.last
@@ -1034,6 +1039,7 @@ step_time(double offset)
1034 tval = tvn.tv_sec; 1039 tval = tvn.tv_sec;
1035 strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval); 1040 strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &tval);
1036 bb_error_msg("setting time to %s.%06u (offset %+fs)", buf, (unsigned)tvn.tv_usec, offset); 1041 bb_error_msg("setting time to %s.%06u (offset %+fs)", buf, (unsigned)tvn.tv_usec, offset);
1042 //maybe? G.FREQHOLD_cnt = 0;
1037 1043
1038 /* Correct various fields which contain time-relative values: */ 1044 /* Correct various fields which contain time-relative values: */
1039 1045
@@ -1709,6 +1715,28 @@ update_local_clock(peer_t *p)
1709 tmx.freq = G.discipline_freq_drift * 65536e6; 1715 tmx.freq = G.discipline_freq_drift * 65536e6;
1710#endif 1716#endif
1711 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 tmx.status = STA_PLL;
1719 if (G.FREQHOLD_cnt != 0) {
1720 G.FREQHOLD_cnt--;
1721 /* man adjtimex on STA_FREQHOLD:
1722 * "Normally adjustments made via ADJ_OFFSET result in dampened
1723 * frequency adjustments also being made.
1724 * This flag prevents the small frequency adjustment from being
1725 * made when correcting for an ADJ_OFFSET value."
1726 *
1727 * Use this flag for a few first adjustments at the beginning
1728 * of ntpd execution, otherwise even relatively small initial
1729 * offset tend to cause largish changes to in-kernel tmx.freq.
1730 * If ntpd was restarted due to e.g. switch to another network,
1731 * this destroys already well-established tmx.freq value.
1732 */
1733 tmx.status |= STA_FREQHOLD;
1734 }
1735 if (G.ntp_status & LI_PLUSSEC)
1736 tmx.status |= STA_INS;
1737 if (G.ntp_status & LI_MINUSSEC)
1738 tmx.status |= STA_DEL;
1739
1712 tmx.constant = (int)G.poll_exp - 4; 1740 tmx.constant = (int)G.poll_exp - 4;
1713 /* EXPERIMENTAL. 1741 /* EXPERIMENTAL.
1714 * The below if statement should be unnecessary, but... 1742 * The below if statement should be unnecessary, but...
@@ -1722,25 +1750,18 @@ update_local_clock(peer_t *p)
1722 */ 1750 */
1723 if (G.offset_to_jitter_ratio >= TIMECONST_HACK_GATE) 1751 if (G.offset_to_jitter_ratio >= TIMECONST_HACK_GATE)
1724 tmx.constant--; 1752 tmx.constant--;
1753 if (tmx.constant < 0)
1754 tmx.constant = 0;
1755
1725 tmx.offset = (long)(offset * 1000000); /* usec */ 1756 tmx.offset = (long)(offset * 1000000); /* usec */
1726 if (SLEW_THRESHOLD < STEP_THRESHOLD) { 1757 if (SLEW_THRESHOLD < STEP_THRESHOLD) {
1727 if (tmx.offset > (long)(SLEW_THRESHOLD * 1000000)) { 1758 if (tmx.offset > (long)(SLEW_THRESHOLD * 1000000)) {
1728 tmx.offset = (long)(SLEW_THRESHOLD * 1000000); 1759 tmx.offset = (long)(SLEW_THRESHOLD * 1000000);
1729 tmx.constant--;
1730 } 1760 }
1731 if (tmx.offset < -(long)(SLEW_THRESHOLD * 1000000)) { 1761 if (tmx.offset < -(long)(SLEW_THRESHOLD * 1000000)) {
1732 tmx.offset = -(long)(SLEW_THRESHOLD * 1000000); 1762 tmx.offset = -(long)(SLEW_THRESHOLD * 1000000);
1733 tmx.constant--;
1734 } 1763 }
1735 } 1764 }
1736 if (tmx.constant < 0)
1737 tmx.constant = 0;
1738
1739 tmx.status = STA_PLL;
1740 if (G.ntp_status & LI_PLUSSEC)
1741 tmx.status |= STA_INS;
1742 if (G.ntp_status & LI_MINUSSEC)
1743 tmx.status |= STA_DEL;
1744 1765
1745 //tmx.esterror = (uint32_t)(clock_jitter * 1e6); 1766 //tmx.esterror = (uint32_t)(clock_jitter * 1e6);
1746 //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6); 1767 //tmx.maxerror = (uint32_t)((sys_rootdelay / 2 + sys_rootdisp) * 1e6);
@@ -2227,6 +2248,7 @@ static NOINLINE void ntp_init(char **argv)
2227 if (BURSTPOLL != 0) 2248 if (BURSTPOLL != 0)
2228 G.poll_exp = BURSTPOLL; /* speeds up initial sync */ 2249 G.poll_exp = BURSTPOLL; /* speeds up initial sync */
2229 G.last_script_run = G.reftime = G.last_update_recv_time = gettime1900d(); /* sets G.cur_time too */ 2250 G.last_script_run = G.reftime = G.last_update_recv_time = gettime1900d(); /* sets G.cur_time too */
2251 G.FREQHOLD_cnt = 8;
2230 2252
2231 /* Parse options */ 2253 /* Parse options */
2232 peers = NULL; 2254 peers = NULL;