sourcestats: track leap status

This moves the leap status of the last sample from the source instance
to the sourcestats instance in order to make them both accumulate the
same data.
This commit is contained in:
Miroslav Lichvar 2018-08-01 16:19:28 +02:00
parent 4ceb9e4cd0
commit 05078e4252
3 changed files with 15 additions and 12 deletions

View file

@ -54,6 +54,7 @@ static int initialised = 0;
/* ================================================== */
/* Structure used to hold info for selecting between sources */
struct SelectInfo {
NTP_Leap leap;
int stratum;
int select_ok;
double std_dev;
@ -91,7 +92,6 @@ typedef enum {
source */
struct SRC_Instance_Record {
SST_Stats stats;
NTP_Leap leap_status; /* Leap status */
int index; /* Index back into the array of source */
uint32_t ref_id; /* The reference ID of this source
(i.e. from its IP address, NOT the
@ -291,7 +291,6 @@ void SRC_DestroyInstance(SRC_Instance instance)
void
SRC_ResetInstance(SRC_Instance instance)
{
instance->leap_status = LEAP_Normal;
instance->active = 0;
instance->updates = 0;
instance->reachability = 0;
@ -349,8 +348,6 @@ void SRC_AccumulateSample
assert(initialised);
inst->leap_status = leap_status;
DEBUG_LOG("ip=[%s] t=%s ofs=%f del=%f disp=%f str=%d",
source_to_string(inst), UTI_TimespecToString(sample_time), -offset,
root_delay, root_dispersion, stratum);
@ -362,7 +359,8 @@ void SRC_AccumulateSample
/* WE HAVE TO NEGATE OFFSET IN THIS CALL, IT IS HERE THAT THE SENSE OF OFFSET
IS FLIPPED */
SST_AccumulateSample(inst->stats, sample_time, -offset, peer_delay, peer_dispersion, root_delay, root_dispersion, stratum);
SST_AccumulateSample(inst->stats, sample_time, -offset, peer_delay, peer_dispersion,
root_delay, root_dispersion, stratum, leap_status);
SST_DoNewRegression(inst->stats);
}
@ -652,7 +650,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->stratum, &si->leap,
&si->lo_limit, &si->hi_limit, &si->root_distance,
&si->std_dev, &first_sample_ago,
&si->last_sample_ago, &si->select_ok);
@ -929,9 +927,9 @@ SRC_SelectSource(SRC_Instance updated_inst)
if (best_trust_depth && !(sources[index]->sel_options & SRC_SELECT_TRUST))
continue;
leap_votes++;
if (sources[index]->leap_status == LEAP_InsertSecond)
if (sources[index]->sel_info.leap == LEAP_InsertSecond)
leap_ins++;
else if (sources[index]->leap_status == LEAP_DeleteSecond)
else if (sources[index]->sel_info.leap == LEAP_DeleteSecond)
leap_del++;
}

View file

@ -178,6 +178,8 @@ struct SST_Stats_Record {
at the times the samples were generated */
int strata[MAX_SAMPLES];
/* The leap status from the last accumulated sample */
NTP_Leap leap;
};
/* ================================================== */
@ -252,6 +254,7 @@ SST_ResetInstance(SST_Stats inst)
inst->nruns = 0;
inst->asymmetry_run = 0;
inst->asymmetry = 0.0;
inst->leap = LEAP_Unsynchronised;
}
/* ================================================== */
@ -291,7 +294,7 @@ SST_AccumulateSample(SST_Stats inst, struct timespec *sample_time,
double offset,
double peer_delay, double peer_dispersion,
double root_delay, double root_dispersion,
int stratum)
int stratum, NTP_Leap leap)
{
int n, m;
@ -321,6 +324,7 @@ SST_AccumulateSample(SST_Stats inst, struct timespec *sample_time,
inst->root_delays[m] = root_delay;
inst->root_dispersions[m] = root_dispersion;
inst->strata[m] = stratum;
inst->leap = leap;
if (inst->peer_delays[n] < inst->fixed_min_delay)
inst->peer_delays[n] = 2.0 * inst->fixed_min_delay - inst->peer_delays[n];
@ -636,7 +640,7 @@ SST_GetFrequencyRange(SST_Stats inst,
void
SST_GetSelectionData(SST_Stats inst, struct timespec *now,
int *stratum,
int *stratum, NTP_Leap *leap,
double *offset_lo_limit,
double *offset_hi_limit,
double *root_distance,
@ -657,6 +661,7 @@ SST_GetSelectionData(SST_Stats inst, struct timespec *now,
j = get_buf_index(inst, inst->best_single_sample);
*stratum = inst->strata[get_buf_index(inst, inst->n_samples - 1)];
*leap = inst->leap;
*std_dev = inst->std_dev;
sample_elapsed = fabs(UTI_DiffTimespecsToDouble(now, &inst->sample_times[i]));

View file

@ -63,7 +63,7 @@ extern void SST_SetRefid(SST_Stats inst, uint32_t refid, IPAddr *addr);
stratum is the stratum of the source from which the sample came.
*/
extern void SST_AccumulateSample(SST_Stats inst, struct timespec *sample_time, double offset, double peer_delay, double peer_dispersion, double root_delay, double root_dispersion, int stratum);
extern void SST_AccumulateSample(SST_Stats inst, struct timespec *sample_time, double offset, double peer_delay, double peer_dispersion, double root_delay, double root_dispersion, int stratum, NTP_Leap leap);
/* This function runs the linear regression operation on the data. It
finds the set of most recent samples that give the tightest
@ -80,7 +80,7 @@ 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,
int *stratum, NTP_Leap *leap,
double *offset_lo_limit,
double *offset_hi_limit,
double *root_distance,