* [PATCH] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning
@ 2016-07-14 7:53 Wanpeng Li
2016-07-14 8:20 ` xinhui
0 siblings, 1 reply; 2+ messages in thread
From: Wanpeng Li @ 2016-07-14 7:53 UTC (permalink / raw)
To: linux-kernel
Cc: Wanpeng Li, Peter Zijlstra (Intel),
Ingo Molnar, Waiman Long, Davidlohr Bueso
From: Wanpeng Li <wanpeng.li@hotmail.com>
When the lock holder vCPU is racing with the queue head:
CPU 0 (lock holder) CPU1 (queue head)
=================== =================
spin_lock(); spin_lock();
pv_kick_node(); pv_wait_head_or_lock();
if (!lp) {
lp = pv_hash(lock, pn);
xchg(&l->locked, _Q_SLOW_VAL);
}
WRITE_ONCE(pn->state, vcpu_halted);
cmpxchg(&pn->state,
vcpu_halted, vcpu_hashed);
WRITE_ONCE(l->locked, _Q_SLOW_VAL);
(void)pv_hash(lock, pn);
In this case, lock holder inserts the pv_node of queue head into the
hash table and set _Q_SLOW_VAL unnecessary. This patch avoids it by
restoring/setting vcpu_halted state after failing adaptive locking
spinning.
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Waiman Long <Waiman.Long@hpe.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
kernel/locking/qspinlock_paravirt.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
index 21ede57..ac7d20b 100644
--- a/kernel/locking/qspinlock_paravirt.h
+++ b/kernel/locking/qspinlock_paravirt.h
@@ -450,7 +450,7 @@ pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node)
goto gotlock;
}
}
- WRITE_ONCE(pn->state, vcpu_halted);
+ WRITE_ONCE(pn->state, vcpu_hashed);
qstat_inc(qstat_pv_wait_head, true);
qstat_inc(qstat_pv_wait_again, waitcnt);
pv_wait(&l->locked, _Q_SLOW_VAL);
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning
2016-07-14 7:53 [PATCH] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning Wanpeng Li
@ 2016-07-14 8:20 ` xinhui
0 siblings, 0 replies; 2+ messages in thread
From: xinhui @ 2016-07-14 8:20 UTC (permalink / raw)
To: Wanpeng Li, linux-kernel
Cc: Wanpeng Li, Peter Zijlstra (Intel),
Ingo Molnar, Waiman Long, Davidlohr Bueso
On 2016年07月14日 15:53, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> When the lock holder vCPU is racing with the queue head:
>
> CPU 0 (lock holder) CPU1 (queue head)
> =================== =================
> spin_lock(); spin_lock();
> pv_kick_node(); pv_wait_head_or_lock();
> if (!lp) {
> lp = pv_hash(lock, pn);
> xchg(&l->locked, _Q_SLOW_VAL);
> }
> WRITE_ONCE(pn->state, vcpu_halted);
> cmpxchg(&pn->state,
> vcpu_halted, vcpu_hashed);
> WRITE_ONCE(l->locked, _Q_SLOW_VAL);
> (void)pv_hash(lock, pn);
>
> In this case, lock holder inserts the pv_node of queue head into the
> hash table and set _Q_SLOW_VAL unnecessary. This patch avoids it by
> restoring/setting vcpu_halted state after failing adaptive locking
> spinning.
>
good catching. this is hash entry leak.
After apply Waiman's pathset "locking/pvqspinlock: Fix missed PV wakeup & support PPC", this is not the big problem.
But we can still save another cmpxchg.
So
Reviewed-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
> Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Waiman Long <Waiman.Long@hpe.com>
> Cc: Davidlohr Bueso <dave@stgolabs.net>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> kernel/locking/qspinlock_paravirt.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
> index 21ede57..ac7d20b 100644
> --- a/kernel/locking/qspinlock_paravirt.h
> +++ b/kernel/locking/qspinlock_paravirt.h
> @@ -450,7 +450,7 @@ pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node)
> goto gotlock;
> }
> }
> - WRITE_ONCE(pn->state, vcpu_halted);
> + WRITE_ONCE(pn->state, vcpu_hashed);
> qstat_inc(qstat_pv_wait_head, true);
> qstat_inc(qstat_pv_wait_again, waitcnt);
> pv_wait(&l->locked, _Q_SLOW_VAL);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-14 8:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-14 7:53 [PATCH] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning Wanpeng Li
2016-07-14 8:20 ` xinhui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).