2 * RT-Mutexes: simple blocking mutual exclusion locks with PI support
4 * started by Ingo Molnar and Thomas Gleixner.
6 * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
7 * Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
8 * Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
9 * Copyright (C) 2006 Esben Nielsen
11 * See Documentation/locking/rt-mutex-design.txt for details.
13 #include <linux/spinlock.h>
14 #include <linux/export.h>
15 #include <linux/sched/signal.h>
16 #include <linux/sched/rt.h>
17 #include <linux/sched/deadline.h>
18 #include <linux/sched/wake_q.h>
19 #include <linux/sched/debug.h>
20 #include <linux/timer.h>
22 #include "rtmutex_common.h"
25 * lock->owner state tracking:
27 * lock->owner holds the task_struct pointer of the owner. Bit 0
28 * is used to keep track of the "lock has waiters" state.
31 * NULL 0 lock is free (fast acquire possible)
32 * NULL 1 lock is free and has waiters and the top waiter
33 * is going to take the lock*
34 * taskpointer 0 lock is held (fast release possible)
35 * taskpointer 1 lock is held and has waiters**
37 * The fast atomic compare exchange based acquire and release is only
38 * possible when bit 0 of lock->owner is 0.
40 * (*) It also can be a transitional state when grabbing the lock
41 * with ->wait_lock is held. To prevent any fast path cmpxchg to the lock,
42 * we need to set the bit0 before looking at the lock, and the owner may be
43 * NULL in this small time, hence this can be a transitional state.
45 * (**) There is a small time when bit 0 is set but there are no
46 * waiters. This can happen when grabbing the lock in the slow path.
47 * To prevent a cmpxchg of the owner releasing the lock, we need to
48 * set this bit before looking at the lock.
52 rt_mutex_set_owner(struct rt_mutex *lock, struct task_struct *owner)
54 unsigned long val = (unsigned long)owner;
56 if (rt_mutex_has_waiters(lock))
57 val |= RT_MUTEX_HAS_WAITERS;
59 lock->owner = (struct task_struct *)val;
62 static inline void clear_rt_mutex_waiters(struct rt_mutex *lock)
64 lock->owner = (struct task_struct *)
65 ((unsigned long)lock->owner & ~RT_MUTEX_HAS_WAITERS);
68 static void fixup_rt_mutex_waiters(struct rt_mutex *lock)
70 unsigned long owner, *p = (unsigned long *) &lock->owner;
72 if (rt_mutex_has_waiters(lock))
76 * The rbtree has no waiters enqueued, now make sure that the
77 * lock->owner still has the waiters bit set, otherwise the
78 * following can happen:
84 * l->owner = T1 | HAS_WAITERS;
92 * l->owner = T1 | HAS_WAITERS;
97 * signal(->T2) signal(->T3)
104 * ==> wait list is empty
108 * fixup_rt_mutex_waiters()
109 * if (wait_list_empty(l) {
111 * owner = l->owner & ~HAS_WAITERS;
115 * rt_mutex_unlock(l) fixup_rt_mutex_waiters()
116 * if (wait_list_empty(l) {
117 * owner = l->owner & ~HAS_WAITERS;
118 * cmpxchg(l->owner, T1, NULL)
119 * ===> Success (l->owner = NULL)
125 * With the check for the waiter bit in place T3 on CPU2 will not
126 * overwrite. All tasks fiddling with the waiters bit are
127 * serialized by l->lock, so nothing else can modify the waiters
128 * bit. If the bit is set then nothing can change l->owner either
129 * so the simple RMW is safe. The cmpxchg() will simply fail if it
130 * happens in the middle of the RMW because the waiters bit is
133 owner = READ_ONCE(*p);
134 if (owner & RT_MUTEX_HAS_WAITERS)
135 WRITE_ONCE(*p, owner & ~RT_MUTEX_HAS_WAITERS);
139 * We can speed up the acquire/release, if there's no debugging state to be
142 #ifndef CONFIG_DEBUG_RT_MUTEXES
143 # define rt_mutex_cmpxchg_relaxed(l,c,n) (cmpxchg_relaxed(&l->owner, c, n) == c)
144 # define rt_mutex_cmpxchg_acquire(l,c,n) (cmpxchg_acquire(&l->owner, c, n) == c)
145 # define rt_mutex_cmpxchg_release(l,c,n) (cmpxchg_release(&l->owner, c, n) == c)
148 * Callers must hold the ->wait_lock -- which is the whole purpose as we force
149 * all future threads that attempt to [Rmw] the lock to the slowpath. As such
150 * relaxed semantics suffice.
152 static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
154 unsigned long owner, *p = (unsigned long *) &lock->owner;
158 } while (cmpxchg_relaxed(p, owner,
159 owner | RT_MUTEX_HAS_WAITERS) != owner);
163 * Safe fastpath aware unlock:
164 * 1) Clear the waiters bit
165 * 2) Drop lock->wait_lock
166 * 3) Try to unlock the lock with cmpxchg
168 static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock,
170 __releases(lock->wait_lock)
172 struct task_struct *owner = rt_mutex_owner(lock);
174 clear_rt_mutex_waiters(lock);
175 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
177 * If a new waiter comes in between the unlock and the cmpxchg
178 * we have two situations:
182 * cmpxchg(p, owner, 0) == owner
183 * mark_rt_mutex_waiters(lock);
189 * mark_rt_mutex_waiters(lock);
191 * cmpxchg(p, owner, 0) != owner
200 return rt_mutex_cmpxchg_release(lock, owner, NULL);
204 # define rt_mutex_cmpxchg_relaxed(l,c,n) (0)
205 # define rt_mutex_cmpxchg_acquire(l,c,n) (0)
206 # define rt_mutex_cmpxchg_release(l,c,n) (0)
208 static inline void mark_rt_mutex_waiters(struct rt_mutex *lock)
210 lock->owner = (struct task_struct *)
211 ((unsigned long)lock->owner | RT_MUTEX_HAS_WAITERS);
215 * Simple slow path only version: lock->owner is protected by lock->wait_lock.
217 static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock,
219 __releases(lock->wait_lock)
222 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
228 rt_mutex_waiter_less(struct rt_mutex_waiter *left,
229 struct rt_mutex_waiter *right)
231 if (left->prio < right->prio)
235 * If both waiters have dl_prio(), we check the deadlines of the
237 * If left waiter has a dl_prio(), and we didn't return 1 above,
238 * then right waiter has a dl_prio() too.
240 if (dl_prio(left->prio))
241 return dl_time_before(left->task->dl.deadline,
242 right->task->dl.deadline);
248 rt_mutex_enqueue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter)
250 struct rb_node **link = &lock->waiters.rb_node;
251 struct rb_node *parent = NULL;
252 struct rt_mutex_waiter *entry;
257 entry = rb_entry(parent, struct rt_mutex_waiter, tree_entry);
258 if (rt_mutex_waiter_less(waiter, entry)) {
259 link = &parent->rb_left;
261 link = &parent->rb_right;
267 lock->waiters_leftmost = &waiter->tree_entry;
269 rb_link_node(&waiter->tree_entry, parent, link);
270 rb_insert_color(&waiter->tree_entry, &lock->waiters);
274 rt_mutex_dequeue(struct rt_mutex *lock, struct rt_mutex_waiter *waiter)
276 if (RB_EMPTY_NODE(&waiter->tree_entry))
279 if (lock->waiters_leftmost == &waiter->tree_entry)
280 lock->waiters_leftmost = rb_next(&waiter->tree_entry);
282 rb_erase(&waiter->tree_entry, &lock->waiters);
283 RB_CLEAR_NODE(&waiter->tree_entry);
287 rt_mutex_enqueue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter)
289 struct rb_node **link = &task->pi_waiters.rb_node;
290 struct rb_node *parent = NULL;
291 struct rt_mutex_waiter *entry;
296 entry = rb_entry(parent, struct rt_mutex_waiter, pi_tree_entry);
297 if (rt_mutex_waiter_less(waiter, entry)) {
298 link = &parent->rb_left;
300 link = &parent->rb_right;
306 task->pi_waiters_leftmost = &waiter->pi_tree_entry;
308 rb_link_node(&waiter->pi_tree_entry, parent, link);
309 rb_insert_color(&waiter->pi_tree_entry, &task->pi_waiters);
313 rt_mutex_dequeue_pi(struct task_struct *task, struct rt_mutex_waiter *waiter)
315 if (RB_EMPTY_NODE(&waiter->pi_tree_entry))
318 if (task->pi_waiters_leftmost == &waiter->pi_tree_entry)
319 task->pi_waiters_leftmost = rb_next(&waiter->pi_tree_entry);
321 rb_erase(&waiter->pi_tree_entry, &task->pi_waiters);
322 RB_CLEAR_NODE(&waiter->pi_tree_entry);
326 * Calculate task priority from the waiter tree priority
328 * Return task->normal_prio when the waiter tree is empty or when
329 * the waiter is not allowed to do priority boosting
331 int rt_mutex_getprio(struct task_struct *task)
333 if (likely(!task_has_pi_waiters(task)))
334 return task->normal_prio;
336 return min(task_top_pi_waiter(task)->prio,
340 struct task_struct *rt_mutex_get_top_task(struct task_struct *task)
342 if (likely(!task_has_pi_waiters(task)))
345 return task_top_pi_waiter(task)->task;
349 * Called by sched_setscheduler() to get the priority which will be
350 * effective after the change.
352 int rt_mutex_get_effective_prio(struct task_struct *task, int newprio)
354 if (!task_has_pi_waiters(task))
357 if (task_top_pi_waiter(task)->task->prio <= newprio)
358 return task_top_pi_waiter(task)->task->prio;
363 * Adjust the priority of a task, after its pi_waiters got modified.
365 * This can be both boosting and unboosting. task->pi_lock must be held.
367 static void __rt_mutex_adjust_prio(struct task_struct *task)
369 int prio = rt_mutex_getprio(task);
371 if (task->prio != prio || dl_prio(prio))
372 rt_mutex_setprio(task, prio);
376 * Adjust task priority (undo boosting). Called from the exit path of
377 * rt_mutex_slowunlock() and rt_mutex_slowlock().
379 * (Note: We do this outside of the protection of lock->wait_lock to
380 * allow the lock to be taken while or before we readjust the priority
381 * of task. We do not use the spin_xx_mutex() variants here as we are
382 * outside of the debug path.)
384 void rt_mutex_adjust_prio(struct task_struct *task)
388 raw_spin_lock_irqsave(&task->pi_lock, flags);
389 __rt_mutex_adjust_prio(task);
390 raw_spin_unlock_irqrestore(&task->pi_lock, flags);
394 * Deadlock detection is conditional:
396 * If CONFIG_DEBUG_RT_MUTEXES=n, deadlock detection is only conducted
397 * if the detect argument is == RT_MUTEX_FULL_CHAINWALK.
399 * If CONFIG_DEBUG_RT_MUTEXES=y, deadlock detection is always
400 * conducted independent of the detect argument.
402 * If the waiter argument is NULL this indicates the deboost path and
403 * deadlock detection is disabled independent of the detect argument
404 * and the config settings.
406 static bool rt_mutex_cond_detect_deadlock(struct rt_mutex_waiter *waiter,
407 enum rtmutex_chainwalk chwalk)
410 * This is just a wrapper function for the following call,
411 * because debug_rt_mutex_detect_deadlock() smells like a magic
412 * debug feature and I wanted to keep the cond function in the
413 * main source file along with the comments instead of having
414 * two of the same in the headers.
416 return debug_rt_mutex_detect_deadlock(waiter, chwalk);
420 * Max number of times we'll walk the boosting chain:
422 int max_lock_depth = 1024;
424 static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p)
426 return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL;
430 * Adjust the priority chain. Also used for deadlock detection.
431 * Decreases task's usage by one - may thus free the task.
433 * @task: the task owning the mutex (owner) for which a chain walk is
435 * @chwalk: do we have to carry out deadlock detection?
436 * @orig_lock: the mutex (can be NULL if we are walking the chain to recheck
437 * things for a task that has just got its priority adjusted, and
438 * is waiting on a mutex)
439 * @next_lock: the mutex on which the owner of @orig_lock was blocked before
440 * we dropped its pi_lock. Is never dereferenced, only used for
441 * comparison to detect lock chain changes.
442 * @orig_waiter: rt_mutex_waiter struct for the task that has just donated
443 * its priority to the mutex owner (can be NULL in the case
444 * depicted above or if the top waiter is gone away and we are
445 * actually deboosting the owner)
446 * @top_task: the current top waiter
448 * Returns 0 or -EDEADLK.
450 * Chain walk basics and protection scope
452 * [R] refcount on task
453 * [P] task->pi_lock held
454 * [L] rtmutex->wait_lock held
456 * Step Description Protected by
457 * function arguments:
459 * @orig_lock if != NULL @top_task is blocked on it
460 * @next_lock Unprotected. Cannot be
461 * dereferenced. Only used for
463 * @orig_waiter if != NULL @top_task is blocked on it
464 * @top_task current, or in case of proxy
465 * locking protected by calling
468 * loop_sanity_check();
470 * [1] lock(task->pi_lock); [R] acquire [P]
471 * [2] waiter = task->pi_blocked_on; [P]
472 * [3] check_exit_conditions_1(); [P]
473 * [4] lock = waiter->lock; [P]
474 * [5] if (!try_lock(lock->wait_lock)) { [P] try to acquire [L]
475 * unlock(task->pi_lock); release [P]
478 * [6] check_exit_conditions_2(); [P] + [L]
479 * [7] requeue_lock_waiter(lock, waiter); [P] + [L]
480 * [8] unlock(task->pi_lock); release [P]
481 * put_task_struct(task); release [R]
482 * [9] check_exit_conditions_3(); [L]
483 * [10] task = owner(lock); [L]
484 * get_task_struct(task); [L] acquire [R]
485 * lock(task->pi_lock); [L] acquire [P]
486 * [11] requeue_pi_waiter(tsk, waiters(lock));[P] + [L]
487 * [12] check_exit_conditions_4(); [P] + [L]
488 * [13] unlock(task->pi_lock); release [P]
489 * unlock(lock->wait_lock); release [L]
492 static int rt_mutex_adjust_prio_chain(struct task_struct *task,
493 enum rtmutex_chainwalk chwalk,
494 struct rt_mutex *orig_lock,
495 struct rt_mutex *next_lock,
496 struct rt_mutex_waiter *orig_waiter,
497 struct task_struct *top_task)
499 struct rt_mutex_waiter *waiter, *top_waiter = orig_waiter;
500 struct rt_mutex_waiter *prerequeue_top_waiter;
501 int ret = 0, depth = 0;
502 struct rt_mutex *lock;
503 bool detect_deadlock;
506 detect_deadlock = rt_mutex_cond_detect_deadlock(orig_waiter, chwalk);
509 * The (de)boosting is a step by step approach with a lot of
510 * pitfalls. We want this to be preemptible and we want hold a
511 * maximum of two locks per step. So we have to check
512 * carefully whether things change under us.
516 * We limit the lock chain length for each invocation.
518 if (++depth > max_lock_depth) {
522 * Print this only once. If the admin changes the limit,
523 * print a new message when reaching the limit again.
525 if (prev_max != max_lock_depth) {
526 prev_max = max_lock_depth;
527 printk(KERN_WARNING "Maximum lock depth %d reached "
528 "task: %s (%d)\n", max_lock_depth,
529 top_task->comm, task_pid_nr(top_task));
531 put_task_struct(task);
537 * We are fully preemptible here and only hold the refcount on
538 * @task. So everything can have changed under us since the
539 * caller or our own code below (goto retry/again) dropped all
544 * [1] Task cannot go away as we did a get_task() before !
546 raw_spin_lock_irq(&task->pi_lock);
549 * [2] Get the waiter on which @task is blocked on.
551 waiter = task->pi_blocked_on;
554 * [3] check_exit_conditions_1() protected by task->pi_lock.
558 * Check whether the end of the boosting chain has been
559 * reached or the state of the chain has changed while we
566 * Check the orig_waiter state. After we dropped the locks,
567 * the previous owner of the lock might have released the lock.
569 if (orig_waiter && !rt_mutex_owner(orig_lock))
573 * We dropped all locks after taking a refcount on @task, so
574 * the task might have moved on in the lock chain or even left
575 * the chain completely and blocks now on an unrelated lock or
578 * We stored the lock on which @task was blocked in @next_lock,
579 * so we can detect the chain change.
581 if (next_lock != waiter->lock)
585 * Drop out, when the task has no waiters. Note,
586 * top_waiter can be NULL, when we are in the deboosting
590 if (!task_has_pi_waiters(task))
593 * If deadlock detection is off, we stop here if we
594 * are not the top pi waiter of the task. If deadlock
595 * detection is enabled we continue, but stop the
596 * requeueing in the chain walk.
598 if (top_waiter != task_top_pi_waiter(task)) {
599 if (!detect_deadlock)
607 * If the waiter priority is the same as the task priority
608 * then there is no further priority adjustment necessary. If
609 * deadlock detection is off, we stop the chain walk. If its
610 * enabled we continue, but stop the requeueing in the chain
613 if (waiter->prio == task->prio) {
614 if (!detect_deadlock)
621 * [4] Get the next lock
625 * [5] We need to trylock here as we are holding task->pi_lock,
626 * which is the reverse lock order versus the other rtmutex
629 if (!raw_spin_trylock(&lock->wait_lock)) {
630 raw_spin_unlock_irq(&task->pi_lock);
636 * [6] check_exit_conditions_2() protected by task->pi_lock and
639 * Deadlock detection. If the lock is the same as the original
640 * lock which caused us to walk the lock chain or if the
641 * current lock is owned by the task which initiated the chain
642 * walk, we detected a deadlock.
644 if (lock == orig_lock || rt_mutex_owner(lock) == top_task) {
645 debug_rt_mutex_deadlock(chwalk, orig_waiter, lock);
646 raw_spin_unlock(&lock->wait_lock);
652 * If we just follow the lock chain for deadlock detection, no
653 * need to do all the requeue operations. To avoid a truckload
654 * of conditionals around the various places below, just do the
655 * minimum chain walk checks.
659 * No requeue[7] here. Just release @task [8]
661 raw_spin_unlock(&task->pi_lock);
662 put_task_struct(task);
665 * [9] check_exit_conditions_3 protected by lock->wait_lock.
666 * If there is no owner of the lock, end of chain.
668 if (!rt_mutex_owner(lock)) {
669 raw_spin_unlock_irq(&lock->wait_lock);
673 /* [10] Grab the next task, i.e. owner of @lock */
674 task = rt_mutex_owner(lock);
675 get_task_struct(task);
676 raw_spin_lock(&task->pi_lock);
679 * No requeue [11] here. We just do deadlock detection.
681 * [12] Store whether owner is blocked
682 * itself. Decision is made after dropping the locks
684 next_lock = task_blocked_on_lock(task);
686 * Get the top waiter for the next iteration
688 top_waiter = rt_mutex_top_waiter(lock);
690 /* [13] Drop locks */
691 raw_spin_unlock(&task->pi_lock);
692 raw_spin_unlock_irq(&lock->wait_lock);
694 /* If owner is not blocked, end of chain. */
701 * Store the current top waiter before doing the requeue
702 * operation on @lock. We need it for the boost/deboost
705 prerequeue_top_waiter = rt_mutex_top_waiter(lock);
707 /* [7] Requeue the waiter in the lock waiter tree. */
708 rt_mutex_dequeue(lock, waiter);
709 waiter->prio = task->prio;
710 rt_mutex_enqueue(lock, waiter);
712 /* [8] Release the task */
713 raw_spin_unlock(&task->pi_lock);
714 put_task_struct(task);
717 * [9] check_exit_conditions_3 protected by lock->wait_lock.
719 * We must abort the chain walk if there is no lock owner even
720 * in the dead lock detection case, as we have nothing to
721 * follow here. This is the end of the chain we are walking.
723 if (!rt_mutex_owner(lock)) {
725 * If the requeue [7] above changed the top waiter,
726 * then we need to wake the new top waiter up to try
729 if (prerequeue_top_waiter != rt_mutex_top_waiter(lock))
730 wake_up_process(rt_mutex_top_waiter(lock)->task);
731 raw_spin_unlock_irq(&lock->wait_lock);
735 /* [10] Grab the next task, i.e. the owner of @lock */
736 task = rt_mutex_owner(lock);
737 get_task_struct(task);
738 raw_spin_lock(&task->pi_lock);
740 /* [11] requeue the pi waiters if necessary */
741 if (waiter == rt_mutex_top_waiter(lock)) {
743 * The waiter became the new top (highest priority)
744 * waiter on the lock. Replace the previous top waiter
745 * in the owner tasks pi waiters tree with this waiter
746 * and adjust the priority of the owner.
748 rt_mutex_dequeue_pi(task, prerequeue_top_waiter);
749 rt_mutex_enqueue_pi(task, waiter);
750 __rt_mutex_adjust_prio(task);
752 } else if (prerequeue_top_waiter == waiter) {
754 * The waiter was the top waiter on the lock, but is
755 * no longer the top prority waiter. Replace waiter in
756 * the owner tasks pi waiters tree with the new top
757 * (highest priority) waiter and adjust the priority
759 * The new top waiter is stored in @waiter so that
760 * @waiter == @top_waiter evaluates to true below and
761 * we continue to deboost the rest of the chain.
763 rt_mutex_dequeue_pi(task, waiter);
764 waiter = rt_mutex_top_waiter(lock);
765 rt_mutex_enqueue_pi(task, waiter);
766 __rt_mutex_adjust_prio(task);
769 * Nothing changed. No need to do any priority
775 * [12] check_exit_conditions_4() protected by task->pi_lock
776 * and lock->wait_lock. The actual decisions are made after we
779 * Check whether the task which owns the current lock is pi
780 * blocked itself. If yes we store a pointer to the lock for
781 * the lock chain change detection above. After we dropped
782 * task->pi_lock next_lock cannot be dereferenced anymore.
784 next_lock = task_blocked_on_lock(task);
786 * Store the top waiter of @lock for the end of chain walk
789 top_waiter = rt_mutex_top_waiter(lock);
791 /* [13] Drop the locks */
792 raw_spin_unlock(&task->pi_lock);
793 raw_spin_unlock_irq(&lock->wait_lock);
796 * Make the actual exit decisions [12], based on the stored
799 * We reached the end of the lock chain. Stop right here. No
800 * point to go back just to figure that out.
806 * If the current waiter is not the top waiter on the lock,
807 * then we can stop the chain walk here if we are not in full
808 * deadlock detection mode.
810 if (!detect_deadlock && waiter != top_waiter)
816 raw_spin_unlock_irq(&task->pi_lock);
818 put_task_struct(task);
824 * Try to take an rt-mutex
826 * Must be called with lock->wait_lock held and interrupts disabled
828 * @lock: The lock to be acquired.
829 * @task: The task which wants to acquire the lock
830 * @waiter: The waiter that is queued to the lock's wait tree if the
831 * callsite called task_blocked_on_lock(), otherwise NULL
833 static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
834 struct rt_mutex_waiter *waiter)
837 * Before testing whether we can acquire @lock, we set the
838 * RT_MUTEX_HAS_WAITERS bit in @lock->owner. This forces all
839 * other tasks which try to modify @lock into the slow path
840 * and they serialize on @lock->wait_lock.
842 * The RT_MUTEX_HAS_WAITERS bit can have a transitional state
843 * as explained at the top of this file if and only if:
845 * - There is a lock owner. The caller must fixup the
846 * transient state if it does a trylock or leaves the lock
847 * function due to a signal or timeout.
849 * - @task acquires the lock and there are no other
850 * waiters. This is undone in rt_mutex_set_owner(@task) at
851 * the end of this function.
853 mark_rt_mutex_waiters(lock);
856 * If @lock has an owner, give up.
858 if (rt_mutex_owner(lock))
862 * If @waiter != NULL, @task has already enqueued the waiter
863 * into @lock waiter tree. If @waiter == NULL then this is a
868 * If waiter is not the highest priority waiter of
871 if (waiter != rt_mutex_top_waiter(lock))
875 * We can acquire the lock. Remove the waiter from the
878 rt_mutex_dequeue(lock, waiter);
882 * If the lock has waiters already we check whether @task is
883 * eligible to take over the lock.
885 * If there are no other waiters, @task can acquire
886 * the lock. @task->pi_blocked_on is NULL, so it does
887 * not need to be dequeued.
889 if (rt_mutex_has_waiters(lock)) {
891 * If @task->prio is greater than or equal to
892 * the top waiter priority (kernel view),
895 if (task->prio >= rt_mutex_top_waiter(lock)->prio)
899 * The current top waiter stays enqueued. We
900 * don't have to change anything in the lock
905 * No waiters. Take the lock without the
906 * pi_lock dance.@task->pi_blocked_on is NULL
907 * and we have no waiters to enqueue in @task
915 * Clear @task->pi_blocked_on. Requires protection by
916 * @task->pi_lock. Redundant operation for the @waiter == NULL
917 * case, but conditionals are more expensive than a redundant
920 raw_spin_lock(&task->pi_lock);
921 task->pi_blocked_on = NULL;
923 * Finish the lock acquisition. @task is the new owner. If
924 * other waiters exist we have to insert the highest priority
925 * waiter into @task->pi_waiters tree.
927 if (rt_mutex_has_waiters(lock))
928 rt_mutex_enqueue_pi(task, rt_mutex_top_waiter(lock));
929 raw_spin_unlock(&task->pi_lock);
932 /* We got the lock. */
933 debug_rt_mutex_lock(lock);
936 * This either preserves the RT_MUTEX_HAS_WAITERS bit if there
937 * are still waiters or clears it.
939 rt_mutex_set_owner(lock, task);
941 rt_mutex_deadlock_account_lock(lock, task);
947 * Task blocks on lock.
949 * Prepare waiter and propagate pi chain
951 * This must be called with lock->wait_lock held and interrupts disabled
953 static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
954 struct rt_mutex_waiter *waiter,
955 struct task_struct *task,
956 enum rtmutex_chainwalk chwalk)
958 struct task_struct *owner = rt_mutex_owner(lock);
959 struct rt_mutex_waiter *top_waiter = waiter;
960 struct rt_mutex *next_lock;
961 int chain_walk = 0, res;
964 * Early deadlock detection. We really don't want the task to
965 * enqueue on itself just to untangle the mess later. It's not
966 * only an optimization. We drop the locks, so another waiter
967 * can come in before the chain walk detects the deadlock. So
968 * the other will detect the deadlock and return -EDEADLOCK,
969 * which is wrong, as the other waiter is not in a deadlock
975 raw_spin_lock(&task->pi_lock);
976 __rt_mutex_adjust_prio(task);
979 waiter->prio = task->prio;
981 /* Get the top priority waiter on the lock */
982 if (rt_mutex_has_waiters(lock))
983 top_waiter = rt_mutex_top_waiter(lock);
984 rt_mutex_enqueue(lock, waiter);
986 task->pi_blocked_on = waiter;
988 raw_spin_unlock(&task->pi_lock);
993 raw_spin_lock(&owner->pi_lock);
994 if (waiter == rt_mutex_top_waiter(lock)) {
995 rt_mutex_dequeue_pi(owner, top_waiter);
996 rt_mutex_enqueue_pi(owner, waiter);
998 __rt_mutex_adjust_prio(owner);
999 if (owner->pi_blocked_on)
1001 } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
1005 /* Store the lock on which owner is blocked or NULL */
1006 next_lock = task_blocked_on_lock(owner);
1008 raw_spin_unlock(&owner->pi_lock);
1010 * Even if full deadlock detection is on, if the owner is not
1011 * blocked itself, we can avoid finding this out in the chain
1014 if (!chain_walk || !next_lock)
1018 * The owner can't disappear while holding a lock,
1019 * so the owner struct is protected by wait_lock.
1020 * Gets dropped in rt_mutex_adjust_prio_chain()!
1022 get_task_struct(owner);
1024 raw_spin_unlock_irq(&lock->wait_lock);
1026 res = rt_mutex_adjust_prio_chain(owner, chwalk, lock,
1027 next_lock, waiter, task);
1029 raw_spin_lock_irq(&lock->wait_lock);
1035 * Remove the top waiter from the current tasks pi waiter tree and
1038 * Called with lock->wait_lock held and interrupts disabled.
1040 static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
1041 struct rt_mutex *lock)
1043 struct rt_mutex_waiter *waiter;
1045 raw_spin_lock(¤t->pi_lock);
1047 waiter = rt_mutex_top_waiter(lock);
1050 * Remove it from current->pi_waiters. We do not adjust a
1051 * possible priority boost right now. We execute wakeup in the
1052 * boosted mode and go back to normal after releasing
1055 rt_mutex_dequeue_pi(current, waiter);
1058 * As we are waking up the top waiter, and the waiter stays
1059 * queued on the lock until it gets the lock, this lock
1060 * obviously has waiters. Just set the bit here and this has
1061 * the added benefit of forcing all new tasks into the
1062 * slow path making sure no task of lower priority than
1063 * the top waiter can steal this lock.
1065 lock->owner = (void *) RT_MUTEX_HAS_WAITERS;
1067 raw_spin_unlock(¤t->pi_lock);
1069 wake_q_add(wake_q, waiter->task);
1073 * Remove a waiter from a lock and give up
1075 * Must be called with lock->wait_lock held and interrupts disabled. I must
1076 * have just failed to try_to_take_rt_mutex().
1078 static void remove_waiter(struct rt_mutex *lock,
1079 struct rt_mutex_waiter *waiter)
1081 bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
1082 struct task_struct *owner = rt_mutex_owner(lock);
1083 struct rt_mutex *next_lock;
1085 raw_spin_lock(¤t->pi_lock);
1086 rt_mutex_dequeue(lock, waiter);
1087 current->pi_blocked_on = NULL;
1088 raw_spin_unlock(¤t->pi_lock);
1091 * Only update priority if the waiter was the highest priority
1092 * waiter of the lock and there is an owner to update.
1094 if (!owner || !is_top_waiter)
1097 raw_spin_lock(&owner->pi_lock);
1099 rt_mutex_dequeue_pi(owner, waiter);
1101 if (rt_mutex_has_waiters(lock))
1102 rt_mutex_enqueue_pi(owner, rt_mutex_top_waiter(lock));
1104 __rt_mutex_adjust_prio(owner);
1106 /* Store the lock on which owner is blocked or NULL */
1107 next_lock = task_blocked_on_lock(owner);
1109 raw_spin_unlock(&owner->pi_lock);
1112 * Don't walk the chain, if the owner task is not blocked
1118 /* gets dropped in rt_mutex_adjust_prio_chain()! */
1119 get_task_struct(owner);
1121 raw_spin_unlock_irq(&lock->wait_lock);
1123 rt_mutex_adjust_prio_chain(owner, RT_MUTEX_MIN_CHAINWALK, lock,
1124 next_lock, NULL, current);
1126 raw_spin_lock_irq(&lock->wait_lock);
1130 * Recheck the pi chain, in case we got a priority setting
1132 * Called from sched_setscheduler
1134 void rt_mutex_adjust_pi(struct task_struct *task)
1136 struct rt_mutex_waiter *waiter;
1137 struct rt_mutex *next_lock;
1138 unsigned long flags;
1140 raw_spin_lock_irqsave(&task->pi_lock, flags);
1142 waiter = task->pi_blocked_on;
1143 if (!waiter || (waiter->prio == task->prio &&
1144 !dl_prio(task->prio))) {
1145 raw_spin_unlock_irqrestore(&task->pi_lock, flags);
1148 next_lock = waiter->lock;
1149 raw_spin_unlock_irqrestore(&task->pi_lock, flags);
1151 /* gets dropped in rt_mutex_adjust_prio_chain()! */
1152 get_task_struct(task);
1154 rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
1155 next_lock, NULL, task);
1159 * __rt_mutex_slowlock() - Perform the wait-wake-try-to-take loop
1160 * @lock: the rt_mutex to take
1161 * @state: the state the task should block in (TASK_INTERRUPTIBLE
1162 * or TASK_UNINTERRUPTIBLE)
1163 * @timeout: the pre-initialized and started timer, or NULL for none
1164 * @waiter: the pre-initialized rt_mutex_waiter
1166 * Must be called with lock->wait_lock held and interrupts disabled
1169 __rt_mutex_slowlock(struct rt_mutex *lock, int state,
1170 struct hrtimer_sleeper *timeout,
1171 struct rt_mutex_waiter *waiter)
1176 /* Try to acquire the lock: */
1177 if (try_to_take_rt_mutex(lock, current, waiter))
1181 * TASK_INTERRUPTIBLE checks for signals and
1182 * timeout. Ignored otherwise.
1184 if (likely(state == TASK_INTERRUPTIBLE)) {
1185 /* Signal pending? */
1186 if (signal_pending(current))
1188 if (timeout && !timeout->task)
1194 raw_spin_unlock_irq(&lock->wait_lock);
1196 debug_rt_mutex_print_deadlock(waiter);
1200 raw_spin_lock_irq(&lock->wait_lock);
1201 set_current_state(state);
1204 __set_current_state(TASK_RUNNING);
1208 static void rt_mutex_handle_deadlock(int res, int detect_deadlock,
1209 struct rt_mutex_waiter *w)
1212 * If the result is not -EDEADLOCK or the caller requested
1213 * deadlock detection, nothing to do here.
1215 if (res != -EDEADLOCK || detect_deadlock)
1219 * Yell lowdly and stop the task right here.
1221 rt_mutex_print_deadlock(w);
1223 set_current_state(TASK_INTERRUPTIBLE);
1229 * Slow path lock function:
1232 rt_mutex_slowlock(struct rt_mutex *lock, int state,
1233 struct hrtimer_sleeper *timeout,
1234 enum rtmutex_chainwalk chwalk)
1236 struct rt_mutex_waiter waiter;
1237 unsigned long flags;
1240 debug_rt_mutex_init_waiter(&waiter);
1241 RB_CLEAR_NODE(&waiter.pi_tree_entry);
1242 RB_CLEAR_NODE(&waiter.tree_entry);
1245 * Technically we could use raw_spin_[un]lock_irq() here, but this can
1246 * be called in early boot if the cmpxchg() fast path is disabled
1247 * (debug, no architecture support). In this case we will acquire the
1248 * rtmutex with lock->wait_lock held. But we cannot unconditionally
1249 * enable interrupts in that early boot case. So we need to use the
1250 * irqsave/restore variants.
1252 raw_spin_lock_irqsave(&lock->wait_lock, flags);
1254 /* Try to acquire the lock again: */
1255 if (try_to_take_rt_mutex(lock, current, NULL)) {
1256 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1260 set_current_state(state);
1262 /* Setup the timer, when timeout != NULL */
1263 if (unlikely(timeout))
1264 hrtimer_start_expires(&timeout->timer, HRTIMER_MODE_ABS);
1266 ret = task_blocks_on_rt_mutex(lock, &waiter, current, chwalk);
1269 /* sleep on the mutex */
1270 ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);
1272 if (unlikely(ret)) {
1273 __set_current_state(TASK_RUNNING);
1274 if (rt_mutex_has_waiters(lock))
1275 remove_waiter(lock, &waiter);
1276 rt_mutex_handle_deadlock(ret, chwalk, &waiter);
1280 * try_to_take_rt_mutex() sets the waiter bit
1281 * unconditionally. We might have to fix that up.
1283 fixup_rt_mutex_waiters(lock);
1285 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1287 /* Remove pending timer: */
1288 if (unlikely(timeout))
1289 hrtimer_cancel(&timeout->timer);
1291 debug_rt_mutex_free_waiter(&waiter);
1297 * Slow path try-lock function:
1299 static inline int rt_mutex_slowtrylock(struct rt_mutex *lock)
1301 unsigned long flags;
1305 * If the lock already has an owner we fail to get the lock.
1306 * This can be done without taking the @lock->wait_lock as
1307 * it is only being read, and this is a trylock anyway.
1309 if (rt_mutex_owner(lock))
1313 * The mutex has currently no owner. Lock the wait lock and try to
1314 * acquire the lock. We use irqsave here to support early boot calls.
1316 raw_spin_lock_irqsave(&lock->wait_lock, flags);
1318 ret = try_to_take_rt_mutex(lock, current, NULL);
1321 * try_to_take_rt_mutex() sets the lock waiters bit
1322 * unconditionally. Clean this up.
1324 fixup_rt_mutex_waiters(lock);
1326 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1332 * Slow path to release a rt-mutex.
1333 * Return whether the current task needs to undo a potential priority boosting.
1335 static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
1336 struct wake_q_head *wake_q)
1338 unsigned long flags;
1340 /* irqsave required to support early boot calls */
1341 raw_spin_lock_irqsave(&lock->wait_lock, flags);
1343 debug_rt_mutex_unlock(lock);
1345 rt_mutex_deadlock_account_unlock(current);
1348 * We must be careful here if the fast path is enabled. If we
1349 * have no waiters queued we cannot set owner to NULL here
1352 * foo->lock->owner = NULL;
1353 * rtmutex_lock(foo->lock); <- fast path
1354 * free = atomic_dec_and_test(foo->refcnt);
1355 * rtmutex_unlock(foo->lock); <- fast path
1358 * raw_spin_unlock(foo->lock->wait_lock);
1360 * So for the fastpath enabled kernel:
1362 * Nothing can set the waiters bit as long as we hold
1363 * lock->wait_lock. So we do the following sequence:
1365 * owner = rt_mutex_owner(lock);
1366 * clear_rt_mutex_waiters(lock);
1367 * raw_spin_unlock(&lock->wait_lock);
1368 * if (cmpxchg(&lock->owner, owner, 0) == owner)
1372 * The fastpath disabled variant is simple as all access to
1373 * lock->owner is serialized by lock->wait_lock:
1375 * lock->owner = NULL;
1376 * raw_spin_unlock(&lock->wait_lock);
1378 while (!rt_mutex_has_waiters(lock)) {
1379 /* Drops lock->wait_lock ! */
1380 if (unlock_rt_mutex_safe(lock, flags) == true)
1382 /* Relock the rtmutex and try again */
1383 raw_spin_lock_irqsave(&lock->wait_lock, flags);
1387 * The wakeup next waiter path does not suffer from the above
1388 * race. See the comments there.
1390 * Queue the next waiter for wakeup once we release the wait_lock.
1392 mark_wakeup_next_waiter(wake_q, lock);
1394 raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
1396 /* check PI boosting */
1401 * debug aware fast / slowpath lock,trylock,unlock
1403 * The atomic acquire/release ops are compiled away, when either the
1404 * architecture does not support cmpxchg or when debugging is enabled.
1407 rt_mutex_fastlock(struct rt_mutex *lock, int state,
1408 int (*slowfn)(struct rt_mutex *lock, int state,
1409 struct hrtimer_sleeper *timeout,
1410 enum rtmutex_chainwalk chwalk))
1412 if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
1413 rt_mutex_deadlock_account_lock(lock, current);
1416 return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK);
1420 rt_mutex_timed_fastlock(struct rt_mutex *lock, int state,
1421 struct hrtimer_sleeper *timeout,
1422 enum rtmutex_chainwalk chwalk,
1423 int (*slowfn)(struct rt_mutex *lock, int state,
1424 struct hrtimer_sleeper *timeout,
1425 enum rtmutex_chainwalk chwalk))
1427 if (chwalk == RT_MUTEX_MIN_CHAINWALK &&
1428 likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
1429 rt_mutex_deadlock_account_lock(lock, current);
1432 return slowfn(lock, state, timeout, chwalk);
1436 rt_mutex_fasttrylock(struct rt_mutex *lock,
1437 int (*slowfn)(struct rt_mutex *lock))
1439 if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
1440 rt_mutex_deadlock_account_lock(lock, current);
1443 return slowfn(lock);
1447 rt_mutex_fastunlock(struct rt_mutex *lock,
1448 bool (*slowfn)(struct rt_mutex *lock,
1449 struct wake_q_head *wqh))
1451 DEFINE_WAKE_Q(wake_q);
1453 if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
1454 rt_mutex_deadlock_account_unlock(current);
1457 bool deboost = slowfn(lock, &wake_q);
1461 /* Undo pi boosting if necessary: */
1463 rt_mutex_adjust_prio(current);
1468 * rt_mutex_lock - lock a rt_mutex
1470 * @lock: the rt_mutex to be locked
1472 void __sched rt_mutex_lock(struct rt_mutex *lock)
1476 rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
1478 EXPORT_SYMBOL_GPL(rt_mutex_lock);
1481 * rt_mutex_lock_interruptible - lock a rt_mutex interruptible
1483 * @lock: the rt_mutex to be locked
1487 * -EINTR when interrupted by a signal
1489 int __sched rt_mutex_lock_interruptible(struct rt_mutex *lock)
1493 return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
1495 EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
1498 * Futex variant with full deadlock detection.
1500 int rt_mutex_timed_futex_lock(struct rt_mutex *lock,
1501 struct hrtimer_sleeper *timeout)
1505 return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
1506 RT_MUTEX_FULL_CHAINWALK,
1511 * rt_mutex_timed_lock - lock a rt_mutex interruptible
1512 * the timeout structure is provided
1515 * @lock: the rt_mutex to be locked
1516 * @timeout: timeout structure or NULL (no timeout)
1520 * -EINTR when interrupted by a signal
1521 * -ETIMEDOUT when the timeout expired
1524 rt_mutex_timed_lock(struct rt_mutex *lock, struct hrtimer_sleeper *timeout)
1528 return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
1529 RT_MUTEX_MIN_CHAINWALK,
1532 EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
1535 * rt_mutex_trylock - try to lock a rt_mutex
1537 * @lock: the rt_mutex to be locked
1539 * This function can only be called in thread context. It's safe to
1540 * call it from atomic regions, but not from hard interrupt or soft
1541 * interrupt context.
1543 * Returns 1 on success and 0 on contention
1545 int __sched rt_mutex_trylock(struct rt_mutex *lock)
1547 if (WARN_ON_ONCE(in_irq() || in_nmi() || in_serving_softirq()))
1550 return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
1552 EXPORT_SYMBOL_GPL(rt_mutex_trylock);
1555 * rt_mutex_unlock - unlock a rt_mutex
1557 * @lock: the rt_mutex to be unlocked
1559 void __sched rt_mutex_unlock(struct rt_mutex *lock)
1561 rt_mutex_fastunlock(lock, rt_mutex_slowunlock);
1563 EXPORT_SYMBOL_GPL(rt_mutex_unlock);
1566 * rt_mutex_futex_unlock - Futex variant of rt_mutex_unlock
1567 * @lock: the rt_mutex to be unlocked
1569 * Returns: true/false indicating whether priority adjustment is
1572 bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
1573 struct wake_q_head *wqh)
1575 if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
1576 rt_mutex_deadlock_account_unlock(current);
1579 return rt_mutex_slowunlock(lock, wqh);
1583 * rt_mutex_destroy - mark a mutex unusable
1584 * @lock: the mutex to be destroyed
1586 * This function marks the mutex uninitialized, and any subsequent
1587 * use of the mutex is forbidden. The mutex must not be locked when
1588 * this function is called.
1590 void rt_mutex_destroy(struct rt_mutex *lock)
1592 WARN_ON(rt_mutex_is_locked(lock));
1593 #ifdef CONFIG_DEBUG_RT_MUTEXES
1598 EXPORT_SYMBOL_GPL(rt_mutex_destroy);
1601 * __rt_mutex_init - initialize the rt lock
1603 * @lock: the rt lock to be initialized
1605 * Initialize the rt lock to unlocked state.
1607 * Initializing of a locked rt lock is not allowed
1609 void __rt_mutex_init(struct rt_mutex *lock, const char *name)
1612 raw_spin_lock_init(&lock->wait_lock);
1613 lock->waiters = RB_ROOT;
1614 lock->waiters_leftmost = NULL;
1616 debug_rt_mutex_init(lock, name);
1618 EXPORT_SYMBOL_GPL(__rt_mutex_init);
1621 * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
1624 * @lock: the rt_mutex to be locked
1625 * @proxy_owner:the task to set as owner
1627 * No locking. Caller has to do serializing itself
1629 * Special API call for PI-futex support. This initializes the rtmutex and
1630 * assigns it to @proxy_owner. Concurrent operations on the rtmutex are not
1631 * possible at this point because the pi_state which contains the rtmutex
1632 * is not yet visible to other tasks.
1634 void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
1635 struct task_struct *proxy_owner)
1637 __rt_mutex_init(lock, NULL);
1638 debug_rt_mutex_proxy_lock(lock, proxy_owner);
1639 rt_mutex_set_owner(lock, proxy_owner);
1640 rt_mutex_deadlock_account_lock(lock, proxy_owner);
1644 * rt_mutex_proxy_unlock - release a lock on behalf of owner
1646 * @lock: the rt_mutex to be locked
1648 * No locking. Caller has to do serializing itself
1650 * Special API call for PI-futex support. This merrily cleans up the rtmutex
1651 * (debugging) state. Concurrent operations on this rt_mutex are not
1652 * possible because it belongs to the pi_state which is about to be freed
1653 * and it is not longer visible to other tasks.
1655 void rt_mutex_proxy_unlock(struct rt_mutex *lock,
1656 struct task_struct *proxy_owner)
1658 debug_rt_mutex_proxy_unlock(lock);
1659 rt_mutex_set_owner(lock, NULL);
1660 rt_mutex_deadlock_account_unlock(proxy_owner);
1664 * rt_mutex_start_proxy_lock() - Start lock acquisition for another task
1665 * @lock: the rt_mutex to take
1666 * @waiter: the pre-initialized rt_mutex_waiter
1667 * @task: the task to prepare
1670 * 0 - task blocked on lock
1671 * 1 - acquired the lock for task, caller should wake it up
1674 * Special API call for FUTEX_REQUEUE_PI support.
1676 int rt_mutex_start_proxy_lock(struct rt_mutex *lock,
1677 struct rt_mutex_waiter *waiter,
1678 struct task_struct *task)
1682 raw_spin_lock_irq(&lock->wait_lock);
1684 if (try_to_take_rt_mutex(lock, task, NULL)) {
1685 raw_spin_unlock_irq(&lock->wait_lock);
1689 /* We enforce deadlock detection for futexes */
1690 ret = task_blocks_on_rt_mutex(lock, waiter, task,
1691 RT_MUTEX_FULL_CHAINWALK);
1693 if (ret && !rt_mutex_owner(lock)) {
1695 * Reset the return value. We might have
1696 * returned with -EDEADLK and the owner
1697 * released the lock while we were walking the
1698 * pi chain. Let the waiter sort it out.
1704 remove_waiter(lock, waiter);
1706 raw_spin_unlock_irq(&lock->wait_lock);
1708 debug_rt_mutex_print_deadlock(waiter);
1714 * rt_mutex_next_owner - return the next owner of the lock
1716 * @lock: the rt lock query
1718 * Returns the next owner of the lock or NULL
1720 * Caller has to serialize against other accessors to the lock
1723 * Special API call for PI-futex support
1725 struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock)
1727 if (!rt_mutex_has_waiters(lock))
1730 return rt_mutex_top_waiter(lock)->task;
1734 * rt_mutex_finish_proxy_lock() - Complete lock acquisition
1735 * @lock: the rt_mutex we were woken on
1736 * @to: the timeout, null if none. hrtimer should already have
1738 * @waiter: the pre-initialized rt_mutex_waiter
1740 * Complete the lock acquisition started our behalf by another thread.
1744 * <0 - error, one of -EINTR, -ETIMEDOUT
1746 * Special API call for PI-futex requeue support
1748 int rt_mutex_finish_proxy_lock(struct rt_mutex *lock,
1749 struct hrtimer_sleeper *to,
1750 struct rt_mutex_waiter *waiter)
1754 raw_spin_lock_irq(&lock->wait_lock);
1756 set_current_state(TASK_INTERRUPTIBLE);
1758 /* sleep on the mutex */
1759 ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
1762 remove_waiter(lock, waiter);
1765 * try_to_take_rt_mutex() sets the waiter bit unconditionally. We might
1766 * have to fix that up.
1768 fixup_rt_mutex_waiters(lock);
1770 raw_spin_unlock_irq(&lock->wait_lock);