LWN.net Logo

Timer slack

By Jonathan Corbet
January 12, 2010
One of the best ways to reduce a system's power usage is to avoid waking up the CPU whenever possible. Minimizing wakeups, in turn, is facilitated by ensuring that timers expire at the same time when it makes sense to do so. Waking the processor once to handle two timers is much more efficient than handling them in two separate wakeups. But doing so typically requires adjusting expiration times. For standard (not high resolution) kernel timers, the only way to make that adjustment is with the round_jiffies() function, which makes timeout periods coarser in the hopes that they will coincide more often. This method works to an extent, but it requires code changes wherever timers are used.

Arjan van de Ven has proposed an enhancement to the timer API - called timer slack - which should make it easier to coalesce timer events. In essence, it adds a certain amount of fuzziness to timer expiration times, giving the kernel some flexibility in how the timers are scheduled. That fuzziness is set with:

    void set_timer_slack(struct timer_list *timer, int slack_hz);

In essence, this call says that any timeout scheduled with the given timer can be delayed by up to slack_hz jiffies. By default, the slack is set to 0.4% of the total timeout period - a very conservative value. When the timer is queued, the actual expiration time is determined by means of a simple algorithm to choose a well-defined time within the slack period.

The value of this approach is that it makes it easy to coalesce timer events from multiple sources without needing to change every call site. Additional flexibility can then be had by increasing the slack for specific, frequently-used timers, but, even without that, slack timers should improve power efficiency on many systems.


(Log in to post comments)

Timer slack

Posted Jan 21, 2010 15:03 UTC (Thu) by jch (guest, #51929) [Link]

What about user-space? Can we pass a slack to epoll_wait?

Timer slack

Posted Jan 21, 2010 21:11 UTC (Thu) by arjan (subscriber, #36785) [Link]

poll uses hrtimers, which already have slack...
you can set your slack using prctl().

Timer slack

Posted Feb 5, 2010 19:50 UTC (Fri) by oak (guest, #2786) [Link]

> In essence, this call says that any timeout scheduled with the given
timer can be delayed by up to slack_hz jiffies.

Can the timeout be delivered earlier too?

Timer slack

Posted Feb 5, 2010 21:21 UTC (Fri) by farnz (guest, #17727) [Link]

No. That would be a contract breach; timers are guaranteed to not fire until the time period has elapsed.

If you want a timer to fire earlier, set it to fire earlier; if you have a large range of times in which it can fire, set it to fire at the earliest of those times, and give it a very large slack, so that it can be merged with the firing of another timer.

Copyright © 2010, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds