summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-03-24 23:54:21 +0100
committerLennart Poettering <lennart@poettering.net>2014-03-24 23:54:21 +0100
commit52444dc478fe38b5b69a771923ab429a41927aa5 (patch)
treeb675a79f9eb50befdfba808c766b991692edcfea /src
parent56dc9aec21ab23f76fadf45585adf88e71aa8078 (diff)
sd-event: initialization perturbation value right before we use it
That way, we don't forget to initialize it when the watchdog is initialized before all event sources.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/sd-event/sd-event.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index a4b67431ef..d6a3d1c3f4 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -733,12 +733,30 @@ _public_ int sd_event_add_io(
return 0;
}
+static void initialize_perturb(sd_event *e) {
+ sd_id128_t bootid = {};
+
+ /* When we sleep for longer, we try to realign the wakeup to
+ the same time wihtin each minute/second/250ms, so that
+ events all across the system can be coalesced into a single
+ CPU wakeup. However, let's take some system-specific
+ randomness for this value, so that in a network of systems
+ with synced clocks timer events are distributed a
+ bit. Here, we calculate a perturbation usec offset from the
+ boot ID. */
+
+ if (_likely_(e->perturb != (usec_t) -1))
+ return;
+
+ if (sd_id128_get_boot(&bootid) >= 0)
+ e->perturb = (bootid.qwords[0] ^ bootid.qwords[1]) % USEC_PER_MINUTE;
+}
+
static int event_setup_timer_fd(
sd_event *e,
struct clock_data *d,
clockid_t clock) {
- sd_id128_t bootid = {};
struct epoll_event ev = {};
int r, fd;
@@ -762,20 +780,6 @@ static int event_setup_timer_fd(
}
d->fd = fd;
-
- /* When we sleep for longer, we try to realign the wakeup to
- the same time wihtin each minute/second/250ms, so that
- events all across the system can be coalesced into a single
- CPU wakeup. However, let's take some system-specific
- randomness for this value, so that in a network of systems
- with synced clocks timer events are distributed a
- bit. Here, we calculate a perturbation usec offset from the
- boot ID. */
-
- if (e->perturb == (usec_t) -1)
- if (sd_id128_get_boot(&bootid) >= 0)
- e->perturb = (bootid.qwords[0] ^ bootid.qwords[1]) % USEC_PER_MINUTE;
-
return 0;
}
@@ -1588,6 +1592,8 @@ static usec_t sleep_between(sd_event *e, usec_t a, usec_t b) {
if (b <= a + 1)
return a;
+ initialize_perturb(e);
+
/*
Find a good time to wake up again between times a and b. We
have two goals here: