rtmutex_common.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * RT Mutexes: blocking mutual exclusion locks with PI support
  3. *
  4. * started by Ingo Molnar and Thomas Gleixner:
  5. *
  6. * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  7. * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  8. *
  9. * This file contains the private data structure and API definitions.
  10. */
  11. #ifndef __KERNEL_RTMUTEX_COMMON_H
  12. #define __KERNEL_RTMUTEX_COMMON_H
  13. #include <linux/rtmutex.h>
  14. /*
  15. * The rtmutex in kernel tester is independent of rtmutex debugging. We
  16. * call schedule_rt_mutex_test() instead of schedule() for the tasks which
  17. * belong to the tester. That way we can delay the wakeup path of those
  18. * threads to provoke lock stealing and testing of complex boosting scenarios.
  19. */
  20. #ifdef CONFIG_RT_MUTEX_TESTER
  21. extern void schedule_rt_mutex_test(struct rt_mutex *lock);
  22. #define schedule_rt_mutex(_lock) \
  23. do { \
  24. if (!(current->flags & PF_MUTEX_TESTER)) \
  25. schedule(); \
  26. else \
  27. schedule_rt_mutex_test(_lock); \
  28. } while (0)
  29. #else
  30. # define schedule_rt_mutex(_lock) schedule()
  31. #endif
  32. /*
  33. * This is the control structure for tasks blocked on a rt_mutex,
  34. * which is allocated on the kernel stack on of the blocked task.
  35. *
  36. * @list_entry: pi node to enqueue into the mutex waiters list
  37. * @pi_list_entry: pi node to enqueue into the mutex owner waiters list
  38. * @task: task reference to the blocked task
  39. */
  40. struct rt_mutex_waiter {
  41. struct plist_node list_entry;
  42. struct plist_node pi_list_entry;
  43. struct task_struct *task;
  44. struct rt_mutex *lock;
  45. #ifdef CONFIG_DEBUG_RT_MUTEXES
  46. unsigned long ip;
  47. struct pid *deadlock_task_pid;
  48. struct rt_mutex *deadlock_lock;
  49. #endif
  50. };
  51. /*
  52. * Various helpers to access the waiters-plist:
  53. */
  54. static inline int rt_mutex_has_waiters(struct rt_mutex *lock)
  55. {
  56. return !plist_head_empty(&lock->wait_list);
  57. }
  58. static inline struct rt_mutex_waiter *
  59. rt_mutex_top_waiter(struct rt_mutex *lock)
  60. {
  61. struct rt_mutex_waiter *w;
  62. w = plist_first_entry(&lock->wait_list, struct rt_mutex_waiter,
  63. list_entry);
  64. BUG_ON(w->lock != lock);
  65. return w;
  66. }
  67. static inline int task_has_pi_waiters(struct task_struct *p)
  68. {
  69. return !plist_head_empty(&p->pi_waiters);
  70. }
  71. static inline struct rt_mutex_waiter *
  72. task_top_pi_waiter(struct task_struct *p)
  73. {
  74. return plist_first_entry(&p->pi_waiters, struct rt_mutex_waiter,
  75. pi_list_entry);
  76. }
  77. /*
  78. * lock->owner state tracking:
  79. */
  80. #define RT_MUTEX_HAS_WAITERS 1UL
  81. #define RT_MUTEX_OWNER_MASKALL 1UL
  82. static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock)
  83. {
  84. return (struct task_struct *)
  85. ((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL);
  86. }
  87. /*
  88. * PI-futex support (proxy locking functions, etc.):
  89. */
  90. extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
  91. extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  92. struct task_struct *proxy_owner);
  93. extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
  94. struct task_struct *proxy_owner);
  95. extern int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
  96. struct rt_mutex_waiter *waiter,
  97. struct task_struct *task,
  98. int detect_deadlock);
  99. extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
  100. struct hrtimer_sleeper *to,
  101. struct rt_mutex_waiter *waiter,
  102. int detect_deadlock);
  103. #ifdef CONFIG_DEBUG_RT_MUTEXES
  104. # include "rtmutex-debug.h"
  105. #else
  106. # include "rtmutex.h"
  107. #endif
  108. #endif