]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
local: add new driver call to set synchronization status
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 9 Dec 2014 14:42:56 +0000 (15:42 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Dec 2014 14:35:56 +0000 (15:35 +0100)
This will be used to set the kernel adjtimex() variables to allow other
applications running on the system to know if the system clock is
synchronized and the estimated error and the maximum error.

local.c
local.h
localp.h
reference.c
sys_generic.c
sys_generic.h
sys_linux.c
sys_netbsd.c
sys_solaris.c
sys_sunos.c

diff --git a/local.c b/local.c
index d5762d9158c95bc0ab8680b4521483fc02c4e814..c7b742a0be195ef789686c433f5ec8b3d226989f 100644 (file)
--- a/local.c
+++ b/local.c
@@ -56,6 +56,7 @@ static lcl_AccrueOffsetDriver drv_accrue_offset;
 static lcl_ApplyStepOffsetDriver drv_apply_step_offset;
 static lcl_OffsetCorrectionDriver drv_offset_convert;
 static lcl_SetLeapDriver drv_set_leap;
+static lcl_SetSyncStatusDriver drv_set_sync_status;
 
 /* ================================================== */
 
@@ -557,7 +558,8 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
                           lcl_AccrueOffsetDriver accrue_offset,
                           lcl_ApplyStepOffsetDriver apply_step_offset,
                           lcl_OffsetCorrectionDriver offset_convert,
-                          lcl_SetLeapDriver set_leap)
+                          lcl_SetLeapDriver set_leap,
+                          lcl_SetSyncStatusDriver set_sync_status)
 {
   drv_read_freq = read_freq;
   drv_set_freq = set_freq;
@@ -565,6 +567,7 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
   drv_apply_step_offset = apply_step_offset;
   drv_offset_convert = offset_convert;
   drv_set_leap = set_leap;
+  drv_set_sync_status = set_sync_status;
 
   current_freq_ppm = (*drv_read_freq)();
 
@@ -632,3 +635,13 @@ LCL_SetTempComp(double comp)
 }
 
 /* ================================================== */
+
+void
+LCL_SetSyncStatus(int synchronised, double est_error, double max_error)
+{
+  if (drv_set_sync_status) {
+    (drv_set_sync_status)(synchronised, est_error, max_error);
+  }
+}
+
+/* ================================================== */
diff --git a/local.h b/local.h
index aff9004fe5d1c724febdee524c203279e6b9e67a..f0c351605b97c2428b8ed2651c7a1c4e1e223529 100644 (file)
--- a/local.h
+++ b/local.h
@@ -206,4 +206,8 @@ extern void LCL_SetLeap(int leap);
    due to clamping or rounding). */
 extern double LCL_SetTempComp(double comp);
 
+/* Routine to update the synchronisation status in the kernel to allow other
+   applications to know if the system clock is synchronised and error bounds */
+extern void LCL_SetSyncStatus(int synchronised, double est_error, double max_error);
+
 #endif /* GOT_LOCAL_H */
index ce92f1c733bd1d4804f9af88fea10e5dd76d84fa..321985e143ed98b2f1d90496eb8ff9d889dcaf3d 100644 (file)
--- a/localp.h
+++ b/localp.h
@@ -57,6 +57,9 @@ typedef void (*lcl_OffsetCorrectionDriver)(struct timeval *raw, double *corr, do
 /* System driver to schedule leap second */
 typedef void (*lcl_SetLeapDriver)(int leap);
 
+/* System driver to set the synchronisation status */
+typedef void (*lcl_SetSyncStatusDriver)(int synchronised, double est_error, double max_error);
+
 extern void lcl_InvokeDispersionNotifyHandlers(double dispersion);
 
 extern void
@@ -65,6 +68,7 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
                           lcl_AccrueOffsetDriver accrue_offset,
                           lcl_ApplyStepOffsetDriver apply_step_offset,
                           lcl_OffsetCorrectionDriver offset_convert,
-                          lcl_SetLeapDriver set_leap);
+                          lcl_SetLeapDriver set_leap,
+                          lcl_SetSyncStatusDriver set_sync_status);
 
 #endif /* GOT_LOCALP_H */
index 0103c38d67f2a8888f3cdbb99eab6d1f90a07c97..e6b4bd5b760d970cd92d08645f6bb481f6e6100b 100644 (file)
@@ -928,6 +928,8 @@ REF_SetReference(int stratum,
     LOG(LOGS_WARN, LOGF_Reference, "System clock was stepped by %.6f seconds", -step_offset);
   }
 
+  LCL_SetSyncStatus(are_we_synchronised, offset_sd, offset_sd + root_delay / 2.0 + root_dispersion);
+
   abs_freq_ppm = LCL_ReadAbsoluteFrequency();
 
   write_log(&now,
@@ -1016,6 +1018,8 @@ REF_SetUnsynchronised(void)
   update_leap_status(LEAP_Unsynchronised, 0);
   are_we_synchronised = 0;
 
+  LCL_SetSyncStatus(0, 0.0, 0.0);
+
   write_log(&now,
             "0.0.0.0",
             0,
index 2adbbfe0db2caa9392c6fd7113af19591371d743..3cdb18461fa34ddb5ea702f449aaae887e4b070b 100644 (file)
@@ -275,7 +275,8 @@ SYS_Generic_CompleteFreqDriver(double max_set_freq_ppm, double max_set_freq_dela
                                lcl_ReadFrequencyDriver sys_read_freq,
                                lcl_SetFrequencyDriver sys_set_freq,
                                lcl_ApplyStepOffsetDriver sys_apply_step_offset,
-                               lcl_SetLeapDriver sys_set_leap)
+                               lcl_SetLeapDriver sys_set_leap,
+                               lcl_SetSyncStatusDriver sys_set_sync_status)
 {
   max_freq = max_set_freq_ppm;
   max_freq_change_delay = max_set_freq_delay * (1.0 + max_freq / 1.0e6);
@@ -291,7 +292,7 @@ SYS_Generic_CompleteFreqDriver(double max_set_freq_ppm, double max_set_freq_dela
   lcl_RegisterSystemDrivers(read_frequency, set_frequency,
                             accrue_offset, sys_apply_step_offset ?
                               sys_apply_step_offset : apply_step_offset,
-                            offset_convert, sys_set_leap);
+                            offset_convert, sys_set_leap, NULL);
 
   LCL_AddParameterChangeHandler(handle_step, NULL);
 }
index 45c14e2b56480449b6e25f5a756e97287940192f..453208381e013121976d4b2bb861112bb9a4b895 100644 (file)
@@ -35,7 +35,8 @@ extern void SYS_Generic_CompleteFreqDriver(double max_set_freq_ppm, double max_s
                                            lcl_ReadFrequencyDriver sys_read_freq,
                                            lcl_SetFrequencyDriver sys_set_freq,
                                            lcl_ApplyStepOffsetDriver sys_apply_step_offset,
-                                           lcl_SetLeapDriver sys_set_leap);
+                                           lcl_SetLeapDriver sys_set_leap,
+                                           lcl_SetSyncStatusDriver sys_set_sync_status);
 
 extern void SYS_Generic_Finalise(void);
 
index b342505537a326573c4eb94fcd38d1de7fc5b48c..d2091b99575a8e0684c9a57278750aea1a89fe9a 100644 (file)
@@ -338,7 +338,7 @@ SYS_Linux_Initialise(void)
                                  1.0 / tick_update_hz,
                                  read_frequency, set_frequency,
                                  have_setoffset ? apply_step_offset : NULL,
-                                 set_leap);
+                                 set_leap, NULL);
 }
 
 /* ================================================== */
index 8c08d4ee8a8ec4693f56740759bfdf8f369ef1d4..c54de3fbfda6c8535fb2f1fc03dc158e04d1f962 100644 (file)
@@ -307,7 +307,8 @@ SYS_NetBSD_Initialise(void)
   lcl_RegisterSystemDrivers(read_frequency, set_frequency, 
                             accrue_offset, apply_step_offset,
                             get_offset_correction,
-                            NULL /* set_leap */);
+                            NULL /* set_leap */,
+                            NULL /* set_sync_status */);
 
 }
 
index 0c8dedbd4c2c2f78ea4819f97c174d3537601843..2802a90a2158026d1d8ab0419801692e848ac867 100644 (file)
@@ -426,7 +426,8 @@ SYS_Solaris_Initialise(void)
   lcl_RegisterSystemDrivers(read_frequency, set_frequency, 
                             accrue_offset, apply_step_offset,
                             get_offset_correction,
-                            NULL /* set_leap */);
+                            NULL /* set_leap */,
+                            NULL /* set_sync_status */);
 
   /* Turn off the kernel switch that keeps the system clock in step
      with the non-volatile clock */
index d45f58f324f0e817a85b949a4be7fd62a9cfefca..9231dca49785af7b79af303d91432e5d1901b51f 100644 (file)
@@ -379,7 +379,8 @@ SYS_SunOS_Initialise(void)
   lcl_RegisterSystemDrivers(read_frequency, set_frequency, 
                             accrue_offset, apply_step_offset,
                             get_offset_correction,
-                            NULL /* set_leap */);
+                            NULL /* set_leap */,
+                            NULL /* set_sync_status */);
 
   /* Turn off the kernel switch that keeps the system clock in step
      with the non-volatile clock */