Skip to contentSkip to conversation

x86/kvm: Don't use pvqspinlock code if only 1 vCPU

PATCH Applied Waiman Long 3 participants 4 messages Jul 17, 2018 – Jul 19, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/kvm: Don't use pvqspinlock code if only 1 vCPU

On a VM with only 1 vCPU, the locking fast path will always be successful. In this case, there is no need to use the the PV qspinlock code which has higher overhead on the unlock side than the native qspinlock code.

---
 arch/x86/kernel/kvm.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/kvm.c +4 -0
index 5b2300b..575c9a5 100644
@@ -748,6 +748,10 @@ void __init kvm_spinlock_init(void)
 	if (kvm_para_has_hint(KVM_HINTS_REALTIME))
 		return;
 
+	/* Don't use the pvqspinlock code if there is only 1 vCPU. */
+	if (num_possible_cpus() == 1)
+		return;
+
 	__pv_init_lock_hash();
 	pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath;
 	pv_lock_ops.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock);
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw
Quoted 16 lines · Waiman Long

On a VM with only 1 vCPU, the locking fast path will always be successful. In this case, there is no need to use the the PV qspinlock code which has higher overhead on the unlock side than the native qspinlock code.

---
 arch/x86/kernel/kvm.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/kvm.c +0 -0
index 5b2300b..575c9a5 100644

arch/x86/kernel/kvm.c void __init kvm_spinlock_init(void) · line 757

Quoted 10 lines
arch/x86/kernel/kvm.c +4 -0
@@ -748,6 +748,10 @@ void __init kvm_spinlock_init(void)
 	if (kvm_para_has_hint(KVM_HINTS_REALTIME))
 		return;
 
+	/* Don't use the pvqspinlock code if there is only 1 vCPU. */
+	if (num_possible_cpus() == 1)
+		return;
+
 	__pv_init_lock_hash();
 	pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath;
 	pv_lock_ops.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock);

Queued, thanks.

Paolo

#2 lore raw
In reply to Waiman Long
Quoted 4 lines · Waiman Long

On a VM with only 1 vCPU, the locking fast path will always be successful. In this case, there is no need to use the the PV qspinlock code which has higher overhead on the unlock side than the native qspinlock code.

Why not make this global? That is for both KVM and Xen and any other virtualized guest that uses this?

Quoted 24 lines
---
 arch/x86/kernel/kvm.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/kvm.c +4 -0
index 5b2300b..575c9a5 100644
@@ -748,6 +748,10 @@ void __init kvm_spinlock_init(void)
 	if (kvm_para_has_hint(KVM_HINTS_REALTIME))
 		return;
 
+	/* Don't use the pvqspinlock code if there is only 1 vCPU. */
+	if (num_possible_cpus() == 1)
+		return;
+
 	__pv_init_lock_hash();
 	pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath;
 	pv_lock_ops.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock);
Signature · 1 line
1.8.3.1
#3 lore raw
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Waiman Long

On a VM with only 1 vCPU, the locking fast path will always be successful. In this case, there is no need to use the the PV qspinlock code which has higher overhead on the unlock side than the native qspinlock code.

Why not make this global? That is for both KVM and Xen and any other virtualized guest that uses this?

Right, I will send another patch for Xen. The pvqspinlock code has to be explicitly opted in. Right now, both Xen and KVM used it in the tree. I am not sure about other out-of-tree modules. There is nothing I can do for those.

Cheers,
Longman