From cf3c7b3bd69bfb9c1d06451927168067fb229f7b Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 20 May 2014 17:05:05 +0200 Subject: [PATCH] sys: add apply_step_offset function to generic driver Move the generic code away from the Linux driver and keep there only stepping by adjtimex(ADJ_SETOFFSET). --- sys_generic.c | 25 ++++++++++++++++++++++++- sys_linux.c | 30 ++++-------------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/sys_generic.c b/sys_generic.c index 5232b76..d6c109d 100644 --- a/sys_generic.c +++ b/sys_generic.c @@ -235,6 +235,28 @@ offset_convert(struct timeval *raw, *err = fabs(duration) <= max_freq_change_delay ? slew_error : 0.0; } +/* ================================================== */ +/* Positive means currently fast of true time, i.e. jump backwards */ + +static void +apply_step_offset(double offset) +{ + struct timeval old_time, new_time; + double err; + + LCL_ReadRawTime(&old_time); + UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); + + if (settimeofday(&new_time, NULL) < 0) { + LOG_FATAL(LOGF_SysGeneric, "settimeofday() failed"); + } + + LCL_ReadRawTime(&old_time); + UTI_DiffTimevalsToDouble(&err, &old_time, &new_time); + + lcl_InvokeDispersionNotifyHandlers(fabs(err)); +} + /* ================================================== */ void @@ -254,7 +276,8 @@ SYS_Generic_CompleteFreqDriver(double max_set_freq_ppm, double max_set_freq_dela offset_register = 0.0; lcl_RegisterSystemDrivers(read_frequency, set_frequency, - accrue_offset, sys_apply_step_offset, + accrue_offset, sys_apply_step_offset ? + sys_apply_step_offset : apply_step_offset, offset_convert, sys_set_leap); LCL_AddParameterChangeHandler(handle_step, NULL); diff --git a/sys_linux.c b/sys_linux.c index 078604f..930f55f 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -52,7 +52,6 @@ int LockAll = 0; #include #endif -#include "localp.h" #include "sys_generic.h" #include "sys_linux.h" #include "conf.h" @@ -110,30 +109,8 @@ our_round(double x) { static void apply_step_offset(double offset) { - struct timeval old_time, new_time; - double err; - - if (have_setoffset) { - if (TMX_ApplyStepOffset(-offset) < 0) { - LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); - } - } else { - if (gettimeofday(&old_time, NULL) < 0) { - LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed"); - } - - UTI_AddDoubleToTimeval(&old_time, -offset, &new_time); - - if (settimeofday(&new_time, NULL) < 0) { - LOG_FATAL(LOGF_SysLinux, "settimeofday() failed"); - } - - if (gettimeofday(&old_time, NULL) < 0) { - LOG_FATAL(LOGF_SysLinux, "gettimeofday() failed"); - } - - UTI_DiffTimevalsToDouble(&err, &old_time, &new_time); - lcl_InvokeDispersionNotifyHandlers(fabs(err)); + if (TMX_ApplyStepOffset(-offset) < 0) { + LOG_FATAL(LOGF_SysLinux, "adjtimex() failed"); } } @@ -417,7 +394,8 @@ SYS_Linux_Initialise(void) SYS_Generic_CompleteFreqDriver(1.0e6 * max_tick_bias / nominal_tick, 1.0 / tick_update_hz, read_frequency, set_frequency, - apply_step_offset, set_leap); + have_setoffset ? apply_step_offset : NULL, + set_leap); } /* ================================================== */