Skip to content

Commit 408894e

Browse files
Ingo MolnarIngo Molnar
authored andcommitted
[PATCH] mutex subsystem, debugging code
mutex implementation - add debugging code. Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Arjan van de Ven <[email protected]>
1 parent f3f54ff commit 408894e

File tree

7 files changed

+637
-0
lines changed

7 files changed

+637
-0
lines changed

include/linux/mutex-debug.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __LINUX_MUTEX_DEBUG_H
2+
#define __LINUX_MUTEX_DEBUG_H
3+
4+
/*
5+
* Mutexes - debugging helpers:
6+
*/
7+
8+
#define __DEBUG_MUTEX_INITIALIZER(lockname) \
9+
, .held_list = LIST_HEAD_INIT(lockname.held_list), \
10+
.name = #lockname , .magic = &lockname
11+
12+
#define mutex_init(sem) __mutex_init(sem, __FUNCTION__)
13+
14+
extern void FASTCALL(mutex_destroy(struct mutex *lock));
15+
16+
extern void mutex_debug_show_all_locks(void);
17+
extern void mutex_debug_show_held_locks(struct task_struct *filter);
18+
extern void mutex_debug_check_no_locks_held(struct task_struct *task);
19+
extern void mutex_debug_check_no_locks_freed(const void *from, const void *to);
20+
21+
#endif

include/linux/sched.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,11 @@ struct task_struct {
817817
/* Protection of proc_dentry: nesting proc_lock, dcache_lock, write_lock_irq(&tasklist_lock); */
818818
spinlock_t proc_lock;
819819

820+
#ifdef CONFIG_DEBUG_MUTEXES
821+
/* mutex deadlock detection */
822+
struct mutex_waiter *blocked_on;
823+
#endif
824+
820825
/* journalling filesystem info */
821826
void *journal_info;
822827

kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
99
rcupdate.o intermodule.o extable.o params.o posix-timers.o \
1010
kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o
1111

12+
obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
1213
obj-$(CONFIG_FUTEX) += futex.o
1314
obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
1415
obj-$(CONFIG_SMP) += cpu.o spinlock.o

kernel/fork.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,10 @@ static task_t *copy_process(unsigned long clone_flags,
979979
}
980980
#endif
981981

982+
#ifdef CONFIG_DEBUG_MUTEXES
983+
p->blocked_on = NULL; /* not blocked yet */
984+
#endif
985+
982986
p->tgid = p->pid;
983987
if (clone_flags & CLONE_THREAD)
984988
p->tgid = current->tgid;

0 commit comments

Comments
 (0)