login
Header Space

 
 

Re: [BUG] long freezes on thinkpad t60

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Miklos Szeredi <miklos@...>
Cc: <cebbert@...>, <chris@...>, <linux-kernel@...>, <tglx@...>, <torvalds@...>, <akpm@...>
Date: Monday, June 18, 2007 - 4:12 am

* Miklos Szeredi <miklos@szeredi.hu> wrote:



yeah. The problem is, that the open-coded loop there is totally fine, 
and we have similar loops elsewhere, so this problem could hit us again, 
in an even harder to debug place! Since this affects our basic SMP 
primitives, quite some caution is warranted i think.

So ... to inquire about the scope of the problem, another possibility 
would be for the _spin loop_ being 'too nice', not wait_task_inactive() 
being too agressive!

To test this theory, could you try the patch below, does this fix your 
hangs too? This change causes the memory access of the "easy" spin-loop 
portion to be more agressive: after the REP; NOP we'd not do the 
'easy-loop' with a simple CMPB, but we'd re-attempt the atomic op. (in 
theory the non-LOCK-ed memory accesses should have a similar effect, but 
maybe the Core2Duo has some special optimization for non-LOCK-ed 
cacheline accesses that causes cacheline starvation?)

	Ingo

---------------------------------------------------->
Subject: [patch] x86: fix spin-loop starvation bug
From: Ingo Molnar <mingo@elte.hu>

Miklos Szeredi reported very long pauses (several seconds, sometimes 
more) on his T60 (with a Core2Duo) which he managed to track down to 
wait_task_inactive()'s open-coded busy-loop. He observed that an 
interrupt on one core tries to acquire the runqueue-lock but does not 
succeed in doing so for a very long time - while wait_task_inactive() on 
the other core loops waiting for the first core to deschedule a task 
(which it wont do while spinning in an interrupt handler).

The problem is: both the spin_lock() code and the wait_task_inactive() 
loop uses cpu_relax()/rep_nop(), so in theory the CPU should have 
guaranteed MESI-fairness to the two cores - but that didnt happen: one 
of the cores was able to monopolize the cacheline that holds the 
runqueue lock, for extended periods of time.

This patch changes the spin-loop to assert an atomic op after every REP 
NOP instance - this will cause the CPU to express its "MESI interest" in 
that cacheline after every REP NOP.

Reported-and-debugged-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 include/asm-i386/spinlock.h    |   16 ++++------------
 include/asm-x86_64/processor.h |    8 ++++++--
 include/asm-x86_64/spinlock.h  |   15 +++------------
 3 files changed, 13 insertions(+), 26 deletions(-)

Index: linux-cfs-2.6.22-rc5.q/include/asm-i386/spinlock.h
===================================================================
--- linux-cfs-2.6.22-rc5.q.orig/include/asm-i386/spinlock.h
+++ linux-cfs-2.6.22-rc5.q/include/asm-i386/spinlock.h
@@ -37,10 +37,7 @@ static inline void __raw_spin_lock(raw_s
 	asm volatile("\n1:\t"
 		     LOCK_PREFIX " ; decb %0\n\t"
 		     "jns 3f\n"
-		     "2:\t"
-		     "rep;nop\n\t"
-		     "cmpb $0,%0\n\t"
-		     "jle 2b\n\t"
+		     "rep; nop\n\t"
 		     "jmp 1b\n"
 		     "3:\n\t"
 		     : "+m" (lock->slock) : : "memory");
@@ -65,21 +62,16 @@ static inline void __raw_spin_lock_flags
 		"testl $0x200, %[flags]\n\t"
 		"jz 4f\n\t"
 		STI_STRING "\n"
-		"3:\t"
-		"rep;nop\n\t"
-		"cmpb $0, %[slock]\n\t"
-		"jle 3b\n\t"
+		"rep; nop\n\t"
 		CLI_STRING "\n\t"
 		"jmp 1b\n"
 		"4:\t"
-		"rep;nop\n\t"
-		"cmpb $0, %[slock]\n\t"
-		"jg 1b\n\t"
+		"rep; nop\n\t"
 		"jmp 4b\n"
 		"5:\n\t"
 		: [slock] "+m" (lock->slock)
 		: [flags] "r" (flags)
-	 	  CLI_STI_INPUT_ARGS
+		  CLI_STI_INPUT_ARGS
 		: "memory" CLI_STI_CLOBBERS);
 }
 #endif
Index: linux-cfs-2.6.22-rc5.q/include/asm-x86_64/processor.h
===================================================================
--- linux-cfs-2.6.22-rc5.q.orig/include/asm-x86_64/processor.h
+++ linux-cfs-2.6.22-rc5.q/include/asm-x86_64/processor.h
@@ -358,7 +358,7 @@ struct extended_sigtable {
 /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
 static inline void rep_nop(void)
 {
-	__asm__ __volatile__("rep;nop": : :"memory");
+	__asm__ __volatile__("rep; nop" : : : "memory");
 }
 
 /* Stop speculative execution */
@@ -389,7 +389,11 @@ static inline void prefetchw(void *x) 
 
 #define spin_lock_prefetch(x)  prefetchw(x)
 
-#define cpu_relax()   rep_nop()
+static inline void cpu_relax(void)
+{
+	smp_mb(); /* Core2Duo needs this to not starve other cores */
+	rep_nop();
+}
 
 /*
  *      NSC/Cyrix CPU indexed register access macros
Index: linux-cfs-2.6.22-rc5.q/include/asm-x86_64/spinlock.h
===================================================================
--- linux-cfs-2.6.22-rc5.q.orig/include/asm-x86_64/spinlock.h
+++ linux-cfs-2.6.22-rc5.q/include/asm-x86_64/spinlock.h
@@ -28,10 +28,7 @@ static inline void __raw_spin_lock(raw_s
 		"\n1:\t"
 		LOCK_PREFIX " ; decl %0\n\t"
 		"jns 2f\n"
-		"3:\n"
-		"rep;nop\n\t"
-		"cmpl $0,%0\n\t"
-		"jle 3b\n\t"
+		"rep; nop\n\t"
 		"jmp 1b\n"
 		"2:\t" : "=m" (lock->slock) : : "memory");
 }
@@ -49,16 +46,10 @@ static inline void __raw_spin_lock_flags
 		"testl $0x200, %1\n\t"	/* interrupts were disabled? */
 		"jz 4f\n\t"
 	        "sti\n"
-		"3:\t"
-		"rep;nop\n\t"
-		"cmpl $0, %0\n\t"
-		"jle 3b\n\t"
+		"rep; nop\n\t"
 		"cli\n\t"
 		"jmp 1b\n"
-		"4:\t"
-		"rep;nop\n\t"
-		"cmpl $0, %0\n\t"
-		"jg 1b\n\t"
+		"rep; nop\n\t"
 		"jmp 4b\n"
 		"5:\n\t"
 		: "+m" (lock->slock) : "r" ((unsigned)flags) : "memory");
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu May 24, 8:04 am)
Re: [BUG] long freezes on thinkpad t60, Henrique de Moraes Holschuh..., (Thu May 24, 6:08 pm)
Re: [BUG] long freezes on thinkpad t60, Kok, Auke, (Thu May 24, 6:13 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Fri May 25, 2:58 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 8:54 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu May 24, 10:03 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 10:10 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu May 24, 10:28 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 10:42 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 10:44 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu May 24, 1:09 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu May 24, 5:01 pm)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Fri May 25, 5:51 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Thu Jun 14, 12:04 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Sat Jun 16, 6:37 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Sun Jun 17, 5:46 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 2:43 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 3:24 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 4:12 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Mon Jun 18, 12:34 pm)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Wed Jun 20, 5:36 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 20, 1:34 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 3:30 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 11:50 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 12:08 pm)
Re: [BUG] long freezes on thinkpad t60, Chuck Ebbert, (Thu Jun 21, 12:44 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 1:31 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:18 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 4:36 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:16 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Fri Jun 22, 4:17 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Sat Jun 23, 6:36 am)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Mon Jun 25, 2:45 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Sat Jun 23, 12:39 pm)
Re: [BUG] long freezes on thinkpad t60, Eric Dumazet, (Thu Jun 21, 2:29 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 2:44 pm)
Re: [BUG] long freezes on thinkpad t60, Nick Piggin, (Tue Jun 26, 4:42 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Tue Jun 26, 1:23 pm)
Re: [BUG] long freezes on thinkpad t60, Nick Piggin, (Wed Jun 27, 1:23 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 27, 2:04 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 27, 3:47 pm)
Re: [BUG] long freezes on thinkpad t60, Nick Piggin, (Mon Jul 2, 3:06 am)
Re: [BUG] long freezes on thinkpad t60, Davide Libenzi, (Wed Jun 27, 4:17 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 27, 6:11 pm)
Re: [BUG] long freezes on thinkpad t60, Davide Libenzi, (Wed Jun 27, 7:30 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Wed Jun 27, 8:46 pm)
Re: [BUG] long freezes on thinkpad t60, Davide Libenzi, (Wed Jun 27, 11:03 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Wed Jun 27, 4:10 pm)
Re: [BUG] long freezes on thinkpad t60, Nick Piggin, (Wed Jun 27, 2:20 am)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Tue Jun 26, 6:56 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:12 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 3:56 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 4:10 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:23 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 3:35 pm)
Re: [BUG] long freezes on thinkpad t60, Eric Dumazet, (Thu Jun 21, 4:36 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:09 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 4:14 pm)
[patch] spinlock debug: make looping nicer, Ingo Molnar, (Thu Jun 21, 4:42 pm)
Re: [patch] spinlock debug: make looping nicer, Linus Torvalds, (Thu Jun 21, 4:58 pm)
Re: [patch] spinlock debug: make looping nicer, Ingo Molnar, (Thu Jun 21, 5:15 pm)
Re: [patch] spinlock debug: make looping nicer, Jarek Poplawski, (Fri Jun 22, 3:00 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:30 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 4:48 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 5:06 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 12:32 pm)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Thu Jun 21, 3:38 am)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Thu Jun 21, 12:01 pm)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Fri Jun 22, 6:38 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Thu Jun 21, 4:39 am)
Re: [BUG] long freezes on thinkpad t60, Jarek Poplawski, (Thu Jun 21, 7:09 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 2:00 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Mon Jun 18, 2:25 pm)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 1:41 pm)
Re: [BUG] long freezes on thinkpad t60, Linus Torvalds, (Mon Jun 18, 1:48 pm)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 2:02 pm)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 4:25 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 4:31 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 4:34 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 5:18 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 5:38 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 5:44 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 6:18 am)
Re: [BUG] long freezes on thinkpad t60, Ingo Molnar, (Mon Jun 18, 8:36 am)
Re: [BUG] long freezes on thinkpad t60, Miklos Szeredi, (Mon Jun 18, 9:10 am)
Re: [BUG] long freezes on thinkpad t60, Andrew Morton, (Mon Jun 18, 4:20 am)
Re: [BUG] long freezes on thinkpad t60, Ravikiran G Thirumalai, (Tue Jun 19, 12:22 am)
Re: [BUG] long freezes on thinkpad t60, Chuck Ebbert, (Fri Jun 15, 5:25 pm)
speck-geostationary