sources: split source selection from sample accumulation

This will allow postponing source selection and reference update, which
could be useful in burst modes.
This commit is contained in:
Miroslav Lichvar 2014-04-03 18:11:37 +02:00
parent de5178575f
commit 0094128ca6
4 changed files with 18 additions and 16 deletions

View file

@ -1179,6 +1179,8 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
root_delay, root_dispersion,
message->stratum, (NTP_Leap) pkt_leap);
SRC_SelectSource(inst->source);
/* Now examine the registers. First though, if the prediction is
not even within +/- the peer distance of the peer, we are clearly
not tracking the peer at all well, so we back off the sampling

View file

@ -549,6 +549,7 @@ poll_timeout(void *arg)
SRC_UpdateReachability(inst->source, 1);
SRC_AccumulateSample(inst->source, &sample_time, offset,
inst->delay, dispersion, inst->delay, dispersion, stratum, inst->leap_status);
SRC_SelectSource(inst->source);
log_sample(inst, &sample_time, 1, 0, 0.0, offset, dispersion);
} else {

View file

@ -314,8 +314,6 @@ void SRC_AccumulateSample
IS FLIPPED */
SST_AccumulateSample(inst->stats, sample_time, -offset, peer_delay, peer_dispersion, root_delay, root_dispersion, stratum);
SST_DoNewRegression(inst->stats);
/* And redo clock selection */
SRC_SelectSource(inst->ref_id);
}
/* ================================================== */
@ -344,7 +342,7 @@ SRC_UnsetSelectable(SRC_Instance inst)
/* If this was the previous reference source, we have to reselect! */
if (inst->index == selected_source_index) {
SRC_SelectSource(0);
SRC_SelectSource(NULL);
}
}
@ -364,7 +362,7 @@ SRC_UpdateReachability(SRC_Instance inst, int reachable)
if (!reachable && inst->index == selected_source_index) {
/* Try to select a better source */
SRC_SelectSource(0);
SRC_SelectSource(NULL);
}
}
@ -501,7 +499,7 @@ combine_sources(int n_sel_sources, struct timeval *ref_time, double *offset,
or match_refid is equal to the selected reference source refid */
void
SRC_SelectSource(uint32_t match_refid)
SRC_SelectSource(SRC_Instance updated_inst)
{
int i, j, index, old_selected_index, sel_prefer;
struct timeval now, ref_time;
@ -862,8 +860,8 @@ SRC_SelectSource(uint32_t match_refid)
/* Update score, but only for source pairs where one source
has a new sample */
if (sources[i]->ref_id == match_refid ||
sources[selected_source_index]->ref_id == match_refid) {
if (sources[i] == updated_inst ||
sources[selected_source_index] == updated_inst) {
sources[i]->sel_score *= sel_src_distance / distance;
@ -881,8 +879,9 @@ SRC_SelectSource(uint32_t match_refid)
}
#if 0
LOG(LOGS_INFO, LOGF_Sources, "select score=%f refid=%lx match_refid=%lx status=%d dist=%f",
sources[i]->sel_score, sources[i]->ref_id, match_refid, sources[i]->status, distance);
LOG(LOGS_INFO, LOGF_Sources, "select score=%f refid=%x match_refid=%x status=%d dist=%f",
sources[i]->sel_score, sources[i]->ref_id, updated_inst ? updated_inst->ref_id : 0,
sources[i]->status, distance);
#endif
if (max_score < sources[i]->sel_score) {
@ -919,10 +918,10 @@ SRC_SelectSource(uint32_t match_refid)
sources[selected_source_index]->status = SRC_SYNC;
/* Update local reference only when a new source was selected or a new
sample was received (i.e. match_refid is equal to selected refid) */
/* Update local reference only when a new source was selected
or the selected source has a new sample */
if (selected_source_index != old_selected_index ||
match_refid == sources[selected_source_index]->ref_id) {
updated_inst == sources[selected_source_index]) {
/* Now just use the statistics of the selected source combined with
the other selectable sources for trimming the local clock */
@ -978,7 +977,7 @@ void
SRC_ReselectSource(void)
{
selected_source_index = INVALID_SOURCE;
SRC_SelectSource(0);
SRC_SelectSource(NULL);
}
/* ================================================== */

View file

@ -131,11 +131,11 @@ extern void SRC_ResetReachability(SRC_Instance inst);
/* This routine is used to select the best source from amongst those
we currently have valid data on, and use it as the tracking base
for the local time. Updates are only made to the local reference
if a new source is selected or match_addr is equal to the selected
reference source address. (This avoids updating the frequency
if a new source is selected or updated_inst is the selected
reference source. (This avoids updating the frequency
tracking for every sample from other sources - only the ones from
the selected reference make a difference) */
extern void SRC_SelectSource(uint32_t match_refid);
extern void SRC_SelectSource(SRC_Instance updated_inst);
/* Force reselecting the best source */
extern void SRC_ReselectSource(void);