[PATCH] Prevent spinlock debug from timing out too early

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In modern Linux loops_per_jiffie doesn't have much relationship to how
fast the CPU can really execute loops because delay works in a different way. 
Unfortunately the spinlock debugging code used it for that, which
caused it it time timeout much earlier that a second.

A second is quite a long time for a spinlock, but there are situations
that can hold them quite long (debug output over slow serial
line, SCSI driver in recovery etc.), so it's better to not time out
too early.

This patch changes it to use jiffies to check for the timeout.
It has the small drawback over the previous case that if jiffies 
doesn't tick anymore you won't get any timed out spinlocks, but 
normally NMI watchdog should catch that anyways.

Signed-off-by:  Andi Kleen <[email protected]>

Index: linux-2.6.15/lib/spinlock_debug.c
===================================================================
--- linux-2.6.15.orig/lib/spinlock_debug.c
+++ linux-2.6.15/lib/spinlock_debug.c
@@ -68,13 +68,13 @@ static inline void debug_spin_unlock(spi
 static void __spin_lock_debug(spinlock_t *lock)
 {
 	int print_once = 1;
-	u64 i;
 
 	for (;;) {
-		for (i = 0; i < loops_per_jiffy * HZ; i++) {
-			cpu_relax();
+		unsigned long timeout = jiffies + HZ;
+		while (time_before(jiffies, timeout)) {
 			if (__raw_spin_trylock(&lock->raw_lock))
 				return;
+			cpu_relax();
 		}
 		/* lockup suspected: */
 		if (print_once) {
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux