All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -rt] sched: teach migrate_disable about atomic contexts
@ 2011-09-02 12:41 Peter Zijlstra
  2011-09-06 18:08 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Zijlstra @ 2011-09-02 12:41 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: linux-kernel

Subject: sched: teach migrate_disable about atomic contexts
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
Date: Fri Sep 02 14:29:27 CEST 2011

 <NMI>  [<ffffffff812dafd8>] spin_bug+0x94/0xa8
 [<ffffffff812db07f>] do_raw_spin_lock+0x43/0xea
 [<ffffffff814fa9be>] _raw_spin_lock_irqsave+0x6b/0x85
 [<ffffffff8106ff9e>] ? migrate_disable+0x75/0x12d
 [<ffffffff81078aaf>] ? pin_current_cpu+0x36/0xb0
 [<ffffffff8106ff9e>] migrate_disable+0x75/0x12d
 [<ffffffff81115b9d>] pagefault_disable+0xe/0x1f
 [<ffffffff81047027>] copy_from_user_nmi+0x74/0xe6
 [<ffffffff810489d7>] perf_callchain_user+0xf3/0x135

Now clearly we can't go around taking locks from NMI context, cure
this by short-circuiting migrate_disable() when we're in an atomic
context already.

Add some extra debugging to avoid things like:

  preempt_disable()
  migrate_disable();

  preempt_enable();
  migrate_enable();

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-wbot4vsmwhi8vmbf83hsclk6@git.kernel.org
---
 include/linux/sched.h |    3 +++
 kernel/sched.c        |   21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -6135,6 +6135,17 @@ void migrate_disable(void)
 	unsigned long flags;
 	struct rq *rq;
 
+	if (in_atomic()) {
+#ifdef CONFIG_SCHED_DEBUG
+		p->migrate_disable_atomic++;
+#endif
+		return;
+	}
+
+#ifdef CONFIG_SCHED_DEBUG
+	WARN_ON_ONCE(p->migrate_disable_atomic);
+#endif
+
 	preempt_disable();
 	if (p->migrate_disable) {
 		p->migrate_disable++;
@@ -6183,6 +6194,16 @@ void migrate_enable(void)
 	unsigned long flags;
 	struct rq *rq;
 
+	if (in_atomic()) {
+#ifdef CONFIG_SCHED_DEBUG
+		p->migrate_disable_atomic--;
+#endif
+		return;
+	}
+
+#ifdef CONFIG_SCHED_DEBUG
+	WARN_ON_ONCE(p->migrate_disable_atomic);
+#endif
 	WARN_ON_ONCE(p->migrate_disable <= 0);
 
 	preempt_disable();
Index: linux-2.6/include/linux/sched.h
===================================================================
--- linux-2.6.orig/include/linux/sched.h
+++ linux-2.6/include/linux/sched.h
@@ -1264,6 +1264,9 @@ struct task_struct {
 	unsigned int policy;
 #ifdef CONFIG_PREEMPT_RT_FULL
 	int migrate_disable;
+#ifdef CONFIG_SCHED_DEBUG
+	int migrate_disable_atomic;
+#endif
 #endif
 	cpumask_t cpus_allowed;
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH -rt] sched: teach migrate_disable about atomic contexts
  2011-09-02 12:41 [PATCH -rt] sched: teach migrate_disable about atomic contexts Peter Zijlstra
@ 2011-09-06 18:08 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2011-09-06 18:08 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Thomas Gleixner, linux-kernel

Em Fri, Sep 02, 2011 at 02:41:37PM +0200, Peter Zijlstra escreveu:
> Subject: sched: teach migrate_disable about atomic contexts
> From: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Date: Fri Sep 02 14:29:27 CEST 2011
> 
>  <NMI>  [<ffffffff812dafd8>] spin_bug+0x94/0xa8
>  [<ffffffff812db07f>] do_raw_spin_lock+0x43/0xea
>  [<ffffffff814fa9be>] _raw_spin_lock_irqsave+0x6b/0x85
>  [<ffffffff8106ff9e>] ? migrate_disable+0x75/0x12d
>  [<ffffffff81078aaf>] ? pin_current_cpu+0x36/0xb0
>  [<ffffffff8106ff9e>] migrate_disable+0x75/0x12d
>  [<ffffffff81115b9d>] pagefault_disable+0xe/0x1f
>  [<ffffffff81047027>] copy_from_user_nmi+0x74/0xe6
>  [<ffffffff810489d7>] perf_callchain_user+0xf3/0x135
> 
> Now clearly we can't go around taking locks from NMI context, cure
> this by short-circuiting migrate_disable() when we're in an atomic
> context already.
> 
> Add some extra debugging to avoid things like:
> 
>   preempt_disable()
>   migrate_disable();
> 
>   preempt_enable();
>   migrate_enable();
> 
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Link: http://lkml.kernel.org/n/tip-wbot4vsmwhi8vmbf83hsclk6@git.kernel.org

Now I can collect callchains with perf on linux RT, thanks.

Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-06 18:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-02 12:41 [PATCH -rt] sched: teach migrate_disable about atomic contexts Peter Zijlstra
2011-09-06 18:08 ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.