From d0eb9427c2db49a76b549e51b03fbbc077438333 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 27 Feb 2018 17:35:16 +0100 Subject: [PATCH] ntp: add burst option When the burst option is specified in the server/pool directive and the current poll is longer than the minimum poll, initiate on each poll a burst with 1 good sample and 2 or 4 total samples according to the difference between the current and minimum poll. --- candm.h | 1 + client.c | 1 + cmdmon.c | 1 + cmdparse.c | 3 +++ doc/chrony.conf.adoc | 7 +++++++ ntp_core.c | 14 ++++++++++++++ srcparams.h | 1 + 7 files changed, 28 insertions(+) diff --git a/candm.h b/candm.h index b03448c..6798a9d 100644 --- a/candm.h +++ b/candm.h @@ -252,6 +252,7 @@ typedef struct { #define REQ_ADDSRC_TRUST 0x20 #define REQ_ADDSRC_REQUIRE 0x40 #define REQ_ADDSRC_INTERLEAVED 0x80 +#define REQ_ADDSRC_BURST 0x100 typedef struct { IPAddr ip_addr; diff --git a/client.c b/client.c index 847afac..7c403aa 100644 --- a/client.c +++ b/client.c @@ -1109,6 +1109,7 @@ process_cmd_add_server_or_peer(CMD_Request *msg, char *line) (data.params.auto_offline ? REQ_ADDSRC_AUTOOFFLINE : 0) | (data.params.iburst ? REQ_ADDSRC_IBURST : 0) | (data.params.interleaved ? REQ_ADDSRC_INTERLEAVED : 0) | + (data.params.burst ? REQ_ADDSRC_BURST : 0) | (data.params.sel_options & SRC_SELECT_PREFER ? REQ_ADDSRC_PREFER : 0) | (data.params.sel_options & SRC_SELECT_NOSELECT ? REQ_ADDSRC_NOSELECT : 0) | (data.params.sel_options & SRC_SELECT_TRUST ? REQ_ADDSRC_TRUST : 0) | diff --git a/cmdmon.c b/cmdmon.c index 283ba97..9d1eb95 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -801,6 +801,7 @@ handle_add_source(NTP_Source_Type type, CMD_Request *rx_message, CMD_Reply *tx_m params.auto_offline = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_AUTOOFFLINE ? 1 : 0; params.iburst = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_IBURST ? 1 : 0; params.interleaved = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_INTERLEAVED ? 1 : 0; + params.burst = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_BURST ? 1 : 0; params.sel_options = (ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_PREFER ? SRC_SELECT_PREFER : 0) | (ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_NOSELECT ? SRC_SELECT_NOSELECT : 0) | diff --git a/cmdparse.c b/cmdparse.c index c4e26bf..a228530 100644 --- a/cmdparse.c +++ b/cmdparse.c @@ -51,6 +51,7 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src) src->params.online = 1; src->params.auto_offline = 0; src->params.presend_minpoll = SRC_DEFAULT_PRESEND_MINPOLL; + src->params.burst = 0; src->params.iburst = 0; src->params.min_stratum = SRC_DEFAULT_MINSTRATUM; src->params.poll_target = SRC_DEFAULT_POLLTARGET; @@ -84,6 +85,8 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src) if (!strcasecmp(cmd, "auto_offline")) { src->params.auto_offline = 1; + } else if (!strcasecmp(cmd, "burst")) { + src->params.burst = 1; } else if (!strcasecmp(cmd, "iburst")) { src->params.iburst = 1; } else if (!strcasecmp(cmd, "offline")) { diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 84a23ff..d5f64dc 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -83,6 +83,13 @@ With this option, the interval between the first four requests sent to the server will be 2 seconds instead of the interval specified by the *minpoll* option, which allows *chronyd* to make the first update of the clock shortly after start. +*burst*::: +With this option, *chronyd* will shorten the interval between up to four +requests to 2 seconds when it cannot get a good measurement from the server. +The number of requests in the burst is limited by the current polling interval +to keep the average interval at or above the minimum interval, i.e. the current +interval needs to be at least two times longer than the minimum interval in +order to allow a burst with two requests. *key* _ID_::: The NTP protocol supports the inclusion of checksums in the packets, to prevent computers having their system time upset by rogue packets being sent to them. diff --git a/ntp_core.c b/ntp_core.c index 0b4ce90..db8f7b9 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -88,6 +88,7 @@ struct NCR_Instance_Record { SCH_TimeoutID tx_timeout_id; /* Timeout ID for next transmission */ int tx_suspended; /* Boolean indicating we can't transmit yet */ + int auto_burst; /* If 1, initiate a burst on each poll */ int auto_offline; /* If 1, automatically go offline if server/peer isn't responding */ @@ -236,6 +237,10 @@ static ARR_Instance broadcasts; #define IBURST_GOOD_SAMPLES 4 #define IBURST_TOTAL_SAMPLES SOURCE_REACH_BITS +/* Number of samples in automatic burst */ +#define BURST_GOOD_SAMPLES 1 +#define MAX_BURST_TOTAL_SAMPLES 4 + /* Time to wait after sending packet to 'warm up' link */ #define WARM_UP_DELAY 2.0 @@ -557,6 +562,7 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar result->max_delay_ratio = CLAMP(0.0, params->max_delay_ratio, MAX_MAXDELAYRATIO); result->max_delay_dev_ratio = CLAMP(0.0, params->max_delay_dev_ratio, MAX_MAXDELAYDEVRATIO); result->offset_correction = params->offset; + result->auto_burst = params->burst; result->auto_offline = params->auto_offline; result->poll_target = params->poll_target; @@ -1121,6 +1127,14 @@ transmit_timeout(void *arg) if (inst->burst_total_samples_to_go <= 0) take_offline(inst); break; + case MD_ONLINE: + /* Start a new burst if the burst option is enabled and the average + polling interval including the burst will not fall below the + minimum polling interval */ + if (inst->auto_burst && inst->local_poll > inst->minpoll && inst->local_poll > 1) + NCR_InitiateSampleBurst(inst, BURST_GOOD_SAMPLES, + MIN(1 << (inst->local_poll - inst->minpoll), + MAX_BURST_TOTAL_SAMPLES)); default: break; } diff --git a/srcparams.h b/srcparams.h index 5bd591d..7a73bad 100644 --- a/srcparams.h +++ b/srcparams.h @@ -35,6 +35,7 @@ typedef struct { int online; int auto_offline; int presend_minpoll; + int burst; int iburst; int min_stratum; int poll_target;