public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tile: ns2cycles must be called with preempt disabled.
@ 2013-03-22 17:37 Henrik Austad
  2013-03-22 19:37 ` Chris Metcalf
  0 siblings, 1 reply; 6+ messages in thread
From: Henrik Austad @ 2013-03-22 17:37 UTC (permalink / raw)
  To: Chris Metcalf; +Cc: LKML, Henrik Austad

ns2cycles use per_cpu variables, and will, eventually, find its way into
smp_processord_id(). The latter must be called with either preempt
disabled, irq's off, from a thread locked to a single core or early in
the bootprocess (according to debug_smp_processor_id())

BUG: using smp_processor_id() in preemptible [00000000] code: systemd-modules/367
caller is ns2cycles+0x40/0xb8

Starting stack dump of tid 367, pid 367 (systemd-modules) on cpu 2 at cycle 20969956421
  frame 0: 0xfffffff70004b860 dump_stack+0x0/0x20 (sp 0xfffffe407993fa90)
  frame 1: 0xfffffff7006abc28 debug_smp_processor_id+0x1a8/0x1e0 (sp 0xfffffe407993fa90)
  frame 2: 0xfffffff7004d7b40 ns2cycles+0x40/0xb8 (sp 0xfffffe407993fab8)
  frame 3: 0xfffffff7004dc578 __ndelay+0x38/0x80 (sp 0xfffffe407993fae0)

Note: wrapping the -entire- delay-loop in a preempt-off section can be a
bad idea as long delays would case kernel lockups without being able to
preempt the thread at all.

Signed-off-by: Henrik Austad <haustad@cisco.com>
---
 arch/tile/lib/delay.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/tile/lib/delay.c b/arch/tile/lib/delay.c
index cdacdd1..a53cdcd 100644
--- a/arch/tile/lib/delay.c
+++ b/arch/tile/lib/delay.c
@@ -30,7 +30,9 @@ EXPORT_SYMBOL(__udelay);
 void __ndelay(unsigned long nsecs)
 {
 	cycles_t target = get_cycles();
+	preempt_disable();
 	target += ns2cycles(nsecs);
+	preempt_enable();
 	while (get_cycles() < target)
 		cpu_relax();
 }
-- 
1.7.2.5


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

end of thread, other threads:[~2013-03-26 13:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-22 17:37 [PATCH] tile: ns2cycles must be called with preempt disabled Henrik Austad
2013-03-22 19:37 ` Chris Metcalf
2013-03-23  7:23   ` [PATCH] tile: ns2cycles should use __raw_get_cpu_var Henrik Austad
2013-03-23 14:13     ` Chris Metcalf
2013-03-26  7:16       ` Henrik Austad
2013-03-26 13:14         ` Chris Metcalf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox