From: Harlan Stenn Date: Wed, 15 Mar 2006 07:29:27 +0000 (-0500) Subject: [Bug 472] configurable driftfile write frequency X-Git-Tag: NTP_4_2_1P10_RC~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8df450a1840ad4afd6de553bd3e58962f08955b2;p=thirdparty%2Fntp.git [Bug 472] configurable driftfile write frequency bk: 4417c257EwfGmlwlcOt-13VzdDkTtA --- diff --git a/html/miscopt.html b/html/miscopt.html index 6fd4af2f5..73c7f617a 100644 --- a/html/miscopt.html +++ b/html/miscopt.html @@ -22,10 +22,22 @@
The broadcast and multicast modes require a special calibration to determine the network delay between the local and remote servers. Ordinarily, this is done automatically by the initial protocol exchanges between the client and server. In some cases, the calibration procedure may fail due to network or server access controls, for example. This command specifies the default delay to be used under these circumstances. Typically (for Ethernet), a number between 0.003 and 0.007 seconds is appropriate. The default when this command is not used is 0.004 seconds.
calldelay delay
This option controls the delay in seconds between the first and second packets sent in burst or iburst mode to allow additional time for a modem or ISDN call to complete. -
driftfile driftfile +
driftfile driftfile [ + minutes [ tolerance ] ]
This command specifies the complete path and name of the file used to record the frequency of the local clock oscillator. This is the same operation as the -f command linke option. If the file exists, it is read at startup in order to set the initial frequency and then updated once per hour with the current frequency computed by the daemon. If the file name is specified, but the file itself does not exist, the starts with an initial frequency of zero and creates the file when writing it for the first time. If this command is not given, the daemon will always start with an initial frequency of zero.

The file format consists of a single line containing a single floating point number, which records the frequency offset measured in parts-per-million (PPM). The file is updated by first writing the current drift value into a temporary file and then renaming this file to replace the old version. This implies that ntpd must have write permission for the directory the drift file is located in, and that file system links, symbolic or otherwise, should be avoided.

-
enable [ auth | bclient | calibrate | kernel | monitor | ntp | pps | stats]
+ +

The two optional values determine how often the file is written, and +are particuarly useful when is it desirable to avoid spinning up the +disk unnecessarily. The parameter minutes is how often the file will be written. If omitted or less +than 1, the interval will be 60 minutes (one hour). The parameter tolerance is the +threshold to skip writing the new value. If the new value is within +tolerance percent of the last value written (compared out to 3 +decimal places), the write will be +skipped. The default is 0.0, which means that the write will occur +unless the current and previous values are the same. A tolerance of +.1 equates roughly to a difference in the 2nd decimal place.

+
enable [ auth | bclient | calibrate | kernel | monitor | ntp | pps | stats]
disable [ auth | bclient | calibrate | kernel | monitor | ntp | pps | stats ]
Provides a way to enable or disable various system options. Flags not mentioned are unaffected. Note that all of these flags can be controlled remotely using the ntpdc utility program.
@@ -108,4 +120,4 @@ - \ No newline at end of file + diff --git a/include/ntpd.h b/include/ntpd.h index 63681636d..971202895 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -209,7 +209,7 @@ extern l_fp sys_revoketime; /* ntp_util.c */ extern void init_util P((void)); -extern void hourly_stats P((void)); +extern void write_stats P((void)); extern void stats_config P((int, char *)); extern void record_peer_stats P((struct sockaddr_storage *, int, double, double, double, double)); extern void record_loop_stats P((double, double, double, double, int)); @@ -422,6 +422,8 @@ extern u_long timer_xmtcalls; /* ntp_util.c */ extern int stats_control; /* write stats to fileset? */ +extern int stats_write_period; /* # of seconds between writes. */ +extern double stats_write_tolerance; /* ntpd.c */ extern volatile int debug; /* debugging flag */ diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 1575bf244..250d1abe5 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -872,6 +872,16 @@ getconfig( stats_config(STATS_FREQ_FILE, tokens[1]); else stats_config(STATS_FREQ_FILE, (char *)0); + stats_write_period = stats_write_tolerance = 0; + if (ntokens >= 3) + stats_write_period = 60 * atol(tokens[2]); + if (stats_write_period <= 0) + stats_write_period = 3600; + if (ntokens >= 4) { + double ftemp; + sscanf(tokens[3], "%lf", &ftemp); + stats_write_tolerance = ftemp / 100; + } break; case CONFIG_PIDFILE: diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index d04138158..6c96d24b4 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -44,7 +44,7 @@ volatile int alarm_flag; */ static u_long adjust_timer; /* second timer */ static u_long keys_timer; /* minute timer */ -static u_long hourly_timer; /* hour timer */ +static u_long stats_timer; /* stats timer */ static u_long huffpuff_timer; /* huff-n'-puff timer */ #ifdef OPENSSL static u_long revoke_timer; /* keys revoke timer */ @@ -148,7 +148,7 @@ init_timer(void) alarm_flag = 0; alarm_overflow = 0; adjust_timer = 1; - hourly_timer = HOUR; + stats_timer = 0; huffpuff_timer = 0; current_time = 0; timer_overflows = 0; @@ -336,11 +336,12 @@ timer(void) #endif /* OPENSSL */ /* - * Finally, call the hourly routine. + * Finally, periodically write stats. */ - if (hourly_timer <= current_time) { - hourly_timer += HOUR; - hourly_stats(); + if (stats_timer <= current_time) { + if (stats_timer != 0) + write_stats(); + stats_timer += stats_write_period; } } diff --git a/ntpd/ntp_util.c b/ntpd/ntp_util.c index c6fa46512..5c0cea470 100644 --- a/ntpd/ntp_util.c +++ b/ntpd/ntp_util.c @@ -53,6 +53,9 @@ static char *key_file_name; */ static char *stats_drift_file; static char *stats_temp_file; +int stats_write_period = 3600; /* # of seconds between writes. */ +double stats_write_tolerance = 0; +static double prev_drift_comp = 99999.; /* * Statistics file stuff @@ -122,7 +125,7 @@ init_util(void) * hourly_stats - print some interesting stats */ void -hourly_stats(void) +write_stats(void) { FILE *fp; @@ -206,6 +209,11 @@ hourly_stats(void) record_sys_stats(); + if ((u_long)(fabs(prev_drift_comp - drift_comp) * 1e9) <= + (u_long)(fabs(stats_write_tolerance * drift_comp) * 1e9)) { + return; + } + prev_drift_comp = drift_comp; if (stats_drift_file != 0) { if ((fp = fopen(stats_temp_file, "w")) == NULL) { msyslog(LOG_ERR, "can't open %s: %m", @@ -336,6 +344,7 @@ stats_config( break; } fclose(fp); + prev_drift_comp = old_drift / 1e6; msyslog(LOG_INFO, "frequency initialized %.3f PPM from %s", old_drift, stats_drift_file); diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 546814087..3bd68ffb5 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -990,6 +990,7 @@ finish( { msyslog(LOG_NOTICE, "ntpd exiting on signal %d", sig); + write_stats(); #ifdef HAVE_DNSREGISTRATION if (mdns != NULL) DNSServiceRefDeallocate(mdns);