]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: adjust initial delay for polling interval
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 16 Nov 2015 11:28:42 +0000 (12:28 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 16 Nov 2015 13:48:02 +0000 (14:48 +0100)
First packet after setting a source to online was sent with constant
delay (0.2s). If the period in which the source was offline was shorter
than the current polling interval, the new packet was sent sooner than
it would be if the source wasn't switched to offline and back.

Don't reset the local tx timestamp when mode is changed. When starting
the initial transmit timeout, adjust the delay to make the interval
between the two packets at least as long as the current polling
interval.

ntp_core.c

index 90bb87d2368c2c28c0dec0880dc9af2e398d6591..8fecb835f5f234539469e75c2cc6f2790befdfe2 100644 (file)
@@ -375,6 +375,9 @@ restart_timeout(NCR_Instance inst, double delay)
 static void
 start_initial_timeout(NCR_Instance inst)
 {
+  double delay, last_tx;
+  struct timeval now;
+
   if (!inst->tx_timeout_id) {
     /* This will be the first transmission after mode change */
 
@@ -382,7 +385,18 @@ start_initial_timeout(NCR_Instance inst)
     SRC_SetActive(inst->source);
   }
 
-  restart_timeout(inst, INITIAL_DELAY);
+  /* In case the offline period was too short, adjust the delay to keep
+     the interval between packets at least as long as the current polling
+     interval */
+  SCH_GetLastEventTime(&now, NULL, NULL);
+  UTI_DiffTimevalsToDouble(&last_tx, &now, &inst->local_tx);
+  if (last_tx < 0.0)
+    last_tx = 0.0;
+  delay = get_transmit_delay(inst, 0, 0.0) - last_tx;
+  if (delay < INITIAL_DELAY)
+    delay = INITIAL_DELAY;
+
+  restart_timeout(inst, delay);
 }
 
 /* ================================================== */
@@ -499,6 +513,8 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar
   result->tx_suspended = 1;
   result->opmode = params->online ? MD_ONLINE : MD_OFFLINE;
   result->local_poll = result->minpoll;
+  result->local_tx.tv_sec = 0;
+  result->local_tx.tv_usec = 0;
   
   NCR_ResetInstance(result);
 
@@ -556,8 +572,6 @@ NCR_ResetInstance(NCR_Instance instance)
   instance->remote_orig.lo = 0;
   instance->local_rx.tv_sec = 0;
   instance->local_rx.tv_usec = 0;
-  instance->local_tx.tv_sec = 0;
-  instance->local_tx.tv_usec = 0;
   instance->local_ntp_tx.hi = 0;
   instance->local_ntp_tx.lo = 0;