sourcestats: move stratum to sources

The stratum value is not needed in sourcestats. Keep it in the source
itself.
This commit is contained in:
Miroslav Lichvar 2021-02-03 12:54:08 +01:00
parent 144fcdde34
commit f74eb67567
3 changed files with 20 additions and 20 deletions

View file

@ -54,7 +54,6 @@ static int initialised = 0;
/* ================================================== */ /* ================================================== */
/* Structure used to hold info for selecting between sources */ /* Structure used to hold info for selecting between sources */
struct SelectInfo { struct SelectInfo {
int stratum;
int select_ok; int select_ok;
double std_dev; double std_dev;
double root_distance; double root_distance;
@ -132,7 +131,10 @@ struct SRC_Instance_Record {
struct SelectInfo sel_info; struct SelectInfo sel_info;
/* Latest leap status */ /* Current stratum */
int stratum;
/* Current leap status */
NTP_Leap leap; NTP_Leap leap;
/* Flag indicating the source has a leap second vote */ /* Flag indicating the source has a leap second vote */
@ -313,6 +315,7 @@ SRC_ResetInstance(SRC_Instance instance)
instance->distant = 0; instance->distant = 0;
instance->status = SRC_BAD_STATS; instance->status = SRC_BAD_STATS;
instance->sel_score = 1.0; instance->sel_score = 1.0;
instance->stratum = 0;
instance->leap = LEAP_Unsynchronised; instance->leap = LEAP_Unsynchronised;
instance->leap_vote = 0; instance->leap_vote = 0;
@ -407,6 +410,8 @@ SRC_AccumulateSample(SRC_Instance inst, NTP_Sample *sample)
return; return;
} }
inst->stratum = sample->stratum;
SST_AccumulateSample(inst->stats, sample); SST_AccumulateSample(inst->stats, sample);
SST_DoNewRegression(inst->stats); SST_DoNewRegression(inst->stats);
} }
@ -808,7 +813,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
} }
si = &sources[i]->sel_info; si = &sources[i]->sel_info;
SST_GetSelectionData(sources[i]->stats, &now, &si->stratum, SST_GetSelectionData(sources[i]->stats, &now,
&si->lo_limit, &si->hi_limit, &si->root_distance, &si->lo_limit, &si->hi_limit, &si->root_distance,
&si->std_dev, &first_sample_ago, &si->std_dev, &first_sample_ago,
&si->last_sample_ago, &si->select_ok); &si->last_sample_ago, &si->select_ok);
@ -890,10 +895,10 @@ SRC_SelectSource(SRC_Instance updated_inst)
source can settle down to a state where only one server is serving its source can settle down to a state where only one server is serving its
local unsychronised time and others are synchronised to it. */ local unsychronised time and others are synchronised to it. */
if (si->stratum >= orphan_stratum && sources[i]->type == SRC_NTP) { if (sources[i]->stratum >= orphan_stratum && sources[i]->type == SRC_NTP) {
mark_source(sources[i], SRC_ORPHAN); mark_source(sources[i], SRC_ORPHAN);
if (si->stratum == orphan_stratum && sources[i]->reachability && if (sources[i]->stratum == orphan_stratum && sources[i]->reachability &&
(orphan_source == INVALID_SOURCE || (orphan_source == INVALID_SOURCE ||
sources[i]->ref_id < sources[orphan_source]->ref_id)) sources[i]->ref_id < sources[orphan_source]->ref_id))
orphan_source = i; orphan_source = i;
@ -1131,10 +1136,10 @@ SRC_SelectSource(SRC_Instance updated_inst)
/* Find minimum stratum */ /* Find minimum stratum */
index = sel_sources[0]; index = sel_sources[0];
min_stratum = sources[index]->sel_info.stratum; min_stratum = sources[index]->stratum;
for (i = 1; i < n_sel_sources; i++) { for (i = 1; i < n_sel_sources; i++) {
index = sel_sources[i]; index = sel_sources[i];
stratum = sources[index]->sel_info.stratum; stratum = sources[index]->stratum;
if (stratum < min_stratum) if (stratum < min_stratum)
min_stratum = stratum; min_stratum = stratum;
} }
@ -1147,7 +1152,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
if (selected_source_index != INVALID_SOURCE) if (selected_source_index != INVALID_SOURCE)
sel_src_distance = sources[selected_source_index]->sel_info.root_distance + sel_src_distance = sources[selected_source_index]->sel_info.root_distance +
(sources[selected_source_index]->sel_info.stratum - min_stratum) * stratum_weight; (sources[selected_source_index]->stratum - min_stratum) * stratum_weight;
for (i = 0; i < n_sources; i++) { for (i = 0; i < n_sources; i++) {
/* Reset score for non-selectable sources */ /* Reset score for non-selectable sources */
@ -1159,7 +1164,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
} }
distance = sources[i]->sel_info.root_distance + distance = sources[i]->sel_info.root_distance +
(sources[i]->sel_info.stratum - min_stratum) * stratum_weight; (sources[i]->stratum - min_stratum) * stratum_weight;
if (sources[i]->type == SRC_NTP) if (sources[i]->type == SRC_NTP)
distance += reselect_distance; distance += reselect_distance;
@ -1247,7 +1252,7 @@ SRC_SelectSource(SRC_Instance updated_inst)
combined = combine_sources(n_sel_sources, &ref_time, &src_offset, &src_offset_sd, combined = combine_sources(n_sel_sources, &ref_time, &src_offset, &src_offset_sd,
&src_frequency, &src_frequency_sd, &src_skew); &src_frequency, &src_frequency_sd, &src_skew);
REF_SetReference(sources[selected_source_index]->sel_info.stratum, REF_SetReference(sources[selected_source_index]->stratum,
leap_status, combined, leap_status, combined,
sources[selected_source_index]->ref_id, sources[selected_source_index]->ref_id,
sources[selected_source_index]->ip_addr, sources[selected_source_index]->ip_addr,
@ -1492,6 +1497,8 @@ SRC_ReportSource(int index, RPT_SourceReport *report, struct timespec *now)
report->ip_addr.family = IPADDR_INET4; report->ip_addr.family = IPADDR_INET4;
} }
report->stratum = src->stratum;
switch (src->status) { switch (src->status) {
case SRC_FALSETICKER: case SRC_FALSETICKER:
report->state = RPT_FALSETICKER; report->state = RPT_FALSETICKER;

View file

@ -177,9 +177,6 @@ struct SST_Stats_Record {
/* This array contains the root dispersions of each sample at the /* This array contains the root dispersions of each sample at the
time of the measurements */ time of the measurements */
double root_dispersions[MAX_SAMPLES]; double root_dispersions[MAX_SAMPLES];
/* The stratum from the last accumulated sample */
int stratum;
}; };
/* ================================================== */ /* ================================================== */
@ -321,7 +318,6 @@ SST_AccumulateSample(SST_Stats inst, NTP_Sample *sample)
inst->peer_dispersions[m] = sample->peer_dispersion; inst->peer_dispersions[m] = sample->peer_dispersion;
inst->root_delays[m] = sample->root_delay; inst->root_delays[m] = sample->root_delay;
inst->root_dispersions[m] = sample->root_dispersion; inst->root_dispersions[m] = sample->root_dispersion;
inst->stratum = sample->stratum;
if (inst->peer_delays[n] < inst->fixed_min_delay) if (inst->peer_delays[n] < inst->fixed_min_delay)
inst->peer_delays[n] = 2.0 * inst->fixed_min_delay - inst->peer_delays[n]; inst->peer_delays[n] = 2.0 * inst->fixed_min_delay - inst->peer_delays[n];
@ -650,7 +646,6 @@ SST_GetFrequencyRange(SST_Stats inst,
void void
SST_GetSelectionData(SST_Stats inst, struct timespec *now, SST_GetSelectionData(SST_Stats inst, struct timespec *now,
int *stratum,
double *offset_lo_limit, double *offset_lo_limit,
double *offset_hi_limit, double *offset_hi_limit,
double *root_distance, double *root_distance,
@ -670,7 +665,6 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now,
i = get_runsbuf_index(inst, inst->best_single_sample); i = get_runsbuf_index(inst, inst->best_single_sample);
j = get_buf_index(inst, inst->best_single_sample); j = get_buf_index(inst, inst->best_single_sample);
*stratum = inst->stratum;
*std_dev = inst->std_dev; *std_dev = inst->std_dev;
sample_elapsed = fabs(UTI_DiffTimespecsToDouble(now, &inst->sample_times[i])); sample_elapsed = fabs(UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]));
@ -885,7 +879,7 @@ SST_SaveToFile(SST_Stats inst, FILE *out)
inst->root_delays[j], inst->root_delays[j],
inst->root_dispersions[j], inst->root_dispersions[j],
1.0, /* used to be inst->weights[i] */ 1.0, /* used to be inst->weights[i] */
inst->stratum /* used to be an array */); 0 /* used to be an array of strata */);
} }
@ -907,6 +901,7 @@ SST_LoadFromFile(SST_Stats inst, FILE *in)
int i; int i;
char line[1024]; char line[1024];
double weight; double weight;
int stratum;
SST_ResetInstance(inst); SST_ResetInstance(inst);
@ -930,7 +925,7 @@ SST_LoadFromFile(SST_Stats inst, FILE *in)
&(inst->root_delays[i]), &(inst->root_delays[i]),
&(inst->root_dispersions[i]), &(inst->root_dispersions[i]),
&weight, /* not used anymore */ &weight, /* not used anymore */
&inst->stratum) != 10)) { &stratum /* not used anymore */) != 10)) {
/* This is the branch taken if the read FAILED */ /* This is the branch taken if the read FAILED */
@ -978,7 +973,6 @@ SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timespec *no
report->orig_latest_meas = inst->orig_offsets[j]; report->orig_latest_meas = inst->orig_offsets[j];
report->latest_meas = inst->offsets[i]; report->latest_meas = inst->offsets[i];
report->latest_meas_err = 0.5*inst->root_delays[j] + inst->root_dispersions[j]; report->latest_meas_err = 0.5*inst->root_delays[j] + inst->root_dispersions[j];
report->stratum = inst->stratum;
/* Align the sample time to reduce the leak of the receive timestamp */ /* Align the sample time to reduce the leak of the receive timestamp */
last_sample_time = inst->sample_times[i]; last_sample_time = inst->sample_times[i];

View file

@ -69,7 +69,6 @@ extern void SST_GetFrequencyRange(SST_Stats inst, double *lo, double *hi);
/* Get data needed for selection */ /* Get data needed for selection */
extern void extern void
SST_GetSelectionData(SST_Stats inst, struct timespec *now, SST_GetSelectionData(SST_Stats inst, struct timespec *now,
int *stratum,
double *offset_lo_limit, double *offset_lo_limit,
double *offset_hi_limit, double *offset_hi_limit,
double *root_distance, double *root_distance,