From: Andrew Morton <akpm@linux-foundation.org>
To: Arjan van de Ven <arjan@infradead.org>
Cc: linux-kernel@vger.kernel.org, tglx@tglx.de, mingo@elte.hu,
Cyrill Gorcunov <gorcunov@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] timers: Introduce the concept of timer slack for legacy timers
Date: Wed, 13 Jan 2010 13:52:19 -0800 [thread overview]
Message-ID: <20100113135219.f7e8a2f9.akpm@linux-foundation.org> (raw)
In-Reply-To: <20100109133744.29829988@infradead.org>
On Sat, 9 Jan 2010 13:37:44 -0800
Arjan van de Ven <arjan@infradead.org> wrote:
> While HR timers have had the concept of timer slack for quite some time
> now, the legacy timers lacked this concept, and had to make do with
> round_jiffies() and friends.
>
> Timer slack is important for power management; grouping timers reduces
> the number of wakeups which in turn reduces power consumption.
>
> This patch introduces timer slack to the legacy timers using the following
> pieces:
> * A slack field in the timer struct
> * An api (set_timer_slack) that callers can use to set explicit timer slack
> * A default slack of 0.4% of the requested delay for callers that do not set
> any explicit slack
> * Rounding code that is part of mod_timer() that tries to
> group timers around jiffies values every 'power of two'
> (so quick timers will group around every 2, but longer timers
> will group around every 4, 8, 16, 32 etc)
>
> ...
>
> +/**
> + * set_timer_slack - set the allowed slack for a timer
> + * @slack_hz: the amount of time (in jiffies) allowed for rounding
> + *
> + * Set the amount of time, in jiffies, that a certain timer has
> + * in terms of slack. By setting this value, the timer subsystem
> + * will schedule the actual timer somewhere between
> + * the time mod_timer() asks for, and that time plus the slack.
> + *
> + * By setting the slack to -1, a percentage of the delay is used
> + * instead.
> + */
> +void set_timer_slack(struct timer_list *timer, int slack_hz)
> +{
> + timer->slack = slack_hz;
> +}
> +EXPORT_SYMBOL_GPL(set_timer_slack);
I suppose this could be inlined.
> }
> EXPORT_SYMBOL(mod_timer_pending);
>
> +/*
> + * Decide where to put the timer while taking the slack into account
> + *
> + * Algorithm:
> + * 1) calculate the maximum (absolute) time
> + * 2) calculate the highest bit where the expires and new max are different
> + * 3) use this bit to make a mask
> + * 4) use the bitmask to round down the maximum time, so that all last
> + * bits are zeros
> + */
> +static inline
> +unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
> +{
> + unsigned long expires_limit, mask;
> + int bit;
> +
> + expires_limit = expires + timer->slack;
> +
> + if (timer->slack < 0) /* auto slack: use 0.4% */
> + expires_limit = expires + (expires - jiffies)/256;
> +
> + mask = expires ^ expires_limit;
> +
> + if (mask == 0)
> + return expires;
> +
> + bit = find_last_bit(&mask, BITS_PER_LONG);
> +
> + mask = (1 << bit) - 1;
> +
> + expires_limit = expires_limit & ~(mask);
> +
> + return expires_limit;
> +}
OK, so by default this causes every timer in the system to have a bit
of slack (unless they're really short-term?), so the feature does get
runtime tested.
But the set_timer_slack() interface has no callers. Perhaps it should?
next prev parent reply other threads:[~2010-01-13 21:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-09 21:37 [PATCH] timers: Introduce the concept of timer slack for legacy timers Arjan van de Ven
2010-01-13 21:52 ` Andrew Morton [this message]
2010-01-14 5:45 ` Arjan van de Ven
2010-01-14 6:07 ` Andrew Morton
2010-01-14 9:53 ` Arjan van de Ven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100113135219.f7e8a2f9.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=arjan@infradead.org \
--cc=gorcunov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=tglx@tglx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.