mutex-debug.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Mutexes: blocking mutual exclusion locks
  3. *
  4. * started by Ingo Molnar:
  5. *
  6. * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  7. *
  8. * This file contains mutex debugging related internal declarations,
  9. * prototypes and inline functions, for the CONFIG_DEBUG_MUTEXES case.
  10. * More details are in kernel/mutex-debug.c.
  11. */
  12. extern spinlock_t debug_mutex_lock;
  13. extern struct list_head debug_mutex_held_locks;
  14. extern int debug_mutex_on;
  15. /*
  16. * In the debug case we carry the caller's instruction pointer into
  17. * other functions, but we dont want the function argument overhead
  18. * in the nondebug case - hence these macros:
  19. */
  20. #define __IP_DECL__ , unsigned long ip
  21. #define __IP__ , ip
  22. #define __RET_IP__ , (unsigned long)__builtin_return_address(0)
  23. /*
  24. * This must be called with lock->wait_lock held.
  25. */
  26. extern void debug_mutex_set_owner(struct mutex *lock,
  27. struct thread_info *new_owner __IP_DECL__);
  28. static inline void debug_mutex_clear_owner(struct mutex *lock)
  29. {
  30. lock->owner = NULL;
  31. }
  32. extern void debug_mutex_init_waiter(struct mutex_waiter *waiter);
  33. extern void debug_mutex_wake_waiter(struct mutex *lock,
  34. struct mutex_waiter *waiter);
  35. extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
  36. extern void debug_mutex_add_waiter(struct mutex *lock,
  37. struct mutex_waiter *waiter,
  38. struct thread_info *ti __IP_DECL__);
  39. extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
  40. struct thread_info *ti);
  41. extern void debug_mutex_unlock(struct mutex *lock);
  42. extern void debug_mutex_init(struct mutex *lock, const char *name);
  43. #define debug_spin_lock_save(lock, flags) \
  44. do { \
  45. local_irq_save(flags); \
  46. if (debug_mutex_on) \
  47. spin_lock(lock); \
  48. } while (0)
  49. #define debug_spin_unlock_restore(lock, flags) \
  50. do { \
  51. if (debug_mutex_on) \
  52. spin_unlock(lock); \
  53. local_irq_restore(flags); \
  54. preempt_check_resched(); \
  55. } while (0)
  56. #define spin_lock_mutex(lock, flags) \
  57. do { \
  58. struct mutex *l = container_of(lock, struct mutex, wait_lock); \
  59. \
  60. DEBUG_WARN_ON(in_interrupt()); \
  61. debug_spin_lock_save(&debug_mutex_lock, flags); \
  62. spin_lock(lock); \
  63. DEBUG_WARN_ON(l->magic != l); \
  64. } while (0)
  65. #define spin_unlock_mutex(lock, flags) \
  66. do { \
  67. spin_unlock(lock); \
  68. debug_spin_unlock_restore(&debug_mutex_lock, flags); \
  69. } while (0)
  70. #define DEBUG_OFF() \
  71. do { \
  72. if (debug_mutex_on) { \
  73. debug_mutex_on = 0; \
  74. console_verbose(); \
  75. if (spin_is_locked(&debug_mutex_lock)) \
  76. spin_unlock(&debug_mutex_lock); \
  77. } \
  78. } while (0)
  79. #define DEBUG_BUG() \
  80. do { \
  81. if (debug_mutex_on) { \
  82. DEBUG_OFF(); \
  83. BUG(); \
  84. } \
  85. } while (0)
  86. #define DEBUG_WARN_ON(c) \
  87. do { \
  88. if (unlikely(c && debug_mutex_on)) { \
  89. DEBUG_OFF(); \
  90. WARN_ON(1); \
  91. } \
  92. } while (0)
  93. # define DEBUG_BUG_ON(c) \
  94. do { \
  95. if (unlikely(c)) \
  96. DEBUG_BUG(); \
  97. } while (0)
  98. #ifdef CONFIG_SMP
  99. # define SMP_DEBUG_WARN_ON(c) DEBUG_WARN_ON(c)
  100. # define SMP_DEBUG_BUG_ON(c) DEBUG_BUG_ON(c)
  101. #else
  102. # define SMP_DEBUG_WARN_ON(c) do { } while (0)
  103. # define SMP_DEBUG_BUG_ON(c) do { } while (0)
  104. #endif