chiark / gitweb /
sd-event: try to move each wakeup to the same spot within every 10s
authorLennart Poettering <lennart@poettering.net>
Wed, 11 Dec 2013 22:41:21 +0000 (23:41 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Dec 2013 22:41:21 +0000 (23:41 +0100)
In addition to the same spot within every 1min, every 1s, every 250s

src/libsystemd-bus/sd-event.c

index 9fceb7b13edd794b99655e0d644244047678d71b..462dd413e27c263cd804ffaf8f15fdf794cc9158 100644 (file)
@@ -1379,8 +1379,9 @@ static usec_t sleep_between(sd_event *e, usec_t a, usec_t b) {
           We implement this by waking up everywhere at the same time
           within any given minute if we can, synchronised via the
           perturbation value determined from the boot ID. If we can't,
           We implement this by waking up everywhere at the same time
           within any given minute if we can, synchronised via the
           perturbation value determined from the boot ID. If we can't,
-          then we try to find the same spot in every 1s and then 250ms
-          step. Otherwise, we pick the last possible time to wake up.
+          then we try to find the same spot in every 10s, then 1s and
+          then 250ms step. Otherwise, we pick the last possible time
+          to wake up.
         */
 
         c = (b / USEC_PER_MINUTE) * USEC_PER_MINUTE + e->perturb;
         */
 
         c = (b / USEC_PER_MINUTE) * USEC_PER_MINUTE + e->perturb;
@@ -1391,6 +1392,17 @@ static usec_t sleep_between(sd_event *e, usec_t a, usec_t b) {
                 c -= USEC_PER_MINUTE;
         }
 
                 c -= USEC_PER_MINUTE;
         }
 
+        if (c >= a)
+                return c;
+
+        c = (b / (USEC_PER_SEC*10)) * (USEC_PER_SEC*10) + (e->perturb % (USEC_PER_SEC*10));
+        if (c >= b) {
+                if (_unlikely_(c < USEC_PER_SEC*10))
+                        return b;
+
+                c -= USEC_PER_SEC*10;
+        }
+
         if (c >= a)
                 return c;
 
         if (c >= a)
                 return c;