ntpd: disable unused code; show kernel's clock drift correction
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
bfc2a32d88
commit
61313117a0
@ -49,7 +49,7 @@
|
||||
#define RETRY_INTERVAL 5 /* on error, retry in N secs */
|
||||
#define QUERYTIME_MAX 15 /* wait for reply up to N secs */
|
||||
|
||||
#define FREQ_TOLERANCE 15e-6 /* % frequency tolerance (15 PPM) */
|
||||
#define FREQ_TOLERANCE 0.000015 /* % frequency tolerance (15 PPM) */
|
||||
#define MINPOLL 4 /* % minimum poll interval (6: 64 s) */
|
||||
#define MAXPOLL 12 /* % maximum poll interval (12: 1.1h, 17: 36.4h) (was 17) */
|
||||
#define MINDISP 0.01 /* % minimum dispersion (s) */
|
||||
@ -59,7 +59,7 @@
|
||||
#define MIN_SELECTED 1 /* % minimum intersection survivors */
|
||||
#define MIN_CLUSTERED 3 /* % minimum cluster survivors */
|
||||
|
||||
#define MAXFREQ 0.000500 /* frequency tolerance (500 PPM) */
|
||||
#define MAXDRIFT 0.000500 /* frequency drift we can correct (500 PPM) */
|
||||
|
||||
/* Clock discipline parameters and constants */
|
||||
#define STEP_THRESHOLD 0.128 /* step threshold (s) */
|
||||
@ -70,8 +70,8 @@
|
||||
/* Poll-adjust threshold.
|
||||
* When we see that offset is small enough compared to discipline jitter,
|
||||
* we grow a counter: += MINPOLL. When it goes over POLLADJ_LIMIT,
|
||||
* we poll_ext++. If offset isn't small, counter -= poll_ext*2,
|
||||
* and when it goes below -POLLADJ_LIMIT, we poll_ext--
|
||||
* we poll_exp++. If offset isn't small, counter -= poll_exp*2,
|
||||
* and when it goes below -POLLADJ_LIMIT, we poll_exp--
|
||||
*/
|
||||
#define POLLADJ_LIMIT 30
|
||||
/* If offset < POLLADJ_GATE * discipline_jitter, then we can increase
|
||||
@ -88,6 +88,7 @@
|
||||
/* Parameter averaging constant */
|
||||
#define AVG 4
|
||||
|
||||
|
||||
enum {
|
||||
NTP_VERSION = 4,
|
||||
NTP_MAXSTRATUM = 15,
|
||||
@ -251,13 +252,17 @@ struct globals {
|
||||
uint8_t discipline_state; // doc calls it c.state
|
||||
uint8_t poll_exp; // s.poll
|
||||
int polladj_count; // c.count
|
||||
double discipline_jitter; // c.jitter
|
||||
long kernel_freq_drift;
|
||||
double last_update_offset; // c.last
|
||||
double last_update_recv_time; // s.t
|
||||
double discipline_jitter; // c.jitter
|
||||
//TODO: add s.jitter - grep for it here and see clock_combine() in doc
|
||||
#define USING_KERNEL_PLL_LOOP 1
|
||||
#if !USING_KERNEL_PLL_LOOP
|
||||
double discipline_freq_drift; // c.freq
|
||||
//TODO: conditionally calculate wander? it's used only for logging
|
||||
double discipline_wander; // c.wander
|
||||
double last_update_recv_time; // s.t
|
||||
//TODO: add s.jitter - grep for it here and see clock_combine() in doc
|
||||
#endif
|
||||
};
|
||||
#define G (*ptr_to_globals)
|
||||
|
||||
@ -1153,25 +1158,27 @@ update_local_clock(peer_t *p, double t)
|
||||
* (Any other state does not reach this, they all return earlier)
|
||||
* By this time, freq_drift and G.last_update_offset are set
|
||||
* to values suitable for adjtimex.
|
||||
*
|
||||
* Calculate the new frequency drift and frequency stability (wander).
|
||||
*/
|
||||
#if !USING_KERNEL_PLL_LOOP
|
||||
/* Calculate the new frequency drift and frequency stability (wander).
|
||||
* Compute the clock wander as the RMS of exponentially weighted
|
||||
* frequency differences. This is not used directly, but can,
|
||||
* along with the jitter, be a highly useful monitoring and
|
||||
* debugging tool.
|
||||
*/
|
||||
dtemp = G.discipline_freq_drift + freq_drift;
|
||||
G.discipline_freq_drift = MAXD(MIND(MAXFREQ, dtemp), -MAXFREQ);
|
||||
G.discipline_freq_drift = MAXD(MIND(MAXDRIFT, dtemp), -MAXDRIFT);
|
||||
etemp = SQUARE(G.discipline_wander);
|
||||
dtemp = SQUARE(dtemp);
|
||||
G.discipline_wander = SQRT(etemp + (dtemp - etemp) / AVG);
|
||||
|
||||
VERB3 {
|
||||
bb_error_msg("discipline freq_drift=%.9f(int:%ld corr:%e) wander=%f",
|
||||
VERB3 bb_error_msg("discipline freq_drift=%.9f(int:%ld corr:%e) wander=%f",
|
||||
G.discipline_freq_drift,
|
||||
(long)(G.discipline_freq_drift * 65536e6),
|
||||
freq_drift,
|
||||
G.discipline_wander);
|
||||
#endif
|
||||
VERB3 {
|
||||
memset(&tmx, 0, sizeof(tmx));
|
||||
if (adjtimex(&tmx) < 0)
|
||||
bb_perror_msg_and_die("adjtimex");
|
||||
@ -1192,7 +1199,7 @@ update_local_clock(peer_t *p, double t)
|
||||
}
|
||||
memset(&tmx, 0, sizeof(tmx));
|
||||
#if 0
|
||||
//doesn't work, offset remains 0 (!):
|
||||
//doesn't work, offset remains 0 (!) in kernel:
|
||||
//ntpd: set adjtimex freq:1786097 tmx.offset:77487
|
||||
//ntpd: prev adjtimex freq:1786097 tmx.offset:0
|
||||
//ntpd: cur adjtimex freq:1786097 tmx.offset:0
|
||||
@ -1218,14 +1225,21 @@ update_local_clock(peer_t *p, double t)
|
||||
rc = adjtimex(&tmx);
|
||||
if (rc < 0)
|
||||
bb_perror_msg_and_die("adjtimex");
|
||||
if (G.kernel_freq_drift != tmx.freq / 65536) {
|
||||
G.kernel_freq_drift = tmx.freq / 65536;
|
||||
VERB2 bb_error_msg("kernel clock drift: %ld ppm", G.kernel_freq_drift);
|
||||
}
|
||||
VERB3 {
|
||||
bb_error_msg("adjtimex:%d freq:%ld offset:%ld constant:%ld status:0x%x",
|
||||
rc, tmx.freq, tmx.offset, tmx.constant, tmx.status);
|
||||
#if 0
|
||||
/* always gives the same output as above msg */
|
||||
memset(&tmx, 0, sizeof(tmx));
|
||||
if (adjtimex(&tmx) < 0)
|
||||
bb_perror_msg_and_die("adjtimex");
|
||||
VERB3 bb_error_msg("c adjtimex freq:%ld offset:%ld constant:%ld status:0x%x",
|
||||
tmx.freq, tmx.offset, tmx.constant, tmx.status);
|
||||
#endif
|
||||
}
|
||||
// #define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */ - ?
|
||||
// it appeared after a while:
|
||||
|
Loading…
Reference in New Issue
Block a user