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. * @tree_entry: pi node to enqueue into the mutex waiters tree
  37. * @pi_tree_entry: pi node to enqueue into the mutex owner waiters tree
  38. * @task: task reference to the blocked task
  39. */
  40. struct rt_mutex_waiter {
  41. struct rb_node tree_entry;
  42. struct rb_node pi_tree_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. int prio;
  51. };
  52. /*
  53. * Various helpers to access the waiters-tree:
  54. */
  55. static inline int rt_mutex_has_waiters(struct rt_mutex *lock)
  56. {
  57. return !RB_EMPTY_ROOT(&lock->waiters);
  58. }
  59. static inline struct rt_mutex_waiter *
  60. rt_mutex_top_waiter(struct rt_mutex *lock)
  61. {
  62. struct rt_mutex_waiter *w;
  63. w = rb_entry(lock->waiters_leftmost, struct rt_mutex_waiter,
  64. tree_entry);
  65. BUG_ON(w->lock != lock);
  66. return w;
  67. }
  68. static inline int task_has_pi_waiters(struct task_struct *p)
  69. {
  70. return !RB_EMPTY_ROOT(&p->pi_waiters);
  71. }
  72. static inline struct rt_mutex_waiter *
  73. task_top_pi_waiter(struct task_struct *p)
  74. {
  75. return rb_entry(p->pi_waiters_leftmost, struct rt_mutex_waiter,
  76. pi_tree_entry);
  77. }
  78. /*
  79. * lock->owner state tracking:
  80. */
  81. #define RT_MUTEX_HAS_WAITERS 1UL
  82. #define RT_MUTEX_OWNER_MASKALL 1UL
  83. static inline struct task_struct *rt_mutex_owner(struct rt_mutex *lock)
  84. {
  85. return (struct task_struct *)
  86. ((unsigned long)lock->owner & ~RT_MUTEX_OWNER_MASKALL);
  87. }
  88. /*
  89. * PI-futex support (proxy locking functions, etc.):
  90. */
  91. extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
  92. extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  93. struct task_struct *proxy_owner);
  94. extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
  95. struct task_struct *proxy_owner);
  96. extern int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
  97. struct rt_mutex_waiter *waiter,
  98. struct task_struct *task,
  99. int detect_deadlock);
  100. extern int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
  101. struct hrtimer_sleeper *to,
  102. struct rt_mutex_waiter *waiter,
  103. int detect_deadlock);
  104. #ifdef CONFIG_DEBUG_RT_MUTEXES
  105. # include "rtmutex-debug.h"
  106. #else
  107. # include "rtmutex.h"
  108. #endif
  109. #endif