sources: give access to sourcestats instance
Give access to the sourcestats instance and remove all functions that just translated to SST calls.
This commit is contained in:
parent
ed286f3617
commit
1045adaa88
3 changed files with 17 additions and 83 deletions
17
ntp_core.c
17
ntp_core.c
|
@ -703,7 +703,7 @@ get_poll_adj(NCR_Instance inst, double error_in_estimate, double peer_distance)
|
||||||
poll_adj = -shift - inst->poll_score + 0.5;
|
poll_adj = -shift - inst->poll_score + 0.5;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int samples = SRC_Samples(inst->source);
|
int samples = SST_Samples(SRC_GetSourcestats(inst->source));
|
||||||
|
|
||||||
/* Adjust polling interval so that the number of sourcestats samples
|
/* Adjust polling interval so that the number of sourcestats samples
|
||||||
remains close to the target value */
|
remains close to the target value */
|
||||||
|
@ -1227,6 +1227,8 @@ static int
|
||||||
receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr,
|
receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
NTP_Local_Timestamp *rx_ts, NTP_Packet *message, int length)
|
NTP_Local_Timestamp *rx_ts, NTP_Packet *message, int length)
|
||||||
{
|
{
|
||||||
|
SST_Stats stats;
|
||||||
|
|
||||||
int pkt_leap;
|
int pkt_leap;
|
||||||
uint32_t pkt_refid, pkt_key_id;
|
uint32_t pkt_refid, pkt_key_id;
|
||||||
double pkt_root_delay;
|
double pkt_root_delay;
|
||||||
|
@ -1280,6 +1282,8 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
|
|
||||||
/* ==================== */
|
/* ==================== */
|
||||||
|
|
||||||
|
stats = SRC_GetSourcestats(inst->source);
|
||||||
|
|
||||||
pkt_leap = NTP_LVM_TO_LEAP(message->lvm);
|
pkt_leap = NTP_LVM_TO_LEAP(message->lvm);
|
||||||
pkt_refid = ntohl(message->reference_id);
|
pkt_refid = ntohl(message->reference_id);
|
||||||
pkt_root_delay = UTI_Ntp32ToDouble(message->root_delay);
|
pkt_root_delay = UTI_Ntp32ToDouble(message->root_delay);
|
||||||
|
@ -1347,7 +1351,7 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
precision = LCL_GetSysPrecisionAsQuantum() +
|
precision = LCL_GetSysPrecisionAsQuantum() +
|
||||||
UTI_Log2ToDouble(message->precision);
|
UTI_Log2ToDouble(message->precision);
|
||||||
|
|
||||||
SRC_GetFrequencyRange(inst->source, &source_freq_lo, &source_freq_hi);
|
SST_GetFrequencyRange(stats, &source_freq_lo, &source_freq_hi);
|
||||||
|
|
||||||
UTI_Ntp64ToTimespec(&message->receive_ts, &remote_receive);
|
UTI_Ntp64ToTimespec(&message->receive_ts, &remote_receive);
|
||||||
UTI_Ntp64ToTimespec(&message->transmit_ts, &remote_transmit);
|
UTI_Ntp64ToTimespec(&message->transmit_ts, &remote_transmit);
|
||||||
|
@ -1416,16 +1420,15 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
minimum one currently in the stats data register is less than an
|
minimum one currently in the stats data register is less than an
|
||||||
administrator-defined value */
|
administrator-defined value */
|
||||||
testB = inst->max_delay_ratio <= 1.0 ||
|
testB = inst->max_delay_ratio <= 1.0 ||
|
||||||
delay / SRC_MinRoundTripDelay(inst->source) <= inst->max_delay_ratio;
|
delay / SST_MinRoundTripDelay(stats) <= inst->max_delay_ratio;
|
||||||
|
|
||||||
/* Test C requires that the ratio of the increase in delay from the minimum
|
/* Test C requires that the ratio of the increase in delay from the minimum
|
||||||
one in the stats data register to the standard deviation of the offsets
|
one in the stats data register to the standard deviation of the offsets
|
||||||
in the register is less than an administrator-defined value or the
|
in the register is less than an administrator-defined value or the
|
||||||
difference between measured offset and predicted offset is larger than
|
difference between measured offset and predicted offset is larger than
|
||||||
the increase in delay */
|
the increase in delay */
|
||||||
testC = SRC_IsGoodSample(inst->source, -offset, delay,
|
testC = SST_IsGoodSample(stats, -offset, delay, inst->max_delay_dev_ratio,
|
||||||
inst->max_delay_dev_ratio, LCL_GetMaxClockError(),
|
LCL_GetMaxClockError(), &sample_time);
|
||||||
&sample_time);
|
|
||||||
|
|
||||||
/* Test D requires that the remote peer is not synchronised to us to
|
/* Test D requires that the remote peer is not synchronised to us to
|
||||||
prevent a synchronisation loop */
|
prevent a synchronisation loop */
|
||||||
|
@ -1514,7 +1517,7 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr,
|
||||||
|
|
||||||
if (good_packet) {
|
if (good_packet) {
|
||||||
/* Do this before we accumulate a new sample into the stats registers, obviously */
|
/* Do this before we accumulate a new sample into the stats registers, obviously */
|
||||||
estimated_offset = SRC_PredictOffset(inst->source, &sample_time);
|
estimated_offset = SST_PredictOffset(stats, &sample_time);
|
||||||
|
|
||||||
SRC_AccumulateSample(inst->source,
|
SRC_AccumulateSample(inst->source,
|
||||||
&sample_time,
|
&sample_time,
|
||||||
|
|
52
sources.c
52
sources.c
|
@ -309,22 +309,12 @@ SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* Function to get the range of frequencies, relative to the given
|
|
||||||
source, that we believe the local clock lies within. The return
|
|
||||||
values are in terms of the number of seconds fast (+ve) or slow
|
|
||||||
(-ve) relative to the source that the local clock becomes after a
|
|
||||||
given amount of local time has elapsed.
|
|
||||||
|
|
||||||
Suppose the initial offset relative to the source is U (fast +ve,
|
SST_Stats
|
||||||
slow -ve) and a time interval T elapses measured in terms of the
|
SRC_GetSourcestats(SRC_Instance instance)
|
||||||
local clock. Then the error relative to the source at the end of
|
|
||||||
the interval should lie in the interval [U+T*lo, U+T*hi]. */
|
|
||||||
|
|
||||||
void SRC_GetFrequencyRange(SRC_Instance instance, double *lo, double *hi)
|
|
||||||
{
|
{
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
return instance->stats;
|
||||||
SST_GetFrequencyRange(instance->stats, lo, hi);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
@ -405,7 +395,7 @@ special_mode_end(void)
|
||||||
|
|
||||||
/* Check if the source could still have enough samples to be selectable */
|
/* Check if the source could still have enough samples to be selectable */
|
||||||
if (SOURCE_REACH_BITS - 1 - sources[i]->reachability_size +
|
if (SOURCE_REACH_BITS - 1 - sources[i]->reachability_size +
|
||||||
SRC_Samples(sources[i]) >= MIN_SAMPLES_FOR_REGRESS)
|
SST_Samples(sources[i]->stats) >= MIN_SAMPLES_FOR_REGRESS)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1103,32 +1093,6 @@ SRC_SetReselectDistance(double distance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
double
|
|
||||||
SRC_PredictOffset(SRC_Instance inst, struct timespec *when)
|
|
||||||
{
|
|
||||||
return SST_PredictOffset(inst->stats, when);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
double
|
|
||||||
SRC_MinRoundTripDelay(SRC_Instance inst)
|
|
||||||
{
|
|
||||||
return SST_MinRoundTripDelay(inst->stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
int
|
|
||||||
SRC_IsGoodSample(SRC_Instance inst, double offset, double delay,
|
|
||||||
double max_delay_dev_ratio, double clock_error, struct timespec *when)
|
|
||||||
{
|
|
||||||
return SST_IsGoodSample(inst->stats, offset, delay, max_delay_dev_ratio,
|
|
||||||
clock_error, when);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
/* This routine is registered as a callback with the local clock
|
/* This routine is registered as a callback with the local clock
|
||||||
module, to be called whenever the local clock changes frequency or
|
module, to be called whenever the local clock changes frequency or
|
||||||
|
@ -1413,11 +1377,3 @@ SRC_GetType(int index)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
int
|
|
||||||
SRC_Samples(SRC_Instance inst)
|
|
||||||
{
|
|
||||||
return SST_Samples(inst->stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
31
sources.h
31
sources.h
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
#include "ntp.h"
|
#include "ntp.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
#include "sourcestats.h"
|
||||||
|
|
||||||
/* Size of the source reachability register */
|
/* Size of the source reachability register */
|
||||||
#define SOURCE_REACH_BITS 8
|
#define SOURCE_REACH_BITS 8
|
||||||
|
@ -73,18 +74,8 @@ extern void SRC_ResetInstance(SRC_Instance instance);
|
||||||
/* Function to change the sources's reference ID and IP address */
|
/* Function to change the sources's reference ID and IP address */
|
||||||
extern void SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr);
|
extern void SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr);
|
||||||
|
|
||||||
/* Function to get the range of frequencies, relative to the given
|
/* Function to get access to the sourcestats instance */
|
||||||
source, that we believe the local clock lies within. The return
|
extern SST_Stats SRC_GetSourcestats(SRC_Instance instance);
|
||||||
values are in terms of the number of seconds fast (+ve) or slow
|
|
||||||
(-ve) relative to the source that the local clock becomes after a
|
|
||||||
given amount of local time has elapsed.
|
|
||||||
|
|
||||||
Suppose the initial offset relative to the source is U (fast +ve,
|
|
||||||
slow -ve) and a time interval T elapses measured in terms of the
|
|
||||||
local clock. Then the error relative to the source at the end of
|
|
||||||
the interval should lie in the interval [U+T*lo, U+T*hi]. */
|
|
||||||
|
|
||||||
extern void SRC_GetFrequencyRange(SRC_Instance instance, double *lo, double *hi);
|
|
||||||
|
|
||||||
/* This function is called by one of the source drivers when it has
|
/* This function is called by one of the source drivers when it has
|
||||||
a new sample that is to be accumulated.
|
a new sample that is to be accumulated.
|
||||||
|
@ -143,19 +134,6 @@ extern void SRC_ReselectSource(void);
|
||||||
/* Set reselect distance */
|
/* Set reselect distance */
|
||||||
extern void SRC_SetReselectDistance(double distance);
|
extern void SRC_SetReselectDistance(double distance);
|
||||||
|
|
||||||
/* Predict the offset of the local clock relative to a given source at
|
|
||||||
a given local cooked time. Positive indicates local clock is FAST
|
|
||||||
relative to reference. */
|
|
||||||
extern double SRC_PredictOffset(SRC_Instance inst, struct timespec *when);
|
|
||||||
|
|
||||||
/* Return the minimum peer delay amongst the previous samples
|
|
||||||
currently held in the register */
|
|
||||||
extern double SRC_MinRoundTripDelay(SRC_Instance inst);
|
|
||||||
|
|
||||||
/* This routine determines if a new sample is good enough that it should be
|
|
||||||
accumulated */
|
|
||||||
extern int SRC_IsGoodSample(SRC_Instance inst, double offset, double delay, double max_delay_dev_ratio, double clock_error, struct timespec *when);
|
|
||||||
|
|
||||||
extern void SRC_DumpSources(void);
|
extern void SRC_DumpSources(void);
|
||||||
extern void SRC_ReloadSources(void);
|
extern void SRC_ReloadSources(void);
|
||||||
extern void SRC_RemoveDumpFiles(void);
|
extern void SRC_RemoveDumpFiles(void);
|
||||||
|
@ -170,7 +148,4 @@ extern int SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report, struc
|
||||||
|
|
||||||
extern SRC_Type SRC_GetType(int index);
|
extern SRC_Type SRC_GetType(int index);
|
||||||
|
|
||||||
extern int SRC_Samples(SRC_Instance inst);
|
|
||||||
|
|
||||||
#endif /* GOT_SOURCES_H */
|
#endif /* GOT_SOURCES_H */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue