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:
Miroslav Lichvar
2014-05-20 17:05:05 +02:00
parent 0b7f64cb33
commit cf3c7b3bd6
2 changed files with 28 additions and 27 deletions

View File

@@ -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);