]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Enforce timeout class separation from last dispatched timeout
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 17 Dec 2010 15:09:12 +0000 (16:09 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 17 Dec 2010 15:09:12 +0000 (16:09 +0100)
sched.c

diff --git a/sched.c b/sched.c
index 47fc9425b285b7374614e09c10e06c18b85d67a9..9324e01e1c23f04ed8e495af31039d69767a55a1 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -110,6 +110,9 @@ static SCH_TimeoutID next_tqe_id;
 /* Pointer to head of free list */
 static TimerQueueEntry *tqe_free_list = NULL;
 
+/* Timestamp when was last timeout dispatched for each class */
+static struct timeval last_class_dispatch[SCH_NumberOfClasses];
+
 /* ================================================== */
 
 static int need_to_exit;
@@ -337,6 +340,7 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double randomness,
   double new_min_delay;
 
   assert(initialised);
+  assert(class < SCH_NumberOfClasses);
 
   if (randomness > 0.0) {
     r = random() % 0xffff / (0xffff - 1.0) * randomness + 1.0;
@@ -347,6 +351,12 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double randomness,
   LCL_ReadRawTime(&now);
   new_min_delay = min_delay;
 
+  /* Check the separation from the last dispatched timeout */
+  UTI_DiffTimevalsToDouble(&diff, &now, &last_class_dispatch[class]);
+  if (diff < separation && diff >= 0.0 && diff + new_min_delay < separation) {
+    new_min_delay = separation - diff;
+  }
+
   /* Scan through list for entries in the same class and increase min_delay
      if necessary to keep at least the separation away */
   for (ptr = timer_queue.next; ptr != &timer_queue; ptr = ptr->next) {
@@ -433,6 +443,8 @@ dispatch_timeouts(struct timeval *now) {
          (UTI_CompareTimevals(now, &(timer_queue.next->tv)) >= 0)) {
     ptr = timer_queue.next;
 
+    last_class_dispatch[ptr->class] = *now;
+
     handler = ptr->handler;
     arg = ptr->arg;