Cache minimum peer delay in sourcestats

This commit is contained in:
Miroslav Lichvar 2010-12-03 17:25:50 +01:00
parent 0de82a70a6
commit feb8811f37

View file

@ -77,6 +77,9 @@ struct SST_Stats_Record {
root distance at the present time */ root distance at the present time */
int best_single_sample; int best_single_sample;
/* The index of the sample with minimum delay in peer_delays */
int min_delay_sample;
/* This is the estimated offset (+ve => local fast) at a particular time */ /* This is the estimated offset (+ve => local fast) at a particular time */
double estimated_offset; double estimated_offset;
double estimated_offset_sd; double estimated_offset_sd;
@ -144,6 +147,11 @@ struct SST_Stats_Record {
/* ================================================== */ /* ================================================== */
static void find_min_delay_sample(SST_Stats inst);
static int get_buf_index(SST_Stats inst, int i);
/* ================================================== */
void void
SST_Initialise(void) SST_Initialise(void)
{ {
@ -173,6 +181,7 @@ SST_CreateInstance(unsigned long refid, IPAddr *addr)
inst->runs_samples = 0; inst->runs_samples = 0;
inst->last_sample = 0; inst->last_sample = 0;
inst->best_single_sample = 0; inst->best_single_sample = 0;
inst->min_delay_sample = 0;
inst->estimated_frequency = 0; inst->estimated_frequency = 0;
inst->skew = 2000.0e-6; inst->skew = 2000.0e-6;
inst->skew_dirn = SST_Skew_Nochange; inst->skew_dirn = SST_Skew_Nochange;
@ -202,6 +211,9 @@ SST_DeleteInstance(SST_Stats inst)
static void static void
prune_register(SST_Stats inst, int new_oldest) prune_register(SST_Stats inst, int new_oldest)
{ {
if (!new_oldest)
return;
assert(inst->n_samples >= new_oldest); assert(inst->n_samples >= new_oldest);
inst->n_samples -= new_oldest; inst->n_samples -= new_oldest;
inst->runs_samples += new_oldest; inst->runs_samples += new_oldest;
@ -209,6 +221,8 @@ prune_register(SST_Stats inst, int new_oldest)
inst->runs_samples = inst->n_samples * (REGRESS_RUNS_RATIO - 1); inst->runs_samples = inst->n_samples * (REGRESS_RUNS_RATIO - 1);
assert(inst->n_samples + inst->runs_samples <= MAX_SAMPLES * REGRESS_RUNS_RATIO); assert(inst->n_samples + inst->runs_samples <= MAX_SAMPLES * REGRESS_RUNS_RATIO);
find_min_delay_sample(inst);
} }
/* ================================================== */ /* ================================================== */
@ -239,6 +253,9 @@ SST_AccumulateSample(SST_Stats inst, struct timeval *sample_time,
inst->root_dispersions[m] = root_dispersion; inst->root_dispersions[m] = root_dispersion;
inst->strata[m] = stratum; inst->strata[m] = stratum;
if (!inst->n_samples || inst->peer_delays[m] < inst->peer_delays[inst->min_delay_sample])
inst->min_delay_sample = m;
++inst->n_samples; ++inst->n_samples;
} }
@ -325,6 +342,22 @@ find_best_sample_index(SST_Stats inst, double *times_back)
/* ================================================== */ /* ================================================== */
static void
find_min_delay_sample(SST_Stats inst)
{
int i, index;
inst->min_delay_sample = get_buf_index(inst, 0);
for (i = 1; i < inst->n_samples; i++) {
index = get_buf_index(inst, i);
if (inst->peer_delays[index] < inst->peer_delays[inst->min_delay_sample])
inst->min_delay_sample = index;
}
}
/* ================================================== */
/* This defines the assumed ratio between the standard deviation of /* This defines the assumed ratio between the standard deviation of
the samples and the peer distance as measured from the round trip the samples and the peer distance as measured from the round trip
time. E.g. a value of 4 means that we think the standard deviation time. E.g. a value of 4 means that we think the standard deviation
@ -655,15 +688,9 @@ SST_PredictOffset(SST_Stats inst, struct timeval *when)
double double
SST_MinRoundTripDelay(SST_Stats inst) SST_MinRoundTripDelay(SST_Stats inst)
{ {
double min_delay, delay; if (!inst->n_samples)
int i; return DBL_MAX;
return inst->peer_delays[inst->min_delay_sample];
for (i = 0, min_delay = DBL_MAX; i < inst->n_samples; i++) {
delay = inst->peer_delays[get_buf_index(inst, i)];
if (delay < min_delay)
min_delay = delay;
}
return min_delay;
} }
/* ================================================== */ /* ================================================== */
@ -748,6 +775,8 @@ SST_LoadFromFile(SST_Stats inst, FILE *in)
inst->last_sample = inst->n_samples - 1; inst->last_sample = inst->n_samples - 1;
inst->runs_samples = 0; inst->runs_samples = 0;
find_min_delay_sample(inst);
return 1; return 1;
} }