[PATCH] Handle immediate step in local module instead of system driver

[ Thread Index | Date Index | More chrony.tuxfamily.org/chrony-dev Archives ]


This fixes the problem where scheduler wasn't notified about performed
steps and it also makes the command available on all supported systems.
---
 chrony.texi   |    3 ---
 local.c       |   21 ++++++++++++---------
 localp.h      |    5 -----
 sys_linux.c   |   38 +-------------------------------------
 sys_netbsd.c  |    2 +-
 sys_solaris.c |    2 +-
 sys_sunos.c   |    2 +-
 7 files changed, 16 insertions(+), 57 deletions(-)

diff --git a/chrony.texi b/chrony.texi
index 9fc672f..f3d0c85 100644
--- a/chrony.texi
+++ b/chrony.texi
@@ -3075,9 +3075,6 @@ clock by the equivalent amount, making it correct immediately.
 BE WARNED - certain software will be seriously affected by such jumps to
 the system time.  (That is the reason why chronyd uses slewing
 normally.)
-
-The @code{makestep} command is currently only available on the Linux
-version of chrony.
 @c }}}
 @c {{{ manual
 @node manual command
diff --git a/local.c b/local.c
index c1542bd..f97a727 100644
--- a/local.c
+++ b/local.c
@@ -53,7 +53,6 @@ static lcl_SetFrequencyDriver drv_set_freq;
 static lcl_AccrueOffsetDriver drv_accrue_offset;
 static lcl_ApplyStepOffsetDriver drv_apply_step_offset;
 static lcl_OffsetCorrectionDriver drv_offset_convert;
-static lcl_ImmediateStepDriver drv_immediate_step;
 static lcl_SetLeapDriver drv_set_leap;
 
 /* ================================================== */
@@ -536,7 +535,6 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
                           lcl_AccrueOffsetDriver accrue_offset,
                           lcl_ApplyStepOffsetDriver apply_step_offset,
                           lcl_OffsetCorrectionDriver offset_convert,
-                          lcl_ImmediateStepDriver immediate_step,
                           lcl_SetLeapDriver set_leap)
 {
   drv_read_freq = read_freq;
@@ -544,7 +542,6 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
   drv_accrue_offset = accrue_offset;
   drv_apply_step_offset = apply_step_offset;
   drv_offset_convert = offset_convert;
-  drv_immediate_step = immediate_step;
   drv_set_leap = set_leap;
 
   current_freq_ppm = (*drv_read_freq)();
@@ -563,15 +560,21 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
 int
 LCL_MakeStep(void)
 {
-  if (drv_immediate_step) {
-    (drv_immediate_step)();
+  struct timeval raw;
+  double correction;
+
+  LCL_ReadRawTime(&raw);
+  correction = LCL_GetOffsetCorrection(&raw);
+
+  /* Cancel remaining slew and make the step */
+  LCL_AccumulateOffset(-correction);
+  LCL_ApplyStepOffset(correction);
+
 #ifdef TRACEON
-    LOG(LOGS_INFO, LOGF_Local, "Made step to system time to apply remaining slew");
+  LOG(LOGS_INFO, LOGF_Local, "Made step to system time to apply remaining slew", correction);
 #endif
-    return 1;
-  }
 
-  return 0;
+  return 1;
 }
 
 /* ================================================== */
diff --git a/localp.h b/localp.h
index 045c903..47d7eb1 100644
--- a/localp.h
+++ b/localp.h
@@ -56,10 +56,6 @@ typedef void (*lcl_ApplyStepOffsetDriver)(double offset);
    raw time to get the corrected time */
 typedef void (*lcl_OffsetCorrectionDriver)(struct timeval *raw, double *corr);
 
-/* System driver to stop slewing the current offset and to apply is
-   as an immediate step instead */
-typedef void (*lcl_ImmediateStepDriver)(void);
-
 /* System driver to schedule leap second */
 typedef void (*lcl_SetLeapDriver)(int leap);
 
@@ -71,7 +67,6 @@ lcl_RegisterSystemDrivers(lcl_ReadFrequencyDriver read_freq,
                           lcl_AccrueOffsetDriver accrue_offset,
                           lcl_ApplyStepOffsetDriver apply_step_offset,
                           lcl_OffsetCorrectionDriver offset_convert,
-                          lcl_ImmediateStepDriver immediate_step_driver,
                           lcl_SetLeapDriver set_leap);
 
 #endif /* GOT_LOCALP_H */
diff --git a/sys_linux.c b/sys_linux.c
index 4821121..a6167d9 100644
--- a/sys_linux.c
+++ b/sys_linux.c
@@ -607,42 +607,6 @@ again:
 /* ================================================== */
 
 static void
-immediate_step(void)
-{
-  struct timeval old_time, new_time;
-  struct timezone tz;
-  long offset;
-
-  if (fast_slewing) {
-    abort_slew();
-  }
-
-  offset = 0;
-  if (TMX_ApplyOffset(&offset) < 0) {
-    CROAK("adjtimex() failed in immediate_step");
-  }
-
-  offset_register -= (double) offset / 1.0e6;
-  slow_slewing = 0;
-
-  if (gettimeofday(&old_time, &tz) < 0) {
-    CROAK("gettimeofday() failed in immediate_step");
-  }
-
-  UTI_AddDoubleToTimeval(&old_time, -offset_register, &new_time);
-
-  if (settimeofday(&new_time, &tz) < 0) {
-    CROAK("settimeofday() failed in immediate_step");
-  }
-
-  offset_register = 0.0;
-
-  return;
-}
-
-/* ================================================== */
-
-static void
 set_leap(int leap)
 {
   if (TMX_SetLeap(leap) < 0) {
@@ -884,7 +848,7 @@ SYS_Linux_Initialise(void)
 
   lcl_RegisterSystemDrivers(read_frequency, set_frequency,
                             accrue_offset, apply_step_offset,
-                            get_offset_correction, immediate_step, set_leap);
+                            get_offset_correction, set_leap);
 }
 
 /* ================================================== */
diff --git a/sys_netbsd.c b/sys_netbsd.c
index 01cab82..4641ee4 100644
--- a/sys_netbsd.c
+++ b/sys_netbsd.c
@@ -309,7 +309,7 @@ SYS_NetBSD_Initialise(void)
 
   lcl_RegisterSystemDrivers(read_frequency, set_frequency, 
                             accrue_offset, apply_step_offset,
-                            get_offset_correction, NULL /* immediate_step */,
+                            get_offset_correction,
                             NULL /* set_leap */);
 
 }
diff --git a/sys_solaris.c b/sys_solaris.c
index a1d2264..6c65705 100644
--- a/sys_solaris.c
+++ b/sys_solaris.c
@@ -444,7 +444,7 @@ SYS_Solaris_Initialise(void)
 
   lcl_RegisterSystemDrivers(read_frequency, set_frequency, 
                             accrue_offset, apply_step_offset,
-                            get_offset_correction, NULL /* immediate_step */,
+                            get_offset_correction,
                             NULL /* set_leap */);
 
   /* Turn off the kernel switch that keeps the system clock in step
diff --git a/sys_sunos.c b/sys_sunos.c
index 2224e0b..13bb262 100644
--- a/sys_sunos.c
+++ b/sys_sunos.c
@@ -395,7 +395,7 @@ SYS_SunOS_Initialise(void)
 
   lcl_RegisterSystemDrivers(read_frequency, set_frequency, 
                             accrue_offset, apply_step_offset,
-                            get_offset_correction, NULL /* immediate_step */,
+                            get_offset_correction,
                             NULL /* set_leap */);
 
   /* Turn off the kernel switch that keeps the system clock in step
-- 
1.6.5.2


--6TrnltStXW4iwmi0--

---
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble?  Email listmaster@xxxxxxxxxxxxxxxxxxxx.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/