]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
hwclock: make minimum sampling separation configurable
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 19 Jan 2017 11:45:44 +0000 (12:45 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 23 Jan 2017 14:58:55 +0000 (15:58 +0100)
hwclock.c
hwclock.h
ntp_io_linux.c
test/unit/hwclock.c

index c44a795034bbce83739b54fcb4eeeeb9b1753059..e6f26fdf8764d52c76b9ef7ffc6aeb91b8acfe97 100644 (file)
--- a/hwclock.c
+++ b/hwclock.c
@@ -39,9 +39,6 @@
 /* Maximum number of samples per clock */
 #define MAX_SAMPLES 16
 
-/* Minimum interval between samples (in seconds) */
-#define MIN_SAMPLE_SEPARATION 1.0
-
 struct HCL_Instance_Record {
   /* HW and local reference timestamp */
   struct timespec hw_ref;
@@ -58,6 +55,9 @@ struct HCL_Instance_Record {
   /* Maximum error of the last sample */
   double last_err;
 
+  /* Minimum interval between samples */
+  double min_separation;
+
   /* Flag indicating the offset and frequency values are valid */
   int valid_coefs;
 
@@ -86,7 +86,7 @@ handle_slew(struct timespec *raw, struct timespec *cooked, double dfreq,
 /* ================================================== */
 
 HCL_Instance
-HCL_CreateInstance(void)
+HCL_CreateInstance(double min_separation)
 {
   HCL_Instance clock;
 
@@ -95,6 +95,7 @@ HCL_CreateInstance(void)
   clock->y_data[MAX_SAMPLES - 1] = 0.0;
   clock->n_samples = 0;
   clock->valid_coefs = 0;
+  clock->min_separation = min_separation;
 
   LCL_AddParameterChangeHandler(handle_slew, clock);
 
@@ -115,7 +116,7 @@ int
 HCL_NeedsNewSample(HCL_Instance clock, struct timespec *now)
 {
   if (!clock->n_samples ||
-      fabs(UTI_DiffTimespecsToDouble(now, &clock->local_ref)) >= MIN_SAMPLE_SEPARATION)
+      fabs(UTI_DiffTimespecsToDouble(now, &clock->local_ref)) >= clock->min_separation)
     return 1;
 
   return 0;
@@ -140,7 +141,7 @@ HCL_AccumulateSample(HCL_Instance clock, struct timespec *hw_ts,
     hw_delta = UTI_DiffTimespecsToDouble(hw_ts, &clock->hw_ref);
     local_delta = UTI_DiffTimespecsToDouble(local_ts, &clock->local_ref) / local_freq;
 
-    if (hw_delta <= 0.0 || local_delta < MIN_SAMPLE_SEPARATION / 2.0) {
+    if (hw_delta <= 0.0 || local_delta < clock->min_separation / 2.0) {
       clock->n_samples = 0;
       DEBUG_LOG(LOGF_HwClocks, "HW clock reset interval=%f", local_delta);
     }
index 11a79b0a4117201974215b9b060232ea6b526d91..f80d09a55d5da9a7ebc3d4e81bc4bf00ffab8eaa 100644 (file)
--- a/hwclock.h
+++ b/hwclock.h
@@ -29,7 +29,7 @@
 typedef struct HCL_Instance_Record *HCL_Instance;
 
 /* Create a new HW clock instance */
-extern HCL_Instance HCL_CreateInstance(void);
+extern HCL_Instance HCL_CreateInstance(double min_separation);
 
 /* Destroy a HW clock instance */
 extern void HCL_DestroyInstance(HCL_Instance clock);
index 41a8903625268b597e27018db7be854894a746f5..3a87cad36f5d86a7f766149d8999001d427efc7f 100644 (file)
@@ -179,7 +179,7 @@ add_interface(CNF_HwTsInterface *conf_iface)
   iface->tx_comp = conf_iface->tx_comp;
   iface->rx_comp = conf_iface->rx_comp;
 
-  iface->clock = HCL_CreateInstance();
+  iface->clock = HCL_CreateInstance(1.0);
 
   DEBUG_LOG(LOGF_NtpIOLinux, "Enabled HW timestamping on %s", iface->name);
 
index f5667ed19c0d52b102e6720cc5111b36139de4ac..51e41ec005b0cd1daa875602a9ad01dedd029ad5 100644 (file)
@@ -31,7 +31,7 @@ test_unit(void)
 
   LCL_Initialise();
 
-  clock = HCL_CreateInstance();
+  clock = HCL_CreateInstance(1.0);
 
   for (i = 0; i < 2000; i++) {
     UTI_ZeroTimespec(&start_hw_ts);
@@ -43,7 +43,7 @@ test_unit(void)
 
     freq = TST_GetRandomDouble(0.9, 1.1);
     jitter = TST_GetRandomDouble(10.0e-9, 1000.0e-9);
-    interval = TST_GetRandomDouble(MIN_SAMPLE_SEPARATION / 10, MIN_SAMPLE_SEPARATION * 10.0);
+    interval = TST_GetRandomDouble(0.1, 10.0);
 
     clock->n_samples = 0;
     clock->valid_coefs = 0;