* [PATCH] lockdep: Simplify a bit hardirq <-> softirq transitions
@ 2013-11-20 0:07 Frederic Weisbecker
2013-11-20 0:09 ` Frederic Weisbecker
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2013-11-20 0:07 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar
Cc: LKML, Frederic Weisbecker, Sebastian Andrzej Siewior,
Linus Torvalds, Andrew Morton
Instead of saving the hardirq state on a per CPU variable, which require
an explicit call before the softirq handling and some complication,
just save and restore the hardirq tracing state through functions
return values and parameters.
It simplifies a bit the black magic that works around the fact that
softirqs can be called from hardirqs while hardirqs can nest on softirqs
but those two cases have very different semantics and only the latter
case assume both states.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
kernel/softirq.c | 37 ++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/kernel/softirq.c b/kernel/softirq.c
index eb0acf4..dc43ee8 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -215,40 +215,35 @@ EXPORT_SYMBOL(local_bh_enable_ip);
#ifdef CONFIG_TRACE_IRQFLAGS
/*
- * Convoluted means of passing __do_softirq() a message through the various
- * architecture execute_on_stack() bits.
- *
* When we run softirqs from irq_exit() and thus on the hardirq stack we need
* to keep the lockdep irq context tracking as tight as possible in order to
* not miss-qualify lock contexts and miss possible deadlocks.
*/
-static DEFINE_PER_CPU(int, softirq_from_hardirq);
-static inline void lockdep_softirq_from_hardirq(void)
+static inline bool lockdep_softirq_start(void)
{
- this_cpu_write(softirq_from_hardirq, 1);
-}
+ bool in_hardirq = false;
-static inline void lockdep_softirq_start(void)
-{
- if (this_cpu_read(softirq_from_hardirq))
+ if (trace_hardirq_context(current)) {
+ in_hardirq = true;
trace_hardirq_exit();
+ }
+
lockdep_softirq_enter();
+
+ return in_hardirq;
}
-static inline void lockdep_softirq_end(void)
+static inline void lockdep_softirq_end(bool in_hardirq)
{
lockdep_softirq_exit();
- if (this_cpu_read(softirq_from_hardirq)) {
- this_cpu_write(softirq_from_hardirq, 0);
+
+ if (in_hardirq)
trace_hardirq_enter();
- }
}
-
#else
-static inline void lockdep_softirq_from_hardirq(void) { }
-static inline void lockdep_softirq_start(void) { }
-static inline void lockdep_softirq_end(void) { }
+static inline bool lockdep_softirq_start(void) { return false; }
+static inline void lockdep_softirq_end(bool in_hardirq) { }
#endif
asmlinkage void __do_softirq(void)
@@ -257,6 +252,7 @@ asmlinkage void __do_softirq(void)
unsigned long old_flags = current->flags;
int max_restart = MAX_SOFTIRQ_RESTART;
struct softirq_action *h;
+ bool in_hardirq;
__u32 pending;
int cpu;
@@ -271,7 +267,7 @@ asmlinkage void __do_softirq(void)
account_irq_enter_time(current);
__local_bh_disable(_RET_IP_, SOFTIRQ_OFFSET);
- lockdep_softirq_start();
+ in_hardirq = lockdep_softirq_start();
cpu = smp_processor_id();
restart:
@@ -318,7 +314,7 @@ restart:
wakeup_softirqd();
}
- lockdep_softirq_end();
+ lockdep_softirq_end(in_hardirq);
account_irq_exit_time(current);
__local_bh_enable(SOFTIRQ_OFFSET);
WARN_ON_ONCE(in_interrupt());
@@ -367,7 +363,6 @@ void irq_enter(void)
static inline void invoke_softirq(void)
{
if (!force_irqthreads) {
- lockdep_softirq_from_hardirq();
#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
/*
* We can safely execute softirq on the current stack if
--
1.8.3.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lockdep: Simplify a bit hardirq <-> softirq transitions
2013-11-20 0:07 [PATCH] lockdep: Simplify a bit hardirq <-> softirq transitions Frederic Weisbecker
@ 2013-11-20 0:09 ` Frederic Weisbecker
2013-11-21 10:17 ` Peter Zijlstra
2013-11-27 14:07 ` [tip:core/locking] " tip-bot for Frederic Weisbecker
2 siblings, 0 replies; 4+ messages in thread
From: Frederic Weisbecker @ 2013-11-20 0:09 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar
Cc: LKML, Sebastian Andrzej Siewior, Linus Torvalds, Andrew Morton
On Wed, Nov 20, 2013 at 01:07:34AM +0100, Frederic Weisbecker wrote:
> Instead of saving the hardirq state on a per CPU variable, which require
> an explicit call before the softirq handling and some complication,
> just save and restore the hardirq tracing state through functions
> return values and parameters.
>
> It simplifies a bit the black magic that works around the fact that
> softirqs can be called from hardirqs while hardirqs can nest on softirqs
> but those two cases have very different semantics and only the latter
> case assume both states.
>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
It applies on top of:
"[tip:core/urgent] lockdep: Correctly annotate hardirq context in irq_exit()"
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lockdep: Simplify a bit hardirq <-> softirq transitions
2013-11-20 0:07 [PATCH] lockdep: Simplify a bit hardirq <-> softirq transitions Frederic Weisbecker
2013-11-20 0:09 ` Frederic Weisbecker
@ 2013-11-21 10:17 ` Peter Zijlstra
2013-11-27 14:07 ` [tip:core/locking] " tip-bot for Frederic Weisbecker
2 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2013-11-21 10:17 UTC (permalink / raw)
To: Frederic Weisbecker
Cc: Ingo Molnar, LKML, Sebastian Andrzej Siewior, Linus Torvalds,
Andrew Morton
On Wed, Nov 20, 2013 at 01:07:34AM +0100, Frederic Weisbecker wrote:
> Instead of saving the hardirq state on a per CPU variable, which require
> an explicit call before the softirq handling and some complication,
> just save and restore the hardirq tracing state through functions
> return values and parameters.
>
> It simplifies a bit the black magic that works around the fact that
> softirqs can be called from hardirqs while hardirqs can nest on softirqs
> but those two cases have very different semantics and only the latter
> case assume both states.
>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
> kernel/softirq.c | 37 ++++++++++++++++---------------------
> 1 file changed, 16 insertions(+), 21 deletions(-)
>
> diff --git a/kernel/softirq.c b/kernel/softirq.c
> index eb0acf4..dc43ee8 100644
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -215,40 +215,35 @@ EXPORT_SYMBOL(local_bh_enable_ip);
>
> #ifdef CONFIG_TRACE_IRQFLAGS
> /*
> * When we run softirqs from irq_exit() and thus on the hardirq stack we need
> * to keep the lockdep irq context tracking as tight as possible in order to
> * not miss-qualify lock contexts and miss possible deadlocks.
> */
>
> +static inline bool lockdep_softirq_start(void)
> {
> + bool in_hardirq = false;
>
> + if (trace_hardirq_context(current)) {
> + in_hardirq = true;
> trace_hardirq_exit();
> + }
> +
> lockdep_softirq_enter();
> +
> + return in_hardirq;
> }
>
> +static inline void lockdep_softirq_end(bool in_hardirq)
> {
> lockdep_softirq_exit();
> +
> + if (in_hardirq)
> trace_hardirq_enter();
> }
Yeah, I suppose that works. Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
* [tip:core/locking] lockdep: Simplify a bit hardirq <-> softirq transitions
2013-11-20 0:07 [PATCH] lockdep: Simplify a bit hardirq <-> softirq transitions Frederic Weisbecker
2013-11-20 0:09 ` Frederic Weisbecker
2013-11-21 10:17 ` Peter Zijlstra
@ 2013-11-27 14:07 ` tip-bot for Frederic Weisbecker
2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Frederic Weisbecker @ 2013-11-27 14:07 UTC (permalink / raw)
To: linux-tip-commits
Cc: linux-kernel, hpa, mingo, torvalds, peterz, paulmck, fweisbec,
akpm, tglx, bigeasy
Commit-ID: 5c4853b60ca8ec3d989ce05a5e995d15c3ed52c0
Gitweb: http://git.kernel.org/tip/5c4853b60ca8ec3d989ce05a5e995d15c3ed52c0
Author: Frederic Weisbecker <fweisbec@gmail.com>
AuthorDate: Wed, 20 Nov 2013 01:07:34 +0100
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 27 Nov 2013 11:09:40 +0100
lockdep: Simplify a bit hardirq <-> softirq transitions
Instead of saving the hardirq state on a per CPU variable, which require
an explicit call before the softirq handling and some complication,
just save and restore the hardirq tracing state through functions
return values and parameters.
It simplifies a bit the black magic that works around the fact that
softirqs can be called from hardirqs while hardirqs can nest on softirqs
but those two cases have very different semantics and only the latter
case assume both states.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1384906054-30676-1-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/softirq.c | 37 ++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/kernel/softirq.c b/kernel/softirq.c
index f84aa48..9a4500e 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -213,40 +213,35 @@ EXPORT_SYMBOL(local_bh_enable_ip);
#ifdef CONFIG_TRACE_IRQFLAGS
/*
- * Convoluted means of passing __do_softirq() a message through the various
- * architecture execute_on_stack() bits.
- *
* When we run softirqs from irq_exit() and thus on the hardirq stack we need
* to keep the lockdep irq context tracking as tight as possible in order to
* not miss-qualify lock contexts and miss possible deadlocks.
*/
-static DEFINE_PER_CPU(int, softirq_from_hardirq);
-static inline void lockdep_softirq_from_hardirq(void)
+static inline bool lockdep_softirq_start(void)
{
- this_cpu_write(softirq_from_hardirq, 1);
-}
+ bool in_hardirq = false;
-static inline void lockdep_softirq_start(void)
-{
- if (this_cpu_read(softirq_from_hardirq))
+ if (trace_hardirq_context(current)) {
+ in_hardirq = true;
trace_hardirq_exit();
+ }
+
lockdep_softirq_enter();
+
+ return in_hardirq;
}
-static inline void lockdep_softirq_end(void)
+static inline void lockdep_softirq_end(bool in_hardirq)
{
lockdep_softirq_exit();
- if (this_cpu_read(softirq_from_hardirq)) {
- this_cpu_write(softirq_from_hardirq, 0);
+
+ if (in_hardirq)
trace_hardirq_enter();
- }
}
-
#else
-static inline void lockdep_softirq_from_hardirq(void) { }
-static inline void lockdep_softirq_start(void) { }
-static inline void lockdep_softirq_end(void) { }
+static inline bool lockdep_softirq_start(void) { return false; }
+static inline void lockdep_softirq_end(bool in_hardirq) { }
#endif
asmlinkage void __do_softirq(void)
@@ -255,6 +250,7 @@ asmlinkage void __do_softirq(void)
unsigned long old_flags = current->flags;
int max_restart = MAX_SOFTIRQ_RESTART;
struct softirq_action *h;
+ bool in_hardirq;
__u32 pending;
int cpu;
@@ -269,7 +265,7 @@ asmlinkage void __do_softirq(void)
account_irq_enter_time(current);
__local_bh_disable(_RET_IP_, SOFTIRQ_OFFSET);
- lockdep_softirq_start();
+ in_hardirq = lockdep_softirq_start();
cpu = smp_processor_id();
restart:
@@ -316,7 +312,7 @@ restart:
wakeup_softirqd();
}
- lockdep_softirq_end();
+ lockdep_softirq_end(in_hardirq);
account_irq_exit_time(current);
__local_bh_enable(SOFTIRQ_OFFSET);
WARN_ON_ONCE(in_interrupt());
@@ -365,7 +361,6 @@ void irq_enter(void)
static inline void invoke_softirq(void)
{
if (!force_irqthreads) {
- lockdep_softirq_from_hardirq();
#ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
/*
* We can safely execute softirq on the current stack if
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-11-27 14:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-20 0:07 [PATCH] lockdep: Simplify a bit hardirq <-> softirq transitions Frederic Weisbecker
2013-11-20 0:09 ` Frederic Weisbecker
2013-11-21 10:17 ` Peter Zijlstra
2013-11-27 14:07 ` [tip:core/locking] " tip-bot for Frederic Weisbecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome