xref: /linux/include/linux/debug_locks.h (revision 9127d4b1d9b2e8fba8e7fbc7f88ea93e5eb01396)
19a11b49aSIngo Molnar #ifndef __LINUX_DEBUG_LOCKING_H
29a11b49aSIngo Molnar #define __LINUX_DEBUG_LOCKING_H
39a11b49aSIngo Molnar 
49b7f750dSAlexey Dobriyan struct task_struct;
59b7f750dSAlexey Dobriyan 
69a11b49aSIngo Molnar extern int debug_locks;
79a11b49aSIngo Molnar extern int debug_locks_silent;
89a11b49aSIngo Molnar 
99a11b49aSIngo Molnar /*
109a11b49aSIngo Molnar  * Generic 'turn off all lock debugging' function:
119a11b49aSIngo Molnar  */
129a11b49aSIngo Molnar extern int debug_locks_off(void);
139a11b49aSIngo Molnar 
149a11b49aSIngo Molnar /*
159a11b49aSIngo Molnar  * In the debug case we carry the caller's instruction pointer into
169a11b49aSIngo Molnar  * other functions, but we dont want the function argument overhead
179a11b49aSIngo Molnar  * in the nondebug case - hence these macros:
189a11b49aSIngo Molnar  */
199a11b49aSIngo Molnar #define _RET_IP_		(unsigned long)__builtin_return_address(0)
209a11b49aSIngo Molnar #define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
219a11b49aSIngo Molnar 
229a11b49aSIngo Molnar #define DEBUG_LOCKS_WARN_ON(c)						\
239a11b49aSIngo Molnar ({									\
249a11b49aSIngo Molnar 	int __ret = 0;							\
259a11b49aSIngo Molnar 									\
269a11b49aSIngo Molnar 	if (unlikely(c)) {						\
27*9127d4b1SIngo Molnar 		if (debug_locks_off() && !debug_locks_silent)		\
289a11b49aSIngo Molnar 			WARN_ON(1);					\
299a11b49aSIngo Molnar 		__ret = 1;						\
309a11b49aSIngo Molnar 	}								\
319a11b49aSIngo Molnar 	__ret;								\
329a11b49aSIngo Molnar })
339a11b49aSIngo Molnar 
349a11b49aSIngo Molnar #ifdef CONFIG_SMP
359a11b49aSIngo Molnar # define SMP_DEBUG_LOCKS_WARN_ON(c)			DEBUG_LOCKS_WARN_ON(c)
369a11b49aSIngo Molnar #else
379a11b49aSIngo Molnar # define SMP_DEBUG_LOCKS_WARN_ON(c)			do { } while (0)
389a11b49aSIngo Molnar #endif
399a11b49aSIngo Molnar 
409a11b49aSIngo Molnar #ifdef CONFIG_DEBUG_LOCKING_API_SELFTESTS
419a11b49aSIngo Molnar   extern void locking_selftest(void);
429a11b49aSIngo Molnar #else
439a11b49aSIngo Molnar # define locking_selftest()	do { } while (0)
449a11b49aSIngo Molnar #endif
459a11b49aSIngo Molnar 
46f86e4513SKyle McMartin struct task_struct;
47f86e4513SKyle McMartin 
489a11b49aSIngo Molnar #ifdef CONFIG_LOCKDEP
499a11b49aSIngo Molnar extern void debug_show_all_locks(void);
509a11b49aSIngo Molnar extern void debug_show_held_locks(struct task_struct *task);
519a11b49aSIngo Molnar extern void debug_check_no_locks_freed(const void *from, unsigned long len);
529a11b49aSIngo Molnar extern void debug_check_no_locks_held(struct task_struct *task);
539a11b49aSIngo Molnar #else
549a11b49aSIngo Molnar static inline void debug_show_all_locks(void)
559a11b49aSIngo Molnar {
569a11b49aSIngo Molnar }
579a11b49aSIngo Molnar 
589a11b49aSIngo Molnar static inline void debug_show_held_locks(struct task_struct *task)
599a11b49aSIngo Molnar {
609a11b49aSIngo Molnar }
619a11b49aSIngo Molnar 
629a11b49aSIngo Molnar static inline void
639a11b49aSIngo Molnar debug_check_no_locks_freed(const void *from, unsigned long len)
649a11b49aSIngo Molnar {
659a11b49aSIngo Molnar }
669a11b49aSIngo Molnar 
679a11b49aSIngo Molnar static inline void
689a11b49aSIngo Molnar debug_check_no_locks_held(struct task_struct *task)
699a11b49aSIngo Molnar {
709a11b49aSIngo Molnar }
719a11b49aSIngo Molnar #endif
729a11b49aSIngo Molnar 
739a11b49aSIngo Molnar #endif
74