sources: separate update of leap status
Remove leap status from the NTP sample and set it independently from the sample accumulation in order to accept a leap second sooner when samples are filtered.
This commit is contained in:
parent
ff9301567e
commit
2582be8754
8 changed files with 20 additions and 10 deletions
1
ntp.h
1
ntp.h
|
@ -152,7 +152,6 @@ typedef struct {
|
|||
double root_delay;
|
||||
double root_dispersion;
|
||||
int stratum;
|
||||
NTP_Leap leap;
|
||||
} NTP_Sample;
|
||||
|
||||
#endif /* GOT_NTP_H */
|
||||
|
|
|
@ -1682,7 +1682,6 @@ process_response(NCR_Instance inst, NTP_Local_Address *local_addr,
|
|||
sample.root_delay = pkt_root_delay + sample.peer_delay;
|
||||
sample.root_dispersion = pkt_root_dispersion + sample.peer_dispersion;
|
||||
sample.stratum = MAX(message->stratum, inst->min_stratum);
|
||||
sample.leap = (NTP_Leap)pkt_leap;
|
||||
|
||||
/* 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
|
||||
|
@ -1772,6 +1771,7 @@ process_response(NCR_Instance inst, NTP_Local_Address *local_addr,
|
|||
inst->tx_count = 0;
|
||||
|
||||
SRC_UpdateReachability(inst->source, synced_packet);
|
||||
SRC_SetLeapStatus(inst->source, pkt_leap);
|
||||
|
||||
if (good_packet) {
|
||||
/* Adjust the polling interval, accumulate the sample, etc. */
|
||||
|
|
|
@ -415,7 +415,6 @@ accumulate_sample(RCL_Instance instance, struct timespec *sample_time, double of
|
|||
sample.root_delay = instance->delay;
|
||||
sample.peer_dispersion = dispersion;
|
||||
sample.root_dispersion = dispersion;
|
||||
sample.leap = instance->leap_status;
|
||||
|
||||
/* Handle special case when PPS is used with the local reference */
|
||||
if (instance->pps_active && instance->lock_ref == -1)
|
||||
|
@ -704,6 +703,7 @@ poll_timeout(void *arg)
|
|||
|
||||
if (SPF_GetFilteredSample(inst->filter, &sample)) {
|
||||
SRC_UpdateReachability(inst->source, 1);
|
||||
SRC_SetLeapStatus(inst->source, inst->leap_status);
|
||||
SRC_AccumulateSample(inst->source, &sample);
|
||||
SRC_SelectSource(inst->source);
|
||||
|
||||
|
|
|
@ -387,7 +387,6 @@ combine_selected_samples(SPF_Instance filter, int n, NTP_Sample *result)
|
|||
result->peer_delay = mean_peer_delay;
|
||||
result->root_delay = mean_root_delay;
|
||||
result->stratum = last_sample->stratum;
|
||||
result->leap = last_sample->leap;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
12
sources.c
12
sources.c
|
@ -326,6 +326,17 @@ SRC_GetSourcestats(SRC_Instance instance)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
SRC_SetLeapStatus(SRC_Instance inst, NTP_Leap leap)
|
||||
{
|
||||
if (REF_IsLeapSecondClose())
|
||||
return;
|
||||
|
||||
inst->leap = leap;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
/* This function is called by one of the source drivers when it has
|
||||
a new sample that is to be accumulated.
|
||||
|
||||
|
@ -351,7 +362,6 @@ SRC_AccumulateSample(SRC_Instance inst, NTP_Sample *sample)
|
|||
|
||||
SST_AccumulateSample(inst->stats, sample);
|
||||
SST_DoNewRegression(inst->stats);
|
||||
inst->leap = sample->leap;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
|
|
@ -79,8 +79,10 @@ extern void SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr);
|
|||
/* Function to get access to the sourcestats instance */
|
||||
extern SST_Stats SRC_GetSourcestats(SRC_Instance instance);
|
||||
|
||||
/* This function is called by one of the source drivers when it has
|
||||
a new sample that is to be accumulated */
|
||||
/* Function to set the current leap status according to the source */
|
||||
extern void SRC_SetLeapStatus(SRC_Instance instance, NTP_Leap leap);
|
||||
|
||||
/* Function to accumulate a new sample from the source */
|
||||
extern void SRC_AccumulateSample(SRC_Instance instance, NTP_Sample *sample);
|
||||
|
||||
/* This routine sets the source as receiving reachability updates */
|
||||
|
|
|
@ -35,6 +35,9 @@ test_unit(void)
|
|||
|
||||
LCL_Initialise();
|
||||
|
||||
memset(&sample_in, 0, sizeof (sample_in));
|
||||
memset(&sample_out, 0, sizeof (sample_out));
|
||||
|
||||
for (i = 0; i <= 100; i++) {
|
||||
max_samples = random() % 20 + 1;
|
||||
min_samples = random() % (max_samples) + 1;
|
||||
|
@ -57,7 +60,6 @@ test_unit(void)
|
|||
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.stratum = random() % 16;
|
||||
sample_in.leap = random() % 4;
|
||||
|
||||
TEST_CHECK(SPF_AccumulateSample(filter, &sample_in));
|
||||
TEST_CHECK(!SPF_AccumulateSample(filter, &sample_in));
|
||||
|
@ -95,7 +97,6 @@ test_unit(void)
|
|||
sample_out.peer_delay <= 2.0e-2);
|
||||
TEST_CHECK(sample_out.root_delay >= 1.0e-1 &&
|
||||
sample_out.root_delay <= 2.0e-1);
|
||||
TEST_CHECK(sample_out.leap >= 0 && sample_out.leap <= 3);
|
||||
TEST_CHECK(sample_out.stratum >= 0 && sample_out.stratum <= 15);
|
||||
|
||||
if (max_samples == 1)
|
||||
|
|
|
@ -71,7 +71,6 @@ test_unit(void)
|
|||
sample.root_delay = sample.peer_delay;
|
||||
sample.root_dispersion = sample.peer_dispersion;
|
||||
sample.stratum = 1;
|
||||
sample.leap = LEAP_Normal;
|
||||
|
||||
DEBUG_LOG("source %d sample %d offset %f delay %f disp %f", j, k,
|
||||
sample.offset, sample.peer_delay, sample.peer_dispersion);
|
||||
|
|
Loading…
Reference in a new issue