Don't update local reference unnecessarily
Local reference is now updated only when a new source is selected or match_addr is equal to the selected source, match_addr 0 is no longer treated specially.
This commit is contained in:
parent
0c4968ec51
commit
7f6ed73145
2 changed files with 28 additions and 28 deletions
27
sources.c
27
sources.c
|
@ -404,13 +404,13 @@ source_to_string(SRC_Instance inst)
|
||||||
/* This function selects the current reference from amongst the pool
|
/* This function selects the current reference from amongst the pool
|
||||||
of sources we are holding.
|
of sources we are holding.
|
||||||
|
|
||||||
Updates are only made to the local reference if match_addr is zero or is
|
Updates are only made to the local reference if a new source is selected
|
||||||
equal to the selected reference source address */
|
or match_addr is equal to the selected reference source address */
|
||||||
|
|
||||||
void
|
void
|
||||||
SRC_SelectSource(unsigned long match_addr)
|
SRC_SelectSource(unsigned long match_addr)
|
||||||
{
|
{
|
||||||
int i, j, index;
|
int i, j, index, old_selected_index;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
double src_offset, src_offset_sd, src_frequency, src_skew;
|
double src_offset, src_offset_sd, src_frequency, src_skew;
|
||||||
double src_accrued_dispersion;
|
double src_accrued_dispersion;
|
||||||
|
@ -425,14 +425,15 @@ SRC_SelectSource(unsigned long match_addr)
|
||||||
double total_root_dispersion;
|
double total_root_dispersion;
|
||||||
|
|
||||||
NTP_Leap leap_status = LEAP_Normal;
|
NTP_Leap leap_status = LEAP_Normal;
|
||||||
|
old_selected_index = selected_source_index;
|
||||||
|
|
||||||
if (n_sources == 0) {
|
if (n_sources == 0) {
|
||||||
/* In this case, we clearly cannot synchronise to anything */
|
/* In this case, we clearly cannot synchronise to anything */
|
||||||
if (selected_source_index != INVALID_SOURCE) {
|
if (selected_source_index != INVALID_SOURCE) {
|
||||||
LOG(LOGS_INFO, LOGF_Sources, "Can't synchronise: no sources");
|
LOG(LOGS_INFO, LOGF_Sources, "Can't synchronise: no sources");
|
||||||
}
|
|
||||||
selected_source_index = INVALID_SOURCE;
|
selected_source_index = INVALID_SOURCE;
|
||||||
REF_SetUnsynchronised();
|
REF_SetUnsynchronised();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,7 +582,6 @@ SRC_SelectSource(unsigned long match_addr)
|
||||||
LOG(LOGS_INFO, LOGF_Sources, "Can't synchronise: no majority");
|
LOG(LOGS_INFO, LOGF_Sources, "Can't synchronise: no majority");
|
||||||
}
|
}
|
||||||
selected_source_index = INVALID_SOURCE;
|
selected_source_index = INVALID_SOURCE;
|
||||||
REF_SetUnsynchronised();
|
|
||||||
|
|
||||||
/* .. and mark all sources as falsetickers (so they appear thus
|
/* .. and mark all sources as falsetickers (so they appear thus
|
||||||
on the outputs from the command client) */
|
on the outputs from the command client) */
|
||||||
|
@ -750,6 +750,11 @@ SRC_SelectSource(unsigned long match_addr)
|
||||||
|
|
||||||
sources[selected_source_index]->status = SRC_SYNC;
|
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_addr is equal to selected ref_id) */
|
||||||
|
if (selected_source_index != old_selected_index ||
|
||||||
|
match_addr == sources[selected_source_index]->ref_id) {
|
||||||
|
|
||||||
/* Now just use the statistics of the selected source for
|
/* Now just use the statistics of the selected source for
|
||||||
trimming the local clock */
|
trimming the local clock */
|
||||||
|
|
||||||
|
@ -763,9 +768,6 @@ SRC_SelectSource(unsigned long match_addr)
|
||||||
total_root_dispersion = (src_accrued_dispersion +
|
total_root_dispersion = (src_accrued_dispersion +
|
||||||
sources[selected_source_index]->sel_info.root_dispersion);
|
sources[selected_source_index]->sel_info.root_dispersion);
|
||||||
|
|
||||||
if ((match_addr == 0) ||
|
|
||||||
(match_addr == sources[selected_source_index]->ref_id)) {
|
|
||||||
|
|
||||||
REF_SetReference(min_stratum, leap_status,
|
REF_SetReference(min_stratum, leap_status,
|
||||||
sources[selected_source_index]->ref_id,
|
sources[selected_source_index]->ref_id,
|
||||||
sources[selected_source_index]->ip_addr,
|
sources[selected_source_index]->ip_addr,
|
||||||
|
@ -782,11 +784,7 @@ SRC_SelectSource(unsigned long match_addr)
|
||||||
LOG(LOGS_INFO, LOGF_Sources, "Can't synchronise: no selectable sources");
|
LOG(LOGS_INFO, LOGF_Sources, "Can't synchronise: no selectable sources");
|
||||||
}
|
}
|
||||||
selected_source_index = INVALID_SOURCE;
|
selected_source_index = INVALID_SOURCE;
|
||||||
REF_SetUnsynchronised();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -795,9 +793,12 @@ SRC_SelectSource(unsigned long match_addr)
|
||||||
LOG(LOGS_INFO, LOGF_Sources, "Can't synchronise: no reachable sources");
|
LOG(LOGS_INFO, LOGF_Sources, "Can't synchronise: no reachable sources");
|
||||||
}
|
}
|
||||||
selected_source_index = INVALID_SOURCE;
|
selected_source_index = INVALID_SOURCE;
|
||||||
REF_SetUnsynchronised();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selected_source_index == INVALID_SOURCE &&
|
||||||
|
selected_source_index != old_selected_index) {
|
||||||
|
REF_SetUnsynchronised();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
11
sources.h
11
sources.h
|
@ -134,12 +134,11 @@ extern void SRC_ResetReachability(SRC_Instance inst);
|
||||||
|
|
||||||
/* This routine is used to select the best source from amongst those
|
/* 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
|
we currently have valid data on, and use it as the tracking base
|
||||||
for the local time. If match_addr is zero it means we must start
|
for the local time. Updates are only made to the local reference
|
||||||
tracking the (newly) selected reference unconditionally, otherwise
|
if a new source is selected or match_addr is equal to the selected
|
||||||
it is equal to the address we should track if it turns out to be
|
reference source address. (This avoids updating the frequency
|
||||||
the best reference. (This avoids updating the frequency tracking
|
tracking for every sample from other sources - only the ones from
|
||||||
for every sample from other sources - only the ones from the
|
the selected reference make a difference) */
|
||||||
selected reference make a difference) */
|
|
||||||
extern void SRC_SelectSource(unsigned long match_addr);
|
extern void SRC_SelectSource(unsigned long match_addr);
|
||||||
|
|
||||||
/* Force reselecting the best source */
|
/* Force reselecting the best source */
|
||||||
|
|
Loading…
Reference in a new issue