rtmutex_common.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. pid_t 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_OWNER_PENDING 1UL
  81. #define RT_MUTEX_HAS_WAITERS 2UL
  82. #define RT_MUTEX_OWNER_MASKALL 3UL
  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. static inline struct task_struct *rt_mutex_real_owner(struct rt_mutex *lock)
  89. {
  90. return (struct task_struct *)
  91. ((unsigned long)lock->owner & ~RT_MUTEX_HAS_WAITERS);
  92. }
  93. static inline unsigned long rt_mutex_owner_pending(struct rt_mutex *lock)
  94. {
  95. return (unsigned long)lock->owner & RT_MUTEX_OWNER_PENDING;
  96. }
  97. /*
  98. * PI-futex support (proxy locking functions, etc.):
  99. */
  100. extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
  101. extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  102. struct task_struct *proxy_owner);
  103. extern void rt_mutex_proxy_unlock(struct rt_mutex *lock,
  104. struct task_struct *proxy_owner);
  105. #endif