Skip to contentSkip to conversation

xen/spinlock: Don't use pvqspinlock if only 1 vCPU

PATCH Superseded Waiman Long 2 participants 5 messages Jul 19, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/spinlock: Don't use pvqspinlock if only 1 vCPU

On a VM with only 1 vCPU, the locking fast paths 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/xen/spinlock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/xen/spinlock.c +2 -1
index cd97a62..38f47ae 100644
@@ -130,7 +130,8 @@ void xen_uninit_lock_cpu(int cpu)
 void __init xen_init_spinlocks(void)
 {
 
-	if (!xen_pvspin) {
+	/*  Don't need to use pvqspinlock code if there is only 1 vCPU. */
+	if (!xen_pvspin || num_possible_cpus() == 1) {
 		printk(KERN_DEBUG "xen: PV spinlocks disabled\n");
 		return;
 	}
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 15 lines · Waiman Long

On a VM with only 1 vCPU, the locking fast paths 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/xen/spinlock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/xen/spinlock.c +0 -0
index cd97a62..38f47ae 100644

arch/x86/xen/spinlock.c void xen_uninit_lock_cpu(int cpu) · line 137

Quoted 9 lines
arch/x86/xen/spinlock.c +2 -1
@@ -130,7 +130,8 @@ void xen_uninit_lock_cpu(int cpu)
 void __init xen_init_spinlocks(void)
 {
 
-	if (!xen_pvspin) {
+	/*  Don't need to use pvqspinlock code if there is only 1 vCPU. */
+	if (!xen_pvspin || num_possible_cpus() == 1) {
 		printk(KERN_DEBUG "xen: PV spinlocks disabled\n");
 		return;
 	}

I think we need to set xen_pvspin to false for such configurations. Notice that xen_init_lock_cpu() will try to perform some additional pvspinlock initializations.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

On a VM with only 1 vCPU, the locking fast paths 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/xen/spinlock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/xen/spinlock.c +0 -0
index cd97a62..38f47ae 100644

arch/x86/xen/spinlock.c void xen_uninit_lock_cpu(int cpu) · line 137

Quoted 9 lines
arch/x86/xen/spinlock.c +2 -1
@@ -130,7 +130,8 @@ void xen_uninit_lock_cpu(int cpu)
 void __init xen_init_spinlocks(void)
 {
 
-	if (!xen_pvspin) {
+	/*  Don't need to use pvqspinlock code if there is only 1 vCPU. */
+	if (!xen_pvspin || num_possible_cpus() == 1) {
 		printk(KERN_DEBUG "xen: PV spinlocks disabled\n");
 		return;
 	}

I think we need to set xen_pvspin to false for such configurations. Notice that xen_init_lock_cpu() will try to perform some additional pvspinlock initializations.

-boris

#3 lore raw
Quoted 31 lines · Boris Ostrovsky
Quoted 15 lines · Waiman Long

On a VM with only 1 vCPU, the locking fast paths 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/xen/spinlock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/xen/spinlock.c +0 -0
index cd97a62..38f47ae 100644

arch/x86/xen/spinlock.c void xen_uninit_lock_cpu(int cpu) · line 137

Quoted 9 lines
arch/x86/xen/spinlock.c +2 -1
@@ -130,7 +130,8 @@ void xen_uninit_lock_cpu(int cpu)
 void __init xen_init_spinlocks(void)
 {
 
-	if (!xen_pvspin) {
+	/*  Don't need to use pvqspinlock code if there is only 1 vCPU. */
+	if (!xen_pvspin || num_possible_cpus() == 1) {
 		printk(KERN_DEBUG "xen: PV spinlocks disabled\n");
 		return;
 	}

I think we need to set xen_pvspin to false for such configurations. Notice that xen_init_lock_cpu() will try to perform some additional pvspinlock initializations.

Quoted 1 line

-boris

The other pvqspinlock initialization has no runtime impact other than allocating a bit of extra memory. Anyway, I will revise the patch to disable xen_pvspin under such condition.

-Longman

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
In reply to Boris Ostrovsky
Quoted 31 lines · Boris Ostrovsky
Quoted 15 lines · Waiman Long

On a VM with only 1 vCPU, the locking fast paths 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/xen/spinlock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/xen/spinlock.c +0 -0
index cd97a62..38f47ae 100644

arch/x86/xen/spinlock.c void xen_uninit_lock_cpu(int cpu) · line 137

Quoted 9 lines
arch/x86/xen/spinlock.c +2 -1
@@ -130,7 +130,8 @@ void xen_uninit_lock_cpu(int cpu)
 void __init xen_init_spinlocks(void)
 {
 
-	if (!xen_pvspin) {
+	/*  Don't need to use pvqspinlock code if there is only 1 vCPU. */
+	if (!xen_pvspin || num_possible_cpus() == 1) {
 		printk(KERN_DEBUG "xen: PV spinlocks disabled\n");
 		return;
 	}

I think we need to set xen_pvspin to false for such configurations. Notice that xen_init_lock_cpu() will try to perform some additional pvspinlock initializations.

Quoted 1 line

-boris

The other pvqspinlock initialization has no runtime impact other than allocating a bit of extra memory. Anyway, I will revise the patch to disable xen_pvspin under such condition.

-Longman