xref: /linux/include/linux/debug_locks.h (revision 9eeba6138cefc0435695463ddadb0d95e0a6bcd2)
19a11b49aSIngo Molnar #ifndef __LINUX_DEBUG_LOCKING_H
29a11b49aSIngo Molnar #define __LINUX_DEBUG_LOCKING_H
39a11b49aSIngo Molnar 
4ca31e146SEduard - Gabriel Munteanu #include <linux/kernel.h>
5*9eeba613SFrederic Weisbecker #include <asm/atomic.h>
6ca31e146SEduard - Gabriel Munteanu 
79b7f750dSAlexey Dobriyan struct task_struct;
89b7f750dSAlexey Dobriyan 
99a11b49aSIngo Molnar extern int debug_locks;
109a11b49aSIngo Molnar extern int debug_locks_silent;
119a11b49aSIngo Molnar 
12*9eeba613SFrederic Weisbecker 
13*9eeba613SFrederic Weisbecker static inline int __debug_locks_off(void)
14*9eeba613SFrederic Weisbecker {
15*9eeba613SFrederic Weisbecker 	return xchg(&debug_locks, 0);
16*9eeba613SFrederic Weisbecker }
17*9eeba613SFrederic Weisbecker 
189a11b49aSIngo Molnar /*
199a11b49aSIngo Molnar  * Generic 'turn off all lock debugging' function:
209a11b49aSIngo Molnar  */
219a11b49aSIngo Molnar extern int debug_locks_off(void);
229a11b49aSIngo Molnar 
239a11b49aSIngo Molnar #define DEBUG_LOCKS_WARN_ON(c)						\
249a11b49aSIngo Molnar ({									\
259a11b49aSIngo Molnar 	int __ret = 0;							\
269a11b49aSIngo Molnar 									\
2753b9d87fSAndrew Morton 	if (!oops_in_progress && unlikely(c)) {				\
289127d4b1SIngo Molnar 		if (debug_locks_off() && !debug_locks_silent)		\
299a11b49aSIngo Molnar 			WARN_ON(1);					\
309a11b49aSIngo Molnar 		__ret = 1;						\
319a11b49aSIngo Molnar 	}								\
329a11b49aSIngo Molnar 	__ret;								\
339a11b49aSIngo Molnar })
349a11b49aSIngo Molnar 
359a11b49aSIngo Molnar #ifdef CONFIG_SMP
369a11b49aSIngo Molnar # define SMP_DEBUG_LOCKS_WARN_ON(c)			DEBUG_LOCKS_WARN_ON(c)
379a11b49aSIngo Molnar #else
389a11b49aSIngo Molnar # define SMP_DEBUG_LOCKS_WARN_ON(c)			do { } while (0)
399a11b49aSIngo Molnar #endif
409a11b49aSIngo Molnar 
419a11b49aSIngo Molnar #ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS
429a11b49aSIngo Molnar   extern void locking_selftest(void);
439a11b49aSIngo Molnar #else
449a11b49aSIngo Molnar # define locking_selftest()	do { } while (0)
459a11b49aSIngo Molnar #endif
469a11b49aSIngo Molnar 
47f86e4513SKyle McMartin struct task_struct;
48f86e4513SKyle McMartin 
499a11b49aSIngo Molnar #ifdef CONFIG_LOCKDEP
509a11b49aSIngo Molnar extern void debug_show_all_locks(void);
5182a1fcb9SIngo Molnar extern void __debug_show_held_locks(struct task_struct *task);
529a11b49aSIngo Molnar extern void debug_show_held_locks(struct task_struct *task);
539a11b49aSIngo Molnar extern void debug_check_no_locks_freed(const void *from, unsigned long len);
549a11b49aSIngo Molnar extern void debug_check_no_locks_held(struct task_struct *task);
559a11b49aSIngo Molnar #else
569a11b49aSIngo Molnar static inline void debug_show_all_locks(void)
579a11b49aSIngo Molnar {
589a11b49aSIngo Molnar }
599a11b49aSIngo Molnar 
6082a1fcb9SIngo Molnar static inline void __debug_show_held_locks(struct task_struct *task)
6182a1fcb9SIngo Molnar {
6282a1fcb9SIngo Molnar }
6382a1fcb9SIngo Molnar 
649a11b49aSIngo Molnar static inline void debug_show_held_locks(struct task_struct *task)
659a11b49aSIngo Molnar {
669a11b49aSIngo Molnar }
679a11b49aSIngo Molnar 
689a11b49aSIngo Molnar static inline void
699a11b49aSIngo Molnar debug_check_no_locks_freed(const void *from, unsigned long len)
709a11b49aSIngo Molnar {
719a11b49aSIngo Molnar }
729a11b49aSIngo Molnar 
739a11b49aSIngo Molnar static inline void
749a11b49aSIngo Molnar debug_check_no_locks_held(struct task_struct *task)
759a11b49aSIngo Molnar {
769a11b49aSIngo Molnar }
779a11b49aSIngo Molnar #endif
789a11b49aSIngo Molnar 
799a11b49aSIngo Molnar #endif
80