2 * (C) Copyright 2007-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
13 static spinlock_t __lock
= SPIN_LOCK_UNLOCKED
;
14 static int ldep_enabled
;
20 spin_lock_intsave(&__lock
, &mask
);
22 spin_unlock_intrestore(&__lock
, mask
);
25 static int __get_stack_slot()
29 if (current
->nr_locks
== LDEP_STACK_SIZE
) {
30 con_printf(NULL
, "task '%s' exceeded the number of tracked "
31 "locks (%d)! disabling ldep!\n", current
->name
,
39 static void print_held_locks()
41 struct held_lock
*cur
;
44 con_printf(NULL
, "\nlocks currently held:\n");
45 for(i
=0; i
<current
->nr_locks
; i
++) {
46 cur
= ¤t
->lock_stack
[i
];
47 con_printf(NULL
, " #%d: (%s), at %p\n", i
, cur
->lockname
,
52 void ldep_lock(void *lock
, struct lock_class
*c
, char *lockname
)
54 void *ra
= __builtin_return_address(0);
55 struct held_lock
*cur
;
59 spin_lock_intsave(&__lock
, &mask
);
64 /* ok, no issues, add the lock we're trying to get to the stack */
65 if (__get_stack_slot())
68 cur
= ¤t
->lock_stack
[current
->nr_locks
-1];
71 cur
->lockname
= lockname
;
75 spin_unlock_intrestore(&__lock
, mask
);
78 void ldep_unlock(void *lock
, char *lockname
)
80 void *ra
= __builtin_return_address(0);
81 struct held_lock
*cur
;
86 spin_lock_intsave(&__lock
, &mask
);
91 for(i
=0; i
<current
->nr_locks
; i
++) {
92 cur
= ¤t
->lock_stack
[i
];
93 if (cur
->lock
== lock
)
97 con_printf(NULL
, "task '%s' is trying to release lock it doesn't have:\n",
99 con_printf(NULL
, " (%s), at %p\n", lockname
, ra
);
107 if (i
!= current
->nr_locks
-1)
108 memcpy(¤t
->lock_stack
[i
],
109 ¤t
->lock_stack
[i
+1],
110 current
->nr_locks
- i
- 1);
116 spin_unlock_intrestore(&__lock
, mask
);
121 void *ra
= __builtin_return_address(0);
125 spin_lock_intsave(&__lock
, &mask
);
130 if (!current
->nr_locks
)
133 con_printf(NULL
, "task '%s' is holding a lock when it shouldn't have:\n",
135 con_printf(NULL
, " at %p\n", ra
);
142 spin_unlock_intrestore(&__lock
, mask
);