Lines Matching full:lock

27 #include <trace/events/lock.h>
36 struct rt_mutex *lock, in __ww_mutex_add_waiter() argument
42 static inline void __ww_mutex_check_waiters(struct rt_mutex *lock, in __ww_mutex_check_waiters() argument
47 static inline void ww_mutex_lock_acquired(struct ww_mutex *lock, in ww_mutex_lock_acquired() argument
52 static inline int __ww_mutex_check_kill(struct rt_mutex *lock, in __ww_mutex_check_kill() argument
66 * lock->owner state tracking:
68 * lock->owner holds the task_struct pointer of the owner. Bit 0
69 * is used to keep track of the "lock has waiters" state.
72 * NULL 0 lock is free (fast acquire possible)
73 * NULL 1 lock is free and has waiters and the top waiter
74 * is going to take the lock*
75 * taskpointer 0 lock is held (fast release possible)
76 * taskpointer 1 lock is held and has waiters**
79 * possible when bit 0 of lock->owner is 0.
81 * (*) It also can be a transitional state when grabbing the lock
82 * with ->wait_lock is held. To prevent any fast path cmpxchg to the lock,
83 * we need to set the bit0 before looking at the lock, and the owner may be
87 * waiters. This can happen when grabbing the lock in the slow path.
88 * To prevent a cmpxchg of the owner releasing the lock, we need to
89 * set this bit before looking at the lock.
93 rt_mutex_owner_encode(struct rt_mutex_base *lock, struct task_struct *owner) in rt_mutex_owner_encode() argument
97 if (rt_mutex_has_waiters(lock)) in rt_mutex_owner_encode()
104 rt_mutex_set_owner(struct rt_mutex_base *lock, struct task_struct *owner) in rt_mutex_set_owner() argument
107 * lock->wait_lock is held but explicit acquire semantics are needed in rt_mutex_set_owner()
108 * for a new lock owner so WRITE_ONCE is insufficient. in rt_mutex_set_owner()
110 xchg_acquire(&lock->owner, rt_mutex_owner_encode(lock, owner)); in rt_mutex_set_owner()
113 static __always_inline void rt_mutex_clear_owner(struct rt_mutex_base *lock) in rt_mutex_clear_owner() argument
115 /* lock->wait_lock is held so the unlock provides release semantics. */ in rt_mutex_clear_owner()
116 WRITE_ONCE(lock->owner, rt_mutex_owner_encode(lock, NULL)); in rt_mutex_clear_owner()
119 static __always_inline void clear_rt_mutex_waiters(struct rt_mutex_base *lock) in clear_rt_mutex_waiters() argument
121 lock->owner = (struct task_struct *) in clear_rt_mutex_waiters()
122 ((unsigned long)lock->owner & ~RT_MUTEX_HAS_WAITERS); in clear_rt_mutex_waiters()
126 fixup_rt_mutex_waiters(struct rt_mutex_base *lock, bool acquire_lock) in fixup_rt_mutex_waiters() argument
128 unsigned long owner, *p = (unsigned long *) &lock->owner; in fixup_rt_mutex_waiters()
130 if (rt_mutex_has_waiters(lock)) in fixup_rt_mutex_waiters()
135 * lock->owner still has the waiters bit set, otherwise the in fixup_rt_mutex_waiters()
141 * lock(l->lock) in fixup_rt_mutex_waiters()
145 * unlock(l->lock) in fixup_rt_mutex_waiters()
149 * lock(l->lock) in fixup_rt_mutex_waiters()
153 * unlock(l->lock) in fixup_rt_mutex_waiters()
156 * lock(l->lock) in fixup_rt_mutex_waiters()
159 * unlock(l->lock) in fixup_rt_mutex_waiters()
160 * lock(l->lock) in fixup_rt_mutex_waiters()
164 * unlock(l->lock) in fixup_rt_mutex_waiters()
165 * lock(l->lock) in fixup_rt_mutex_waiters()
172 * lock(l->lock) in fixup_rt_mutex_waiters()
185 * serialized by l->lock, so nothing else can modify the waiters in fixup_rt_mutex_waiters()
199 * in case that the lock acquisition failed it might in fixup_rt_mutex_waiters()
214 static __always_inline bool rt_mutex_cmpxchg_acquire(struct rt_mutex_base *lock, in rt_mutex_cmpxchg_acquire() argument
218 return try_cmpxchg_acquire(&lock->owner, &old, new); in rt_mutex_cmpxchg_acquire()
221 static __always_inline bool rt_mutex_try_acquire(struct rt_mutex_base *lock) in rt_mutex_try_acquire() argument
223 return rt_mutex_cmpxchg_acquire(lock, NULL, current); in rt_mutex_try_acquire()
226 static __always_inline bool rt_mutex_cmpxchg_release(struct rt_mutex_base *lock, in rt_mutex_cmpxchg_release() argument
230 return try_cmpxchg_release(&lock->owner, &old, new); in rt_mutex_cmpxchg_release()
235 * all future threads that attempt to [Rmw] the lock to the slowpath. As such
238 static __always_inline void mark_rt_mutex_waiters(struct rt_mutex_base *lock) in mark_rt_mutex_waiters() argument
240 unsigned long owner, *p = (unsigned long *) &lock->owner; in mark_rt_mutex_waiters()
258 * 2) Drop lock->wait_lock
259 * 3) Try to unlock the lock with cmpxchg
261 static __always_inline bool unlock_rt_mutex_safe(struct rt_mutex_base *lock, in unlock_rt_mutex_safe() argument
263 __releases(lock->wait_lock) in unlock_rt_mutex_safe()
265 struct task_struct *owner = rt_mutex_owner(lock); in unlock_rt_mutex_safe()
267 clear_rt_mutex_waiters(lock); in unlock_rt_mutex_safe()
268 raw_spin_unlock_irqrestore(&lock->wait_lock, flags); in unlock_rt_mutex_safe()
274 * lock(wait_lock); in unlock_rt_mutex_safe()
276 * mark_rt_mutex_waiters(lock); in unlock_rt_mutex_safe()
277 * acquire(lock); in unlock_rt_mutex_safe()
281 * lock(wait_lock); in unlock_rt_mutex_safe()
282 * mark_rt_mutex_waiters(lock); in unlock_rt_mutex_safe()
287 * lock(wait_lock); in unlock_rt_mutex_safe()
290 * lock(wait_lock); in unlock_rt_mutex_safe()
291 * acquire(lock); in unlock_rt_mutex_safe()
293 return rt_mutex_cmpxchg_release(lock, owner, NULL); in unlock_rt_mutex_safe()
297 static __always_inline bool rt_mutex_cmpxchg_acquire(struct rt_mutex_base *lock, in rt_mutex_cmpxchg_acquire() argument
305 static int __sched rt_mutex_slowtrylock(struct rt_mutex_base *lock);
307 static __always_inline bool rt_mutex_try_acquire(struct rt_mutex_base *lock) in rt_mutex_try_acquire() argument
316 return rt_mutex_slowtrylock(lock); in rt_mutex_try_acquire()
319 static __always_inline bool rt_mutex_cmpxchg_release(struct rt_mutex_base *lock, in rt_mutex_cmpxchg_release() argument
326 static __always_inline void mark_rt_mutex_waiters(struct rt_mutex_base *lock) in mark_rt_mutex_waiters() argument
328 lock->owner = (struct task_struct *) in mark_rt_mutex_waiters()
329 ((unsigned long)lock->owner | RT_MUTEX_HAS_WAITERS); in mark_rt_mutex_waiters()
333 * Simple slow path only version: lock->owner is protected by lock->wait_lock.
335 static __always_inline bool unlock_rt_mutex_safe(struct rt_mutex_base *lock, in unlock_rt_mutex_safe() argument
337 __releases(lock->wait_lock) in unlock_rt_mutex_safe()
339 lock->owner = NULL; in unlock_rt_mutex_safe()
340 raw_spin_unlock_irqrestore(&lock->wait_lock, flags); in unlock_rt_mutex_safe()
361 lockdep_assert_held(&waiter->lock->wait_lock); in waiter_update_prio()
374 lockdep_assert_held(&waiter->lock->wait_lock); in waiter_clone_prio()
476 rt_mutex_enqueue(struct rt_mutex_base *lock, struct rt_mutex_waiter *waiter) in rt_mutex_enqueue() argument
478 lockdep_assert_held(&lock->wait_lock); in rt_mutex_enqueue()
480 rb_add_cached(&waiter->tree.entry, &lock->waiters, __waiter_less); in rt_mutex_enqueue()
484 rt_mutex_dequeue(struct rt_mutex_base *lock, struct rt_mutex_waiter *waiter) in rt_mutex_dequeue() argument
486 lockdep_assert_held(&lock->wait_lock); in rt_mutex_dequeue()
491 rb_erase_cached(&waiter->tree.entry, &lock->waiters); in rt_mutex_dequeue()
523 static __always_inline void rt_mutex_adjust_prio(struct rt_mutex_base *lock, in rt_mutex_adjust_prio() argument
528 lockdep_assert_held(&lock->wait_lock); in rt_mutex_adjust_prio()
529 lockdep_assert(rt_mutex_owner(lock) == p); in rt_mutex_adjust_prio()
598 return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL; in task_blocked_on_lock()
613 * comparison to detect lock chain changes.
647 * [1] lock(task->pi_lock); [R] acquire [P1]
650 * [4] lock = waiter->lock; [P1]
651 * [5] if (!try_lock(lock->wait_lock)) { [P1] try to acquire [L]
656 * [7] requeue_lock_waiter(lock, waiter); [P1] + [L]
660 * [10] task = owner(lock); [L]
662 * lock(task->pi_lock); [L] acquire [P2]
663 * [11] requeue_pi_waiter(tsk, waiters(lock));[P2] + [L]
666 * unlock(lock->wait_lock); release [L]
669 * Where P1 is the blocking task and P2 is the lock owner; going up one step
684 struct rt_mutex_base *lock; in rt_mutex_adjust_prio_chain() local
698 * We limit the lock chain length for each invocation. in rt_mutex_adjust_prio_chain()
709 printk(KERN_WARNING "Maximum lock depth %d reached " in rt_mutex_adjust_prio_chain()
749 * the previous owner of the lock might have released the lock. in rt_mutex_adjust_prio_chain()
756 * the task might have moved on in the lock chain or even left in rt_mutex_adjust_prio_chain()
757 * the chain completely and blocks now on an unrelated lock or in rt_mutex_adjust_prio_chain()
760 * We stored the lock on which @task was blocked in @next_lock, in rt_mutex_adjust_prio_chain()
763 if (next_lock != waiter->lock) in rt_mutex_adjust_prio_chain()
767 * There could be 'spurious' loops in the lock graph due to ww_mutex, in rt_mutex_adjust_prio_chain()
828 * [4] Get the next lock; per holding task->pi_lock we can't unblock in rt_mutex_adjust_prio_chain()
829 * and guarantee @lock's existence. in rt_mutex_adjust_prio_chain()
831 lock = waiter->lock; in rt_mutex_adjust_prio_chain()
834 * which is the reverse lock order versus the other rtmutex in rt_mutex_adjust_prio_chain()
837 * Per the above, holding task->pi_lock guarantees lock exists, so in rt_mutex_adjust_prio_chain()
838 * inverting this lock order is infeasible from a life-time in rt_mutex_adjust_prio_chain()
841 if (!raw_spin_trylock(&lock->wait_lock)) { in rt_mutex_adjust_prio_chain()
849 * lock->wait_lock. in rt_mutex_adjust_prio_chain()
851 * Deadlock detection. If the lock is the same as the original in rt_mutex_adjust_prio_chain()
852 * lock which caused us to walk the lock chain or if the in rt_mutex_adjust_prio_chain()
853 * current lock is owned by the task which initiated the chain in rt_mutex_adjust_prio_chain()
856 if (lock == orig_lock || rt_mutex_owner(lock) == top_task) { in rt_mutex_adjust_prio_chain()
871 raw_spin_unlock(&lock->wait_lock); in rt_mutex_adjust_prio_chain()
876 * If we just follow the lock chain for deadlock detection, no in rt_mutex_adjust_prio_chain()
889 * [9] check_exit_conditions_3 protected by lock->wait_lock. in rt_mutex_adjust_prio_chain()
890 * If there is no owner of the lock, end of chain. in rt_mutex_adjust_prio_chain()
892 if (!rt_mutex_owner(lock)) { in rt_mutex_adjust_prio_chain()
893 raw_spin_unlock_irq(&lock->wait_lock); in rt_mutex_adjust_prio_chain()
897 /* [10] Grab the next task, i.e. owner of @lock */ in rt_mutex_adjust_prio_chain()
898 task = get_task_struct(rt_mutex_owner(lock)); in rt_mutex_adjust_prio_chain()
911 top_waiter = rt_mutex_top_waiter(lock); in rt_mutex_adjust_prio_chain()
915 raw_spin_unlock_irq(&lock->wait_lock); in rt_mutex_adjust_prio_chain()
925 * operation on @lock. We need it for the boost/deboost in rt_mutex_adjust_prio_chain()
928 prerequeue_top_waiter = rt_mutex_top_waiter(lock); in rt_mutex_adjust_prio_chain()
930 /* [7] Requeue the waiter in the lock waiter tree. */ in rt_mutex_adjust_prio_chain()
931 rt_mutex_dequeue(lock, waiter); in rt_mutex_adjust_prio_chain()
946 rt_mutex_enqueue(lock, waiter); in rt_mutex_adjust_prio_chain()
952 * Since we hold lock->waiter_lock, task cannot unblock, even if we in rt_mutex_adjust_prio_chain()
959 * [9] check_exit_conditions_3 protected by lock->wait_lock. in rt_mutex_adjust_prio_chain()
961 * We must abort the chain walk if there is no lock owner even in rt_mutex_adjust_prio_chain()
962 * in the dead lock detection case, as we have nothing to in rt_mutex_adjust_prio_chain()
965 if (!rt_mutex_owner(lock)) { in rt_mutex_adjust_prio_chain()
969 * to get the lock. in rt_mutex_adjust_prio_chain()
971 top_waiter = rt_mutex_top_waiter(lock); in rt_mutex_adjust_prio_chain()
974 raw_spin_unlock_irq(&lock->wait_lock); in rt_mutex_adjust_prio_chain()
979 * [10] Grab the next task, i.e. the owner of @lock in rt_mutex_adjust_prio_chain()
981 * Per holding lock->wait_lock and checking for !owner above, there in rt_mutex_adjust_prio_chain()
984 task = get_task_struct(rt_mutex_owner(lock)); in rt_mutex_adjust_prio_chain()
988 if (waiter == rt_mutex_top_waiter(lock)) { in rt_mutex_adjust_prio_chain()
991 * waiter on the lock. Replace the previous top waiter in rt_mutex_adjust_prio_chain()
998 rt_mutex_adjust_prio(lock, task); in rt_mutex_adjust_prio_chain()
1002 * The waiter was the top waiter on the lock, but is in rt_mutex_adjust_prio_chain()
1012 waiter = rt_mutex_top_waiter(lock); in rt_mutex_adjust_prio_chain()
1015 rt_mutex_adjust_prio(lock, task); in rt_mutex_adjust_prio_chain()
1025 * and lock->wait_lock. The actual decisions are made after we in rt_mutex_adjust_prio_chain()
1028 * Check whether the task which owns the current lock is pi in rt_mutex_adjust_prio_chain()
1029 * blocked itself. If yes we store a pointer to the lock for in rt_mutex_adjust_prio_chain()
1030 * the lock chain change detection above. After we dropped in rt_mutex_adjust_prio_chain()
1035 * Store the top waiter of @lock for the end of chain walk in rt_mutex_adjust_prio_chain()
1038 top_waiter = rt_mutex_top_waiter(lock); in rt_mutex_adjust_prio_chain()
1042 raw_spin_unlock_irq(&lock->wait_lock); in rt_mutex_adjust_prio_chain()
1048 * We reached the end of the lock chain. Stop right here. No in rt_mutex_adjust_prio_chain()
1055 * If the current waiter is not the top waiter on the lock, in rt_mutex_adjust_prio_chain()
1075 * Must be called with lock->wait_lock held and interrupts disabled
1077 * @lock: The lock to be acquired.
1078 * @task: The task which wants to acquire the lock
1079 * @waiter: The waiter that is queued to the lock's wait tree if the
1083 try_to_take_rt_mutex(struct rt_mutex_base *lock, struct task_struct *task, in try_to_take_rt_mutex() argument
1086 lockdep_assert_held(&lock->wait_lock); in try_to_take_rt_mutex()
1089 * Before testing whether we can acquire @lock, we set the in try_to_take_rt_mutex()
1090 * RT_MUTEX_HAS_WAITERS bit in @lock->owner. This forces all in try_to_take_rt_mutex()
1091 * other tasks which try to modify @lock into the slow path in try_to_take_rt_mutex()
1092 * and they serialize on @lock->wait_lock. in try_to_take_rt_mutex()
1097 * - There is a lock owner. The caller must fixup the in try_to_take_rt_mutex()
1098 * transient state if it does a trylock or leaves the lock in try_to_take_rt_mutex()
1101 * - @task acquires the lock and there are no other in try_to_take_rt_mutex()
1105 mark_rt_mutex_waiters(lock); in try_to_take_rt_mutex()
1108 * If @lock has an owner, give up. in try_to_take_rt_mutex()
1110 if (rt_mutex_owner(lock)) in try_to_take_rt_mutex()
1115 * into @lock waiter tree. If @waiter == NULL then this is a in try_to_take_rt_mutex()
1119 struct rt_mutex_waiter *top_waiter = rt_mutex_top_waiter(lock); in try_to_take_rt_mutex()
1122 * If waiter is the highest priority waiter of @lock, in try_to_take_rt_mutex()
1127 * We can acquire the lock. Remove the waiter from the in try_to_take_rt_mutex()
1128 * lock waiters tree. in try_to_take_rt_mutex()
1130 rt_mutex_dequeue(lock, waiter); in try_to_take_rt_mutex()
1136 * If the lock has waiters already we check whether @task is in try_to_take_rt_mutex()
1137 * eligible to take over the lock. in try_to_take_rt_mutex()
1140 * the lock. @task->pi_blocked_on is NULL, so it does in try_to_take_rt_mutex()
1143 if (rt_mutex_has_waiters(lock)) { in try_to_take_rt_mutex()
1146 rt_mutex_top_waiter(lock))) in try_to_take_rt_mutex()
1151 * don't have to change anything in the lock in try_to_take_rt_mutex()
1156 * No waiters. Take the lock without the in try_to_take_rt_mutex()
1174 * Finish the lock acquisition. @task is the new owner. If in try_to_take_rt_mutex()
1178 if (rt_mutex_has_waiters(lock)) in try_to_take_rt_mutex()
1179 rt_mutex_enqueue_pi(task, rt_mutex_top_waiter(lock)); in try_to_take_rt_mutex()
1187 rt_mutex_set_owner(lock, task); in try_to_take_rt_mutex()
1193 * Task blocks on lock.
1197 * This must be called with lock->wait_lock held and interrupts disabled
1199 static int __sched task_blocks_on_rt_mutex(struct rt_mutex_base *lock, in task_blocks_on_rt_mutex() argument
1205 struct task_struct *owner = rt_mutex_owner(lock); in task_blocks_on_rt_mutex()
1210 lockdep_assert_held(&lock->wait_lock); in task_blocks_on_rt_mutex()
1229 waiter->lock = lock; in task_blocks_on_rt_mutex()
1233 /* Get the top priority waiter on the lock */ in task_blocks_on_rt_mutex()
1234 if (rt_mutex_has_waiters(lock)) in task_blocks_on_rt_mutex()
1235 top_waiter = rt_mutex_top_waiter(lock); in task_blocks_on_rt_mutex()
1236 rt_mutex_enqueue(lock, waiter); in task_blocks_on_rt_mutex()
1246 rtm = container_of(lock, struct rt_mutex, rtmutex); in task_blocks_on_rt_mutex()
1250 rt_mutex_dequeue(lock, waiter); in task_blocks_on_rt_mutex()
1261 if (waiter == rt_mutex_top_waiter(lock)) { in task_blocks_on_rt_mutex()
1265 rt_mutex_adjust_prio(lock, owner); in task_blocks_on_rt_mutex()
1272 /* Store the lock on which owner is blocked or NULL */ in task_blocks_on_rt_mutex()
1285 * The owner can't disappear while holding a lock, in task_blocks_on_rt_mutex()
1291 raw_spin_unlock_irq(&lock->wait_lock); in task_blocks_on_rt_mutex()
1293 res = rt_mutex_adjust_prio_chain(owner, chwalk, lock, in task_blocks_on_rt_mutex()
1296 raw_spin_lock_irq(&lock->wait_lock); in task_blocks_on_rt_mutex()
1305 * Called with lock->wait_lock held and interrupts disabled.
1308 struct rt_mutex_base *lock) in mark_wakeup_next_waiter() argument
1312 lockdep_assert_held(&lock->wait_lock); in mark_wakeup_next_waiter()
1316 waiter = rt_mutex_top_waiter(lock); in mark_wakeup_next_waiter()
1326 rt_mutex_adjust_prio(lock, current); in mark_wakeup_next_waiter()
1330 * queued on the lock until it gets the lock, this lock in mark_wakeup_next_waiter()
1334 * the top waiter can steal this lock. in mark_wakeup_next_waiter()
1336 lock->owner = (void *) RT_MUTEX_HAS_WAITERS; in mark_wakeup_next_waiter()
1353 static int __sched __rt_mutex_slowtrylock(struct rt_mutex_base *lock) in __rt_mutex_slowtrylock() argument
1355 int ret = try_to_take_rt_mutex(lock, current, NULL); in __rt_mutex_slowtrylock()
1358 * try_to_take_rt_mutex() sets the lock waiters bit in __rt_mutex_slowtrylock()
1361 fixup_rt_mutex_waiters(lock, true); in __rt_mutex_slowtrylock()
1367 * Slow path try-lock function:
1369 static int __sched rt_mutex_slowtrylock(struct rt_mutex_base *lock) in rt_mutex_slowtrylock() argument
1375 * If the lock already has an owner we fail to get the lock. in rt_mutex_slowtrylock()
1376 * This can be done without taking the @lock->wait_lock as in rt_mutex_slowtrylock()
1379 if (rt_mutex_owner(lock)) in rt_mutex_slowtrylock()
1383 * The mutex has currently no owner. Lock the wait lock and try to in rt_mutex_slowtrylock()
1384 * acquire the lock. We use irqsave here to support early boot calls. in rt_mutex_slowtrylock()
1386 raw_spin_lock_irqsave(&lock->wait_lock, flags); in rt_mutex_slowtrylock()
1388 ret = __rt_mutex_slowtrylock(lock); in rt_mutex_slowtrylock()
1390 raw_spin_unlock_irqrestore(&lock->wait_lock, flags); in rt_mutex_slowtrylock()
1395 static __always_inline int __rt_mutex_trylock(struct rt_mutex_base *lock) in __rt_mutex_trylock() argument
1397 if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) in __rt_mutex_trylock()
1400 return rt_mutex_slowtrylock(lock); in __rt_mutex_trylock()
1406 static void __sched rt_mutex_slowunlock(struct rt_mutex_base *lock) in rt_mutex_slowunlock() argument
1412 raw_spin_lock_irqsave(&lock->wait_lock, flags); in rt_mutex_slowunlock()
1414 debug_rt_mutex_unlock(lock); in rt_mutex_slowunlock()
1421 * foo->lock->owner = NULL; in rt_mutex_slowunlock()
1422 * rtmutex_lock(foo->lock); <- fast path in rt_mutex_slowunlock()
1424 * rtmutex_unlock(foo->lock); <- fast path in rt_mutex_slowunlock()
1427 * raw_spin_unlock(foo->lock->wait_lock); in rt_mutex_slowunlock()
1432 * lock->wait_lock. So we do the following sequence: in rt_mutex_slowunlock()
1434 * owner = rt_mutex_owner(lock); in rt_mutex_slowunlock()
1435 * clear_rt_mutex_waiters(lock); in rt_mutex_slowunlock()
1436 * raw_spin_unlock(&lock->wait_lock); in rt_mutex_slowunlock()
1437 * if (cmpxchg(&lock->owner, owner, 0) == owner) in rt_mutex_slowunlock()
1442 * lock->owner is serialized by lock->wait_lock: in rt_mutex_slowunlock()
1444 * lock->owner = NULL; in rt_mutex_slowunlock()
1445 * raw_spin_unlock(&lock->wait_lock); in rt_mutex_slowunlock()
1447 while (!rt_mutex_has_waiters(lock)) { in rt_mutex_slowunlock()
1448 /* Drops lock->wait_lock ! */ in rt_mutex_slowunlock()
1449 if (unlock_rt_mutex_safe(lock, flags) == true) in rt_mutex_slowunlock()
1452 raw_spin_lock_irqsave(&lock->wait_lock, flags); in rt_mutex_slowunlock()
1461 mark_wakeup_next_waiter(&wqh, lock); in rt_mutex_slowunlock()
1462 raw_spin_unlock_irqrestore(&lock->wait_lock, flags); in rt_mutex_slowunlock()
1467 static __always_inline void __rt_mutex_unlock(struct rt_mutex_base *lock) in __rt_mutex_unlock() argument
1469 if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) in __rt_mutex_unlock()
1472 rt_mutex_slowunlock(lock); in __rt_mutex_unlock()
1476 static bool rtmutex_spin_on_owner(struct rt_mutex_base *lock, in rtmutex_spin_on_owner() argument
1485 if (owner != rt_mutex_owner(lock)) in rtmutex_spin_on_owner()
1489 * the lock owner still matches @owner. If that fails, in rtmutex_spin_on_owner()
1496 * - the lock owner has been scheduled out in rtmutex_spin_on_owner()
1503 !rt_mutex_waiter_is_top_waiter(lock, waiter)) { in rtmutex_spin_on_owner()
1513 static bool rtmutex_spin_on_owner(struct rt_mutex_base *lock, in rtmutex_spin_on_owner() argument
1529 * Remove a waiter from a lock and give up
1531 * Must be called with lock->wait_lock held and interrupts disabled. It must
1534 static void __sched remove_waiter(struct rt_mutex_base *lock, in remove_waiter() argument
1537 bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock)); in remove_waiter()
1538 struct task_struct *owner = rt_mutex_owner(lock); in remove_waiter()
1541 lockdep_assert_held(&lock->wait_lock); in remove_waiter()
1544 rt_mutex_dequeue(lock, waiter); in remove_waiter()
1550 * waiter of the lock and there is an owner to update. in remove_waiter()
1559 if (rt_mutex_has_waiters(lock)) in remove_waiter()
1560 rt_mutex_enqueue_pi(owner, rt_mutex_top_waiter(lock)); in remove_waiter()
1562 rt_mutex_adjust_prio(lock, owner); in remove_waiter()
1564 /* Store the lock on which owner is blocked or NULL */ in remove_waiter()
1579 raw_spin_unlock_irq(&lock->wait_lock); in remove_waiter()
1581 rt_mutex_adjust_prio_chain(owner, RT_MUTEX_MIN_CHAINWALK, lock, in remove_waiter()
1584 raw_spin_lock_irq(&lock->wait_lock); in remove_waiter()
1589 * @lock: the rt_mutex to take
1596 * Must be called with lock->wait_lock held and interrupts disabled
1598 static int __sched rt_mutex_slowlock_block(struct rt_mutex_base *lock, in rt_mutex_slowlock_block() argument
1604 struct rt_mutex *rtm = container_of(lock, struct rt_mutex, rtmutex); in rt_mutex_slowlock_block()
1609 /* Try to acquire the lock: */ in rt_mutex_slowlock_block()
1610 if (try_to_take_rt_mutex(lock, current, waiter)) in rt_mutex_slowlock_block()
1628 if (waiter == rt_mutex_top_waiter(lock)) in rt_mutex_slowlock_block()
1629 owner = rt_mutex_owner(lock); in rt_mutex_slowlock_block()
1632 raw_spin_unlock_irq(&lock->wait_lock); in rt_mutex_slowlock_block()
1634 if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner)) in rt_mutex_slowlock_block()
1637 raw_spin_lock_irq(&lock->wait_lock); in rt_mutex_slowlock_block()
1669 * __rt_mutex_slowlock - Locking slowpath invoked with lock::wait_lock held
1670 * @lock: The rtmutex to block lock
1676 static int __sched __rt_mutex_slowlock(struct rt_mutex_base *lock, in __rt_mutex_slowlock() argument
1682 struct rt_mutex *rtm = container_of(lock, struct rt_mutex, rtmutex); in __rt_mutex_slowlock()
1686 lockdep_assert_held(&lock->wait_lock); in __rt_mutex_slowlock()
1688 /* Try to acquire the lock again: */ in __rt_mutex_slowlock()
1689 if (try_to_take_rt_mutex(lock, current, NULL)) { in __rt_mutex_slowlock()
1699 trace_contention_begin(lock, LCB_F_RT); in __rt_mutex_slowlock()
1701 ret = task_blocks_on_rt_mutex(lock, waiter, current, ww_ctx, chwalk); in __rt_mutex_slowlock()
1703 ret = rt_mutex_slowlock_block(lock, ww_ctx, state, NULL, waiter); in __rt_mutex_slowlock()
1706 /* acquired the lock */ in __rt_mutex_slowlock()
1714 remove_waiter(lock, waiter); in __rt_mutex_slowlock()
1722 fixup_rt_mutex_waiters(lock, true); in __rt_mutex_slowlock()
1724 trace_contention_end(lock, ret); in __rt_mutex_slowlock()
1729 static inline int __rt_mutex_slowlock_locked(struct rt_mutex_base *lock, in __rt_mutex_slowlock_locked() argument
1739 ret = __rt_mutex_slowlock(lock, ww_ctx, state, RT_MUTEX_MIN_CHAINWALK, in __rt_mutex_slowlock_locked()
1748 * @lock: The rtmutex to block lock
1752 static int __sched rt_mutex_slowlock(struct rt_mutex_base *lock, in rt_mutex_slowlock() argument
1772 * rtmutex with lock->wait_lock held. But we cannot unconditionally in rt_mutex_slowlock()
1776 raw_spin_lock_irqsave(&lock->wait_lock, flags); in rt_mutex_slowlock()
1777 ret = __rt_mutex_slowlock_locked(lock, ww_ctx, state); in rt_mutex_slowlock()
1778 raw_spin_unlock_irqrestore(&lock->wait_lock, flags); in rt_mutex_slowlock()
1784 static __always_inline int __rt_mutex_lock(struct rt_mutex_base *lock, in __rt_mutex_lock() argument
1789 if (likely(rt_mutex_try_acquire(lock))) in __rt_mutex_lock()
1792 return rt_mutex_slowlock(lock, NULL, state); in __rt_mutex_lock()
1802 * rtlock_slowlock_locked - Slow path lock acquisition for RT locks
1803 * @lock: The underlying RT mutex
1805 static void __sched rtlock_slowlock_locked(struct rt_mutex_base *lock) in rtlock_slowlock_locked() argument
1810 lockdep_assert_held(&lock->wait_lock); in rtlock_slowlock_locked()
1812 if (try_to_take_rt_mutex(lock, current, NULL)) in rtlock_slowlock_locked()
1820 trace_contention_begin(lock, LCB_F_RT); in rtlock_slowlock_locked()
1822 task_blocks_on_rt_mutex(lock, &waiter, current, NULL, RT_MUTEX_MIN_CHAINWALK); in rtlock_slowlock_locked()
1825 /* Try to acquire the lock again */ in rtlock_slowlock_locked()
1826 if (try_to_take_rt_mutex(lock, current, &waiter)) in rtlock_slowlock_locked()
1829 if (&waiter == rt_mutex_top_waiter(lock)) in rtlock_slowlock_locked()
1830 owner = rt_mutex_owner(lock); in rtlock_slowlock_locked()
1833 raw_spin_unlock_irq(&lock->wait_lock); in rtlock_slowlock_locked()
1835 if (!owner || !rtmutex_spin_on_owner(lock, &waiter, owner)) in rtlock_slowlock_locked()
1838 raw_spin_lock_irq(&lock->wait_lock); in rtlock_slowlock_locked()
1849 fixup_rt_mutex_waiters(lock, true); in rtlock_slowlock_locked()
1852 trace_contention_end(lock, 0); in rtlock_slowlock_locked()
1855 static __always_inline void __sched rtlock_slowlock(struct rt_mutex_base *lock) in rtlock_slowlock() argument
1859 raw_spin_lock_irqsave(&lock->wait_lock, flags); in rtlock_slowlock()
1860 rtlock_slowlock_locked(lock); in rtlock_slowlock()
1861 raw_spin_unlock_irqrestore(&lock->wait_lock, flags); in rtlock_slowlock()