[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-edaac8e3167501cda336231d00611bf59c164346@git.kernel.org>
Date: Tue, 22 Sep 2009 13:34:16 GMT
From: tip-bot for Ingo Molnar <mingo@...e.hu>
To: linux-tip-commits@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, hpa@...or.com, mingo@...hat.com,
torvalds@...ux-foundation.org, a.p.zijlstra@...llo.nl,
davem@...emloft.net, akpm@...ux-foundation.org, tglx@...utronix.de,
mingo@...e.hu
Subject: [tip:core/printk] ratelimit: Fix/allow use in atomic contexts
Commit-ID: edaac8e3167501cda336231d00611bf59c164346
Gitweb: http://git.kernel.org/tip/edaac8e3167501cda336231d00611bf59c164346
Author: Ingo Molnar <mingo@...e.hu>
AuthorDate: Tue, 22 Sep 2009 14:44:11 +0200
Committer: Ingo Molnar <mingo@...e.hu>
CommitDate: Tue, 22 Sep 2009 14:05:48 +0200
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@...llo.nl>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: David S. Miller <davem@...emloft.net>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@...e.hu>
---
lib/ratelimit.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/lib/ratelimit.c b/lib/ratelimit.c
index 0e2c28e..69bfcac 100644
--- a/lib/ratelimit.c
+++ b/lib/ratelimit.c
@@ -28,7 +28,15 @@ int __ratelimit(struct ratelimit_state *rs)
if (!rs->interval)
return 1;
- spin_lock_irqsave(&rs->lock, flags);
+ /*
+ * If we contend on this state's lock then almost
+ * by definition we are too busy to print a message,
+ * in addition to the one that will be printed by
+ * the entity that is holding the lock already:
+ */
+ if (!spin_trylock_irqsave(&rs->lock, flags))
+ return 1;
+
if (!rs->begin)
rs->begin = jiffies;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists