ia64/linux-2.6.18-xen.hg

annotate kernel/mutex-debug.c @ 562:66faefe721eb

pvSCSI backend driver

Signed-off-by: Tomonari Horikoshi <t.horikoshi@jp.fujitsu.com>
Signed-off-by: Jun Kamada <kama@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 02 09:58:27 2008 +0100 (2008-06-02)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 * kernel/mutex-debug.c
ian@0 3 *
ian@0 4 * Debugging code for mutexes
ian@0 5 *
ian@0 6 * Started by Ingo Molnar:
ian@0 7 *
ian@0 8 * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
ian@0 9 *
ian@0 10 * lock debugging, locking tree, deadlock detection started by:
ian@0 11 *
ian@0 12 * Copyright (C) 2004, LynuxWorks, Inc., Igor Manyilov, Bill Huey
ian@0 13 * Released under the General Public License (GPL).
ian@0 14 */
ian@0 15 #include <linux/mutex.h>
ian@0 16 #include <linux/sched.h>
ian@0 17 #include <linux/delay.h>
ian@0 18 #include <linux/module.h>
ian@0 19 #include <linux/poison.h>
ian@0 20 #include <linux/spinlock.h>
ian@0 21 #include <linux/kallsyms.h>
ian@0 22 #include <linux/interrupt.h>
ian@0 23 #include <linux/debug_locks.h>
ian@0 24
ian@0 25 #include "mutex-debug.h"
ian@0 26
ian@0 27 /*
ian@0 28 * Must be called with lock->wait_lock held.
ian@0 29 */
ian@0 30 void debug_mutex_set_owner(struct mutex *lock, struct thread_info *new_owner)
ian@0 31 {
ian@0 32 lock->owner = new_owner;
ian@0 33 }
ian@0 34
ian@0 35 void debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter)
ian@0 36 {
ian@0 37 memset(waiter, MUTEX_DEBUG_INIT, sizeof(*waiter));
ian@0 38 waiter->magic = waiter;
ian@0 39 INIT_LIST_HEAD(&waiter->list);
ian@0 40 }
ian@0 41
ian@0 42 void debug_mutex_wake_waiter(struct mutex *lock, struct mutex_waiter *waiter)
ian@0 43 {
ian@0 44 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
ian@0 45 DEBUG_LOCKS_WARN_ON(list_empty(&lock->wait_list));
ian@0 46 DEBUG_LOCKS_WARN_ON(waiter->magic != waiter);
ian@0 47 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
ian@0 48 }
ian@0 49
ian@0 50 void debug_mutex_free_waiter(struct mutex_waiter *waiter)
ian@0 51 {
ian@0 52 DEBUG_LOCKS_WARN_ON(!list_empty(&waiter->list));
ian@0 53 memset(waiter, MUTEX_DEBUG_FREE, sizeof(*waiter));
ian@0 54 }
ian@0 55
ian@0 56 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
ian@0 57 struct thread_info *ti)
ian@0 58 {
ian@0 59 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
ian@0 60
ian@0 61 /* Mark the current thread as blocked on the lock: */
ian@0 62 ti->task->blocked_on = waiter;
ian@0 63 waiter->lock = lock;
ian@0 64 }
ian@0 65
ian@0 66 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
ian@0 67 struct thread_info *ti)
ian@0 68 {
ian@0 69 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
ian@0 70 DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
ian@0 71 DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
ian@0 72 ti->task->blocked_on = NULL;
ian@0 73
ian@0 74 list_del_init(&waiter->list);
ian@0 75 waiter->task = NULL;
ian@0 76 }
ian@0 77
ian@0 78 void debug_mutex_unlock(struct mutex *lock)
ian@0 79 {
ian@0 80 DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
ian@0 81 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
ian@0 82 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
ian@0 83 DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
ian@0 84 }
ian@0 85
ian@0 86 void debug_mutex_init(struct mutex *lock, const char *name,
ian@0 87 struct lock_class_key *key)
ian@0 88 {
ian@0 89 #ifdef CONFIG_DEBUG_LOCK_ALLOC
ian@0 90 /*
ian@0 91 * Make sure we are not reinitializing a held lock:
ian@0 92 */
ian@0 93 debug_check_no_locks_freed((void *)lock, sizeof(*lock));
ian@0 94 lockdep_init_map(&lock->dep_map, name, key);
ian@0 95 #endif
ian@0 96 lock->owner = NULL;
ian@0 97 lock->magic = lock;
ian@0 98 }
ian@0 99
ian@0 100 /***
ian@0 101 * mutex_destroy - mark a mutex unusable
ian@0 102 * @lock: the mutex to be destroyed
ian@0 103 *
ian@0 104 * This function marks the mutex uninitialized, and any subsequent
ian@0 105 * use of the mutex is forbidden. The mutex must not be locked when
ian@0 106 * this function is called.
ian@0 107 */
ian@0 108 void fastcall mutex_destroy(struct mutex *lock)
ian@0 109 {
ian@0 110 DEBUG_LOCKS_WARN_ON(mutex_is_locked(lock));
ian@0 111 lock->magic = NULL;
ian@0 112 }
ian@0 113
ian@0 114 EXPORT_SYMBOL_GPL(mutex_destroy);