Lines Matching full:lock
30 * not running. The one lock stealing attempt allowed at slowpath entry
57 * Hybrid PV queued/unfair lock
60 * it will be called once when a lock waiter enter the PV slowpath before
64 * pv_wait_head_or_lock() to signal that it is ready to spin on the lock.
65 * When that bit becomes visible to the incoming waiters, no lock stealing
67 * enter the MCS wait queue. So lock starvation shouldn't happen as long
69 * and hence disabling lock stealing.
71 * When the pending bit isn't set, the lock waiters will stay in the unfair
72 * mode spinning on the lock unless the MCS wait queue is empty. In this
73 * case, the lock waiters will enter the queued mode slowpath trying to
76 * This hybrid PV queued/unfair lock combines the best attributes of a
77 * queued lock (no lock starvation) and an unfair lock (good performance
81 static inline bool pv_hybrid_queued_unfair_trylock(struct qspinlock *lock) in pv_hybrid_queued_unfair_trylock() argument
84 * Stay in unfair lock mode as long as queued mode waiters are in pv_hybrid_queued_unfair_trylock()
88 int val = atomic_read(&lock->val); in pv_hybrid_queued_unfair_trylock()
92 try_cmpxchg_acquire(&lock->locked, &old, _Q_LOCKED_VAL)) { in pv_hybrid_queued_unfair_trylock()
107 * is actively spinning on the lock and no lock stealing is allowed.
110 static __always_inline void set_pending(struct qspinlock *lock) in set_pending() argument
112 WRITE_ONCE(lock->pending, 1); in set_pending()
118 * lock just to be sure that it will get it.
120 static __always_inline bool trylock_clear_pending(struct qspinlock *lock) in trylock_clear_pending() argument
124 return !READ_ONCE(lock->locked) && in trylock_clear_pending()
125 try_cmpxchg_acquire(&lock->locked_pending, &old, _Q_LOCKED_VAL); in trylock_clear_pending()
128 static __always_inline void set_pending(struct qspinlock *lock) in set_pending() argument
130 atomic_or(_Q_PENDING_VAL, &lock->val); in set_pending()
133 static __always_inline bool trylock_clear_pending(struct qspinlock *lock) in trylock_clear_pending() argument
137 old = atomic_read(&lock->val); in trylock_clear_pending()
145 } while (!atomic_try_cmpxchg_acquire (&lock->val, &old, new)); in trylock_clear_pending()
152 * Lock and MCS node addresses hash table for fast lookup
168 struct qspinlock *lock; member
208 static struct qspinlock **pv_hash(struct qspinlock *lock, struct pv_node *node) in pv_hash() argument
210 unsigned long offset, hash = hash_ptr(lock, pv_lock_hash_bits); in pv_hash()
217 if (try_cmpxchg(&he->lock, &old, lock)) { in pv_hash()
220 return &he->lock; in pv_hash()
226 * This is guaranteed by ensuring every blocked lock only ever consumes in pv_hash()
230 * The single entry is guaranteed by having the lock owner unhash in pv_hash()
236 static struct pv_node *pv_unhash(struct qspinlock *lock) in pv_unhash() argument
238 unsigned long offset, hash = hash_ptr(lock, pv_lock_hash_bits); in pv_unhash()
243 if (READ_ONCE(he->lock) == lock) { in pv_unhash()
245 WRITE_ONCE(he->lock, NULL); in pv_unhash()
253 * having the lock owner do the unhash -- IFF the unlock sees the in pv_unhash()
328 * to hash this lock. in pv_wait_node()
337 * MCS lock will be released soon. in pv_wait_node()
351 * Called after setting next->locked = 1 when we're the lock owner.
357 static void pv_kick_node(struct qspinlock *lock, struct mcs_spinlock *node) in pv_kick_node() argument
381 * Put the lock into the hash table and set the _Q_SLOW_VAL. in pv_kick_node()
387 WRITE_ONCE(lock->locked, _Q_SLOW_VAL); in pv_kick_node()
388 (void)pv_hash(lock, pn); in pv_kick_node()
392 * Wait for l->locked to become clear and acquire the lock;
396 * The current value of the lock will be returned for additional processing.
399 pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node) in pv_wait_head_or_lock() argument
426 * Set the pending bit in the active lock spinning loop to in pv_wait_head_or_lock()
427 * disable lock stealing before attempting to acquire the lock. in pv_wait_head_or_lock()
429 set_pending(lock); in pv_wait_head_or_lock()
431 if (trylock_clear_pending(lock)) in pv_wait_head_or_lock()
435 clear_pending(lock); in pv_wait_head_or_lock()
439 lp = pv_hash(lock, pn); in pv_wait_head_or_lock()
452 if (xchg(&lock->locked, _Q_SLOW_VAL) == 0) { in pv_wait_head_or_lock()
454 * The lock was free and now we own the lock. in pv_wait_head_or_lock()
455 * Change the lock value back to _Q_LOCKED_VAL in pv_wait_head_or_lock()
458 WRITE_ONCE(lock->locked, _Q_LOCKED_VAL); in pv_wait_head_or_lock()
466 pv_wait(&lock->locked, _Q_SLOW_VAL); in pv_wait_head_or_lock()
469 * Because of lock stealing, the queue head vCPU may not be in pv_wait_head_or_lock()
470 * able to acquire the lock before it has to wait again. in pv_wait_head_or_lock()
481 return (u32)(atomic_read(&lock->val) | _Q_LOCKED_VAL); in pv_wait_head_or_lock()
499 __pv_queued_spin_unlock_slowpath(struct qspinlock *lock, u8 locked) in __pv_queued_spin_unlock_slowpath() argument
505 "pvqspinlock: lock 0x%lx has corrupted value 0x%x!\n", in __pv_queued_spin_unlock_slowpath()
506 (unsigned long)lock, atomic_read(&lock->val)); in __pv_queued_spin_unlock_slowpath()
513 * pv_unhash *after* we've read the lock being _Q_SLOW_VAL. in __pv_queued_spin_unlock_slowpath()
523 node = pv_unhash(lock); in __pv_queued_spin_unlock_slowpath()
527 * release the lock. in __pv_queued_spin_unlock_slowpath()
529 smp_store_release(&lock->locked, 0); in __pv_queued_spin_unlock_slowpath()
532 * At this point the memory pointed at by lock can be freed/reused, in __pv_queued_spin_unlock_slowpath()
543 __visible __lockfunc void __pv_queued_spin_unlock(struct qspinlock *lock) in __pv_queued_spin_unlock() argument
549 * unhash. Otherwise it would be possible to have multiple @lock in __pv_queued_spin_unlock()
552 if (try_cmpxchg_release(&lock->locked, &locked, 0)) in __pv_queued_spin_unlock()
555 __pv_queued_spin_unlock_slowpath(lock, locked); in __pv_queued_spin_unlock()