locking/qspinlock: Optimize pending state waiting for unlock
PATCH v2 1/1 locking/qspinlock: Optimize pending state waiting for unlock
From: Guo Ren <[email protected]>
When we're pending, we only care about lock value. The xchg_tail wouldn't affect the pending state. That means the hardware thread could stay in a sleep state and leaves the rest execution units' resources of pipeline to other hardware threads. This situation is the SMT scenarios in the same core. Not an entering low-power state situation. Of course, the granularity between cores is "cacheline", but the granularity between SMT hw threads of the same core could be "byte" which internal LSU handles. For example, when a hw-thread yields the resources of the core to other hw-threads, this patch could help the hw-thread stay in the sleep state and prevent it from being woken up by other hw-threads xchg_tail.
---
Changes in v2:
- Add acked tag
- Optimize commit log
- Add discussion Link tag
--- kernel/locking/qspinlock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/locking/qspinlock.c +2 -2
@@ -371,7 +371,7 @@ void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)/* * We're pending, wait for the owner to go away. * -* 0,1,1 -> 0,1,0 +* 0,1,1 -> *,1,0 * * this wait loop must be a load-acquire such that we match the * store-release that clears the locked bit and create lock
@@ -380,7 +380,7 @@ void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)* barriers. */ if (val & _Q_LOCKED_MASK) -atomic_cond_read_acquire (&lock->val, !(VAL & _Q_LOCKED_MASK)); +smp_cond_load_acquire (&lock->locked, !VAL );/* * take ownership and clear the pending bit.
Signature · 1 line
2.36.1
Waiman Long
reviewerQuoted 45 lines · On 1/4/23 21:19, [email protected] wrote:
From: Guo Ren <[email protected]>
When we're pending, we only care about lock value. The
xchg_tailwouldn't affect the pending state. That means the hardware thread could stay in a sleep state and leaves the rest execution units' resources of pipeline to other hardware threads. This situation is the SMT scenarios in the same core. Not an entering low-power state situation. Of course, the granularity between cores is "cacheline", but the granularity between SMT hw threads of the same core could be "byte" which internal LSU handles. For example, when a hw-thread yields the resources of the core to other hw-threads, this patch could help the hw-thread stay in the sleep state and prevent it from being woken up by other hw-threadsxchg_tail.Signed-off-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>Acked-by Waiman Long <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Boqun Feng <[email protected]>Cc Will Deacon <[email protected]>Cc Ingo Molnar <[email protected]>---
Changes in v2:
- Add acked tag
- Optimize commit log
- Add discussion Link tag--- kernel/locking/qspinlock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/locking/qspinlock.c +1
-1@@ -371,7 +371,7 @@ void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)/* * We're pending, wait for the owner to go away. * -* 0,1,1 -> 0,1,0 +* 0,1,1 -> *,1,0 * * this wait loop must be a load-acquire such that we match the * store-release that clears the locked bit and create lock
kernel/locking/qspinlock.c void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val) · line 386
Quoted 8 lines
kernel/locking/qspinlock.c +1
-1@@ -380,7 +380,7 @@ void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)* barriers. */ if (val & _Q_LOCKED_MASK) -atomic_cond_read_acquire (&lock->val, !(VAL & _Q_LOCKED_MASK)); +smp_cond_load_acquire (&lock->locked, !VAL );/* * take ownership and clear the pending bit.
Yes, the new patch description looks good to me. Thank for sending the v2.
Cheers,
Longman
[tip: locking/core] locking/qspinlock: Micro-optimize pending state waiting for unlock
In reply to [email protected]The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 4282494a20cdcaf38d553f2c2ff6f252084f979c Gitweb: https://git.kernel.org/tip/4282494a20cdcaf38d553f2c2ff6f252084f979c Author: Guo Ren <[email protected]> AuthorDate: Wed, 04 Jan 2023 21:19:52 -05:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 05 Jan 2023 11:01:50 +01:00
locking/qspinlock: Micro-optimize pending state waiting for unlock
When we're pending, we only care about lock value. The xchg_tail wouldn't affect the pending state. That means the hardware thread could stay in a sleep state and leaves the rest execution units' resources of pipeline to other hardware threads. This situation is the SMT scenarios in the same core. Not an entering low-power state situation. Of course, the granularity between cores is "cacheline", but the granularity between SMT hw threads of the same core could be "byte" which internal LSU handles. For example, when a hw-thread yields the resources of the core to other hw-threads, this patch could help the hw-thread stay in the sleep state and prevent it from being woken up by other hw-threads xchg_tail.
--- kernel/locking/qspinlock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/locking/qspinlock.c +2 -2
@@ -371,7 +371,7 @@ void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)/* * We're pending, wait for the owner to go away. * -* 0,1,1 -> 0,1,0 +* 0,1,1 -> *,1,0 * * this wait loop must be a load-acquire such that we match the * store-release that clears the locked bit and create lock
@@ -380,7 +380,7 @@ void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)* barriers. */ if (val & _Q_LOCKED_MASK) -atomic_cond_read_acquire (&lock->val, !(VAL & _Q_LOCKED_MASK)); +smp_cond_load_acquire (&lock->locked, !VAL );/* * take ownership and clear the pending bit.