mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] Spinlock timeout
@ 2004-07-06 21:16 Jake Moilanen
  2004-07-06 21:39 ` Stephen Hemminger
       [not found] ` <20040706204314.GA16951@galt.devicelogics.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Jake Moilanen @ 2004-07-06 21:16 UTC (permalink / raw)
  To: Andrew Morton, Linus Torvalds; +Cc: linux-kernel

This will cause a BUG() when a spinlock is held for longer then X
seconds.  It is useful for catching deadlocks since not all archs
have a NMI watchdog.

It is also helpful to find locks that are held too long.

Please comment or apply.

Thanks,
Jake

Signed-off-by: Jake Moilanen <moilanen@austin.ibm.com>

---


diff -puN arch/alpha/Kconfig~spinlock-timeout arch/alpha/Kconfig
--- linux-2.6/arch/alpha/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/alpha/Kconfig	Tue Jul  6 15:16:51 2004
@@ -664,6 +664,20 @@ config DEBUG_SPINLOCK
 	  best used in conjunction with the NMI watchdog so that spinlock
 	  deadlocks are also debuggable.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config DEBUG_RWLOCK
 	bool "Read-write spinlock debugging"
 	depends on DEBUG_KERNEL
diff -puN arch/alpha/defconfig~spinlock-timeout arch/alpha/defconfig
--- linux-2.6/arch/alpha/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/alpha/defconfig	Tue Jul  6 15:16:51 2004
@@ -868,6 +868,7 @@ CONFIG_MATHEMU=y
 # CONFIG_DEBUG_SLAB is not set
 CONFIG_MAGIC_SYSRQ=y
 # CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 # CONFIG_DEBUG_RWLOCK is not set
 # CONFIG_DEBUG_SEMAPHORE is not set
 CONFIG_DEBUG_INFO=y
diff -puN arch/arm/Kconfig~spinlock-timeout arch/arm/Kconfig
--- linux-2.6/arch/arm/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/arm/Kconfig	Tue Jul  6 15:16:51 2004
@@ -721,6 +721,20 @@ config DEBUG_SPINLOCK
 	  best used in conjunction with the NMI watchdog so that spinlock
 	  deadlocks are also debuggable.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config DEBUG_WAITQ
 	bool "Wait queue debugging"
 	depends on DEBUG_KERNEL
diff -puN arch/arm/defconfig~spinlock-timeout arch/arm/defconfig
--- linux-2.6/arch/arm/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/arm/defconfig	Tue Jul  6 15:16:51 2004
@@ -507,5 +507,6 @@ CONFIG_FRAME_POINTER=y
 CONFIG_DEBUG_ERRORS=y
 CONFIG_DEBUG_USER=y
 # CONFIG_DEBUG_INFO is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_DEBUG_LL=y
diff -puN arch/arm26/Kconfig~spinlock-timeout arch/arm26/Kconfig
--- linux-2.6/arch/arm26/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/arm26/Kconfig	Tue Jul  6 15:16:51 2004
@@ -284,6 +284,20 @@ config DEBUG_SPINLOCK
 	  best used in conjunction with the NMI watchdog so that spinlock
 	  deadlocks are also debuggable.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config DEBUG_WAITQ
 	bool "Wait queue debugging"
 	depends on DEBUG_KERNEL
diff -puN arch/arm26/defconfig~spinlock-timeout arch/arm26/defconfig
--- linux-2.6/arch/arm26/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/arm26/defconfig	Tue Jul  6 15:16:51 2004
@@ -344,6 +344,7 @@ CONFIG_DEBUG_KERNEL=y
 CONFIG_DEBUG_SLAB=y
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_DEBUG_SPINLOCK=y
+# CONFIG_SPINLOCK_TIMEOUT is not set
 CONFIG_DEBUG_WAITQ=y
 CONFIG_DEBUG_BUGVERBOSE=y
 CONFIG_DEBUG_ERRORS=y
diff -puN arch/i386/Kconfig~spinlock-timeout arch/i386/Kconfig
--- linux-2.6/arch/i386/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/i386/Kconfig	Tue Jul  6 15:16:51 2004
@@ -1237,6 +1237,20 @@ config DEBUG_SPINLOCK
 	  best used in conjunction with the NMI watchdog so that spinlock
 	  deadlocks are also debuggable.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config DEBUG_PAGEALLOC
 	bool "Page alloc debugging"
 	depends on DEBUG_KERNEL
diff -puN arch/i386/defconfig~spinlock-timeout arch/i386/defconfig
--- linux-2.6/arch/i386/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/i386/defconfig	Tue Jul  6 15:16:51 2004
@@ -1216,6 +1216,7 @@ CONFIG_OPROFILE=y
 # CONFIG_DEBUG_KERNEL is not set
 CONFIG_EARLY_PRINTK=y
 CONFIG_DEBUG_SPINLOCK_SLEEP=y
+# CONFIG_SPINLOCK_TIMEOUT is not set
 # CONFIG_FRAME_POINTER is not set
 CONFIG_X86_FIND_SMP_CONFIG=y
 CONFIG_X86_MPPARSE=y
diff -puN arch/ia64/Kconfig~spinlock-timeout arch/ia64/Kconfig
--- linux-2.6/arch/ia64/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/ia64/Kconfig	Tue Jul  6 15:16:51 2004
@@ -459,6 +459,20 @@ config DEBUG_SPINLOCK_SLEEP
 	    If you say Y here, various routines which may sleep will become very
 	    noisy if they are called with a spinlock held.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config IA64_DEBUG_CMPXCHG
 	bool "Turn on compare-and-exchange bug checking (slow!)"
 	depends on DEBUG_KERNEL
diff -puN arch/ia64/defconfig~spinlock-timeout arch/ia64/defconfig
--- linux-2.6/arch/ia64/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/ia64/defconfig	Tue Jul  6 15:16:51 2004
@@ -1093,6 +1093,7 @@ CONFIG_MAGIC_SYSRQ=y
 # CONFIG_DEBUG_SLAB is not set
 # CONFIG_DEBUG_SPINLOCK is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 # CONFIG_IA64_DEBUG_CMPXCHG is not set
 # CONFIG_IA64_DEBUG_IRQ is not set
 CONFIG_DEBUG_INFO=y
diff -puN arch/mips/Kconfig~spinlock-timeout arch/mips/Kconfig
--- linux-2.6/arch/mips/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/mips/Kconfig	Tue Jul  6 15:16:51 2004
@@ -1314,6 +1314,20 @@ config DEBUG_SPINLOCK_SLEEP
 	  If you say Y here, various routines which may sleep will become very
 	  noisy if they are called with a spinlock held.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config RTC_DS1742
 	bool "DS1742 BRAM/RTC support"
 	depends on TOSHIBA_JMR3927 || TOSHIBA_RBTX4927
diff -puN arch/mips/defconfig~spinlock-timeout arch/mips/defconfig
--- linux-2.6/arch/mips/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/mips/defconfig	Tue Jul  6 15:16:51 2004
@@ -122,6 +122,7 @@ CONFIG_CPU_HAS_LLDSCD=y
 CONFIG_CPU_HAS_SYNC=y
 # CONFIG_PREEMPT is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 
 #
 # Bus options (PCI, PCMCIA, EISA, ISA, TC)
diff -puN arch/ppc/Kconfig~spinlock-timeout arch/ppc/Kconfig
--- linux-2.6/arch/ppc/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/ppc/Kconfig	Tue Jul  6 15:16:51 2004
@@ -1166,6 +1166,20 @@ config DEBUG_SPINLOCK_SLEEP
 	  If you say Y here, various routines which may sleep will become very
 	  noisy if they are called with a spinlock held.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config KGDB
 	bool "Include kgdb kernel debugger"
 	depends on DEBUG_KERNEL
diff -puN arch/ppc/defconfig~spinlock-timeout arch/ppc/defconfig
--- linux-2.6/arch/ppc/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/ppc/defconfig	Tue Jul  6 15:16:51 2004
@@ -1223,6 +1223,7 @@ CONFIG_ZLIB_DEFLATE=y
 # Kernel hacking
 #
 # CONFIG_DEBUG_KERNEL is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 CONFIG_BOOTX_TEXT=y
 
 #
diff -puN arch/ppc64/Kconfig~spinlock-timeout arch/ppc64/Kconfig
--- linux-2.6/arch/ppc64/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/ppc64/Kconfig	Tue Jul  6 15:16:51 2004
@@ -364,6 +364,20 @@ config MAGIC_SYSRQ
 	  keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
 	  unless you really know what this hack does.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config DEBUGGER
 	bool "Enable debugger hooks"
 	depends on DEBUG_KERNEL
diff -puN arch/ppc64/defconfig~spinlock-timeout arch/ppc64/defconfig
--- linux-2.6/arch/ppc64/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/ppc64/defconfig	Tue Jul  6 15:16:51 2004
@@ -1054,6 +1054,7 @@ CONFIG_DEBUG_STACKOVERFLOW=y
 CONFIG_DEBUG_STACK_USAGE=y
 # CONFIG_DEBUG_SLAB is not set
 CONFIG_MAGIC_SYSRQ=y
+# CONFIG_SPINLOCK_TIMEOUT is not set
 CONFIG_DEBUGGER=y
 CONFIG_XMON=y
 CONFIG_XMON_DEFAULT=y
diff -puN arch/s390/Kconfig~spinlock-timeout arch/s390/Kconfig
--- linux-2.6/arch/s390/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/s390/Kconfig	Tue Jul  6 15:16:51 2004
@@ -423,6 +423,20 @@ config DEBUG_SPINLOCK_SLEEP
 	  If you say Y here, various routines which may sleep will become very
 	  noisy if they are called with a spinlock held.	
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 endmenu
 
 source "security/Kconfig"
diff -puN arch/s390/defconfig~spinlock-timeout arch/s390/defconfig
--- linux-2.6/arch/s390/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/s390/defconfig	Tue Jul  6 15:16:51 2004
@@ -476,6 +476,7 @@ CONFIG_MAGIC_SYSRQ=y
 # CONFIG_DEBUG_SLAB is not set
 # CONFIG_DEBUG_INFO is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 
 #
 # Security options
diff -puN arch/sh/Kconfig~spinlock-timeout arch/sh/Kconfig
--- linux-2.6/arch/sh/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/sh/Kconfig	Tue Jul  6 15:16:51 2004
@@ -675,6 +675,20 @@ config DEBUG_SPINLOCK
 	  best used in conjunction with the NMI watchdog so that spinlock
 	  deadlocks are also debuggable.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config SH_STANDARD_BIOS
 	bool "Use LinuxSH standard BIOS"
 	help
diff -puN arch/sh/defconfig~spinlock-timeout arch/sh/defconfig
--- linux-2.6/arch/sh/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/sh/defconfig	Tue Jul  6 15:16:51 2004
@@ -351,6 +351,7 @@ CONFIG_MSDOS_PARTITION=y
 #
 # CONFIG_MAGIC_SYSRQ is not set
 # CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 CONFIG_SH_STANDARD_BIOS=y
 CONFIG_SH_EARLY_PRINTK=y
 # CONFIG_KGDB is not set
diff -puN arch/sparc/Kconfig~spinlock-timeout arch/sparc/Kconfig
--- linux-2.6/arch/sparc/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/sparc/Kconfig	Tue Jul  6 15:16:51 2004
@@ -440,6 +440,20 @@ config DEBUG_SPINLOCK_SLEEP
 	  If you say Y here, various routines which may sleep will become very
 	  noisy if they are called with a spinlock held.	
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config DEBUG_BUGVERBOSE
 	bool "Verbose BUG() reporting (adds 70K)"
 	depends on DEBUG_KERNEL
diff -puN arch/sparc/defconfig~spinlock-timeout arch/sparc/defconfig
--- linux-2.6/arch/sparc/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/sparc/defconfig	Tue Jul  6 15:16:51 2004
@@ -611,6 +611,7 @@ CONFIG_DEBUG_KERNEL=y
 # CONFIG_DEBUG_SLAB is not set
 CONFIG_MAGIC_SYSRQ=y
 # CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 # CONFIG_DEBUG_HIGHMEM is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
 # CONFIG_DEBUG_BUGVERBOSE is not set
diff -puN arch/sparc64/Kconfig~spinlock-timeout arch/sparc64/Kconfig
--- linux-2.6/arch/sparc64/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/sparc64/Kconfig	Tue Jul  6 15:16:51 2004
@@ -658,6 +658,20 @@ config DEBUG_SPINLOCK_SLEEP
 	  If you say Y here, various routines which may sleep will become very
 	  noisy if they are called with a spinlock held.	
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config DEBUG_BUGVERBOSE
 	bool "Verbose BUG() reporting (adds 70K)"
 	depends on DEBUG_KERNEL
diff -puN arch/sparc64/defconfig~spinlock-timeout arch/sparc64/defconfig
--- linux-2.6/arch/sparc64/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/sparc64/defconfig	Tue Jul  6 15:16:51 2004
@@ -1718,6 +1718,7 @@ CONFIG_DEBUG_KERNEL=y
 CONFIG_MAGIC_SYSRQ=y
 # CONFIG_DEBUG_SPINLOCK is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 # CONFIG_DEBUG_BUGVERBOSE is not set
 # CONFIG_DEBUG_DCFLUSH is not set
 # CONFIG_DEBUG_INFO is not set
diff -puN arch/um/Kconfig~spinlock-timeout arch/um/Kconfig
--- linux-2.6/arch/um/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/um/Kconfig	Tue Jul  6 15:16:51 2004
@@ -222,6 +222,20 @@ config DEBUG_SLAB
 config DEBUG_SPINLOCK
 	bool "Debug spinlocks usage"
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 config DEBUG_INFO
 	bool "Enable kernel debugging symbols"
 	help
diff -puN arch/um/defconfig~spinlock-timeout arch/um/defconfig
--- linux-2.6/arch/um/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/um/defconfig	Tue Jul  6 15:16:51 2004
@@ -399,6 +399,7 @@ CONFIG_MTD_BLKMTD=m
 #
 # CONFIG_DEBUG_SLAB is not set
 # CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 CONFIG_DEBUG_INFO=y
 CONFIG_FRAME_POINTER=y
 CONFIG_PT_PROXY=y
diff -puN arch/x86_64/Kconfig~spinlock-timeout arch/x86_64/Kconfig
--- linux-2.6/arch/x86_64/Kconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/x86_64/Kconfig	Tue Jul  6 15:16:51 2004
@@ -427,6 +427,20 @@ config DEBUG_SPINLOCK
 	  best used in conjunction with the NMI watchdog so that spinlock
 	  deadlocks are also debuggable.
 
+config SPINLOCK_TIMEOUT
+       bool "Spinlocks timeout"	  
+       depends on DEBUG_KERNEL && SMP
+       help
+         If you say Y here, the spinlocks will timeout after X number
+	 of seconds. This is useful for catching deadlocks, and make sure
+	 locks are not held too long.
+
+config SPINLOCK_TIMEOUT_TIME
+	int "Spinlock timeout time in seconds (1-43200)"
+	range 1 43200
+	depends on SPINLOCK_TIMEOUT
+	default "10"
+
 # !SMP for now because the context switch early causes GPF in segment reloading
 # and the GS base checking does the wrong thing then, causing a hang.
 config CHECKING
diff -puN arch/x86_64/defconfig~spinlock-timeout arch/x86_64/defconfig
--- linux-2.6/arch/x86_64/defconfig~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/arch/x86_64/defconfig	Tue Jul  6 15:16:51 2004
@@ -814,6 +814,7 @@ CONFIG_DEBUG_KERNEL=y
 # CONFIG_DEBUG_SLAB is not set
 CONFIG_MAGIC_SYSRQ=y
 # CONFIG_DEBUG_SPINLOCK is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
 # CONFIG_INIT_DEBUG is not set
 # CONFIG_DEBUG_INFO is not set
 # CONFIG_FRAME_POINTER is not set
diff -puN include/linux/jiffies.h~spinlock-timeout include/linux/jiffies.h
--- linux-2.6/include/linux/jiffies.h~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/include/linux/jiffies.h	Tue Jul  6 15:16:51 2004
@@ -3,8 +3,6 @@
 
 #include <linux/kernel.h>
 #include <linux/types.h>
-#include <linux/spinlock.h>
-#include <linux/seqlock.h>
 #include <asm/system.h>
 #include <asm/param.h>			/* for HZ */
 
diff -puN include/linux/spinlock.h~spinlock-timeout include/linux/spinlock.h
--- linux-2.6/include/linux/spinlock.h~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/include/linux/spinlock.h	Tue Jul  6 15:16:51 2004
@@ -38,6 +38,25 @@
 #ifdef CONFIG_SMP
 #include <asm/spinlock.h>
 
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+
+#include <linux/jiffies.h>
+
+#define SPINLOCK_TIMEOUT CONFIG_SPINLOCK_TIMEOUT_TIME
+
+/*
+ * There are paths where jiffies won't be updated and
+ * SPINLOCK_TIMEOUT will not work.  To ensure they work, it is best
+ * to have every arch implement their own SPINLOCK_TIMEOUT routines
+ * that use hardware timers.
+ */
+#ifndef ARCH_HAS_SPINLOCK_TIMEOUT
+#define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ))
+#define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout))
+#endif /* !ARCH_HASH_SPINLOCK_TIMEOUT */
+
+#endif /* CONFIG_SPINLOCK_TIMEOUT */
+
 #else
 
 #if !defined(CONFIG_PREEMPT) && !defined(CONFIG_DEBUG_SPINLOCK)
@@ -216,12 +235,28 @@ do { \
 } while (0)
 
 #else
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+
+static inline void spin_lock(spinlock_t * lock) {
+	unsigned long timeout = get_spinlock_timeout();
+
+	preempt_disable(); 
+	do { 
+		if (check_spinlock_timeout(timeout)) 
+		        BUG();
+	} while (!_raw_spin_trylock(lock));
+}
+
+#else /* CONFIG_SPINLOCK_TIMEOUT */
+
 #define spin_lock(lock)	\
 do { \
 	preempt_disable(); \
 	_raw_spin_lock(lock); \
 } while(0)
 
+#endif /* CONFIG_SPINLOCK_TIMEOUT */
+
 #define write_lock(lock) \
 do { \
 	preempt_disable(); \
@@ -256,22 +291,19 @@ do { \
 #define spin_lock_irqsave(lock, flags) \
 do { \
 	local_irq_save(flags); \
-	preempt_disable(); \
-	_raw_spin_lock(lock); \
+	spin_lock(lock); \
 } while (0)
 
 #define spin_lock_irq(lock) \
 do { \
 	local_irq_disable(); \
-	preempt_disable(); \
-	_raw_spin_lock(lock); \
+	spin_lock(lock); \
 } while (0)
 
 #define spin_lock_bh(lock) \
 do { \
 	local_bh_disable(); \
-	preempt_disable(); \
-	_raw_spin_lock(lock); \
+	spin_lock(lock); \
 } while (0)
 
 #define read_lock_irqsave(lock, flags) \
diff -puN kernel/sched.c~spinlock-timeout kernel/sched.c
--- linux-2.6/kernel/sched.c~spinlock-timeout	Tue Jul  6 15:16:51 2004
+++ linux-2.6-moilanen/kernel/sched.c	Tue Jul  6 15:16:51 2004
@@ -3022,14 +3022,23 @@ EXPORT_SYMBOL(__might_sleep);
  */
 void __sched __preempt_spin_lock(spinlock_t *lock)
 {
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+	unsigned long timeout = get_spinlock_timeout();
+#endif
+
 	if (preempt_count() > 1) {
 		_raw_spin_lock(lock);
 		return;
 	}
 	do {
 		preempt_enable();
-		while (spin_is_locked(lock))
+		while (spin_is_locked(lock)) {
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+			if (check_spinlock_timeout(timeout)) 
+				BUG();
+#endif
 			cpu_relax();
+		}
 		preempt_disable();
 	} while (!_raw_spin_trylock(lock));
 }

_

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

* Re: [PATCH 1/2] Spinlock timeout
  2004-07-06 21:16 [PATCH 1/2] Spinlock timeout Jake Moilanen
@ 2004-07-06 21:39 ` Stephen Hemminger
       [not found] ` <20040706204314.GA16951@galt.devicelogics.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2004-07-06 21:39 UTC (permalink / raw)
  To: linux-kernel

On Tue, 6 Jul 2004 16:16:27 -0500
Jake Moilanen <moilanen@austin.ibm.com> wrote:

> This will cause a BUG() when a spinlock is held for longer then X
> seconds.  It is useful for catching deadlocks since not all archs
> have a NMI watchdog.
> 
> It is also helpful to find locks that are held too long.
> 
> Please comment or apply.
> 
> Thanks,

Just don't ever run on a production or benchmark system because there are
cases where a lock can get hot and statistically take a real long time.

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

* Re: [PATCH 1/2] Spinlock timeout
       [not found] ` <20040706204314.GA16951@galt.devicelogics.com>
@ 2004-07-06 22:15   ` Jake Moilanen
  0 siblings, 0 replies; 3+ messages in thread
From: Jake Moilanen @ 2004-07-06 22:15 UTC (permalink / raw)
  To: jmerkey; +Cc: akpm, torvalds, linux-kernel

On Tue, 6 Jul 2004 14:43:14 -0600
jmerkey@galt.devicelogics.com wrote:

> 
> 
> You should also for the UP case of Linux keep a counter 
> and call BUG() when someone calls a spinlock twice rather than
> just push, cli, and pop interrupt flags.  Guess what, this
> allows you to catch most deadlock bugs with spinlocks 

Isn't this what CONFIG_DEBUG_SPINLOCK is for?

Thanks,
Jake

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

end of thread, other threads:[~2004-07-06 22:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-06 21:16 [PATCH 1/2] Spinlock timeout Jake Moilanen
2004-07-06 21:39 ` Stephen Hemminger
     [not found] ` <20040706204314.GA16951@galt.devicelogics.com>
2004-07-06 22:15   ` Jake Moilanen

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

all inboxes | Powered by JetHome®