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).
This commit is contained in:
parent
0b7f64cb33
commit
cf3c7b3bd6
2 changed files with 28 additions and 27 deletions
|
@ -235,6 +235,28 @@ offset_convert(struct timeval *raw,
|
||||||
*err = fabs(duration) <= max_freq_change_delay ? slew_error : 0.0;
|
*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
|
void
|
||||||
|
@ -254,7 +276,8 @@ SYS_Generic_CompleteFreqDriver(double max_set_freq_ppm, double max_set_freq_dela
|
||||||
offset_register = 0.0;
|
offset_register = 0.0;
|
||||||
|
|
||||||
lcl_RegisterSystemDrivers(read_frequency, set_frequency,
|
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);
|
offset_convert, sys_set_leap);
|
||||||
|
|
||||||
LCL_AddParameterChangeHandler(handle_step, NULL);
|
LCL_AddParameterChangeHandler(handle_step, NULL);
|
||||||
|
|
30
sys_linux.c
30
sys_linux.c
|
@ -52,7 +52,6 @@ int LockAll = 0;
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "localp.h"
|
|
||||||
#include "sys_generic.h"
|
#include "sys_generic.h"
|
||||||
#include "sys_linux.h"
|
#include "sys_linux.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
@ -110,30 +109,8 @@ our_round(double x) {
|
||||||
static void
|
static void
|
||||||
apply_step_offset(double offset)
|
apply_step_offset(double offset)
|
||||||
{
|
{
|
||||||
struct timeval old_time, new_time;
|
if (TMX_ApplyStepOffset(-offset) < 0) {
|
||||||
double err;
|
LOG_FATAL(LOGF_SysLinux, "adjtimex() failed");
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +394,8 @@ SYS_Linux_Initialise(void)
|
||||||
SYS_Generic_CompleteFreqDriver(1.0e6 * max_tick_bias / nominal_tick,
|
SYS_Generic_CompleteFreqDriver(1.0e6 * max_tick_bias / nominal_tick,
|
||||||
1.0 / tick_update_hz,
|
1.0 / tick_update_hz,
|
||||||
read_frequency, set_frequency,
|
read_frequency, set_frequency,
|
||||||
apply_step_offset, set_leap);
|
have_setoffset ? apply_step_offset : NULL,
|
||||||
|
set_leap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
Loading…
Reference in a new issue