aboutsummaryrefslogtreecommitdiff
path: root/networking/ntpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-02-28 02:45:00 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2012-02-28 02:45:00 +0100
commitfc4ebd0d0b189813fa7f8866b0ef590f1ef44f74 (patch)
tree7ced8740a4179e057bab7f53bfe6e07575b702e6 /networking/ntpd.c
parent16c52a5d7bfdfe7f1b9f86a223623a45c7074fa5 (diff)
downloadbusybox-w32-fc4ebd0d0b189813fa7f8866b0ef590f1ef44f74.tar.gz
busybox-w32-fc4ebd0d0b189813fa7f8866b0ef590f1ef44f74.tar.bz2
busybox-w32-fc4ebd0d0b189813fa7f8866b0ef590f1ef44f74.zip
ntpd: fix offset adjustment after step; better step printing
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r--networking/ntpd.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 1df6476c1..a8738951f 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -111,8 +111,8 @@
111#define MAXPOLL 12 /* maximum poll interval (12: 1.1h, 17: 36.4h). std ntpd uses 17 */ 111#define MAXPOLL 12 /* maximum poll interval (12: 1.1h, 17: 36.4h). std ntpd uses 17 */
112/* Actively lower poll when we see such big offsets. 112/* Actively lower poll when we see such big offsets.
113 * With STEP_THRESHOLD = 0.125, it means we try to sync more aggressively 113 * With STEP_THRESHOLD = 0.125, it means we try to sync more aggressively
114 * if offset increases over 0.03 sec */ 114 * if offset increases over ~0.04 sec */
115#define POLLDOWN_OFFSET (STEP_THRESHOLD / 4) 115#define POLLDOWN_OFFSET (STEP_THRESHOLD / 3)
116#define MINDISP 0.01 /* minimum dispersion (sec) */ 116#define MINDISP 0.01 /* minimum dispersion (sec) */
117#define MAXDISP 16 /* maximum dispersion (sec) */ 117#define MAXDISP 16 /* maximum dispersion (sec) */
118#define MAXSTRAT 16 /* maximum stratum (infinity metric) */ 118#define MAXSTRAT 16 /* maximum stratum (infinity metric) */
@@ -127,9 +127,9 @@
127 * we grow a counter: += MINPOLL. When it goes over POLLADJ_LIMIT, 127 * we grow a counter: += MINPOLL. When it goes over POLLADJ_LIMIT,
128 * we poll_exp++. If offset isn't small, counter -= poll_exp*2, 128 * we poll_exp++. If offset isn't small, counter -= poll_exp*2,
129 * and when it goes below -POLLADJ_LIMIT, we poll_exp-- 129 * and when it goes below -POLLADJ_LIMIT, we poll_exp--
130 * (bumped from 30 to 36 since otherwise I often see poll_exp going *2* steps down) 130 * (bumped from 30 to 40 since otherwise I often see poll_exp going *2* steps down)
131 */ 131 */
132#define POLLADJ_LIMIT 36 132#define POLLADJ_LIMIT 40
133/* If offset < POLLADJ_GATE * discipline_jitter, then we can increase 133/* If offset < POLLADJ_GATE * discipline_jitter, then we can increase
134 * poll interval (we think we can't improve timekeeping 134 * poll interval (we think we can't improve timekeeping
135 * by staying at smaller poll). 135 * by staying at smaller poll).
@@ -622,7 +622,11 @@ reset_peer_stats(peer_t *p, double offset)
622 if (small_ofs) { 622 if (small_ofs) {
623 p->filter_datapoint[i].d_recv_time += offset; 623 p->filter_datapoint[i].d_recv_time += offset;
624 if (p->filter_datapoint[i].d_offset != 0) { 624 if (p->filter_datapoint[i].d_offset != 0) {
625 p->filter_datapoint[i].d_offset += offset; 625 p->filter_datapoint[i].d_offset -= offset;
626 //bb_error_msg("p->filter_datapoint[%d].d_offset %f -> %f",
627 // i,
628 // p->filter_datapoint[i].d_offset + offset,
629 // p->filter_datapoint[i].d_offset);
626 } 630 }
627 } else { 631 } else {
628 p->filter_datapoint[i].d_recv_time = G.cur_time; 632 p->filter_datapoint[i].d_recv_time = G.cur_time;
@@ -808,22 +812,24 @@ step_time(double offset)
808{ 812{
809 llist_t *item; 813 llist_t *item;
810 double dtime; 814 double dtime;
811 struct timeval tv; 815 struct timeval tvc, tvn;
812 char buf[80]; 816 char buf[sizeof("yyyy-mm-dd hh:mm:ss") + /*paranoia:*/ 4];
813 time_t tval; 817 time_t tval;
814 818
815 gettimeofday(&tv, NULL); /* never fails */ 819 gettimeofday(&tvc, NULL); /* never fails */
816 dtime = offset + tv.tv_sec; 820 dtime = tvc.tv_sec + (1.0e-6 * tvc.tv_usec) + offset;
817 dtime += 1.0e-6 * tv.tv_usec; 821 d_to_tv(dtime, &tvn);
818 d_to_tv(dtime, &tv); 822 if (settimeofday(&tvn, NULL) == -1)
819
820 if (settimeofday(&tv, NULL) == -1)
821 bb_perror_msg_and_die("settimeofday"); 823 bb_perror_msg_and_die("settimeofday");
822 824
823 tval = tv.tv_sec; 825 VERB2 {
824 strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y", localtime(&tval)); 826 tval = tvc.tv_sec;
825 827 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&tval));
826 bb_error_msg("setting clock to %s (offset %fs)", buf, offset); 828 bb_error_msg("current time is %s.%06u", buf, (unsigned)tvc.tv_usec);
829 }
830 tval = tvn.tv_sec;
831 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&tval));
832 bb_error_msg("setting time to %s.%06u (offset %+fs)", buf, (unsigned)tvn.tv_usec, offset);
827 833
828 /* Correct various fields which contain time-relative values: */ 834 /* Correct various fields which contain time-relative values: */
829 835