diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-03-02 01:22:40 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-03-02 01:22:40 +0100 |
commit | 74584b86656113391763a21ea32fbff6d9fb6a9a (patch) | |
tree | 785d1923cad151c655f73559cbb2426281aeb453 | |
parent | 03a99e3d5c654d3dd8103199e20c8252dab8e091 (diff) | |
download | busybox-w32-74584b86656113391763a21ea32fbff6d9fb6a9a.tar.gz busybox-w32-74584b86656113391763a21ea32fbff6d9fb6a9a.tar.bz2 busybox-w32-74584b86656113391763a21ea32fbff6d9fb6a9a.zip |
ntpd: log jitter on update too; increase assumed clock precision x2 - to 2ms
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ntpd.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index a8738951f..e7e992205 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -276,11 +276,12 @@ struct globals { | |||
276 | unsigned verbose; | 276 | unsigned verbose; |
277 | unsigned peer_cnt; | 277 | unsigned peer_cnt; |
278 | /* refid: 32-bit code identifying the particular server or reference clock | 278 | /* refid: 32-bit code identifying the particular server or reference clock |
279 | * in stratum 0 packets this is a four-character ASCII string, | 279 | * in stratum 0 packets this is a four-character ASCII string, |
280 | * called the kiss code, used for debugging and monitoring | 280 | * called the kiss code, used for debugging and monitoring |
281 | * in stratum 1 packets this is a four-character ASCII string | 281 | * in stratum 1 packets this is a four-character ASCII string |
282 | * assigned to the reference clock by IANA. Example: "GPS " | 282 | * assigned to the reference clock by IANA. Example: "GPS " |
283 | * in stratum 2+ packets, it's IPv4 address or 4 first bytes of MD5 hash of IPv6 | 283 | * in stratum 2+ packets, it's IPv4 address or 4 first bytes |
284 | * of MD5 hash of IPv6 | ||
284 | */ | 285 | */ |
285 | uint32_t refid; | 286 | uint32_t refid; |
286 | uint8_t ntp_status; | 287 | uint8_t ntp_status; |
@@ -289,27 +290,35 @@ struct globals { | |||
289 | * mains-frequency clock incrementing at 60 Hz is 16 ms, even when the | 290 | * mains-frequency clock incrementing at 60 Hz is 16 ms, even when the |
290 | * system clock hardware representation is to the nanosecond. | 291 | * system clock hardware representation is to the nanosecond. |
291 | * | 292 | * |
292 | * Delays, jitters of various kinds are clamper down to precision. | 293 | * Delays, jitters of various kinds are clamped down to precision. |
293 | * | 294 | * |
294 | * If precision_sec is too large, discipline_jitter gets clamped to it | 295 | * If precision_sec is too large, discipline_jitter gets clamped to it |
295 | * and if offset is much smaller than discipline_jitter, poll interval | 296 | * and if offset is smaller than discipline_jitter * POLLADJ_GATE, poll |
296 | * grows even though we really can benefit from staying at smaller one, | 297 | * interval grows even though we really can benefit from staying at |
297 | * collecting non-lagged datapoits and correcting the offset. | 298 | * smaller one, collecting non-lagged datapoits and correcting offset. |
298 | * (Lagged datapoits exist when poll_exp is large but we still have | 299 | * (Lagged datapoits exist when poll_exp is large but we still have |
299 | * systematic offset error - the time distance between datapoints | 300 | * systematic offset error - the time distance between datapoints |
300 | * is significat and older datapoints have smaller offsets. | 301 | * is significant and older datapoints have smaller offsets. |
301 | * This makes our offset estimation a bit smaller than reality) | 302 | * This makes our offset estimation a bit smaller than reality) |
302 | * Due to this effect, setting G_precision_sec close to | 303 | * Due to this effect, setting G_precision_sec close to |
303 | * STEP_THRESHOLD isn't such a good idea - offsets may grow | 304 | * STEP_THRESHOLD isn't such a good idea - offsets may grow |
304 | * too big and we will step. I observed it with -6. | 305 | * too big and we will step. I observed it with -6. |
305 | * | 306 | * |
306 | * OTOH, setting precision too small would result in futile attempts | 307 | * OTOH, setting precision_sec far too small would result in futile |
307 | * to syncronize to the unachievable precision. | 308 | * attempts to syncronize to an unachievable precision. |
308 | * | 309 | * |
309 | * -6 is 1/64 sec, -7 is 1/128 sec and so on. | 310 | * -6 is 1/64 sec, -7 is 1/128 sec and so on. |
311 | * -8 is 1/256 ~= 0.003906 (worked well for me --vda) | ||
312 | * -9 is 1/512 ~= 0.001953 (let's try this for some time) | ||
310 | */ | 313 | */ |
311 | #define G_precision_exp -8 | 314 | #define G_precision_exp -9 |
312 | #define G_precision_sec (1.0 / (1 << (- G_precision_exp))) | 315 | /* |
316 | * G_precision_exp is used only for construction outgoing packets. | ||
317 | * It's ok to set G_precision_sec to a slightly different value | ||
318 | * (One which is "nicer looking" in logs). | ||
319 | * Exact value would be (1.0 / (1 << (- G_precision_exp))): | ||
320 | */ | ||
321 | #define G_precision_sec 0.002 | ||
313 | uint8_t stratum; | 322 | uint8_t stratum; |
314 | /* Bool. After set to 1, never goes back to 0: */ | 323 | /* Bool. After set to 1, never goes back to 0: */ |
315 | smallint initial_poll_complete; | 324 | smallint initial_poll_complete; |
@@ -1334,8 +1343,10 @@ update_local_clock(peer_t *p) | |||
1334 | * weighted offset differences. Used by the poll adjust code. | 1343 | * weighted offset differences. Used by the poll adjust code. |
1335 | */ | 1344 | */ |
1336 | etemp = SQUARE(G.discipline_jitter); | 1345 | etemp = SQUARE(G.discipline_jitter); |
1337 | dtemp = SQUARE(MAXD(fabs(offset - G.last_update_offset), G_precision_sec)); | 1346 | dtemp = SQUARE(offset - G.last_update_offset); |
1338 | G.discipline_jitter = SQRT(etemp + (dtemp - etemp) / AVG); | 1347 | G.discipline_jitter = SQRT(etemp + (dtemp - etemp) / AVG); |
1348 | if (G.discipline_jitter < G_precision_sec) | ||
1349 | G.discipline_jitter = G_precision_sec; | ||
1339 | VERB3 bb_error_msg("discipline jitter=%f", G.discipline_jitter); | 1350 | VERB3 bb_error_msg("discipline jitter=%f", G.discipline_jitter); |
1340 | 1351 | ||
1341 | switch (G.discipline_state) { | 1352 | switch (G.discipline_state) { |
@@ -1495,8 +1506,8 @@ update_local_clock(peer_t *p) | |||
1495 | } | 1506 | } |
1496 | #endif | 1507 | #endif |
1497 | G.kernel_freq_drift = tmx.freq / 65536; | 1508 | G.kernel_freq_drift = tmx.freq / 65536; |
1498 | VERB2 bb_error_msg("update peer:%s, offset:%+f, clock drift:%+ld ppm", | 1509 | VERB2 bb_error_msg("update peer:%s, offset:%+f, jitter:%f, clock drift:%+ld ppm", |
1499 | p->p_dotted, G.last_update_offset, G.kernel_freq_drift); | 1510 | p->p_dotted, G.last_update_offset, G.discipline_jitter, G.kernel_freq_drift); |
1500 | 1511 | ||
1501 | return 1; /* "ok to increase poll interval" */ | 1512 | return 1; /* "ok to increase poll interval" */ |
1502 | } | 1513 | } |