Set reference time to last sample instead of time on update
This is done mainly to fix reported root dispersion to include max clock error after selecting another source without new sample.
This commit is contained in:
parent
bb95c39356
commit
c5587b60b2
4 changed files with 34 additions and 36 deletions
15
reference.c
15
reference.c
|
@ -530,10 +530,10 @@ REF_SetReference(int stratum,
|
|||
double delta_freq1, delta_freq2;
|
||||
double skew1, skew2;
|
||||
double our_frequency;
|
||||
|
||||
double abs_freq_ppm;
|
||||
|
||||
double update_interval;
|
||||
double elapsed;
|
||||
struct timeval now;
|
||||
|
||||
assert(initialised);
|
||||
|
||||
|
@ -570,10 +570,13 @@ REF_SetReference(int stratum,
|
|||
else
|
||||
our_ref_ip.family = IPADDR_UNSPEC;
|
||||
our_ref_time = *ref_time;
|
||||
our_offset = offset;
|
||||
our_root_delay = root_delay;
|
||||
our_root_dispersion = root_dispersion;
|
||||
|
||||
LCL_ReadCookedTime(&now, NULL);
|
||||
UTI_DiffTimevalsToDouble(&elapsed, &now, ref_time);
|
||||
our_offset = offset + elapsed * frequency;
|
||||
|
||||
update_leap_status(leap);
|
||||
|
||||
/* Eliminate updates that are based on totally unreliable frequency
|
||||
|
@ -627,14 +630,14 @@ REF_SetReference(int stratum,
|
|||
|
||||
abs_freq_ppm = LCL_ReadAbsoluteFrequency();
|
||||
|
||||
write_log(ref_time,
|
||||
write_log(&now,
|
||||
our_ref_ip.family != IPADDR_UNSPEC ? UTI_IPToString(&our_ref_ip) : UTI_RefidToString(our_ref_id),
|
||||
our_stratum,
|
||||
abs_freq_ppm,
|
||||
1.0e6*our_skew,
|
||||
our_offset);
|
||||
|
||||
UTI_DiffTimevalsToDouble(&update_interval, ref_time, &last_ref_update);
|
||||
UTI_DiffTimevalsToDouble(&update_interval, &now, &last_ref_update);
|
||||
|
||||
if (drift_file) {
|
||||
/* Update drift file at most once per hour */
|
||||
|
@ -650,7 +653,7 @@ REF_SetReference(int stratum,
|
|||
update_fb_drifts(abs_freq_ppm, update_interval);
|
||||
}
|
||||
|
||||
last_ref_update = *ref_time;
|
||||
last_ref_update = now;
|
||||
last_ref_update_interval = update_interval;
|
||||
|
||||
/* And now set the freq and offset to zero */
|
||||
|
|
22
sources.c
22
sources.c
|
@ -424,9 +424,9 @@ void
|
|||
SRC_SelectSource(unsigned long match_addr)
|
||||
{
|
||||
int i, j, index, old_selected_index;
|
||||
struct timeval now;
|
||||
struct timeval now, ref_time;
|
||||
double src_offset, src_offset_sd, src_frequency, src_skew;
|
||||
double src_accrued_dispersion;
|
||||
double src_root_delay, src_root_dispersion;
|
||||
int n_endpoints, j1, j2;
|
||||
double best_lo, best_hi;
|
||||
int depth, best_depth;
|
||||
|
@ -434,7 +434,6 @@ SRC_SelectSource(unsigned long match_addr)
|
|||
double distance, sel_src_distance;
|
||||
int stratum, min_stratum;
|
||||
struct SelectInfo *si;
|
||||
double total_root_dispersion;
|
||||
int n_badstats_sources;
|
||||
int max_sel_reach, max_badstat_reach;
|
||||
int max_score_index;
|
||||
|
@ -846,25 +845,20 @@ SRC_SelectSource(unsigned long match_addr)
|
|||
/* Now just use the statistics of the selected source for
|
||||
trimming the local clock */
|
||||
|
||||
LCL_ReadCookedTime(&now, NULL);
|
||||
|
||||
SST_GetTrackingData(sources[selected_source_index]->stats, &now,
|
||||
SST_GetTrackingData(sources[selected_source_index]->stats, &ref_time,
|
||||
&src_offset, &src_offset_sd,
|
||||
&src_accrued_dispersion,
|
||||
&src_frequency, &src_skew);
|
||||
|
||||
total_root_dispersion = (src_accrued_dispersion +
|
||||
sources[selected_source_index]->sel_info.root_dispersion);
|
||||
&src_frequency, &src_skew,
|
||||
&src_root_delay, &src_root_dispersion);
|
||||
|
||||
REF_SetReference(min_stratum, leap_status,
|
||||
sources[selected_source_index]->ref_id,
|
||||
sources[selected_source_index]->ip_addr,
|
||||
&now,
|
||||
&ref_time,
|
||||
src_offset,
|
||||
src_frequency,
|
||||
src_skew,
|
||||
sources[selected_source_index]->sel_info.root_delay,
|
||||
total_root_dispersion);
|
||||
src_root_delay,
|
||||
src_root_dispersion);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
@ -582,29 +582,30 @@ SST_GetSelectionData(SST_Stats inst, struct timeval *now,
|
|||
/* ================================================== */
|
||||
|
||||
void
|
||||
SST_GetTrackingData(SST_Stats inst, struct timeval *now,
|
||||
SST_GetTrackingData(SST_Stats inst, struct timeval *ref_time,
|
||||
double *average_offset, double *offset_sd,
|
||||
double *accrued_dispersion,
|
||||
double *frequency, double *skew)
|
||||
double *frequency, double *skew,
|
||||
double *root_delay, double *root_dispersion)
|
||||
{
|
||||
int i;
|
||||
double elapsed_offset, elapsed_sample;
|
||||
int i, j;
|
||||
double elapsed_sample;
|
||||
|
||||
i = get_runsbuf_index(inst, inst->best_single_sample);
|
||||
j = get_buf_index(inst, inst->best_single_sample);
|
||||
|
||||
*ref_time = inst->offset_time;
|
||||
*average_offset = inst->estimated_offset;
|
||||
*offset_sd = inst->estimated_offset_sd;
|
||||
*frequency = inst->estimated_frequency;
|
||||
*skew = inst->skew;
|
||||
*root_delay = inst->root_delays[j];
|
||||
|
||||
UTI_DiffTimevalsToDouble(&elapsed_offset, now, &(inst->offset_time));
|
||||
*average_offset = inst->estimated_offset + inst->estimated_frequency * elapsed_offset;
|
||||
*offset_sd = inst->estimated_offset_sd + elapsed_offset * inst->skew;
|
||||
|
||||
UTI_DiffTimevalsToDouble(&elapsed_sample, now, &inst->sample_times[i]);
|
||||
*accrued_dispersion = inst->skew * elapsed_sample;
|
||||
UTI_DiffTimevalsToDouble(&elapsed_sample, &inst->offset_time, &inst->sample_times[i]);
|
||||
*root_dispersion = inst->root_dispersions[j] + inst->skew * elapsed_sample;
|
||||
|
||||
#ifdef TRACEON
|
||||
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d freq=%f (%.3fppm) skew=%f (%.3fppm) avoff=%f offsd=%f accrdis=%f",
|
||||
inst->n_samples, *frequency, 1.0e6* *frequency, *skew, 1.0e6* *skew, *average_offset, *offset_sd, *accrued_dispersion);
|
||||
LOG(LOGS_INFO, LOGF_SourceStats, "n=%d freq=%f (%.3fppm) skew=%f (%.3fppm) avoff=%f offsd=%f disp=%f",
|
||||
inst->n_samples, *frequency, 1.0e6* *frequency, *skew, 1.0e6* *skew, *average_offset, *offset_sd, *root_dispersion);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -89,10 +89,10 @@ SST_GetSelectionData(SST_Stats inst, struct timeval *now,
|
|||
|
||||
/* Get data needed when setting up tracking on this source */
|
||||
extern void
|
||||
SST_GetTrackingData(SST_Stats inst, struct timeval *now,
|
||||
SST_GetTrackingData(SST_Stats inst, struct timeval *ref_time,
|
||||
double *average_offset, double *offset_sd,
|
||||
double *accrued_dispersion,
|
||||
double *frequency, double *skew);
|
||||
double *frequency, double *skew,
|
||||
double *root_delay, double *root_dispersion);
|
||||
|
||||
/* Get parameters for using this source as the reference */
|
||||
extern void
|
||||
|
|
Loading…
Reference in a new issue