X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fspinlock_debug.c;fp=lib%2Fspinlock_debug.c;h=5cbcb806b08270496d6d62d3eb869699f744ba51;hb=64ba3f394c830ec48a1c31b53dcae312c56f1604;hp=e249970b10b98589402265a87b03389044a57e71;hpb=be1e6109ac94a859551f8e1774eb9a8469fe055c;p=linux-2.6.git diff --git a/lib/spinlock_debug.c b/lib/spinlock_debug.c index e249970b1..5cbcb806b 100644 --- a/lib/spinlock_debug.c +++ b/lib/spinlock_debug.c @@ -6,73 +6,41 @@ * DEBUG_SPINLOCK. */ +#include #include #include -#include #include -#include - -void __spin_lock_init(spinlock_t *lock, const char *name, - struct lock_class_key *key) -{ -#ifdef CONFIG_DEBUG_LOCK_ALLOC - /* - * Make sure we are not reinitializing a held lock: - */ - debug_check_no_locks_freed((void *)lock, sizeof(*lock)); - lockdep_init_map(&lock->dep_map, name, key, 0); -#endif - lock->raw_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; - lock->magic = SPINLOCK_MAGIC; - lock->owner = SPINLOCK_OWNER_INIT; - lock->owner_cpu = -1; -} - -EXPORT_SYMBOL(__spin_lock_init); - -void __rwlock_init(rwlock_t *lock, const char *name, - struct lock_class_key *key) -{ -#ifdef CONFIG_DEBUG_LOCK_ALLOC - /* - * Make sure we are not reinitializing a held lock: - */ - debug_check_no_locks_freed((void *)lock, sizeof(*lock)); - lockdep_init_map(&lock->dep_map, name, key, 0); -#endif - lock->raw_lock = (raw_rwlock_t) __RAW_RW_LOCK_UNLOCKED; - lock->magic = RWLOCK_MAGIC; - lock->owner = SPINLOCK_OWNER_INIT; - lock->owner_cpu = -1; -} - -EXPORT_SYMBOL(__rwlock_init); static void spin_bug(spinlock_t *lock, const char *msg) { + static long print_once = 1; struct task_struct *owner = NULL; - if (!debug_locks_off()) - return; - - if (lock->owner && lock->owner != SPINLOCK_OWNER_INIT) - owner = lock->owner; - printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d (%s)\n", - msg, raw_smp_processor_id(), - current->comm, current->pid, print_tainted()); - printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, " - ".owner_cpu: %d\n", - lock, lock->magic, - owner ? owner->comm : "", - owner ? owner->pid : -1, - lock->owner_cpu); - dump_stack(); + if (xchg(&print_once, 0)) { + if (lock->owner && lock->owner != SPINLOCK_OWNER_INIT) + owner = lock->owner; + printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n", + msg, raw_smp_processor_id(), + current->comm, current->pid); + printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, " + ".owner_cpu: %d\n", + lock, lock->magic, + owner ? owner->comm : "", + owner ? owner->pid : -1, + lock->owner_cpu); + dump_stack(); +#ifdef CONFIG_SMP + /* + * We cannot continue on SMP: + */ +// panic("bad locking"); +#endif + } } #define SPIN_BUG_ON(cond, lock, msg) if (unlikely(cond)) spin_bug(lock, msg) -static inline void -debug_spin_lock_before(spinlock_t *lock) +static inline void debug_spin_lock_before(spinlock_t *lock) { SPIN_BUG_ON(lock->magic != SPINLOCK_MAGIC, lock, "bad magic"); SPIN_BUG_ON(lock->owner == current, lock, "recursion"); @@ -99,22 +67,22 @@ static inline void debug_spin_unlock(spinlock_t *lock) static void __spin_lock_debug(spinlock_t *lock) { - u64 i; - u64 loops = loops_per_jiffy * HZ; int print_once = 1; + u64 i; for (;;) { - for (i = 0; i < loops; i++) { + for (i = 0; i < loops_per_jiffy * HZ; i++) { if (__raw_spin_trylock(&lock->raw_lock)) return; + __delay(1); } /* lockup suspected: */ if (print_once) { print_once = 0; printk(KERN_EMERG "BUG: spinlock lockup on CPU#%d, " - "%s/%d, %p (%s)\n", + "%s/%d, %p\n", raw_smp_processor_id(), current->comm, - current->pid, lock, print_tainted()); + current->pid, lock); dump_stack(); } } @@ -151,13 +119,20 @@ void _raw_spin_unlock(spinlock_t *lock) static void rwlock_bug(rwlock_t *lock, const char *msg) { - if (!debug_locks_off()) - return; - - printk(KERN_EMERG "BUG: rwlock %s on CPU#%d, %s/%d, %p (%s)\n", - msg, raw_smp_processor_id(), current->comm, - current->pid, lock, print_tainted()); - dump_stack(); + static long print_once = 1; + + if (xchg(&print_once, 0)) { + printk(KERN_EMERG "BUG: rwlock %s on CPU#%d, %s/%d, %p\n", + msg, raw_smp_processor_id(), current->comm, + current->pid, lock); + dump_stack(); +#ifdef CONFIG_SMP + /* + * We cannot continue on SMP: + */ + panic("bad locking"); +#endif + } } #define RWLOCK_BUG_ON(cond, lock, msg) if (unlikely(cond)) rwlock_bug(lock, msg) @@ -165,22 +140,22 @@ static void rwlock_bug(rwlock_t *lock, const char *msg) #if 0 /* __write_lock_debug() can lock up - maybe this can too? */ static void __read_lock_debug(rwlock_t *lock) { - u64 i; - u64 loops = loops_per_jiffy * HZ; int print_once = 1; + u64 i; for (;;) { - for (i = 0; i < loops; i++) { + for (i = 0; i < loops_per_jiffy * HZ; i++) { if (__raw_read_trylock(&lock->raw_lock)) return; + __delay(1); } /* lockup suspected: */ if (print_once) { print_once = 0; printk(KERN_EMERG "BUG: read-lock lockup on CPU#%d, " - "%s/%d, %p (%s)\n", + "%s/%d, %p\n", raw_smp_processor_id(), current->comm, - current->pid, lock, print_tainted()); + current->pid, lock); dump_stack(); } } @@ -239,22 +214,22 @@ static inline void debug_write_unlock(rwlock_t *lock) #if 0 /* This can cause lockups */ static void __write_lock_debug(rwlock_t *lock) { - u64 i; - u64 loops = loops_per_jiffy * HZ; int print_once = 1; + u64 i; for (;;) { - for (i = 0; i < loops; i++) { + for (i = 0; i < loops_per_jiffy * HZ; i++) { if (__raw_write_trylock(&lock->raw_lock)) return; + __delay(1); } /* lockup suspected: */ if (print_once) { print_once = 0; printk(KERN_EMERG "BUG: write-lock lockup on CPU#%d, " - "%s/%d, %p (%s)\n", + "%s/%d, %p\n", raw_smp_processor_id(), current->comm, - current->pid, lock, print_tainted()); + current->pid, lock); dump_stack(); } }