From f74eb675670a4007e9a03f16d68e8028c287ed77 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 3 Feb 2021 12:54:08 +0100 Subject: [PATCH] sourcestats: move stratum to sources The stratum value is not needed in sourcestats. Keep it in the source itself. --- sources.c | 27 +++++++++++++++++---------- sourcestats.c | 12 +++--------- sourcestats.h | 1 - 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sources.c b/sources.c index 63647d2..9345055 100644 --- a/sources.c +++ b/sources.c @@ -54,7 +54,6 @@ static int initialised = 0; /* ================================================== */ /* Structure used to hold info for selecting between sources */ struct SelectInfo { - int stratum; int select_ok; double std_dev; double root_distance; @@ -132,7 +131,10 @@ struct SRC_Instance_Record { struct SelectInfo sel_info; - /* Latest leap status */ + /* Current stratum */ + int stratum; + + /* Current leap status */ NTP_Leap leap; /* Flag indicating the source has a leap second vote */ @@ -313,6 +315,7 @@ SRC_ResetInstance(SRC_Instance instance) instance->distant = 0; instance->status = SRC_BAD_STATS; instance->sel_score = 1.0; + instance->stratum = 0; instance->leap = LEAP_Unsynchronised; instance->leap_vote = 0; @@ -407,6 +410,8 @@ SRC_AccumulateSample(SRC_Instance inst, NTP_Sample *sample) return; } + inst->stratum = sample->stratum; + SST_AccumulateSample(inst->stats, sample); SST_DoNewRegression(inst->stats); } @@ -808,7 +813,7 @@ SRC_SelectSource(SRC_Instance updated_inst) } 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->std_dev, &first_sample_ago, &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 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); - if (si->stratum == orphan_stratum && sources[i]->reachability && + if (sources[i]->stratum == orphan_stratum && sources[i]->reachability && (orphan_source == INVALID_SOURCE || sources[i]->ref_id < sources[orphan_source]->ref_id)) orphan_source = i; @@ -1131,10 +1136,10 @@ SRC_SelectSource(SRC_Instance updated_inst) /* Find minimum stratum */ index = sel_sources[0]; - min_stratum = sources[index]->sel_info.stratum; + min_stratum = sources[index]->stratum; for (i = 1; i < n_sel_sources; i++) { index = sel_sources[i]; - stratum = sources[index]->sel_info.stratum; + stratum = sources[index]->stratum; if (stratum < min_stratum) min_stratum = stratum; } @@ -1147,7 +1152,7 @@ SRC_SelectSource(SRC_Instance updated_inst) if (selected_source_index != INVALID_SOURCE) 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++) { /* Reset score for non-selectable sources */ @@ -1159,7 +1164,7 @@ SRC_SelectSource(SRC_Instance updated_inst) } 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) 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, &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, sources[selected_source_index]->ref_id, 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->stratum = src->stratum; + switch (src->status) { case SRC_FALSETICKER: report->state = RPT_FALSETICKER; diff --git a/sourcestats.c b/sourcestats.c index c93b5e4..f35ba84 100644 --- a/sourcestats.c +++ b/sourcestats.c @@ -177,9 +177,6 @@ struct SST_Stats_Record { /* This array contains the root dispersions of each sample at the time of the measurements */ 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->root_delays[m] = sample->root_delay; inst->root_dispersions[m] = sample->root_dispersion; - inst->stratum = sample->stratum; if (inst->peer_delays[n] < inst->fixed_min_delay) inst->peer_delays[n] = 2.0 * inst->fixed_min_delay - inst->peer_delays[n]; @@ -650,7 +646,6 @@ SST_GetFrequencyRange(SST_Stats inst, void SST_GetSelectionData(SST_Stats inst, struct timespec *now, - int *stratum, double *offset_lo_limit, double *offset_hi_limit, double *root_distance, @@ -670,7 +665,6 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now, i = get_runsbuf_index(inst, inst->best_single_sample); j = get_buf_index(inst, inst->best_single_sample); - *stratum = inst->stratum; *std_dev = inst->std_dev; 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_dispersions[j], 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; char line[1024]; double weight; + int stratum; SST_ResetInstance(inst); @@ -930,7 +925,7 @@ SST_LoadFromFile(SST_Stats inst, FILE *in) &(inst->root_delays[i]), &(inst->root_dispersions[i]), &weight, /* not used anymore */ - &inst->stratum) != 10)) { + &stratum /* not used anymore */) != 10)) { /* 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->latest_meas = inst->offsets[i]; 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 */ last_sample_time = inst->sample_times[i]; diff --git a/sourcestats.h b/sourcestats.h index 72fd546..a0f6af9 100644 --- a/sourcestats.h +++ b/sourcestats.h @@ -69,7 +69,6 @@ extern void SST_GetFrequencyRange(SST_Stats inst, double *lo, double *hi); /* Get data needed for selection */ extern void SST_GetSelectionData(SST_Stats inst, struct timespec *now, - int *stratum, double *offset_lo_limit, double *offset_hi_limit, double *root_distance,