]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Include maximum clock frequency error in our dispersion
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 2 Dec 2010 13:56:01 +0000 (14:56 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 3 Dec 2010 12:15:14 +0000 (13:15 +0100)
Add maxclockerror directive to set the stability of the clock (10 ppm by
default) and include it in our dispersion.

chrony.texi
conf.c
conf.h
local.c
local.h
reference.c

index 47086aa5386adcc0de0ae9ccbfbae1c8ca150b64..bee73f5498d42eb0ec73bc8ea929d7a1d097c68d 100644 (file)
@@ -1191,6 +1191,7 @@ directives can occur in any order in the file.
 * mailonchange directive::      Send email if a clock correction above a threshold occurs
 * makestep directive::          Step system clock if large correction is needed
 * manual directive::            Allow manual entry using chronyc's settime cmd.
+* maxclockerror directive::     Set maximum frequency error of local clock
 * maxupdateskew directive::     Stop bad estimates upsetting machine clock
 * noclientlog directive::       Prevent chronyd from gathering data about clients
 * clientloglimit directive::    Set client log memory limit
@@ -2209,6 +2210,25 @@ idea of the two commands is that the @code{manual} command controls the
 manual clock driver's behaviour, whereas the @code{settime} command
 allows samples of manually entered time to be provided).
 @c }}}
+@c {{{ maxclockerror
+@node maxclockerror directive
+@subsection maxclockerror
+The @code{maxclockerror} directive sets the maximum assumed frequency
+error of the local clock.  This is a frequency stability of the clock,
+not an absolute frequency error.
+
+By default, the maximum assumed error is set to 10 ppm.
+
+The syntax is
+
+@example
+maxclockerror <error-in-ppm>
+@end example
+
+Typical values for <error-in-ppm> might be 10 for a low quality clock
+to 0.1 for a high quality clock using a temperature compensated
+crystal oscillator.
+@c }}}
 @c {{{ maxupdateskew
 @node maxupdateskew directive
 @subsection maxupdateskew
diff --git a/conf.c b/conf.c
index e4ed75a894b44df9be888c20810feaeb88b7d8bd..f6fd9b2f451a5acdd94420f9f3b2b20b540e459e 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -77,6 +77,7 @@ static void parse_log(const char *);
 static void parse_logbanner(const char *);
 static void parse_logdir(const char *);
 static void parse_maxupdateskew(const char *);
+static void parse_maxclockerror(const char *);
 static void parse_peer(const char *);
 static void parse_acquisitionport(const char *);
 static void parse_port(const char *);
@@ -120,6 +121,7 @@ static char *drift_file = NULL;
 static char *rtc_file = NULL;
 static unsigned long command_key_id;
 static double max_update_skew = 1000.0;
+static double max_clock_error = 10; /* in ppm */
 
 static int cmd_port = -1;
 
@@ -232,6 +234,7 @@ static const Command commands[] = {
   {"dumponexit", 10, parse_dumponexit},
   {"dumpdir", 7, parse_dumpdir},
   {"maxupdateskew", 13, parse_maxupdateskew},
+  {"maxclockerror", 13, parse_maxclockerror},
   {"commandkey", 10, parse_commandkey},
   {"initstepslew", 12, parse_initstepslew},
   {"local", 5, parse_local},
@@ -593,6 +596,16 @@ parse_maxupdateskew(const char *line)
 
 /* ================================================== */
 
+static void
+parse_maxclockerror(const char *line)
+{
+  if (sscanf(line, "%lf", &max_clock_error) != 1) {
+    LOG(LOGS_WARN, LOGF_Configure, "Could not read max clock error at line %d in file", line_number);
+  }
+}
+
+/* ================================================== */
+
 static void
 parse_driftfile(const char *line)
 {
@@ -1407,6 +1420,14 @@ CNF_GetMaxUpdateSkew(void)
 
 /* ================================================== */
 
+double
+CNF_GetMaxClockError(void)
+{
+  return max_clock_error;
+}
+
+/* ================================================== */
+
 int
 CNF_GetManualEnabled(void)
 {
diff --git a/conf.h b/conf.h
index 9ccef777e4672f2c9ef7b74087e54c9897b2c394..e2aac480244b7fa4258a041bd3c9148ad2fc6105 100644 (file)
--- a/conf.h
+++ b/conf.h
@@ -77,6 +77,7 @@ extern void CNF_GetLinuxFreqScale(int *set, double *freq_scale);
 
 /* Value returned in ppm, as read from file */
 extern double CNF_GetMaxUpdateSkew(void);
+extern double CNF_GetMaxClockError(void);
 extern int CNF_AllowLocalReference(int *stratum);
 
 extern void CNF_SetupAccessRestrictions(void);
diff --git a/local.c b/local.c
index 64d635bf262fc36ba14ce686eda3b9b7b8b88687..da956731631177f99fe3dc62e3eb0e15b2b48244 100644 (file)
--- a/local.c
+++ b/local.c
@@ -34,6 +34,7 @@
 #include <assert.h>
 #include <stddef.h>
 
+#include "conf.h"
 #include "local.h"
 #include "localp.h"
 #include "memory.h"
@@ -91,6 +92,8 @@ static DispersionNotifyListEntry dispersion_notify_list;
 static int precision_log;
 static double precision_quantum;
 
+static double max_clock_error;
+
 /* ================================================== */
 
 /* Define the number of increments of the system clock that we want
@@ -157,6 +160,8 @@ LCL_Initialise(void)
   temp_comp_ppm = 0.0;
 
   calculate_sys_precision();
+
+  max_clock_error = CNF_GetMaxClockError() * 1e-6;
 }
 
 /* ================================================== */
@@ -187,6 +192,14 @@ LCL_GetSysPrecisionAsQuantum(void)
 
 /* ================================================== */
 
+double
+LCL_GetMaxClockError(void)
+{
+  return max_clock_error;
+}
+
+/* ================================================== */
+
 void
 LCL_AddParameterChangeHandler(LCL_ParameterChangeHandler handler, void *anything)
 {
diff --git a/local.h b/local.h
index ce29918241ce8990166fd16dacf37bbb010403bc..06eb697d4b5427b193ac5ccb512e2f121b71a86b 100644 (file)
--- a/local.h
+++ b/local.h
@@ -165,6 +165,10 @@ extern int LCL_GetSysPrecisionAsLog(void);
 /* Routine to read the system precision in terms of the actual time step */
 extern double LCL_GetSysPrecisionAsQuantum(void);
 
+/* Routine to read the maximum frequency error of the local clock.  This
+   is a frequency stability, not an absolute error. */
+extern double LCL_GetMaxClockError(void);
+
 /* Routine to initialise the module (to be called once at program
    start-up) */
 
index 01b53ef599dd18e8886c87af156c04dde2a55c72..c4b6013c1b308fe69ba71530a5cc81e1b8a2a093 100644 (file)
@@ -757,7 +757,7 @@ REF_GetReferenceParams
     *stratum = our_stratum;
 
     UTI_DiffTimevalsToDouble(&elapsed, local_time, &our_ref_time);
-    extra_dispersion = (our_skew + fabs(our_residual_freq)) * elapsed;
+    extra_dispersion = (our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError()) * elapsed;
 
     *leap_status = our_leap_status;
     *ref_id = our_ref_id;
@@ -870,7 +870,7 @@ REF_GetTrackingReport(RPT_TrackingReport *rep)
   if (are_we_synchronised) {
     
     UTI_DiffTimevalsToDouble(&elapsed, &now_cooked, &our_ref_time);
-    extra_dispersion = (our_skew + fabs(our_residual_freq)) * elapsed;
+    extra_dispersion = (our_skew + fabs(our_residual_freq) + LCL_GetMaxClockError()) * elapsed;
     
     rep->ref_id = our_ref_id;
     rep->ip_addr = our_ref_ip;