diff options
author | Phil Carmody <ext-phil.2.carmody@nokia.com> | 2010-10-20 18:57:33 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2010-10-21 11:30:06 -0400 |
commit | dd6414b50fa2b1cd247a8aa8f8bd42414b7453e1 (patch) | |
tree | d6572c35cf1997e2d18e451cb44742c89723d804 /include/linux/timer.h | |
parent | 2bf1c05e3c406925e498d06da66b4828f0209ea6 (diff) |
timer: Permit statically-declared work with deferrable timers
Currently, you have to just define a delayed_work uninitialised, and then
initialise it before first use. That's a tad clumsy. At risk of playing
mind-games with the compiler, fooling it into doing pointer arithmetic
with compile-time-constants, this lets clients properly initialise delayed
work with deferrable timers statically.
This patch was inspired by the issues which lead Artem Bityutskiy to
commit 8eab945c5616fc984 ("sunrpc: make the cache cleaner workqueue
deferrable").
Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Acked-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Cc: Arjan van de Ven <arjan@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/linux/timer.h')
-rw-r--r-- | include/linux/timer.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/timer.h b/include/linux/timer.h index 1794674c1a52..cbfb7a355d30 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h | |||
@@ -48,6 +48,18 @@ extern struct tvec_base boot_tvec_bases; | |||
48 | #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) | 48 | #define __TIMER_LOCKDEP_MAP_INITIALIZER(_kn) |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | /* | ||
52 | * Note that all tvec_bases are 2 byte aligned and lower bit of | ||
53 | * base in timer_list is guaranteed to be zero. Use the LSB to | ||
54 | * indicate whether the timer is deferrable. | ||
55 | * | ||
56 | * A deferrable timer will work normally when the system is busy, but | ||
57 | * will not cause a CPU to come out of idle just to service it; instead, | ||
58 | * the timer will be serviced when the CPU eventually wakes up with a | ||
59 | * subsequent non-deferrable timer. | ||
60 | */ | ||
61 | #define TBASE_DEFERRABLE_FLAG (0x1) | ||
62 | |||
51 | #define TIMER_INITIALIZER(_function, _expires, _data) { \ | 63 | #define TIMER_INITIALIZER(_function, _expires, _data) { \ |
52 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ | 64 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ |
53 | .function = (_function), \ | 65 | .function = (_function), \ |
@@ -59,6 +71,19 @@ extern struct tvec_base boot_tvec_bases; | |||
59 | __FILE__ ":" __stringify(__LINE__)) \ | 71 | __FILE__ ":" __stringify(__LINE__)) \ |
60 | } | 72 | } |
61 | 73 | ||
74 | #define TBASE_MAKE_DEFERRED(ptr) ((struct tvec_base *) \ | ||
75 | ((unsigned char *)(ptr) + TBASE_DEFERRABLE_FLAG)) | ||
76 | |||
77 | #define TIMER_DEFERRED_INITIALIZER(_function, _expires, _data) {\ | ||
78 | .entry = { .prev = TIMER_ENTRY_STATIC }, \ | ||
79 | .function = (_function), \ | ||
80 | .expires = (_expires), \ | ||
81 | .data = (_data), \ | ||
82 | .base = TBASE_MAKE_DEFERRED(&boot_tvec_bases), \ | ||
83 | __TIMER_LOCKDEP_MAP_INITIALIZER( \ | ||
84 | __FILE__ ":" __stringify(__LINE__)) \ | ||
85 | } | ||
86 | |||
62 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ | 87 | #define DEFINE_TIMER(_name, _function, _expires, _data) \ |
63 | struct timer_list _name = \ | 88 | struct timer_list _name = \ |
64 | TIMER_INITIALIZER(_function, _expires, _data) | 89 | TIMER_INITIALIZER(_function, _expires, _data) |