]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 472] configurable driftfile write frequency
authorHarlan Stenn <stenn@ntp.org>
Wed, 15 Mar 2006 07:29:27 +0000 (02:29 -0500)
committerHarlan Stenn <stenn@ntp.org>
Wed, 15 Mar 2006 07:29:27 +0000 (02:29 -0500)
bk: 4417c257EwfGmlwlcOt-13VzdDkTtA

html/miscopt.html
include/ntpd.h
ntpd/ntp_config.c
ntpd/ntp_timer.c
ntpd/ntp_util.c
ntpd/ntpd.c

index 6fd4af2f507ebffae3365fa7f059e73ae7b8699a..73c7f617a91652982505cbb828d2c535ae69e10f 100644 (file)
                        <dd>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.
                        <dt><tt>calldelay <i>delay</i></tt>
                        <dd>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.
-                       <dt><tt>driftfile <i>driftfile</i></tt>
+                       <dt><tt>driftfile <i>driftfile</i> [<i>
+               minutes </i> [<i> tolerance </i>] ]</tt>
                        <dd>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 <tt>-f</tt> 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.
                                <p>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 <tt>ntpd</tt> must have write permission for the directory the drift file is located in, and that file system links, symbolic or otherwise, should be avoided.</p>
-                       <dt><tt>enable [ auth | bclient | calibrate | kernel | monitor | ntp | pps | stats]</tt><br>
+                       
+<p>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 <tt>minutes</tt> is how often the file will be written.  If omitted or less
+than 1, the interval will be 60 minutes (one hour).  The parameter <tt>tolerance</tt> is the
+threshold to skip writing the new value.  If the new value is within
+<tt>tolerance</tt> 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.</p>
+<dt><tt>enable [ auth | bclient | calibrate | kernel | monitor | ntp | pps | stats]</tt><br>
                                <tt>disable [ auth | bclient | calibrate | kernel | monitor | ntp | pps | stats ]</tt>
                        <dd>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 <a href="ntpdc.html"><tt>ntpdc</tt></a> utility program.
                                <dl>
                <script type="text/javascript" language="javascript" src="scripts/footer.txt"></script>
        </body>
 
-</html>
\ No newline at end of file
+</html>
index 63681636d75d42dd151f683b6b00bc5ff111864c..971202895cc624f07efa6e4c92c0db8f62947c0d 100644 (file)
@@ -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 */
index 1575bf244598225071b00f93f999c2187f49b364..250d1abe57f0b5408857c75c6d30e484ac63d1ee 100644 (file)
@@ -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:
index d041381584cff8ae9d8487da4d1477c35aa26091..6c96d24b46c57bbe8e575776c2f66fa8afc19d3b 100644 (file)
@@ -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;
        }
 }
 
index c6fa4651279d6700ec598c20ba1c216c98c8d0f4..5c0cea470f7b6651d54324eddbc1751a55316537 100644 (file)
@@ -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);
index 5468140871d43576c344092b97ab292ba94e719c..3bd68ffb5b3f8bb6c32cc824021d91e73f043506 100644 (file)
@@ -990,6 +990,7 @@ finish(
 {
 
        msyslog(LOG_NOTICE, "ntpd exiting on signal %d", sig);
+       write_stats();
 #ifdef HAVE_DNSREGISTRATION
        if (mdns != NULL)
        DNSServiceRefDeallocate(mdns);