diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-09-22 08:44:11 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-09-22 08:05:48 -0400 |
commit | edaac8e3167501cda336231d00611bf59c164346 (patch) | |
tree | 5ebf22336dccef4fcd601e0a6a2d13ea347ec568 | |
parent | 979f693def9084a452846365dfde5dcb28366333 (diff) |
ratelimit: Fix/allow use in atomic contexts
I'd like to use printk_ratelimit() in NMI context, but it's not
robust right now due to spinlock usage in lib/ratelimit.c. If an
NMI is unlucky enough to hit just that spot we might lock up trying
to take the spinlock again.
Fix that by using a trylock variant. If we contend on that lock we
can genuinely skip the message because the state is just being
accessed by another CPU (or by this CPU).
( We could use atomics for the suppressed messages field, but
i doubt it matters in practice and it makes the code heavier. )
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>
-rw-r--r-- | lib/ratelimit.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/ratelimit.c b/lib/ratelimit.c index 0e2c28e8a0ca..69bfcacda16d 100644 --- a/lib/ratelimit.c +++ b/lib/ratelimit.c | |||
@@ -28,7 +28,15 @@ int __ratelimit(struct ratelimit_state *rs) | |||
28 | if (!rs->interval) | 28 | if (!rs->interval) |
29 | return 1; | 29 | return 1; |
30 | 30 | ||
31 | spin_lock_irqsave(&rs->lock, flags); | 31 | /* |
32 | * If we contend on this state's lock then almost | ||
33 | * by definition we are too busy to print a message, | ||
34 | * in addition to the one that will be printed by | ||
35 | * the entity that is holding the lock already: | ||
36 | */ | ||
37 | if (!spin_trylock_irqsave(&rs->lock, flags)) | ||
38 | return 1; | ||
39 | |||
32 | if (!rs->begin) | 40 | if (!rs->begin) |
33 | rs->begin = jiffies; | 41 | rs->begin = jiffies; |
34 | 42 | ||