Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make poll interval configurable per source #1764

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions docs/man/ntp.toml.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ with any of these options:
# CONFIGURATION

## `[source-defaults]`
Some values are shared between all sources in the daemon. You can configure
these in the `[source-defaults]` section.
Some of the behavior of a source is configurable. You can set defaults for those
settings in the `[source-defaults]` section.

`poll-interval-limits` = { `min` = *min*, `max` = *max* } (**{ min = 4, max = 10}**)
: Specifies the limit on how often a source is queried for a new time. For
most instances the defaults will be adequate. The min and max are given as
the log2 of the number of seconds (i.e. two to the power of the interval).
An interval of 4 equates to 32 seconds, 10 results in an interval of 1024
An interval of 4 equates to 16 seconds, 10 results in an interval of 1024
seconds. If specified, both min and max must be specified.

`initial-poll-interval` = *interval* (**4**)
: Initial poll interval used on startup. The value is given as the log2 of
the number of seconds (i.e. two to the power of the interval). The default
value of 4 results in an interval of 32 seconds.
value of 4 results in an interval of 16 seconds.

## `[[source]]`
Each `[[source]]` is a set of one or more time sources for the daemon to
Expand Down Expand Up @@ -111,6 +111,19 @@ sources.
: `pool` mode only. Specifies a list of IP addresses of servers in the pool
which should not be used. For example: `["127.0.0.1"]`. Empty by default.

`poll-interval-limits` = { `min` = *min*, `max` = *max* } (defaults from `[source-defaults]`)
: Specifies the limit on how often a source is queried for a new time. For
most instances the defaults will be adequate. The min and max are given as
the log2 of the number of seconds (i.e. two to the power of the interval).
An interval of 4 equates to 16 seconds, 10 results in an interval of 1024
seconds. If only one of the two boundaries is specified, the other is
inherited from `[source-defaults]`

`initial-poll-interval` = *interval* (defaults from `[source-defaults]`)
: Initial poll interval used on startup. The value is given as the log2 of
the number of seconds (i.e. two to the power of the interval). The default
value of 4 results in an interval of 16 seconds.

## `[[server]]`
The NTP daemon can be configured to distribute time via any number of
`[[server]]` sections. If no such sections have been defined, the daemon runs in
Expand Down
25 changes: 21 additions & 4 deletions docs/precompiled/man/ntp.toml.5
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,24 @@ As these devices only provide periodic data, they do not count towards
.SH CONFIGURATION
.SS \f[V][source-defaults]\f[R]
.PP
Some values are shared between all sources in the daemon.
You can configure these in the \f[V][source-defaults]\f[R] section.
Some of the behavior of a source is configurable.
You can set defaults for those settings in the
\f[V][source-defaults]\f[R] section.
.TP
\f[V]poll-interval-limits\f[R] = { \f[V]min\f[R] = \f[I]min\f[R], \f[V]max\f[R] = \f[I]max\f[R] } (\f[B]{ min = 4, max = 10}\f[R])
Specifies the limit on how often a source is queried for a new time.
For most instances the defaults will be adequate.
The min and max are given as the log2 of the number of seconds
(i.e.\ two to the power of the interval).
An interval of 4 equates to 32 seconds, 10 results in an interval of
An interval of 4 equates to 16 seconds, 10 results in an interval of
1024 seconds.
If specified, both min and max must be specified.
.TP
\f[V]initial-poll-interval\f[R] = \f[I]interval\f[R] (\f[B]4\f[R])
Initial poll interval used on startup.
The value is given as the log2 of the number of seconds (i.e.\ two to
the power of the interval).
The default value of 4 results in an interval of 32 seconds.
The default value of 4 results in an interval of 16 seconds.
.SS \f[V][[source]]\f[R]
.PP
Each \f[V][[source]]\f[R] is a set of one or more time sources for the
Expand Down Expand Up @@ -144,6 +145,22 @@ Specifies a list of IP addresses of servers in the pool which should not
be used.
For example: \f[V][\[dq]127.0.0.1\[dq]]\f[R].
Empty by default.
.TP
\f[V]poll-interval-limits\f[R] = { \f[V]min\f[R] = \f[I]min\f[R], \f[V]max\f[R] = \f[I]max\f[R] } (defaults from \f[V][source-defaults]\f[R])
Specifies the limit on how often a source is queried for a new time.
For most instances the defaults will be adequate.
The min and max are given as the log2 of the number of seconds
(i.e.\ two to the power of the interval).
An interval of 4 equates to 16 seconds, 10 results in an interval of
1024 seconds.
If only one of the two boundaries is specified, the other is inherited
from \f[V][source-defaults]\f[R]
.TP
\f[V]initial-poll-interval\f[R] = \f[I]interval\f[R] (defaults from \f[V][source-defaults]\f[R])
Initial poll interval used on startup.
The value is given as the log2 of the number of seconds (i.e.\ two to
the power of the interval).
The default value of 4 results in an interval of 16 seconds.
.SS \f[V][[server]]\f[R]
.PP
The NTP daemon can be configured to distribute time via any number of
Expand Down
39 changes: 15 additions & 24 deletions ntp-proto/src/algorithm/kalman/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tracing::{debug, error, info};

use crate::{
clock::NtpClock,
config::{SourceDefaultsConfig, SynchronizationConfig},
config::{SourceConfig, SynchronizationConfig},
packet::NtpLeapIndicator,
system::TimeSnapshot,
time_types::{NtpDuration, NtpTimestamp},
Expand Down Expand Up @@ -89,7 +89,6 @@ pub struct KalmanClockController<C: NtpClock, SourceId: Hash + Eq + Copy + Debug
sources: HashMap<SourceId, (Option<SourceSnapshot<SourceId>>, bool)>,
clock: C,
synchronization_config: SynchronizationConfig,
source_defaults_config: SourceDefaultsConfig,
algo_config: AlgorithmConfig,
freq_offset: f64,
timedata: TimeSnapshot,
Expand Down Expand Up @@ -362,7 +361,6 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug + Send + 'static> TimeSyncC
fn new(
clock: C,
synchronization_config: SynchronizationConfig,
source_defaults_config: SourceDefaultsConfig,
algo_config: Self::AlgorithmConfig,
) -> Result<Self, C::Error> {
// Setup clock
Expand All @@ -372,7 +370,6 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug + Send + 'static> TimeSyncC
sources: HashMap::new(),
clock,
synchronization_config,
source_defaults_config,
algo_config,
freq_offset,
desired_freq: 0.0,
Expand All @@ -387,20 +384,25 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug + Send + 'static> TimeSyncC
Ok(())
}

fn add_source(&mut self, id: SourceId) -> Self::NtpSourceController {
fn add_source(
&mut self,
id: SourceId,
source_config: SourceConfig,
) -> Self::NtpSourceController {
self.sources.insert(id, (None, false));
KalmanSourceController::new(
id,
self.algo_config,
None,
self.source_defaults_config,
source_config,
AveragingBuffer::default(),
)
}

fn add_one_way_source(
&mut self,
id: SourceId,
source_config: SourceConfig,
measurement_noise_estimate: f64,
period: Option<f64>,
) -> Self::OneWaySourceController {
Expand All @@ -409,7 +411,7 @@ impl<C: NtpClock, SourceId: Hash + Eq + Copy + Debug + Send + 'static> TimeSyncC
id,
self.algo_config,
period,
self.source_defaults_config,
source_config,
measurement_noise_estimate,
)
}
Expand Down Expand Up @@ -508,14 +510,13 @@ mod tests {
..SynchronizationConfig::default()
};
let algo_config = AlgorithmConfig::default();
let source_defaults_config = SourceDefaultsConfig::default();
let source_config = SourceConfig::default();
let mut algo = KalmanClockController::new(
TestClock {
has_steered: RefCell::new(false),
current_time: NtpTimestamp::from_fixed_int(0),
},
synchronization_config,
source_defaults_config,
algo_config,
)
.unwrap();
Expand All @@ -524,7 +525,7 @@ mod tests {
// ignore startup steer of frequency.
*algo.clock.has_steered.borrow_mut() = false;

let mut source = algo.add_source(0);
let mut source = algo.add_source(0, source_config);
algo.source_update(0, true);

assert!(algo.in_startup);
Expand Down Expand Up @@ -576,14 +577,12 @@ mod tests {
step_threshold: 1800.0,
..Default::default()
};
let source_defaults_config = SourceDefaultsConfig::default();
let mut algo = KalmanClockController::<_, u32>::new(
TestClock {
has_steered: RefCell::new(false),
current_time: NtpTimestamp::from_fixed_int(0),
},
synchronization_config,
source_defaults_config,
algo_config,
)
.unwrap();
Expand All @@ -606,14 +605,12 @@ mod tests {
..SynchronizationConfig::default()
};
let algo_config = AlgorithmConfig::default();
let source_defaults_config = SourceDefaultsConfig::default();
let mut algo = KalmanClockController::<_, u32>::new(
TestClock {
has_steered: RefCell::new(false),
current_time: NtpTimestamp::from_fixed_int(0),
},
synchronization_config,
source_defaults_config,
algo_config,
)
.unwrap();
Expand All @@ -627,14 +624,12 @@ mod tests {
fn test_jumps_update_state() {
let synchronization_config = SynchronizationConfig::default();
let algo_config = AlgorithmConfig::default();
let source_defaults_config = SourceDefaultsConfig::default();
let mut algo = KalmanClockController::<_, u32>::new(
TestClock {
has_steered: RefCell::new(false),
current_time: NtpTimestamp::from_fixed_int(0),
},
synchronization_config,
source_defaults_config,
algo_config,
)
.unwrap();
Expand Down Expand Up @@ -702,14 +697,12 @@ mod tests {
fn test_freqsteer_update_state() {
let synchronization_config = SynchronizationConfig::default();
let algo_config = AlgorithmConfig::default();
let source_defaults_config = SourceDefaultsConfig::default();
let mut algo = KalmanClockController::<_, u32>::new(
TestClock {
has_steered: RefCell::new(false),
current_time: NtpTimestamp::from_fixed_int(0),
},
synchronization_config,
source_defaults_config,
algo_config,
)
.unwrap();
Expand Down Expand Up @@ -748,14 +741,13 @@ mod tests {
..SynchronizationConfig::default()
};
let algo_config = AlgorithmConfig::default();
let source_defaults_config = SourceDefaultsConfig::default();
let source_config = SourceConfig::default();
let mut algo = KalmanClockController::new(
TestClock {
has_steered: RefCell::new(false),
current_time: NtpTimestamp::from_fixed_int(0),
},
synchronization_config,
source_defaults_config,
algo_config,
)
.unwrap();
Expand All @@ -764,7 +756,7 @@ mod tests {
// ignore startup steer of frequency.
*algo.clock.has_steered.borrow_mut() = false;

let mut source = algo.add_source(0);
let mut source = algo.add_source(0, source_config);
algo.source_update(0, true);

let mut noise = 1e-9;
Expand Down Expand Up @@ -807,14 +799,13 @@ mod tests {
..SynchronizationConfig::default()
};
let algo_config = AlgorithmConfig::default();
let source_defaults_config = SourceDefaultsConfig::default();
let source_config = SourceConfig::default();
let mut algo = KalmanClockController::new(
TestClock {
has_steered: RefCell::new(false),
current_time: NtpTimestamp::from_fixed_int(0),
},
synchronization_config,
source_defaults_config,
algo_config,
)
.unwrap();
Expand All @@ -823,7 +814,7 @@ mod tests {
// ignore startup steer of frequency.
*algo.clock.has_steered.borrow_mut() = false;

let mut source = algo.add_source(0);
let mut source = algo.add_source(0, source_config);
algo.source_update(0, true);

let mut noise = 1e-9;
Expand Down
Loading
Loading