* [PATCH][RFC] Spinlock-timeout
@ 2004-06-05 20:31 Jake Moilanen
2004-06-05 20:51 ` Jan-Benedict Glaw
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Jake Moilanen @ 2004-06-05 20:31 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 259 bytes --]
Here's a patch that will 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 send comments.
Thanks,
Jake
[-- Attachment #2: spinlock-timeout-2.6-1.patch --]
[-- Type: text/x-patch, Size: 19915 bytes --]
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1613 -> 1.1614
# arch/sparc/Kconfig 1.29 -> 1.30
# arch/ia64/defconfig 1.28 -> 1.29
# arch/mips/defconfig 1.12 -> 1.13
# arch/i386/Kconfig 1.113 -> 1.114
# arch/arm26/defconfig 1.3 -> 1.4
# arch/ppc64/defconfig 1.53 -> 1.54
# arch/arm/defconfig 1.6 -> 1.7
# arch/sparc64/defconfig 1.127 -> 1.128
# arch/s390/Kconfig 1.26 -> 1.27
# arch/mips/Kconfig 1.27 -> 1.28
# arch/um/Kconfig 1.16 -> 1.17
# include/linux/spinlock.h 1.29 -> 1.30
# arch/alpha/defconfig 1.26 -> 1.27
# arch/arm/Kconfig 1.51 -> 1.52
# arch/sh/defconfig 1.10 -> 1.11
# arch/ppc64/Kconfig 1.64 -> 1.65
# arch/arm26/Kconfig 1.12 -> 1.13
# arch/i386/defconfig 1.113 -> 1.114
# arch/x86_64/defconfig 1.39 -> 1.40
# arch/sparc/defconfig 1.20 -> 1.21
# arch/x86_64/Kconfig 1.48 -> 1.49
# kernel/sched.c 1.252 -> 1.253
# arch/ppc/defconfig 1.28 -> 1.29
# arch/s390/defconfig 1.36 -> 1.37
# arch/sparc64/Kconfig 1.55 -> 1.56
# arch/ia64/Kconfig 1.66 -> 1.67
# arch/ppc/Kconfig 1.52 -> 1.53
# arch/sh/Kconfig 1.31 -> 1.32
# arch/um/defconfig 1.9 -> 1.10
# arch/alpha/Kconfig 1.37 -> 1.38
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/06/05 moilanen@zippy.ltc.austin.ibm.com 1.1614
# Spinlock timeout
# --------------------------------------------
#
diff -Nru a/arch/alpha/Kconfig b/arch/alpha/Kconfig
--- a/arch/alpha/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/alpha/Kconfig Sat Jun 5 14:25:51 2004
@@ -664,6 +664,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.
+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout checking"
+ 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 -Nru a/arch/alpha/defconfig b/arch/alpha/defconfig
--- a/arch/alpha/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/alpha/defconfig Sat Jun 5 14:25:51 2004
@@ -868,6 +868,7 @@
# 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 -Nru a/arch/arm/Kconfig b/arch/arm/Kconfig
--- a/arch/arm/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/arm/Kconfig Sat Jun 5 14:25:51 2004
@@ -721,6 +721,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.
+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout checking"
+ 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 -Nru a/arch/arm/defconfig b/arch/arm/defconfig
--- a/arch/arm/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/arm/defconfig Sat Jun 5 14:25:51 2004
@@ -507,5 +507,6 @@
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 -Nru a/arch/arm26/Kconfig b/arch/arm26/Kconfig
--- a/arch/arm26/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/arm26/Kconfig Sat Jun 5 14:25:51 2004
@@ -284,6 +284,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.
+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout checking"
+ 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 -Nru a/arch/arm26/defconfig b/arch/arm26/defconfig
--- a/arch/arm26/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/arm26/defconfig Sat Jun 5 14:25:51 2004
@@ -344,6 +344,7 @@
CONFIG_DEBUG_SLAB=y
CONFIG_MAGIC_SYSRQ=y
CONFIG_DEBUG_SPINLOCK=y
+CONFIG_SPINLOCK_TIMEOUT=y
CONFIG_DEBUG_WAITQ=y
CONFIG_DEBUG_BUGVERBOSE=y
CONFIG_DEBUG_ERRORS=y
diff -Nru a/arch/i386/Kconfig b/arch/i386/Kconfig
--- a/arch/i386/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/i386/Kconfig Sat Jun 5 14:25:51 2004
@@ -1247,6 +1247,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.
+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout checking"
+ 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 -Nru a/arch/i386/defconfig b/arch/i386/defconfig
--- a/arch/i386/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/i386/defconfig Sat Jun 5 14:25:51 2004
@@ -1216,6 +1216,7 @@
# 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 -Nru a/arch/ia64/Kconfig b/arch/ia64/Kconfig
--- a/arch/ia64/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/ia64/Kconfig Sat Jun 5 14:25:51 2004
@@ -459,6 +459,20 @@
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 checking"
+ 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 -Nru a/arch/ia64/defconfig b/arch/ia64/defconfig
--- a/arch/ia64/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/ia64/defconfig Sat Jun 5 14:25:51 2004
@@ -1093,6 +1093,7 @@
# 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 -Nru a/arch/mips/Kconfig b/arch/mips/Kconfig
--- a/arch/mips/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/mips/Kconfig Sat Jun 5 14:25:51 2004
@@ -1360,6 +1360,20 @@
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 checking"
+ 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 -Nru a/arch/mips/defconfig b/arch/mips/defconfig
--- a/arch/mips/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/mips/defconfig Sat Jun 5 14:25:51 2004
@@ -125,6 +125,7 @@
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 -Nru a/arch/ppc/Kconfig b/arch/ppc/Kconfig
--- a/arch/ppc/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/ppc/Kconfig Sat Jun 5 14:25:51 2004
@@ -1166,6 +1166,20 @@
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 checking"
+ 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 -Nru a/arch/ppc/defconfig b/arch/ppc/defconfig
--- a/arch/ppc/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/ppc/defconfig Sat Jun 5 14:25:51 2004
@@ -1223,6 +1223,7 @@
# Kernel hacking
#
# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_SPINLOCK_TIMEOUT is not set
CONFIG_BOOTX_TEXT=y
#
diff -Nru a/arch/ppc64/Kconfig b/arch/ppc64/Kconfig
--- a/arch/ppc64/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/ppc64/Kconfig Sat Jun 5 14:25:51 2004
@@ -465,7 +465,21 @@
help
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 checking"
+ 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 -Nru a/arch/ppc64/defconfig b/arch/ppc64/defconfig
--- a/arch/ppc64/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/ppc64/defconfig Sat Jun 5 14:25:51 2004
@@ -1067,6 +1067,7 @@
# CONFIG_PPCDBG is not set
# CONFIG_DEBUG_INFO is not set
CONFIG_DEBUG_SPINLOCK_SLEEP=y
+# CONFIG_SPINLOCK_TIMEOUT is not set
#
# Security options
diff -Nru a/arch/s390/Kconfig b/arch/s390/Kconfig
--- a/arch/s390/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/s390/Kconfig Sat Jun 5 14:25:51 2004
@@ -423,6 +423,20 @@
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 checking"
+ 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 -Nru a/arch/s390/defconfig b/arch/s390/defconfig
--- a/arch/s390/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/s390/defconfig Sat Jun 5 14:25:51 2004
@@ -476,6 +476,7 @@
# 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 -Nru a/arch/sh/Kconfig b/arch/sh/Kconfig
--- a/arch/sh/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/sh/Kconfig Sat Jun 5 14:25:51 2004
@@ -675,6 +675,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.
+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout checking"
+ 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 -Nru a/arch/sh/defconfig b/arch/sh/defconfig
--- a/arch/sh/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/sh/defconfig Sat Jun 5 14:25:51 2004
@@ -351,6 +351,7 @@
#
# 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 -Nru a/arch/sparc/Kconfig b/arch/sparc/Kconfig
--- a/arch/sparc/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/sparc/Kconfig Sat Jun 5 14:25:51 2004
@@ -440,6 +440,20 @@
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 checking"
+ 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 -Nru a/arch/sparc/defconfig b/arch/sparc/defconfig
--- a/arch/sparc/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/sparc/defconfig Sat Jun 5 14:25:51 2004
@@ -611,6 +611,7 @@
# 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 -Nru a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
--- a/arch/sparc64/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/sparc64/Kconfig Sat Jun 5 14:25:51 2004
@@ -658,6 +658,20 @@
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 checking"
+ 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 -Nru a/arch/sparc64/defconfig b/arch/sparc64/defconfig
--- a/arch/sparc64/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/sparc64/defconfig Sat Jun 5 14:25:51 2004
@@ -1718,6 +1718,7 @@
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 -Nru a/arch/um/Kconfig b/arch/um/Kconfig
--- a/arch/um/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/um/Kconfig Sat Jun 5 14:25:51 2004
@@ -222,6 +222,20 @@
config DEBUG_SPINLOCK
bool "Debug spinlocks usage"
+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout checking"
+ 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 -Nru a/arch/um/defconfig b/arch/um/defconfig
--- a/arch/um/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/um/defconfig Sat Jun 5 14:25:51 2004
@@ -399,6 +399,7 @@
#
# 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 -Nru a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
--- a/arch/x86_64/Kconfig Sat Jun 5 14:25:51 2004
+++ b/arch/x86_64/Kconfig Sat Jun 5 14:25:51 2004
@@ -437,6 +437,20 @@
best used in conjunction with the NMI watchdog so that spinlock
deadlocks are also debuggable.
+config SPINLOCK_TIMEOUT
+ bool "Spinlocks timeout checking"
+ 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 -Nru a/arch/x86_64/defconfig b/arch/x86_64/defconfig
--- a/arch/x86_64/defconfig Sat Jun 5 14:25:51 2004
+++ b/arch/x86_64/defconfig Sat Jun 5 14:25:51 2004
@@ -814,6 +814,7 @@
# 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 -Nru a/include/linux/spinlock.h b/include/linux/spinlock.h
--- a/include/linux/spinlock.h Sat Jun 5 14:25:51 2004
+++ b/include/linux/spinlock.h Sat Jun 5 14:25:51 2004
@@ -38,6 +38,16 @@
#ifdef CONFIG_SMP
#include <asm/spinlock.h>
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+
+#include <asm/param.h>
+
+#define SPINLOCK_TIMEOUT CONFIG_SPINLOCK_TIMEOUT_TIME
+extern unsigned long volatile jiffies;
+
+#endif /* CONFIG_SPINLOCK_TIMEOUT */
+
+
#else
#define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
@@ -218,11 +228,27 @@
} while (0)
#else
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+
+static inline void spin_lock(spinlock_t * lock) {
+ unsigned long jiffy_timeout = jiffies + (SPINLOCK_TIMEOUT * HZ);
+
+ preempt_disable();
+ do {
+ if (jiffies >= jiffy_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 { \
diff -Nru a/kernel/sched.c b/kernel/sched.c
--- a/kernel/sched.c Sat Jun 5 14:25:51 2004
+++ b/kernel/sched.c Sat Jun 5 14:25:51 2004
@@ -3958,6 +3958,10 @@
*/
void __sched __preempt_spin_lock(spinlock_t *lock)
{
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+ unsigned long jiffy_timeout = jiffies + (SPINLOCK_TIMEOUT * HZ);
+#endif
+
if (preempt_count() > 1) {
_raw_spin_lock(lock);
return;
@@ -3967,6 +3971,10 @@
while (spin_is_locked(lock))
cpu_relax();
preempt_disable();
+#if defined(CONFIG_SPINLOCK_TIMEOUT)
+ if (jiffies > = jiffy_timeout)
+ BUG();
+#endif
} while (!_raw_spin_trylock(lock));
}
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH][RFC] Spinlock-timeout 2004-06-05 20:31 [PATCH][RFC] Spinlock-timeout Jake Moilanen @ 2004-06-05 20:51 ` Jan-Benedict Glaw 2004-06-10 18:44 ` Jake Moilanen 2004-06-06 10:13 ` Paul Mackerras 2004-06-06 22:23 ` Benjamin Herrenschmidt 2 siblings, 1 reply; 16+ messages in thread From: Jan-Benedict Glaw @ 2004-06-05 20:51 UTC (permalink / raw) To: linux-kernel [-- Attachment #1: Type: text/plain, Size: 2581 bytes --] On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <moilanen@austin.ibm.com> wrote in message <1086467486.20906.59.camel@dhcp-client215.upt.austin.ibm.com>: > Here's a patch that will 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. I like the idea. However, I don't like touching all arch's Kconfig files. I think it's better to either put this into ./lib/Kconfig (well, doesn't really fit there), ot (even better:) put it into the Debug Kconfig file. > diff -Nru a/include/linux/spinlock.h b/include/linux/spinlock.h > --- a/include/linux/spinlock.h Sat Jun 5 14:25:51 2004 > +++ b/include/linux/spinlock.h Sat Jun 5 14:25:51 2004 > @@ -38,6 +38,16 @@ > #ifdef CONFIG_SMP > #include <asm/spinlock.h> > > +#if defined(CONFIG_SPINLOCK_TIMEOUT) > + > +#include <asm/param.h> > + > +#define SPINLOCK_TIMEOUT CONFIG_SPINLOCK_TIMEOUT_TIME > +extern unsigned long volatile jiffies; > + > +#endif /* CONFIG_SPINLOCK_TIMEOUT */ > + > + > #else > > #define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock) I'd say just include <linux/jiffies.h> and drop the whole #ifdef/#endif block. > @@ -218,11 +228,27 @@ > } while (0) > > #else > +#if defined(CONFIG_SPINLOCK_TIMEOUT) > + > +static inline void spin_lock(spinlock_t * lock) { > + unsigned long jiffy_timeout = jiffies + (SPINLOCK_TIMEOUT * HZ); > + > + preempt_disable(); > + do { > + if (jiffies >= jiffy_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 { \ Also, printing out ->module, ->owner and ->oline might help additionally to just BUG()ing. So you see the (former) owner of the lock. > @@ -3967,6 +3971,10 @@ > while (spin_is_locked(lock)) > cpu_relax(); > preempt_disable(); > +#if defined(CONFIG_SPINLOCK_TIMEOUT) > + if (jiffies > = jiffy_timeout) > + BUG(); > +#endif > } while (!_raw_spin_trylock(lock)); > } > Dito. MfG, JBG -- Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA)); [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-05 20:51 ` Jan-Benedict Glaw @ 2004-06-10 18:44 ` Jake Moilanen 2004-06-10 19:24 ` Jan-Benedict Glaw 0 siblings, 1 reply; 16+ messages in thread From: Jake Moilanen @ 2004-06-10 18:44 UTC (permalink / raw) To: Jan-Benedict Glaw; +Cc: linux-kernel On Sat, 2004-06-05 at 15:51, Jan-Benedict Glaw wrote: > On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <moilanen@austin.ibm.com> > wrote in message <1086467486.20906.59.camel@dhcp-client215.upt.austin.ibm.com>: > > Here's a patch that will 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. > > I like the idea. However, I don't like touching all arch's Kconfig > files. I think it's better to either put this into ./lib/Kconfig (well, > doesn't really fit there), ot (even better:) put it into the Debug > Kconfig file. > I think you're right that lib/Kconfig would not be the right place, but I don't think there is a debug Kconfig. I tried keeping the Kconfig additions w/ CONFIG_DEBUG_SPINLOCK. The other option is to make a debug Kconfig, but every arch seems pretty different in what they have for their debug section. > I'd say just include <linux/jiffies.h> and drop the whole #ifdef/#endif > block. You're right, I'll take this out. > > @@ -218,11 +228,27 @@ > > } while (0) > > > > #else > > +#if defined(CONFIG_SPINLOCK_TIMEOUT) > > + > > +static inline void spin_lock(spinlock_t * lock) { > > + unsigned long jiffy_timeout = jiffies + (SPINLOCK_TIMEOUT * HZ); > > + > > + preempt_disable(); > > + do { > > + if (jiffies >= jiffy_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 { \ > > Also, printing out ->module, ->owner and ->oline might help additionally > to just BUG()ing. So you see the (former) owner of the lock. I think this would give us some extra info, but ->module, ->owner, and ->oline is only used for !SMP. I could add that in for all the arch's spinlock_t in their asm/spinlock.h. I'm not sure how well that would be received to increase the size of everyones spinlock_t even though it would only be when CONFIG_DEBUG_SPINLOCK is on. Thanks, Jake ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-10 18:44 ` Jake Moilanen @ 2004-06-10 19:24 ` Jan-Benedict Glaw 2004-06-10 21:00 ` Randy.Dunlap 0 siblings, 1 reply; 16+ messages in thread From: Jan-Benedict Glaw @ 2004-06-10 19:24 UTC (permalink / raw) To: linux-kernel [-- Attachment #1: Type: text/plain, Size: 1628 bytes --] On Thu, 2004-06-10 13:44:52 -0500, Jake Moilanen <moilanen@austin.ibm.com> wrote in message <1086893091.3476.37.camel@dyn95394175.austin.ibm.com>: > On Sat, 2004-06-05 at 15:51, Jan-Benedict Glaw wrote: > > On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <moilanen@austin.ibm.com> > > wrote in message <1086467486.20906.59.camel@dhcp-client215.upt.austin.ibm.com>: > > > Here's a patch that will 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. > > I like the idea. However, I don't like touching all arch's Kconfig > > files. I think it's better to either put this into ./lib/Kconfig (well, > > doesn't really fit there), ot (even better:) put it into the Debug > > Kconfig file. > > I think you're right that lib/Kconfig would not be the right place, but > I don't think there is a debug Kconfig. I tried keeping the Kconfig Not yet:) Somebody is working towards getting all the different debug options into a central Kconfig file. This was on LKML some four weeks ago... > additions w/ CONFIG_DEBUG_SPINLOCK. The other option is to make a debug > Kconfig, but every arch seems pretty different in what they have for > their debug section. As I said, it's been worked on:) MfG, JBG -- Jan-Benedict Glaw jbglaw@lug-owl.de . +49-172-7608481 "Eine Freie Meinung in einem Freien Kopf | Gegen Zensur | Gegen Krieg fuer einen Freien Staat voll Freier Bürger" | im Internet! | im Irak! ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA)); [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-10 19:24 ` Jan-Benedict Glaw @ 2004-06-10 21:00 ` Randy.Dunlap 0 siblings, 0 replies; 16+ messages in thread From: Randy.Dunlap @ 2004-06-10 21:00 UTC (permalink / raw) To: Jan-Benedict Glaw; +Cc: linux-kernel, moilanen On Thu, 10 Jun 2004 21:24:30 +0200 Jan-Benedict Glaw wrote: | On Thu, 2004-06-10 13:44:52 -0500, Jake Moilanen <moilanen@austin.ibm.com> | wrote in message <1086893091.3476.37.camel@dyn95394175.austin.ibm.com>: | > On Sat, 2004-06-05 at 15:51, Jan-Benedict Glaw wrote: | > > On Sat, 2004-06-05 15:31:26 -0500, Jake Moilanen <moilanen@austin.ibm.com> | > > wrote in message <1086467486.20906.59.camel@dhcp-client215.upt.austin.ibm.com>: | > > > Here's a patch that will 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. | > > I like the idea. However, I don't like touching all arch's Kconfig | > > files. I think it's better to either put this into ./lib/Kconfig (well, | > > doesn't really fit there), ot (even better:) put it into the Debug | > > Kconfig file. | > | > I think you're right that lib/Kconfig would not be the right place, but | > I don't think there is a debug Kconfig. I tried keeping the Kconfig | | Not yet:) Somebody is working towards getting all the different debug | options into a central Kconfig file. This was on LKML some four weeks | ago... | | > additions w/ CONFIG_DEBUG_SPINLOCK. The other option is to make a debug | > Kconfig, but every arch seems pretty different in what they have for | > their debug section. | | As I said, it's been worked on:) Yes, I'll make a new version soon.... -- ~Randy ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-05 20:31 [PATCH][RFC] Spinlock-timeout Jake Moilanen 2004-06-05 20:51 ` Jan-Benedict Glaw @ 2004-06-06 10:13 ` Paul Mackerras 2004-06-06 22:23 ` Benjamin Herrenschmidt 2 siblings, 0 replies; 16+ messages in thread From: Paul Mackerras @ 2004-06-06 10:13 UTC (permalink / raw) To: Jake Moilanen; +Cc: linux-kernel Jake Moilanen writes: > Here's a patch that will 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. [snip] > + if (jiffies >= jiffy_timeout) > + BUG(); Don't you need to use time_after()? Regards, Paul. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-05 20:31 [PATCH][RFC] Spinlock-timeout Jake Moilanen 2004-06-05 20:51 ` Jan-Benedict Glaw 2004-06-06 10:13 ` Paul Mackerras @ 2004-06-06 22:23 ` Benjamin Herrenschmidt 2004-06-11 14:05 ` Jake Moilanen 2004-06-11 14:08 ` Jake Moilanen 2 siblings, 2 replies; 16+ messages in thread From: Benjamin Herrenschmidt @ 2004-06-06 22:23 UTC (permalink / raw) To: Jake Moilanen; +Cc: Linux Kernel list On Sat, 2004-06-05 at 15:31, Jake Moilanen wrote: > Here's a patch that will 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 send comments. It would be better to use the timebase on CPUs that have one, no ? Or you'll miss cases where either irqs are disabled or you are on a code path issued by the timer interrupt, and thus jiffies isn't updated ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-06 22:23 ` Benjamin Herrenschmidt @ 2004-06-11 14:05 ` Jake Moilanen 2004-06-11 15:49 ` Benjamin Herrenschmidt 2004-06-11 14:08 ` Jake Moilanen 1 sibling, 1 reply; 16+ messages in thread From: Jake Moilanen @ 2004-06-11 14:05 UTC (permalink / raw) To: Linux Kernel list Cc: Benjamin Herrenschmidt, Paul Mackerras, Jan-Benedict Glaw [-- Attachment #1: Type: text/plain, Size: 1026 bytes --] On Sun, 2004-06-06 at 17:23, Benjamin Herrenschmidt wrote: > On Sat, 2004-06-05 at 15:31, Jake Moilanen wrote: > > Here's a patch that will 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 send comments. > > It would be better to use the timebase on CPUs that have one, no ? Or > you'll miss cases where either irqs are disabled or you are on a code > path issued by the timer interrupt, and thus jiffies isn't updated Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow archs use their timebases if they have one, and if they don't, it uses jiffies. time_after_eq() is used to do the jiffy checking. I also left all of the arch/*/Kconfig changes in until a debug Kconfig is done. I pretty much added in the spinlock timeout on all archs that have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry. Thanks, Jake [-- Attachment #2: spinlock-timeout-2.6-v2.patch --] [-- Type: text/x-patch, Size: 22734 bytes --] ===== arch/alpha/Kconfig 1.37 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.37_BUiPrR 2004-05-18 15:22:12 +00:00 --- arch/alpha/Kconfig 2004-06-09 16:38:19 +00:00 *************** config DEBUG_SPINLOCK *** 664,669 **** --- 664,683 ---- 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 ===== arch/alpha/defconfig 1.25 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.25_bRXYlh 2004-03-23 18:24:34 +00:00 --- arch/alpha/defconfig 2004-06-09 16:38:20 +00:00 *************** CONFIG_MATHEMU=y *** 868,873 **** --- 868,874 ---- # 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 ===== arch/arm/Kconfig 1.62 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.62_2gdtiH 2004-05-24 11:14:29 +00:00 --- arch/arm/Kconfig 2004-06-09 16:38:20 +00:00 *************** config DEBUG_SPINLOCK *** 728,733 **** --- 728,747 ---- 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 ===== arch/arm/defconfig 1.5 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.5_HTP3h7 2003-08-02 19:59:32 +00:00 --- arch/arm/defconfig 2004-06-09 16:38:20 +00:00 *************** CONFIG_FRAME_POINTER=y *** 507,511 **** --- 507,512 ---- 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 ===== arch/arm26/Kconfig 1.12 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.12_fHaOkx 2004-03-13 11:47:59 +00:00 --- arch/arm26/Kconfig 2004-06-09 16:38:20 +00:00 *************** config DEBUG_SPINLOCK *** 284,289 **** --- 284,303 ---- 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 ===== arch/arm26/defconfig 1.3 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.3_BiEksX 2004-03-25 17:57:00 +00:00 --- arch/arm26/defconfig 2004-06-09 16:38:21 +00:00 *************** CONFIG_DEBUG_KERNEL=y *** 344,349 **** --- 344,350 ---- 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 ===== arch/i386/Kconfig 1.122 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.122_GpRUBn 2004-06-03 08:46:43 +00:00 --- arch/i386/Kconfig 2004-06-09 16:38:21 +00:00 *************** config DEBUG_SPINLOCK *** 1247,1252 **** --- 1247,1266 ---- 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 ===== arch/i386/defconfig 1.112 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.112_lLqTPN 2004-06-07 13:29:17 +00:00 --- arch/i386/defconfig 2004-06-09 16:38:21 +00:00 *************** CONFIG_OPROFILE=y *** 1220,1225 **** --- 1220,1226 ---- # 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_4KSTACKS=y CONFIG_X86_FIND_SMP_CONFIG=y ===== arch/ia64/Kconfig 1.74 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.74_cbpL7d 2004-05-24 23:05:32 +00:00 --- arch/ia64/Kconfig 2004-06-09 16:38:21 +00:00 *************** config DEBUG_SPINLOCK_SLEEP *** 468,473 **** --- 468,487 ---- 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 ===== arch/ia64/defconfig 1.30 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.30_JLmbuE 2004-05-21 21:03:19 +00:00 --- arch/ia64/defconfig 2004-06-09 16:38:22 +00:00 *************** CONFIG_MAGIC_SYSRQ=y *** 1089,1094 **** --- 1089,1095 ---- # 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 ===== arch/mips/Kconfig 1.26 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.26_TFCFU4 2004-05-10 11:25:30 +00:00 --- arch/mips/Kconfig 2004-06-09 16:38:22 +00:00 *************** config DEBUG_SPINLOCK_SLEEP *** 1360,1365 **** --- 1360,1379 ---- 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 ===== arch/mips/defconfig 1.11 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.11_dfmkrv 2004-05-10 11:25:30 +00:00 --- arch/mips/defconfig 2004-06-09 16:38:22 +00:00 *************** CONFIG_CPU_HAS_LLDSCD=y *** 125,130 **** --- 125,131 ---- 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) ===== arch/ppc/Kconfig 1.64 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.64_vJsX1V 2004-05-31 12:28:12 +00:00 --- arch/ppc/Kconfig 2004-06-09 16:38:22 +00:00 *************** config DEBUG_SPINLOCK_SLEEP *** 1199,1204 **** --- 1199,1218 ---- 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 ===== arch/ppc/defconfig 1.28 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.28_40DsJm 2004-05-18 14:48:09 +00:00 --- arch/ppc/defconfig 2004-06-09 16:38:23 +00:00 *************** CONFIG_ZLIB_DEFLATE=y *** 1318,1323 **** --- 1318,1324 ---- # Kernel hacking # # CONFIG_DEBUG_KERNEL is not set + # CONFIG_SPINLOCK_TIMEOUT is not set CONFIG_BOOTX_TEXT=y # ===== arch/ppc64/Kconfig 1.56 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.56_5CbvuN 2004-05-25 07:31:51 +00:00 --- arch/ppc64/Kconfig 2004-06-09 16:38:23 +00:00 *************** config MAGIC_SYSRQ *** 387,392 **** --- 387,406 ---- 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 ===== arch/ppc64/defconfig 1.37 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.37_O87Bje 2004-03-31 22:27:07 +00:00 --- arch/ppc64/defconfig 2004-06-09 16:38:23 +00:00 *************** CONFIG_DEBUG_STACKOVERFLOW=y *** 1054,1059 **** --- 1054,1060 ---- 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 ===== arch/s390/Kconfig 1.27 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.27_xMQxUo 2004-04-29 09:41:09 +00:00 --- arch/s390/Kconfig 2004-06-09 16:38:25 +00:00 *************** config DEBUG_SPINLOCK_SLEEP *** 423,428 **** --- 423,442 ---- 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" ===== arch/s390/defconfig 1.45 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.45_TiY8TP 2004-06-03 08:46:41 +00:00 --- arch/s390/defconfig 2004-06-09 16:38:25 +00:00 *************** CONFIG_MAGIC_SYSRQ=y *** 474,479 **** --- 474,480 ---- # 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 ===== arch/sh/Kconfig 1.29 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.29_YVtFVg 2004-03-23 10:05:27 +00:00 --- arch/sh/Kconfig 2004-06-09 16:38:25 +00:00 *************** config DEBUG_SPINLOCK *** 675,680 **** --- 675,694 ---- 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 ===== arch/sh/defconfig 1.9 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.9_Rt2WZH 2004-03-23 18:18:46 +00:00 --- arch/sh/defconfig 2004-06-09 16:38:25 +00:00 *************** CONFIG_MSDOS_PARTITION=y *** 351,356 **** --- 351,357 ---- # # 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 ===== arch/sparc/Kconfig 1.28 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.28_iel758 2004-03-19 06:04:54 +00:00 --- arch/sparc/Kconfig 2004-06-09 16:38:26 +00:00 *************** config DEBUG_SPINLOCK_SLEEP *** 440,445 **** --- 440,459 ---- 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 ===== arch/sparc/defconfig 1.19 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.19_L7AnfA 2004-03-31 06:40:57 +00:00 --- arch/sparc/defconfig 2004-06-09 16:38:26 +00:00 *************** CONFIG_DEBUG_KERNEL=y *** 611,616 **** --- 611,617 ---- # 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 ===== arch/sparc64/Kconfig 1.52 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.52_VPYCq1 2004-05-24 17:09:14 +00:00 --- arch/sparc64/Kconfig 2004-06-09 16:38:26 +00:00 *************** config DEBUG_SPINLOCK_SLEEP *** 658,663 **** --- 658,677 ---- 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 ===== arch/sparc64/defconfig 1.128 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.128_DpO8Es 2004-06-03 21:54:05 +00:00 --- arch/sparc64/defconfig 2004-06-09 16:38:26 +00:00 *************** CONFIG_DEBUG_KERNEL=y *** 1727,1732 **** --- 1727,1733 ---- 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 ===== arch/um/Kconfig 1.14 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.14_MUJWWT 2004-04-12 17:53:57 +00:00 --- arch/um/Kconfig 2004-06-09 16:38:27 +00:00 *************** config DEBUG_SLAB *** 222,227 **** --- 222,241 ---- 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 ===== arch/um/defconfig 1.8 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.8_hSaMgl 2003-06-20 20:19:15 +00:00 --- arch/um/defconfig 2004-06-09 16:38:27 +00:00 *************** CONFIG_MTD_BLKMTD=m *** 399,404 **** --- 399,405 ---- # # 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 ===== arch/x86_64/Kconfig 1.51 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_Kconfig-1.51_34XYCM 2004-05-15 13:32:23 +00:00 --- arch/x86_64/Kconfig 2004-06-09 16:38:27 +00:00 *************** config DEBUG_SPINLOCK *** 436,441 **** --- 436,455 ---- 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 ===== arch/x86_64/defconfig 1.39 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_defconfig-1.39_kfNq3d 2004-06-05 07:25:22 +00:00 --- arch/x86_64/defconfig 2004-06-09 16:38:27 +00:00 *************** CONFIG_DEBUG_KERNEL=y *** 910,915 **** --- 910,916 ---- # 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 ===== include/linux/jiffies.h 1.9 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_jiffies.h-1.9_ezvDfY 2003-12-29 21:38:06 +00:00 --- include/linux/jiffies.h 2004-06-09 16:38:29 +00:00 *************** *** 3,10 **** #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 */ --- 3,8 ---- ===== include/linux/spinlock.h 1.28 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_spinlock.h-1.28_TZkdjr 2004-05-10 11:25:44 +00:00 --- include/linux/spinlock.h 2004-06-10 14:17:37 +00:00 *************** *** 38,43 **** --- 38,69 ---- #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 a get_tb() that can pull from the + * hardware for the time update. + */ + #ifdef HAVE_ARCH_GET_TB + #include <asm/time.h> + #define get_spinlock_timeout() (get_tb() + (tb_ticks_per_jiffy * SPINLOCK_TIMEOUT * HZ)) + #define check_spinlock_timeout(timeout) (get_tb() >= timeout ? 1 : 0) + + #else /* HAVE_ARCH_GET_TB */ + + #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ)) + #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout)) + #endif /* HAVE_ARCH_GET_TB */ + + #endif /* CONFIG_SPINLOCK_TIMEOUT */ + + #else #define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock) *************** do { \ *** 218,228 **** --- 244,270 ---- } 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 { \ ===== kernel/sched.c 1.309 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_sched.c-1.309_8DCjsU 2004-06-06 00:00:00 +00:00 --- kernel/sched.c 2004-06-10 15:13:16 +00:00 *************** EXPORT_SYMBOL(__might_sleep); *** 3998,4011 **** */ void __sched __preempt_spin_lock(spinlock_t *lock) { if (preempt_count() > 1) { _raw_spin_lock(lock); return; } do { preempt_enable(); ! while (spin_is_locked(lock)) cpu_relax(); preempt_disable(); } while (!_raw_spin_trylock(lock)); } --- 3998,4020 ---- */ 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)) { ! #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] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-11 14:05 ` Jake Moilanen @ 2004-06-11 15:49 ` Benjamin Herrenschmidt 2004-06-11 21:19 ` moilanen 2004-06-11 21:22 ` moilanen 0 siblings, 2 replies; 16+ messages in thread From: Benjamin Herrenschmidt @ 2004-06-11 15:49 UTC (permalink / raw) To: Jake Moilanen; +Cc: Linux Kernel list, Paul Mackerras, Jan-Benedict Glaw > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow > archs use their timebases if they have one, and if they don't, it uses > jiffies. time_after_eq() is used to do the jiffy checking. > > I also left all of the arch/*/Kconfig changes in until a debug Kconfig > is done. I pretty much added in the spinlock timeout on all archs that > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry. Nah, that's not how the abstraction should be done. Much simpler in fact. Just do something like this in the generic code: #ifndef ARCH_HAS_SPINLOCK_TIMEOUT #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ)) #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout)) #endif That's all. Then, any arch who has it's own implementation of these 2 function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the way it wants. We shouldn't let anything like get_tb() slip into a common file, it's totally PPC specific. Other archs may have different counters they can use to impement the same thing. That part should be entirely self contained in asm-xxx Ben. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-11 15:49 ` Benjamin Herrenschmidt @ 2004-06-11 21:19 ` moilanen 2004-06-11 22:08 ` Benjamin Herrenschmidt 2004-06-11 21:22 ` moilanen 1 sibling, 1 reply; 16+ messages in thread From: moilanen @ 2004-06-11 21:19 UTC (permalink / raw) To: Benjamin Herrenschmidt Cc: Andrew Morton, Linus Torvalds, Linux Kernel list, Paul Mackerras, Jan-Benedict Glaw > > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow > > archs use their timebases if they have one, and if they don't, it uses > > jiffies. time_after_eq() is used to do the jiffy checking. > > > > I also left all of the arch/*/Kconfig changes in until a debug Kconfig > > is done. I pretty much added in the spinlock timeout on all archs that > > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry. > > Nah, that's not how the abstraction should be done. Much simpler in > fact. Just do something like this in the generic code: > > #ifndef ARCH_HAS_SPINLOCK_TIMEOUT > #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ)) > #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout)) > #endif > > That's all. Then, any arch who has it's own implementation of these 2 > function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the > way it wants. We shouldn't let anything like get_tb() slip into a common > file, it's totally PPC specific. Other archs may have different counters > they can use to impement the same thing. That part should be entirely > self contained in asm-xxx That's much better. Here's hopefully a version that could be merged. Thanks, Jake ===== arch/alpha/Kconfig 1.37 vs edited ===== *** /tmp/Kconfig-1.37-23470 Tue May 18 10:22:12 2004 --- arch/alpha/Kconfig Fri Jun 11 10:56:36 2004 *************** config DEBUG_SPINLOCK *** 664,669 **** --- 664,683 ---- 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 ===== arch/alpha/defconfig 1.25 vs edited ===== *** /tmp/defconfig-1.25-23470 Tue Mar 23 12:24:34 2004 --- arch/alpha/defconfig Fri Jun 11 10:56:36 2004 *************** CONFIG_MATHEMU=y *** 868,873 **** --- 868,874 ---- # 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 ===== arch/arm/Kconfig 1.62 vs edited ===== *** /tmp/Kconfig-1.62-23470 Mon May 24 06:14:29 2004 --- arch/arm/Kconfig Fri Jun 11 10:56:37 2004 *************** config DEBUG_SPINLOCK *** 728,733 **** --- 728,747 ---- 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 ===== arch/arm/defconfig 1.5 vs edited ===== *** /tmp/defconfig-1.5-23470 Sat Aug 2 14:59:32 2003 --- arch/arm/defconfig Fri Jun 11 10:56:37 2004 *************** CONFIG_FRAME_POINTER=y *** 507,511 **** --- 507,512 ---- 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 ===== arch/arm26/Kconfig 1.12 vs edited ===== *** /tmp/Kconfig-1.12-23470 Sat Mar 13 05:47:59 2004 --- arch/arm26/Kconfig Fri Jun 11 10:56:37 2004 *************** config DEBUG_SPINLOCK *** 284,289 **** --- 284,303 ---- 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 ===== arch/arm26/defconfig 1.3 vs edited ===== *** /tmp/defconfig-1.3-23470 Thu Mar 25 11:57:00 2004 --- arch/arm26/defconfig Fri Jun 11 10:56:37 2004 *************** CONFIG_DEBUG_KERNEL=y *** 344,349 **** --- 344,350 ---- 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 ===== arch/i386/Kconfig 1.122 vs edited ===== *** /tmp/Kconfig-1.122-23470 Thu Jun 3 03:46:43 2004 --- arch/i386/Kconfig Fri Jun 11 10:56:38 2004 *************** config DEBUG_SPINLOCK *** 1247,1252 **** --- 1247,1266 ---- 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 ===== arch/i386/defconfig 1.112 vs edited ===== *** /tmp/defconfig-1.112-23470 Mon Jun 7 08:29:17 2004 --- arch/i386/defconfig Fri Jun 11 10:56:38 2004 *************** CONFIG_OPROFILE=y *** 1220,1225 **** --- 1220,1226 ---- # 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_4KSTACKS=y CONFIG_X86_FIND_SMP_CONFIG=y ===== arch/ia64/Kconfig 1.74 vs edited ===== *** /tmp/Kconfig-1.74-23470 Mon May 24 18:05:32 2004 --- arch/ia64/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SPINLOCK_SLEEP *** 468,473 **** --- 468,487 ---- 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 ===== arch/ia64/defconfig 1.30 vs edited ===== *** /tmp/defconfig-1.30-23470 Fri May 21 16:03:19 2004 --- arch/ia64/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_MAGIC_SYSRQ=y *** 1089,1094 **** --- 1089,1095 ---- # 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 ===== arch/mips/Kconfig 1.26 vs edited ===== *** /tmp/Kconfig-1.26-23470 Mon May 10 06:25:30 2004 --- arch/mips/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SPINLOCK_SLEEP *** 1360,1365 **** --- 1360,1379 ---- 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 ===== arch/mips/defconfig 1.11 vs edited ===== *** /tmp/defconfig-1.11-23470 Mon May 10 06:25:30 2004 --- arch/mips/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_CPU_HAS_LLDSCD=y *** 125,130 **** --- 125,131 ---- 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) ===== arch/ppc/Kconfig 1.64 vs edited ===== *** /tmp/Kconfig-1.64-23470 Mon May 31 07:28:12 2004 --- arch/ppc/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SPINLOCK_SLEEP *** 1199,1204 **** --- 1199,1218 ---- 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 ===== arch/ppc/defconfig 1.28 vs edited ===== *** /tmp/defconfig-1.28-23470 Tue May 18 09:48:09 2004 --- arch/ppc/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_ZLIB_DEFLATE=y *** 1318,1323 **** --- 1318,1324 ---- # Kernel hacking # # CONFIG_DEBUG_KERNEL is not set + # CONFIG_SPINLOCK_TIMEOUT is not set CONFIG_BOOTX_TEXT=y # ===== arch/ppc64/Kconfig 1.56 vs edited ===== *** /tmp/Kconfig-1.56-23470 Tue May 25 02:31:51 2004 --- arch/ppc64/Kconfig Fri Jun 11 10:56:39 2004 *************** config MAGIC_SYSRQ *** 387,392 **** --- 387,406 ---- 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 ===== arch/ppc64/defconfig 1.37 vs edited ===== *** /tmp/defconfig-1.37-23470 Wed Mar 31 16:27:07 2004 --- arch/ppc64/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_DEBUG_STACKOVERFLOW=y *** 1054,1059 **** --- 1054,1060 ---- 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 ===== arch/s390/Kconfig 1.27 vs edited ===== *** /tmp/Kconfig-1.27-23470 Thu Apr 29 04:41:09 2004 --- arch/s390/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SPINLOCK_SLEEP *** 423,428 **** --- 423,442 ---- 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" ===== arch/s390/defconfig 1.45 vs edited ===== *** /tmp/defconfig-1.45-23470 Thu Jun 3 03:46:41 2004 --- arch/s390/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_MAGIC_SYSRQ=y *** 474,479 **** --- 474,480 ---- # 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 ===== arch/sh/Kconfig 1.29 vs edited ===== *** /tmp/Kconfig-1.29-23470 Tue Mar 23 04:05:27 2004 --- arch/sh/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SPINLOCK *** 675,680 **** --- 675,694 ---- 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 ===== arch/sh/defconfig 1.9 vs edited ===== *** /tmp/defconfig-1.9-23470 Tue Mar 23 12:18:46 2004 --- arch/sh/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_MSDOS_PARTITION=y *** 351,356 **** --- 351,357 ---- # # 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 ===== arch/sparc/Kconfig 1.28 vs edited ===== *** /tmp/Kconfig-1.28-23470 Fri Mar 19 00:04:54 2004 --- arch/sparc/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SPINLOCK_SLEEP *** 440,445 **** --- 440,459 ---- 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 ===== arch/sparc/defconfig 1.19 vs edited ===== *** /tmp/defconfig-1.19-23470 Wed Mar 31 00:40:57 2004 --- arch/sparc/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_DEBUG_KERNEL=y *** 611,616 **** --- 611,617 ---- # 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 ===== arch/sparc64/Kconfig 1.52 vs edited ===== *** /tmp/Kconfig-1.52-23470 Mon May 24 12:09:14 2004 --- arch/sparc64/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SPINLOCK_SLEEP *** 658,663 **** --- 658,677 ---- 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 ===== arch/sparc64/defconfig 1.128 vs edited ===== *** /tmp/defconfig-1.128-23470 Thu Jun 3 16:54:05 2004 --- arch/sparc64/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_DEBUG_KERNEL=y *** 1727,1732 **** --- 1727,1733 ---- 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 ===== arch/um/Kconfig 1.14 vs edited ===== *** /tmp/Kconfig-1.14-23470 Mon Apr 12 12:53:57 2004 --- arch/um/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SLAB *** 222,227 **** --- 222,241 ---- 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 ===== arch/um/defconfig 1.8 vs edited ===== *** /tmp/defconfig-1.8-23470 Fri Jun 20 15:19:15 2003 --- arch/um/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_MTD_BLKMTD=m *** 399,404 **** --- 399,405 ---- # # 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 ===== arch/x86_64/Kconfig 1.51 vs edited ===== *** /tmp/Kconfig-1.51-23470 Sat May 15 08:32:23 2004 --- arch/x86_64/Kconfig Fri Jun 11 10:56:39 2004 *************** config DEBUG_SPINLOCK *** 436,441 **** --- 436,455 ---- 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 ===== arch/x86_64/defconfig 1.39 vs edited ===== *** /tmp/defconfig-1.39-23470 Sat Jun 5 02:25:22 2004 --- arch/x86_64/defconfig Fri Jun 11 10:56:39 2004 *************** CONFIG_DEBUG_KERNEL=y *** 910,915 **** --- 910,916 ---- # 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 ===== include/linux/jiffies.h 1.9 vs edited ===== *** /tmp/jiffies.h-1.9-23470 Mon Dec 29 15:38:06 2003 --- include/linux/jiffies.h Fri Jun 11 10:56:40 2004 *************** *** 3,10 **** #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 */ --- 3,8 ---- ===== include/linux/spinlock.h 1.28 vs edited ===== *** /tmp/spinlock.h-1.28-23470 Mon May 10 06:25:44 2004 --- include/linux/spinlock.h Fri Jun 11 11:02:53 2004 *************** *** 38,43 **** --- 38,62 ---- #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 #define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock) *************** do { \ *** 218,228 **** --- 237,263 ---- } 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 { \ ===== kernel/sched.c 1.309 vs edited ===== *** /tmp/sched.c-1.309-23470 Sat Jun 5 19:00:00 2004 --- kernel/sched.c Fri Jun 11 10:56:40 2004 *************** EXPORT_SYMBOL(__might_sleep); *** 3998,4011 **** */ void __sched __preempt_spin_lock(spinlock_t *lock) { if (preempt_count() > 1) { _raw_spin_lock(lock); return; } do { preempt_enable(); ! while (spin_is_locked(lock)) cpu_relax(); preempt_disable(); } while (!_raw_spin_trylock(lock)); } --- 3998,4020 ---- */ 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)) { ! #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] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-11 21:19 ` moilanen @ 2004-06-11 22:08 ` Benjamin Herrenschmidt 2004-06-14 13:12 ` Jake Moilanen 0 siblings, 1 reply; 16+ messages in thread From: Benjamin Herrenschmidt @ 2004-06-11 22:08 UTC (permalink / raw) To: moilanen Cc: Andrew Morton, Linus Torvalds, Linux Kernel list, Paul Mackerras, Jan-Benedict Glaw On Fri, 2004-06-11 at 16:19, moilanen@austin.ibm.com wrote: > > > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow > > > archs use their timebases if they have one, and if they don't, it uses > > > jiffies. time_after_eq() is used to do the jiffy checking. > > > > > > I also left all of the arch/*/Kconfig changes in until a debug Kconfig > > > is done. I pretty much added in the spinlock timeout on all archs that > > > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry. > > > > Nah, that's not how the abstraction should be done. Much simpler in > > fact. Just do something like this in the generic code: > > > > #ifndef ARCH_HAS_SPINLOCK_TIMEOUT > > #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ)) > > #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout)) > > #endif > > > > That's all. Then, any arch who has it's own implementation of these 2 > > function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the > > way it wants. We shouldn't let anything like get_tb() slip into a common > > file, it's totally PPC specific. Other archs may have different counters > > they can use to impement the same thing. That part should be entirely > > self contained in asm-xxx > > That's much better. Here's hopefully a version that could be merged. Hehe, almost ;) There's a bit of non-unified diff at the end ... Ben. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-11 22:08 ` Benjamin Herrenschmidt @ 2004-06-14 13:12 ` Jake Moilanen 0 siblings, 0 replies; 16+ messages in thread From: Jake Moilanen @ 2004-06-14 13:12 UTC (permalink / raw) To: Benjamin Herrenschmidt Cc: Andrew Morton, Linus Torvalds, Linux Kernel list, Paul Mackerras, Jan-Benedict Glaw > On Fri, 2004-06-11 at 16:19, moilanen@austin.ibm.com wrote: > > > > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow > > > > archs use their timebases if they have one, and if they don't, it uses > > > > jiffies. time_after_eq() is used to do the jiffy checking. > > > > > > > > I also left all of the arch/*/Kconfig changes in until a debug Kconfig > > > > is done. I pretty much added in the spinlock timeout on all archs that > > > > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry. > > > > > > Nah, that's not how the abstraction should be done. Much simpler in > > > fact. Just do something like this in the generic code: > > > > > > #ifndef ARCH_HAS_SPINLOCK_TIMEOUT > > > #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ)) > > > #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout)) > > > #endif > > > > > > That's all. Then, any arch who has it's own implementation of these 2 > > > function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the > > > way it wants. We shouldn't let anything like get_tb() slip into a common > > > file, it's totally PPC specific. Other archs may have different counters > > > they can use to impement the same thing. That part should be entirely > > > self contained in asm-xxx > > > > That's much better. Here's hopefully a version that could be merged. > > Hehe, almost ;) There's a bit of non-unified diff at the end ... Hmm...not sure how that extra -p option got in there. I did it twice! Here's the unified version. diff -Nru a/arch/alpha/Kconfig b/arch/alpha/Kconfig --- a/arch/alpha/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/alpha/Kconfig Mon Jun 14 08:05:25 2004 @@ -664,6 +664,20 @@ 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 -Nru a/arch/alpha/defconfig b/arch/alpha/defconfig --- a/arch/alpha/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/alpha/defconfig Mon Jun 14 08:05:25 2004 @@ -868,6 +868,7 @@ # 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 -Nru a/arch/arm/Kconfig b/arch/arm/Kconfig --- a/arch/arm/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/arm/Kconfig Mon Jun 14 08:05:25 2004 @@ -728,6 +728,20 @@ 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 -Nru a/arch/arm/defconfig b/arch/arm/defconfig --- a/arch/arm/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/arm/defconfig Mon Jun 14 08:05:25 2004 @@ -507,5 +507,6 @@ 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 -Nru a/arch/arm26/Kconfig b/arch/arm26/Kconfig --- a/arch/arm26/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/arm26/Kconfig Mon Jun 14 08:05:25 2004 @@ -284,6 +284,20 @@ 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 -Nru a/arch/arm26/defconfig b/arch/arm26/defconfig --- a/arch/arm26/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/arm26/defconfig Mon Jun 14 08:05:25 2004 @@ -344,6 +344,7 @@ 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 -Nru a/arch/i386/Kconfig b/arch/i386/Kconfig --- a/arch/i386/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/i386/Kconfig Mon Jun 14 08:05:25 2004 @@ -1247,6 +1247,20 @@ 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 -Nru a/arch/i386/defconfig b/arch/i386/defconfig --- a/arch/i386/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/i386/defconfig Mon Jun 14 08:05:25 2004 @@ -1220,6 +1220,7 @@ # 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_4KSTACKS=y CONFIG_X86_FIND_SMP_CONFIG=y diff -Nru a/arch/ia64/Kconfig b/arch/ia64/Kconfig --- a/arch/ia64/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/ia64/Kconfig Mon Jun 14 08:05:25 2004 @@ -468,6 +468,20 @@ 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 -Nru a/arch/ia64/defconfig b/arch/ia64/defconfig --- a/arch/ia64/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/ia64/defconfig Mon Jun 14 08:05:25 2004 @@ -1089,6 +1089,7 @@ # 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 -Nru a/arch/mips/Kconfig b/arch/mips/Kconfig --- a/arch/mips/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/mips/Kconfig Mon Jun 14 08:05:25 2004 @@ -1360,6 +1360,20 @@ 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 -Nru a/arch/mips/defconfig b/arch/mips/defconfig --- a/arch/mips/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/mips/defconfig Mon Jun 14 08:05:25 2004 @@ -125,6 +125,7 @@ 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 -Nru a/arch/ppc/Kconfig b/arch/ppc/Kconfig --- a/arch/ppc/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/ppc/Kconfig Mon Jun 14 08:05:25 2004 @@ -1199,6 +1199,20 @@ 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 -Nru a/arch/ppc/defconfig b/arch/ppc/defconfig --- a/arch/ppc/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/ppc/defconfig Mon Jun 14 08:05:25 2004 @@ -1318,6 +1318,7 @@ # Kernel hacking # # CONFIG_DEBUG_KERNEL is not set +# CONFIG_SPINLOCK_TIMEOUT is not set CONFIG_BOOTX_TEXT=y # diff -Nru a/arch/ppc64/Kconfig b/arch/ppc64/Kconfig --- a/arch/ppc64/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/ppc64/Kconfig Mon Jun 14 08:05:25 2004 @@ -387,6 +387,20 @@ 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 -Nru a/arch/ppc64/defconfig b/arch/ppc64/defconfig --- a/arch/ppc64/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/ppc64/defconfig Mon Jun 14 08:05:25 2004 @@ -1054,6 +1054,7 @@ 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 -Nru a/arch/s390/Kconfig b/arch/s390/Kconfig --- a/arch/s390/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/s390/Kconfig Mon Jun 14 08:05:25 2004 @@ -423,6 +423,20 @@ 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 -Nru a/arch/s390/defconfig b/arch/s390/defconfig --- a/arch/s390/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/s390/defconfig Mon Jun 14 08:05:25 2004 @@ -474,6 +474,7 @@ # 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 -Nru a/arch/sh/Kconfig b/arch/sh/Kconfig --- a/arch/sh/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/sh/Kconfig Mon Jun 14 08:05:25 2004 @@ -675,6 +675,20 @@ 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 -Nru a/arch/sh/defconfig b/arch/sh/defconfig --- a/arch/sh/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/sh/defconfig Mon Jun 14 08:05:25 2004 @@ -351,6 +351,7 @@ # # 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 -Nru a/arch/sparc/Kconfig b/arch/sparc/Kconfig --- a/arch/sparc/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/sparc/Kconfig Mon Jun 14 08:05:25 2004 @@ -440,6 +440,20 @@ 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 -Nru a/arch/sparc/defconfig b/arch/sparc/defconfig --- a/arch/sparc/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/sparc/defconfig Mon Jun 14 08:05:25 2004 @@ -611,6 +611,7 @@ # 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 -Nru a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig --- a/arch/sparc64/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/sparc64/Kconfig Mon Jun 14 08:05:25 2004 @@ -658,6 +658,20 @@ 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 -Nru a/arch/sparc64/defconfig b/arch/sparc64/defconfig --- a/arch/sparc64/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/sparc64/defconfig Mon Jun 14 08:05:25 2004 @@ -1727,6 +1727,7 @@ 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 -Nru a/arch/um/Kconfig b/arch/um/Kconfig --- a/arch/um/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/um/Kconfig Mon Jun 14 08:05:25 2004 @@ -222,6 +222,20 @@ 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 -Nru a/arch/um/defconfig b/arch/um/defconfig --- a/arch/um/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/um/defconfig Mon Jun 14 08:05:25 2004 @@ -399,6 +399,7 @@ # # 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 -Nru a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig --- a/arch/x86_64/Kconfig Mon Jun 14 08:05:25 2004 +++ b/arch/x86_64/Kconfig Mon Jun 14 08:05:25 2004 @@ -436,6 +436,20 @@ 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 -Nru a/arch/x86_64/defconfig b/arch/x86_64/defconfig --- a/arch/x86_64/defconfig Mon Jun 14 08:05:25 2004 +++ b/arch/x86_64/defconfig Mon Jun 14 08:05:25 2004 @@ -910,6 +910,7 @@ # 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 -Nru a/include/linux/jiffies.h b/include/linux/jiffies.h --- a/include/linux/jiffies.h Mon Jun 14 08:05:25 2004 +++ b/include/linux/jiffies.h Mon Jun 14 08:05:25 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 -Nru a/include/linux/spinlock.h b/include/linux/spinlock.h --- a/include/linux/spinlock.h Mon Jun 14 08:05:25 2004 +++ b/include/linux/spinlock.h Mon Jun 14 08:05:25 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 #define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock) @@ -218,11 +237,27 @@ } 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 { \ diff -Nru a/kernel/sched.c b/kernel/sched.c --- a/kernel/sched.c Mon Jun 14 08:05:25 2004 +++ b/kernel/sched.c Mon Jun 14 08:05:25 2004 @@ -3998,14 +3998,23 @@ */ 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] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-11 15:49 ` Benjamin Herrenschmidt 2004-06-11 21:19 ` moilanen @ 2004-06-11 21:22 ` moilanen 2004-06-11 22:09 ` Benjamin Herrenschmidt 1 sibling, 1 reply; 16+ messages in thread From: moilanen @ 2004-06-11 21:22 UTC (permalink / raw) To: Benjamin Herrenschmidt Cc: Andrew Morton, Linus Torvalds, Linux Kernel list, Paul Mackerras, Jan-Benedict Glaw > > Here's a revision to the patch that uses a HAVE_ARCH_GET_TB to allow > > archs use their timebases if they have one, and if they don't, it uses > > jiffies. time_after_eq() is used to do the jiffy checking. > > > > I also left all of the arch/*/Kconfig changes in until a debug Kconfig > > is done. I pretty much added in the spinlock timeout on all archs that > > have CONFIG_DEBUG_SPINLOCK. If I missed your arch, I'm sorry. > > Nah, that's not how the abstraction should be done. Much simpler in > fact. Just do something like this in the generic code: > > #ifndef ARCH_HAS_SPINLOCK_TIMEOUT > #define get_spinlock_timeout() (jiffies + (SPINLOCK_TIMEOUT * HZ)) > #define check_spinlock_timeout(timeout) (time_after_eq(jiffies, timeout)) > #endif > > That's all. Then, any arch who has it's own implementation of these 2 > function will #define ARCH_HAS_SPINLOCK_TIMEOUT and implement them the > way it wants. We shouldn't let anything like get_tb() slip into a common > file, it's totally PPC specific. Other archs may have different counters > they can use to impement the same thing. That part should be entirely > self contained in asm-xxx Here's the ppc64 add-on for using timebase register for the spinlock timeout. If no one has any issues w/ the base spin-lock timeout patch, or this one, please apply. Thanks, Jake ===== arch/ppc64/kernel/chrp_setup.c 1.47 vs edited ===== *** /tmp/chrp_setup.c-1.47-18066 Tue Apr 27 00:07:31 2004 --- arch/ppc64/kernel/chrp_setup.c Fri Jun 11 11:58:11 2004 *************** chrp_progress(char *s, unsigned short he *** 405,414 **** extern void setup_default_decr(void); - /* Some sane defaults: 125 MHz timebase, 1GHz processor */ - #define DEFAULT_TB_FREQ 125000000UL - #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8) - void __init pSeries_calibrate_decr(void) { struct device_node *cpu; --- 405,410 ---- ===== arch/ppc64/kernel/time.c 1.30 vs edited ===== *** /tmp/time.c-1.30-18066 Mon May 31 12:41:03 2004 --- arch/ppc64/kernel/time.c Fri Jun 11 14:19:48 2004 *************** static unsigned long first_settimeofday *** 81,87 **** #define XSEC_PER_SEC (1024*1024) ! unsigned long tb_ticks_per_jiffy; unsigned long tb_ticks_per_usec; unsigned long tb_ticks_per_sec; unsigned long next_xtime_sync_tb; --- 81,87 ---- #define XSEC_PER_SEC (1024*1024) ! unsigned long tb_ticks_per_jiffy = DEFAULT_TB_FREQ / HZ; unsigned long tb_ticks_per_usec; unsigned long tb_ticks_per_sec; unsigned long next_xtime_sync_tb; ===== include/asm-ppc64/processor.h 1.45 vs edited ===== *** /tmp/processor.h-1.45-18066 Tue Jun 1 04:27:47 2004 --- include/asm-ppc64/processor.h Fri Jun 11 11:58:44 2004 *************** GLUE(.,name): *** 440,445 **** --- 440,448 ---- #endif /* __ASSEMBLY__ */ + /* Some sane defaults: 125 MHz timebase, 1GHz processor */ + #define DEFAULT_TB_FREQ 125000000UL + #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8) /* Macros for setting and retrieving special purpose registers */ ===== include/asm-ppc64/spinlock.h 1.10 vs edited ===== *** /tmp/spinlock.h-1.10-18066 Tue May 25 04:53:02 2004 --- include/asm-ppc64/spinlock.h Fri Jun 11 14:30:57 2004 *************** static __inline__ void _raw_write_lock(r *** 278,282 **** --- 278,293 ---- } #endif /* CONFIG_SPINLINE */ + #ifdef CONFIG_SPINLOCK_TIMEOUT + + #define ARCH_HAS_SPINLOCK_TIMEOUT + + extern unsigned long tb_ticks_per_jiffy; + + #define get_spinlock_timeout() (mftb() + (tb_ticks_per_jiffy * SPINLOCK_TIMEOUT * HZ)) + #define check_spinlock_timeout(timeout) (mftb() >= timeout ? 1 : 0) + + #endif /* CONFIG_SPINLOCK_TIMEOUT */ + #endif /* __KERNEL__ */ #endif /* __ASM_SPINLOCK_H */ ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-11 21:22 ` moilanen @ 2004-06-11 22:09 ` Benjamin Herrenschmidt 2004-06-14 13:13 ` Jake Moilanen 0 siblings, 1 reply; 16+ messages in thread From: Benjamin Herrenschmidt @ 2004-06-11 22:09 UTC (permalink / raw) To: moilanen Cc: Andrew Morton, Linus Torvalds, Linux Kernel list, Paul Mackerras, Jan-Benedict Glaw > Here's the ppc64 add-on for using timebase register for the spinlock > timeout. If no one has any issues w/ the base spin-lock timeout patch, or > this one, please apply. Same comment, make sure you produce a unified diff. Ben. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-11 22:09 ` Benjamin Herrenschmidt @ 2004-06-14 13:13 ` Jake Moilanen 0 siblings, 0 replies; 16+ messages in thread From: Jake Moilanen @ 2004-06-14 13:13 UTC (permalink / raw) To: Benjamin Herrenschmidt Cc: Andrew Morton, Linus Torvalds, Linux Kernel list, Paul Mackerras, Jan-Benedict Glaw > > > Here's the ppc64 add-on for using timebase register for the spinlock > > timeout. If no one has any issues w/ the base spin-lock timeout patch, or > > this one, please apply. > > Same comment, make sure you produce a unified diff. Here's the unified ver. diff -Nru a/arch/ppc64/kernel/chrp_setup.c b/arch/ppc64/kernel/chrp_setup.c --- a/arch/ppc64/kernel/chrp_setup.c Mon Jun 14 08:07:11 2004 +++ b/arch/ppc64/kernel/chrp_setup.c Mon Jun 14 08:07:11 2004 @@ -405,10 +405,6 @@ extern void setup_default_decr(void); -/* Some sane defaults: 125 MHz timebase, 1GHz processor */ -#define DEFAULT_TB_FREQ 125000000UL -#define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8) - void __init pSeries_calibrate_decr(void) { struct device_node *cpu; diff -Nru a/arch/ppc64/kernel/time.c b/arch/ppc64/kernel/time.c --- a/arch/ppc64/kernel/time.c Mon Jun 14 08:07:11 2004 +++ b/arch/ppc64/kernel/time.c Mon Jun 14 08:07:11 2004 @@ -81,7 +81,7 @@ #define XSEC_PER_SEC (1024*1024) -unsigned long tb_ticks_per_jiffy; +unsigned long tb_ticks_per_jiffy = DEFAULT_TB_FREQ / HZ; unsigned long tb_ticks_per_usec; unsigned long tb_ticks_per_sec; unsigned long next_xtime_sync_tb; diff -Nru a/include/asm-ppc64/processor.h b/include/asm-ppc64/processor.h --- a/include/asm-ppc64/processor.h Mon Jun 14 08:07:11 2004 +++ b/include/asm-ppc64/processor.h Mon Jun 14 08:07:11 2004 @@ -440,6 +440,9 @@ #endif /* __ASSEMBLY__ */ +/* Some sane defaults: 125 MHz timebase, 1GHz processor */ +#define DEFAULT_TB_FREQ 125000000UL +#define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8) /* Macros for setting and retrieving special purpose registers */ diff -Nru a/include/asm-ppc64/spinlock.h b/include/asm-ppc64/spinlock.h --- a/include/asm-ppc64/spinlock.h Mon Jun 14 08:07:11 2004 +++ b/include/asm-ppc64/spinlock.h Mon Jun 14 08:07:11 2004 @@ -278,5 +278,16 @@ } #endif /* CONFIG_SPINLINE */ +#ifdef CONFIG_SPINLOCK_TIMEOUT + +#define ARCH_HAS_SPINLOCK_TIMEOUT + +extern unsigned long tb_ticks_per_jiffy; + +#define get_spinlock_timeout() (mftb() + (tb_ticks_per_jiffy * SPINLOCK_TIMEOUT * HZ)) +#define check_spinlock_timeout(timeout) (mftb() >= timeout ? 1 : 0) + +#endif /* CONFIG_SPINLOCK_TIMEOUT */ + #endif /* __KERNEL__ */ #endif /* __ASM_SPINLOCK_H */ ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH][RFC] Spinlock-timeout 2004-06-06 22:23 ` Benjamin Herrenschmidt 2004-06-11 14:05 ` Jake Moilanen @ 2004-06-11 14:08 ` Jake Moilanen 1 sibling, 0 replies; 16+ messages in thread From: Jake Moilanen @ 2004-06-11 14:08 UTC (permalink / raw) To: Linux Kernel list Cc: Benjamin Herrenschmidt, Paul Mackerras, Jan-Benedict Glaw [-- Attachment #1: Type: text/plain, Size: 665 bytes --] On Sun, 2004-06-06 at 17:23, Benjamin Herrenschmidt wrote: > On Sat, 2004-06-05 at 15:31, Jake Moilanen wrote: > > Here's a patch that will 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 send comments. > > It would be better to use the timebase on CPUs that have one, no ? Or > you'll miss cases where either irqs are disabled or you are on a code > path issued by the timer interrupt, and thus jiffies isn't updated Here is the ppc64 add-on for the HAVE_ARCH_GET_TB. Thanks, Jake [-- Attachment #2: spinlock-timeout-2.6-v2-ppc64.patch --] [-- Type: text/x-patch, Size: 2750 bytes --] ===== arch/ppc64/kernel/chrp_setup.c 1.47 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_chrp_setup.c-1.47_T8bKaF 2004-04-27 05:07:31 +00:00 --- arch/ppc64/kernel/chrp_setup.c 2004-06-09 16:38:23 +00:00 *************** chrp_progress(char *s, unsigned short he *** 405,414 **** extern void setup_default_decr(void); - /* Some sane defaults: 125 MHz timebase, 1GHz processor */ - #define DEFAULT_TB_FREQ 125000000UL - #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8) - void __init pSeries_calibrate_decr(void) { struct device_node *cpu; --- 405,410 ---- ===== arch/ppc64/kernel/time.c 1.30 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_time.c-1.30_TupeZw 2004-05-31 17:41:03 +00:00 --- arch/ppc64/kernel/time.c 2004-06-09 16:38:24 +00:00 *************** static unsigned long first_settimeofday *** 81,87 **** #define XSEC_PER_SEC (1024*1024) ! unsigned long tb_ticks_per_jiffy; unsigned long tb_ticks_per_usec; unsigned long tb_ticks_per_sec; unsigned long next_xtime_sync_tb; --- 81,87 ---- #define XSEC_PER_SEC (1024*1024) ! unsigned long tb_ticks_per_jiffy = DEFAULT_TB_FREQ / HZ; unsigned long tb_ticks_per_usec; unsigned long tb_ticks_per_sec; unsigned long next_xtime_sync_tb; ===== include/asm-ppc64/eeh.h 1.10 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_eeh.h-1.10_XhZlsA 2004-06-01 09:27:13 +00:00 --- include/asm-ppc64/eeh.h 2004-06-09 16:38:28 +00:00 *************** *** 24,29 **** --- 24,30 ---- #include <linux/init.h> struct pci_dev; + struct device_node; /* I/O addresses are converted to EEH "tokens" such that a driver will cause * a bad page fault if the address is used directly (i.e. these addresses are ===== include/asm-ppc64/processor.h 1.45 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_processor.h-1.45_nCcpY2 2004-06-01 09:27:47 +00:00 --- include/asm-ppc64/processor.h 2004-06-09 16:38:28 +00:00 *************** GLUE(.,name): *** 440,445 **** --- 440,448 ---- #endif /* __ASSEMBLY__ */ + /* Some sane defaults: 125 MHz timebase, 1GHz processor */ + #define DEFAULT_TB_FREQ 125000000UL + #define DEFAULT_PROC_FREQ (DEFAULT_TB_FREQ * 8) /* Macros for setting and retrieving special purpose registers */ ===== include/asm-ppc64/time.h 1.7 vs edited ===== *** /home/moilanen/sbx/linux-2.6/BitKeeper/tmp/bk_time.h-1.7_ZyJHwv 2002-06-10 02:37:26 +00:00 --- include/asm-ppc64/time.h 2004-06-09 16:38:28 +00:00 *************** *** 20,26 **** --- 20,30 ---- #include <asm/processor.h> #include <asm/paca.h> + #ifdef CONFIG_PPC_ISERIES #include <asm/iSeries/HvCall.h> + #endif + + #define HAVE_ARCH_GET_TB /* time.c */ extern unsigned long tb_ticks_per_jiffy; ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2004-06-14 13:14 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-06-05 20:31 [PATCH][RFC] Spinlock-timeout Jake Moilanen 2004-06-05 20:51 ` Jan-Benedict Glaw 2004-06-10 18:44 ` Jake Moilanen 2004-06-10 19:24 ` Jan-Benedict Glaw 2004-06-10 21:00 ` Randy.Dunlap 2004-06-06 10:13 ` Paul Mackerras 2004-06-06 22:23 ` Benjamin Herrenschmidt 2004-06-11 14:05 ` Jake Moilanen 2004-06-11 15:49 ` Benjamin Herrenschmidt 2004-06-11 21:19 ` moilanen 2004-06-11 22:08 ` Benjamin Herrenschmidt 2004-06-14 13:12 ` Jake Moilanen 2004-06-11 21:22 ` moilanen 2004-06-11 22:09 ` Benjamin Herrenschmidt 2004-06-14 13:13 ` Jake Moilanen 2004-06-11 14:08 ` Jake Moilanen
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.