diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-09-22 08:44:11 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-09-22 09:31:34 -0400 |
commit | 979f693def9084a452846365dfde5dcb28366333 (patch) | |
tree | 4e01718c89c770c82cb3075958a7c0d33631ccf2 /include | |
parent | b8c7f1dc5ca4e0d10709182233cdab932cef593d (diff) |
ratelimit: Use per ratelimit context locking
I'd like to use printk_ratelimit() in atomic context, but that's
not possible right now due to the spinlock usage this commit
introduced more than a year ago:
717115e: printk ratelimiting rewrite
As a first step push the lock into the ratelimit state structure.
This allows us to deal with locking failures to be considered as an
event related to that state being too busy.
Also clean up the code a bit (without changing functionality):
- tidy up the definitions
- clean up the code flow
This also shrinks the code a tiny bit:
text data bss dec hex filename
264 0 4 268 10c ratelimit.o.before
255 0 0 255 ff ratelimit.o.after
( Whole-kernel data size got a bit larger, because we have
two ratelimit-state data structures right now. )
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: David S. Miller <davem@davemloft.net>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/ratelimit.h | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h index 00044b856453..187bc16c1f15 100644 --- a/include/linux/ratelimit.h +++ b/include/linux/ratelimit.h | |||
@@ -1,20 +1,30 @@ | |||
1 | #ifndef _LINUX_RATELIMIT_H | 1 | #ifndef _LINUX_RATELIMIT_H |
2 | #define _LINUX_RATELIMIT_H | 2 | #define _LINUX_RATELIMIT_H |
3 | |||
3 | #include <linux/param.h> | 4 | #include <linux/param.h> |
5 | #include <linux/spinlock_types.h> | ||
4 | 6 | ||
5 | #define DEFAULT_RATELIMIT_INTERVAL (5 * HZ) | 7 | #define DEFAULT_RATELIMIT_INTERVAL (5 * HZ) |
6 | #define DEFAULT_RATELIMIT_BURST 10 | 8 | #define DEFAULT_RATELIMIT_BURST 10 |
7 | 9 | ||
8 | struct ratelimit_state { | 10 | struct ratelimit_state { |
9 | int interval; | 11 | spinlock_t lock; /* protect the state */ |
10 | int burst; | 12 | |
11 | int printed; | 13 | int interval; |
12 | int missed; | 14 | int burst; |
13 | unsigned long begin; | 15 | int printed; |
16 | int missed; | ||
17 | unsigned long begin; | ||
14 | }; | 18 | }; |
15 | 19 | ||
16 | #define DEFINE_RATELIMIT_STATE(name, interval, burst) \ | 20 | #define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \ |
17 | struct ratelimit_state name = {interval, burst,} | 21 | \ |
22 | struct ratelimit_state name = { \ | ||
23 | .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ | ||
24 | .interval = interval_init, \ | ||
25 | .burst = burst_init, \ | ||
26 | } | ||
18 | 27 | ||
19 | extern int __ratelimit(struct ratelimit_state *rs); | 28 | extern int __ratelimit(struct ratelimit_state *rs); |
20 | #endif | 29 | |
30 | #endif /* _LINUX_RATELIMIT_H */ | ||