]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add refclock precision
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 2 Mar 2010 12:10:54 +0000 (13:10 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 2 Mar 2010 13:23:54 +0000 (14:23 +0100)
chrony.texi
conf.c
refclock.c
refclock.h

index 68e185056f8a5e339010dac5bfb8e6cbe82a5d07..a22e6790b8a64c532420dca03abf98936f3e4280 100644 (file)
@@ -2315,6 +2315,9 @@ to be inaccurate (in seconds).  Increasing the value is useful to
 avoid having no majority in the source selection algorithm or to make
 the algorithm prefer other refclocks.  The default is 1e-9 (1
 nanosecond).
+@item precision
+Refclock precision (in seconds).  The default is 1e-6 (1 microsecond)
+for SHM refclock, and 1e-9 (1 nanosecond) for SOCK and PPS refclocks.
 @end table
 
 @c }}}
diff --git a/conf.c b/conf.c
index 359c108c21961b32aa80c7c83ff4c3ce8a42baff..5942ca421ccd5a4c1f527987778ce52eb76ca377 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -437,7 +437,7 @@ parse_refclock(const char *line)
 {
   int i, n, poll, dpoll, filter_length, pps_rate;
   unsigned long ref_id, lock_ref_id;
-  double offset, delay;
+  double offset, delay, precision;
   const char *tmp;
   char name[5], cmd[10 + 1], *param;
   unsigned char ref[5];
@@ -452,6 +452,7 @@ parse_refclock(const char *line)
   pps_rate = 0;
   offset = 0.0;
   delay = 1e-9;
+  precision = 0.0;
   ref_id = 0;
   lock_ref_id = 0;
 
@@ -507,6 +508,9 @@ parse_refclock(const char *line)
     } else if (!strncasecmp(cmd, "delay", 5)) {
       if (sscanf(line, "%lf%n", &delay, &n) != 1)
         break;
+    } else if (!strncasecmp(cmd, "precision", 9)) {
+      if (sscanf(line, "%lf%n", &precision, &n) != 1)
+        break;
     } else {
       LOG(LOGS_WARN, LOGF_Configure, "Unknown refclock parameter %s at line %d", cmd, line_number);
       break;
@@ -522,6 +526,7 @@ parse_refclock(const char *line)
   refclock_sources[i].pps_rate = pps_rate;
   refclock_sources[i].offset = offset;
   refclock_sources[i].delay = delay;
+  refclock_sources[i].precision = precision;
   refclock_sources[i].ref_id = ref_id;
   refclock_sources[i].lock_ref_id = lock_ref_id;
 
index 888c4889f58c0e879dc38ca970de09c2dd85ab02..f0770aa45bc8ef447834b04e88721cef006c3a6d 100644 (file)
@@ -78,6 +78,7 @@ struct RCL_Instance_Record {
   unsigned long lock_ref;
   double offset;
   double delay;
+  double precision;
   SCH_TimeoutID timeout_id;
   SRC_Instance source;
 };
@@ -166,11 +167,14 @@ RCL_AddRefclock(RefclockParameters *params)
 
   if (strncmp(params->driver_name, "SHM", 4) == 0) {
     inst->driver = &RCL_SHM_driver;
+    inst->precision = 1e-6;
   } else if (strncmp(params->driver_name, "SOCK", 4) == 0) {
     inst->driver = &RCL_SOCK_driver;
+    inst->precision = 1e-9;
     pps_source = 1;
   } else if (strncmp(params->driver_name, "PPS", 4) == 0) {
     inst->driver = &RCL_PPS_driver;
+    inst->precision = 1e-9;
     pps_source = 1;
   } else {
     LOG_FATAL(LOGF_Refclock, "unknown refclock driver %s", params->driver_name);
@@ -194,6 +198,8 @@ RCL_AddRefclock(RefclockParameters *params)
   inst->lock_ref = params->lock_ref_id;
   inst->offset = params->offset;
   inst->delay = params->delay;
+  if (params->precision > 0.0)
+    inst->precision = params->precision;
   inst->timeout_id = -1;
   inst->source = NULL;
 
@@ -351,7 +357,7 @@ RCL_AddSample(RCL_Instance instance, struct timeval *sample_time, double offset,
 
   LCL_GetOffsetCorrection(sample_time, &correction, &dispersion);
   UTI_AddDoubleToTimeval(sample_time, correction, &cooked_time);
-  dispersion += LCL_GetSysPrecisionAsQuantum() + filter_get_avg_sample_dispersion(&instance->filter);
+  dispersion += instance->precision + filter_get_avg_sample_dispersion(&instance->filter);
 
   if (!valid_sample_time(instance, sample_time))
     return 0;
@@ -377,7 +383,7 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
 
   LCL_GetOffsetCorrection(pulse_time, &correction, &dispersion);
   UTI_AddDoubleToTimeval(pulse_time, correction, &cooked_time);
-  dispersion += LCL_GetSysPrecisionAsQuantum() + filter_get_avg_sample_dispersion(&instance->filter);
+  dispersion += instance->precision + filter_get_avg_sample_dispersion(&instance->filter);
 
   if (!valid_sample_time(instance, pulse_time))
     return 0;
index a9ab0ae75dda99beacc6971f44ae8cce082110fe..75c37b90b972621a9d156f0b117a35bb145f75d4 100644 (file)
@@ -42,6 +42,7 @@ typedef struct {
   unsigned long lock_ref_id;
   double offset;
   double delay;
+  double precision;
 } RefclockParameters;
 
 typedef struct RCL_Instance_Record *RCL_Instance;