mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-19 13:11:14 +00:00
locking/qspinlock: Use try_cmpxchg() instead of cmpxchg() when locking
When reaching the head of an uncontended queue on the qspinlock slow-path, using a try_cmpxchg() instead of a cmpxchg() operation to transition the lock work to _Q_LOCKED_VAL generates slightly better code for x86 and pretty much identical code for arm64. Reported-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Will Deacon <will.deacon@arm.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Waiman Long <longman@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: boqun.feng@gmail.com Cc: linux-arm-kernel@lists.infradead.org Cc: paulmck@linux.vnet.ibm.com Link: http://lkml.kernel.org/r/1524738868-31318-13-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
9d4646d14d
commit
ae75d9089f
1 changed files with 9 additions and 10 deletions
|
@ -467,16 +467,15 @@ locked:
|
||||||
* Otherwise, we only need to grab the lock.
|
* Otherwise, we only need to grab the lock.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* In the PV case we might already have _Q_LOCKED_VAL set */
|
|
||||||
if ((val & _Q_TAIL_MASK) == tail) {
|
|
||||||
/*
|
/*
|
||||||
|
* In the PV case we might already have _Q_LOCKED_VAL set.
|
||||||
|
*
|
||||||
* The atomic_cond_read_acquire() call above has provided the
|
* The atomic_cond_read_acquire() call above has provided the
|
||||||
* necessary acquire semantics required for locking.
|
* necessary acquire semantics required for locking.
|
||||||
*/
|
*/
|
||||||
old = atomic_cmpxchg_relaxed(&lock->val, val, _Q_LOCKED_VAL);
|
if (((val & _Q_TAIL_MASK) == tail) &&
|
||||||
if (old == val)
|
atomic_try_cmpxchg_relaxed(&lock->val, &val, _Q_LOCKED_VAL))
|
||||||
goto release; /* No contention */
|
goto release; /* No contention */
|
||||||
}
|
|
||||||
|
|
||||||
/* Either somebody is queued behind us or _Q_PENDING_VAL is set */
|
/* Either somebody is queued behind us or _Q_PENDING_VAL is set */
|
||||||
set_locked(lock);
|
set_locked(lock);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue