diff -ru linux-2.4.6-dist/include/asm-i386/spinlock.h linux-2.4.6-kgdb/include/asm-i386/spinlock.h --- linux-2.4.6-dist/include/asm-i386/spinlock.h Fri May 25 21:01:26 2001 +++ linux-2.4.6-kgdb/include/asm-i386/spinlock.h Wed Aug 1 23:11:51 2001 @@ -1,6 +1,8 @@ #ifndef __ASM_SPINLOCK_H #define __ASM_SPINLOCK_H +#include +#include #include #include #include @@ -12,7 +14,7 @@ * initialize their spinlocks properly, tsk tsk. * Remember to turn this off in 2.4. -ben */ -#define SPINLOCK_DEBUG 0 +#define SPINLOCK_DEBUG 1 /* * Your basic SMP spinlocks, allowing only a single CPU anywhere @@ -22,13 +24,16 @@ volatile unsigned int lock; #if SPINLOCK_DEBUG unsigned magic; + void *last_lock_addr; + void *last_lock_current; + int last_lock_processor; #endif } spinlock_t; #define SPINLOCK_MAGIC 0xdead4ead #if SPINLOCK_DEBUG -#define SPINLOCK_MAGIC_INIT , SPINLOCK_MAGIC +#define SPINLOCK_MAGIC_INIT , SPINLOCK_MAGIC, NULL #else #define SPINLOCK_MAGIC_INIT /* */ #endif @@ -75,6 +80,15 @@ return oldval > 0; } +/* This is here because the definition of smp_processor_id() pulls the + * processor id out of the current task_struct, which is defined in + * linux/sched.h, which includes this file because it declares spinlocks. + * So we can't use smp_processor_id() because task_struct hasn't been + * defined yet. Damn these computers. + */ + +#define my_processor_id (((int *)current)[13]) + static inline void spin_lock(spinlock_t *lock) { #if SPINLOCK_DEBUG @@ -84,10 +98,18 @@ printk("eip: %p\n", &&here); BUG(); } + if (spin_is_locked(lock) + && lock->last_lock_processor == my_processor_id) + BUG(); #endif __asm__ __volatile__( spin_lock_string :"=m" (lock->lock) : : "memory"); +#if SPINLOCK_DEBUG + lock->last_lock_addr = &&here; + lock->last_lock_processor = my_processor_id; + lock->last_lock_current = current; +#endif } static inline void spin_unlock(spinlock_t *lock)