[chrony-dev] [PATCH 3/3] Set refclock poll timer based on last poll time, not offset from now |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH 3/3] Set refclock poll timer based on last poll time, not offset from now
- From: Matt Corallo <ntp-lists@xxxxxxxxxxxxxxx>
- Date: Tue, 21 Feb 2023 11:37:05 -0800
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mattcorallo.com; s=1677006062; h=Subject:From:To:From:Subject:To:Cc:Cc: Reply-To:In-Reply-To:References; bh=vUj7iH5SM5VMqNxRR7EcU6rN7l9XYjlIf+TCz0mFmw0=; b=ICuuV62fFQHVXV2snkwQGtSfDT 4GDwy/UH7vuYlT8LQ2FCGQD20NOZd0XFVHplWIvdz+FRzwgNXj61IRgaaP8kpmcOJ2PPLNwA2Yc/c Iw9ZH+i+CGIdQ4W1z3CnCSZGUR2v68/r5p5EtS1OCwulj8UFf53GT6VzIyvXUwS+bvTm5N7pzNQGQ VeEyry2ifAlarKU0JdI7k2KI+1VSBHj3xLdQ+WzJ3XIgZOLDP4TGQLYCn62OX0vmHqDGEku/1LOFm 0jjmxbaIW3p0Tu+xeI9CVNPv3cgoLcK+mFS1dqCkdFlTqag61RSVxYFFC1NSSQVfv3e9kjsBZBLDz 9Qy7dH0Q==;
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=clients.mail.as397444.net; s=1677006063; h=Subject:From:To:From:Subject:To: Cc:Cc:Reply-To:In-Reply-To:References; bh=vUj7iH5SM5VMqNxRR7EcU6rN7l9XYjlIf+TCz0mFmw0=; b=QEUR4FvwImKX1V/F+oRCvlwa3z wX0EgGrpS/230IPEzvFPnP7JeaEMGp7LbgyZTkiJmtmUALnz5tWwW0HuD6sX0oj+TmewAxbt3Tu5C ON1dPg38hm80cet226UPeSkvsYXhwaD01fjrEtOTT19c8PkrpC1yLspt7Jfjl1jTXEh8DVVQjQJO+ SM2yrReXt5dvK+mfoJ8Xi94T/NV3CRQ8QsW4pho55S4XngqYuy5ZeL28ckx/Fn5ULZlhxc8RIllBu xK7b+1JqtgApVwsvJVueq18RcUalTnsmOqbptLRC5iFGQokjxjxiOaKaJJKz+gVPNDnpUs79qmUrX 1S86NB1w==;
When polling refclocks, the next poll time is currently calculated
by adding the desired inter-poll time to the current time. Given
refclock polling occurs at the end of the main loop, this results
in each poll slipping by, roughly, the time taken for the main
loop. While this should be relatively small, this can add up on
refclocks with sub-second poll times.
Specifically, on a 1GHz amd64 AMD GX-412TC with a few PHC refclocks
being polled, a main loop iteration can take a millisecond or two,
depending on the time taken to read the PHC clocks. This easily
adds up to poll interval slippage, slipping the update interval and
leading to samples which are ignored due to missing their
maxlockage setting.
To ensure polling happens at the right interval, we simply track
when the last poll happened and increment with that as a base
rather than the current time.
---
refclock.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/refclock.c b/refclock.c
index 84f7439..da3da94 100644
--- a/refclock.c
+++ b/refclock.c
@@ -62,6 +62,7 @@ struct RCL_Instance_Record {
int driver_parameter_length;
int driver_poll;
int driver_polled;
+ struct timespec next_poll;
int poll;
int leap_status;
int local;
@@ -174,6 +175,8 @@ RCL_AddRefclock(RefclockParameters *params)
inst->driver_parameter_length = 0;
inst->driver_poll = params->driver_poll;
inst->poll = params->poll;
+ inst->next_poll.tv_sec = 0;
+ inst->next_poll.tv_nsec = 0;
inst->driver_polled = 0;
inst->leap_status = LEAP_Normal;
inst->local = params->local;
@@ -762,6 +765,8 @@ poll_timeout(void *arg)
{
NTP_Sample sample;
int poll, stratum;
+ struct timespec now, sched;
+ double delay;
RCL_Instance inst = (RCL_Instance)arg;
@@ -805,7 +810,22 @@ poll_timeout(void *arg)
}
}
- inst->timeout_id = SCH_AddTimeoutByDelay(UTI_Log2ToDouble(poll), poll_timeout, arg);
+ delay = UTI_Log2ToDouble(poll);
+ LCL_ReadRawTime(&now);
+ if (inst->next_poll.tv_nsec == 0 && inst->next_poll.tv_sec == 0) {
+ UTI_AddDoubleToTimespec(&now, delay, &sched);
+ } else {
+ UTI_AddDoubleToTimespec(&inst->next_poll, delay, &sched);
+ if (UTI_CompareTimespecs(&now, &sched) > 0) {
+ UTI_AddDoubleToTimespec(&now, delay, &sched);
+ LOG(LOGS_WARN, "Can't poll fast enough, skipping poll window");
+ }
+ }
+ inst->next_poll = sched;
+ if (UTI_CompareTimespecs(&now, &sched) > 0) {
+ LOG_FATAL("Timeout overflow");
+ }
+ inst->timeout_id = SCH_AddTimeout(&sched, poll_timeout, arg);
}
static void
--
2.39.1
--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble? Email listmaster@xxxxxxxxxxxxxxxxxxxx.