sources: update stratum with leap status
Remove stratum from the NTP sample and update it together with the leap status. This enables a faster update when samples are dropped by the NTP filters.
This commit is contained in:
parent
f74eb67567
commit
1a8dcce84f
8 changed files with 17 additions and 23 deletions
1
ntp.h
1
ntp.h
|
@ -152,7 +152,6 @@ typedef struct {
|
||||||
double peer_dispersion;
|
double peer_dispersion;
|
||||||
double root_delay;
|
double root_delay;
|
||||||
double root_dispersion;
|
double root_dispersion;
|
||||||
int stratum;
|
|
||||||
} NTP_Sample;
|
} NTP_Sample;
|
||||||
|
|
||||||
#endif /* GOT_NTP_H */
|
#endif /* GOT_NTP_H */
|
||||||
|
|
|
@ -1678,7 +1678,6 @@ process_response(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
|
|
||||||
sample.root_delay = pkt_root_delay + sample.peer_delay;
|
sample.root_delay = pkt_root_delay + sample.peer_delay;
|
||||||
sample.root_dispersion = pkt_root_dispersion + sample.peer_dispersion;
|
sample.root_dispersion = pkt_root_dispersion + sample.peer_dispersion;
|
||||||
sample.stratum = MAX(message->stratum, inst->min_stratum);
|
|
||||||
|
|
||||||
/* Update the NTP timestamps. If it's a valid packet from a synchronised
|
/* Update the NTP timestamps. If it's a valid packet from a synchronised
|
||||||
source, the timestamps may be used later when processing a packet in the
|
source, the timestamps may be used later when processing a packet in the
|
||||||
|
@ -1768,7 +1767,7 @@ process_response(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
inst->tx_count = 0;
|
inst->tx_count = 0;
|
||||||
|
|
||||||
SRC_UpdateReachability(inst->source, synced_packet);
|
SRC_UpdateReachability(inst->source, synced_packet);
|
||||||
SRC_SetLeapStatus(inst->source, pkt_leap);
|
SRC_UpdateStatus(inst->source, MAX(message->stratum, inst->min_stratum), pkt_leap);
|
||||||
|
|
||||||
if (good_packet) {
|
if (good_packet) {
|
||||||
/* Adjust the polling interval, accumulate the sample, etc. */
|
/* Adjust the polling interval, accumulate the sample, etc. */
|
||||||
|
|
16
refclock.c
16
refclock.c
|
@ -415,12 +415,6 @@ accumulate_sample(RCL_Instance instance, struct timespec *sample_time, double of
|
||||||
sample.peer_dispersion = dispersion;
|
sample.peer_dispersion = dispersion;
|
||||||
sample.root_dispersion = dispersion;
|
sample.root_dispersion = dispersion;
|
||||||
|
|
||||||
/* Handle special case when PPS is used with the local reference */
|
|
||||||
if (instance->pps_active && instance->lock_ref == -1)
|
|
||||||
sample.stratum = pps_stratum(instance, &sample.time);
|
|
||||||
else
|
|
||||||
sample.stratum = instance->stratum;
|
|
||||||
|
|
||||||
return SPF_AccumulateSample(instance->filter, &sample);
|
return SPF_AccumulateSample(instance->filter, &sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,7 +679,7 @@ static void
|
||||||
poll_timeout(void *arg)
|
poll_timeout(void *arg)
|
||||||
{
|
{
|
||||||
NTP_Sample sample;
|
NTP_Sample sample;
|
||||||
int poll;
|
int poll, stratum;
|
||||||
|
|
||||||
RCL_Instance inst = (RCL_Instance)arg;
|
RCL_Instance inst = (RCL_Instance)arg;
|
||||||
|
|
||||||
|
@ -701,8 +695,14 @@ poll_timeout(void *arg)
|
||||||
inst->driver_polled = 0;
|
inst->driver_polled = 0;
|
||||||
|
|
||||||
if (SPF_GetFilteredSample(inst->filter, &sample)) {
|
if (SPF_GetFilteredSample(inst->filter, &sample)) {
|
||||||
|
/* Handle special case when PPS is used with the local reference */
|
||||||
|
if (inst->pps_active && inst->lock_ref == -1)
|
||||||
|
stratum = pps_stratum(inst, &sample.time);
|
||||||
|
else
|
||||||
|
stratum = inst->stratum;
|
||||||
|
|
||||||
SRC_UpdateReachability(inst->source, 1);
|
SRC_UpdateReachability(inst->source, 1);
|
||||||
SRC_SetLeapStatus(inst->source, inst->leap_status);
|
SRC_UpdateStatus(inst->source, stratum, inst->leap_status);
|
||||||
SRC_AccumulateSample(inst->source, &sample);
|
SRC_AccumulateSample(inst->source, &sample);
|
||||||
SRC_SelectSource(inst->source);
|
SRC_SelectSource(inst->source);
|
||||||
|
|
||||||
|
|
|
@ -386,7 +386,6 @@ combine_selected_samples(SPF_Instance filter, int n, NTP_Sample *result)
|
||||||
result->root_dispersion = MAX(disp, mean_root_dispersion);
|
result->root_dispersion = MAX(disp, mean_root_dispersion);
|
||||||
result->peer_delay = mean_peer_delay;
|
result->peer_delay = mean_peer_delay;
|
||||||
result->root_delay = mean_root_delay;
|
result->root_delay = mean_root_delay;
|
||||||
result->stratum = last_sample->stratum;
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
10
sources.c
10
sources.c
|
@ -374,8 +374,10 @@ get_leap_status(void)
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
SRC_SetLeapStatus(SRC_Instance inst, NTP_Leap leap)
|
SRC_UpdateStatus(SRC_Instance inst, int stratum, NTP_Leap leap)
|
||||||
{
|
{
|
||||||
|
inst->stratum = stratum;
|
||||||
|
|
||||||
if (REF_IsLeapSecondClose(NULL, 0.0))
|
if (REF_IsLeapSecondClose(NULL, 0.0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -401,17 +403,15 @@ SRC_AccumulateSample(SRC_Instance inst, NTP_Sample *sample)
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
|
||||||
DEBUG_LOG("src=%s ts=%s offset=%e delay=%e disp=%e stratum=%d",
|
DEBUG_LOG("src=%s ts=%s offset=%e delay=%e disp=%e",
|
||||||
source_to_string(inst), UTI_TimespecToString(&sample->time), -sample->offset,
|
source_to_string(inst), UTI_TimespecToString(&sample->time), -sample->offset,
|
||||||
sample->root_delay, sample->root_dispersion, sample->stratum);
|
sample->root_delay, sample->root_dispersion);
|
||||||
|
|
||||||
if (REF_IsLeapSecondClose(&sample->time, sample->offset)) {
|
if (REF_IsLeapSecondClose(&sample->time, sample->offset)) {
|
||||||
LOG(LOGS_INFO, "Dropping sample around leap second");
|
LOG(LOGS_INFO, "Dropping sample around leap second");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
inst->stratum = sample->stratum;
|
|
||||||
|
|
||||||
SST_AccumulateSample(inst->stats, sample);
|
SST_AccumulateSample(inst->stats, sample);
|
||||||
SST_DoNewRegression(inst->stats);
|
SST_DoNewRegression(inst->stats);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,8 +87,8 @@ extern void SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr);
|
||||||
/* Function to get access to the sourcestats instance */
|
/* Function to get access to the sourcestats instance */
|
||||||
extern SST_Stats SRC_GetSourcestats(SRC_Instance instance);
|
extern SST_Stats SRC_GetSourcestats(SRC_Instance instance);
|
||||||
|
|
||||||
/* Function to set the current leap status according to the source */
|
/* Function to update the stratum and leap status of the source */
|
||||||
extern void SRC_SetLeapStatus(SRC_Instance instance, NTP_Leap leap);
|
extern void SRC_UpdateStatus(SRC_Instance instance, int stratum, NTP_Leap leap);
|
||||||
|
|
||||||
/* Function to accumulate a new sample from the source */
|
/* Function to accumulate a new sample from the source */
|
||||||
extern void SRC_AccumulateSample(SRC_Instance instance, NTP_Sample *sample);
|
extern void SRC_AccumulateSample(SRC_Instance instance, NTP_Sample *sample);
|
||||||
|
|
|
@ -59,7 +59,6 @@ test_unit(void)
|
||||||
sample_in.root_dispersion = TST_GetRandomDouble(1.0e-3, 2.0e-3);
|
sample_in.root_dispersion = TST_GetRandomDouble(1.0e-3, 2.0e-3);
|
||||||
sample_in.peer_delay = TST_GetRandomDouble(1.0e-2, 2.0e-2);
|
sample_in.peer_delay = TST_GetRandomDouble(1.0e-2, 2.0e-2);
|
||||||
sample_in.root_delay = TST_GetRandomDouble(1.0e-1, 2.0e-1);
|
sample_in.root_delay = TST_GetRandomDouble(1.0e-1, 2.0e-1);
|
||||||
sample_in.stratum = random() % 16;
|
|
||||||
|
|
||||||
TEST_CHECK(SPF_AccumulateSample(filter, &sample_in));
|
TEST_CHECK(SPF_AccumulateSample(filter, &sample_in));
|
||||||
TEST_CHECK(!SPF_AccumulateSample(filter, &sample_in));
|
TEST_CHECK(!SPF_AccumulateSample(filter, &sample_in));
|
||||||
|
@ -97,7 +96,6 @@ test_unit(void)
|
||||||
sample_out.peer_delay <= 2.0e-2);
|
sample_out.peer_delay <= 2.0e-2);
|
||||||
TEST_CHECK(sample_out.root_delay >= 1.0e-1 &&
|
TEST_CHECK(sample_out.root_delay >= 1.0e-1 &&
|
||||||
sample_out.root_delay <= 2.0e-1);
|
sample_out.root_delay <= 2.0e-1);
|
||||||
TEST_CHECK(sample_out.stratum >= 0 && sample_out.stratum <= 15);
|
|
||||||
|
|
||||||
if (max_samples == 1)
|
if (max_samples == 1)
|
||||||
TEST_CHECK(!memcmp(&sample_in, &sample_out, sizeof (sample_in)));
|
TEST_CHECK(!memcmp(&sample_in, &sample_out, sizeof (sample_in)));
|
||||||
|
|
|
@ -79,10 +79,9 @@ test_unit(void)
|
||||||
sample.peer_dispersion = TST_GetRandomDouble(1.0e-6, 1.0e-1);
|
sample.peer_dispersion = TST_GetRandomDouble(1.0e-6, 1.0e-1);
|
||||||
sample.root_delay = sample.peer_delay;
|
sample.root_delay = sample.peer_delay;
|
||||||
sample.root_dispersion = sample.peer_dispersion;
|
sample.root_dispersion = sample.peer_dispersion;
|
||||||
sample.stratum = 1;
|
|
||||||
|
|
||||||
if (random() % 2)
|
if (random() % 2)
|
||||||
SRC_SetLeapStatus(srcs[j], random() % 4);
|
SRC_UpdateStatus(srcs[j], 1, random() % 4);
|
||||||
|
|
||||||
DEBUG_LOG("source %d sample %d offset %f delay %f disp %f", j, k,
|
DEBUG_LOG("source %d sample %d offset %f delay %f disp %f", j, k,
|
||||||
sample.offset, sample.peer_delay, sample.peer_dispersion);
|
sample.offset, sample.peer_delay, sample.peer_dispersion);
|
||||||
|
|
Loading…
Reference in a new issue