From c2ba3ad6604ef2e189d7e0a36d6911116e84d3ab Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 10 Oct 2013 21:16:21 +0200 Subject: event: add timer accuracy/coalescing logic In order to improve energy consumption we should minimize our wake-ups when handling timers. Hence, for each timer take an accuracy value and schedule the actual wake-up time somewhere between the specified time and the specified timer plus the accuracy. The specified time of timer event sources hence becomes the time the handler is called the *earliest*, and the specified time plus the accuracy the time by which it is called the *latest*, leaving the library the freedom to schedule the wake-up somewhere inbetween. If the accuracy is specified as 0 the default of 250ms will be used. When scheduling timeouts we will now try to elapse them at the same point within each second, across the entire system. We do this by using a fixed perturbation value keyed off the boot id. If this point within a second is not in the acceptable range, we try again with a fixed time within each 250ms time step. If that doesn't work either, we wake up at the last possible time. --- src/shared/prioq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/shared/prioq.c') diff --git a/src/shared/prioq.c b/src/shared/prioq.c index 2d166360aa..537befc623 100644 --- a/src/shared/prioq.c +++ b/src/shared/prioq.c @@ -217,7 +217,8 @@ _pure_ static struct prioq_item* find_item(Prioq *q, void *data, unsigned *idx) assert(q); if (idx) { - if (*idx > q->n_items) + if (*idx == PRIOQ_IDX_NULL || + *idx > q->n_items) return NULL; i = q->items + *idx; -- cgit v1.2.3-54-g00ecf