Skip to contentSkip to conversation

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

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

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

PATCH v2 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

---
 arch/x86/xen/spinlock.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/xen/spinlock.c +4 -0
index cd97a62..973f10e 100644
@@ -130,6 +130,10 @@ void xen_uninit_lock_cpu(int cpu)
 void __init xen_init_spinlocks(void)
 {
 
+	/*  Don't need to use pvqspinlock code if there is only 1 vCPU. */
+	if (num_possible_cpus() == 1)
+		xen_pvspin = false;
+
 	if (!xen_pvspin) {
 		printk(KERN_DEBUG "xen: PV spinlocks disabled\n");
 		return;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 8 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)

static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)

{
	native_smp_prepare_cpus(max_cpus);
-	if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+	if (num_possible_cpus() == 1 ||
+	    kvm_para_has_hint(KVM_HINTS_REALTIME))
		static_branch_disable(&virt_spin_lock_key);
}
#2 lore raw
Quoted 18 lines · Davidlohr Bueso
Quoted 8 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 8 lines
arch/x86/kernel/kvm.c +2 -1
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

-Longman

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

#3 lore raw
In reply to Davidlohr Bueso
Quoted 18 lines · Davidlohr Bueso
Quoted 8 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 8 lines
arch/x86/kernel/kvm.c +2 -1
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

-Longman

#4 lore raw
Quoted 15 lines · Waiman Long
Quoted 13 lines · Davidlohr Bueso
Quoted 8 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 16 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 13 lines
arch/x86/kernel/kvm.c +2 -1
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Regards,
Wanpeng Li

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

#5 lore raw
In reply to Waiman Long
Quoted 15 lines · Waiman Long
Quoted 13 lines · Davidlohr Bueso
Quoted 8 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 16 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 13 lines
arch/x86/kernel/kvm.c +2 -1
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Regards,
Wanpeng Li

#6 lore raw
Quoted 11 lines · Wanpeng Li
Quoted 10 lines · Waiman Long
Quoted 8 lines · Davidlohr Bueso
Quoted 6 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to

s/veriable
variable

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
Quoted 8 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 5 lines
arch/x86/kernel/kvm.c +2 -1
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

How does this differ then from xen, then? I mean, same principle applies.

Quoted 3 lines

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Hmm I would think that my patch would be more appropiate as it actually does what the comment says.

Thanks,
Davidlohr

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

#7 lore raw
In reply to Wanpeng Li
Quoted 11 lines · Wanpeng Li
Quoted 10 lines · Waiman Long
Quoted 8 lines · Davidlohr Bueso
Quoted 6 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to

s/veriable
variable

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
Quoted 8 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 5 lines
arch/x86/kernel/kvm.c +2 -1
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

How does this differ then from xen, then? I mean, same principle applies.

Quoted 3 lines

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Hmm I would think that my patch would be more appropiate as it actually does what the comment says.

Thanks,
Davidlohr

#8 lore raw
Quoted 39 lines · Davidlohr Bueso
Quoted 11 lines · Wanpeng Li
Quoted 10 lines · Waiman Long
Quoted 8 lines · Davidlohr Bueso
Quoted 6 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to

s/veriable
variable

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
Quoted 8 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 5 lines
arch/x86/kernel/kvm.c +2 -1
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

Quoted 8 lines

How does this differ then from xen, then? I mean, same principle applies.

Quoted 3 lines

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Hmm I would think that my patch would be more appropiate as it actually does what the comment says.

Both would be needed actually yes, but also disabling the virt_spin_lock_key would be more robust imo.

Thanks,
Davidlohr

#9 lore raw
In reply to Davidlohr Bueso
Quoted 39 lines · Davidlohr Bueso
Quoted 11 lines · Wanpeng Li
Quoted 10 lines · Waiman Long
Quoted 8 lines · Davidlohr Bueso
Quoted 6 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to

s/veriable
variable

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
Quoted 8 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 5 lines
arch/x86/kernel/kvm.c +2 -1
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

Quoted 8 lines

How does this differ then from xen, then? I mean, same principle applies.

Quoted 3 lines

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Hmm I would think that my patch would be more appropiate as it actually does what the comment says.

Both would be needed actually yes, but also disabling the virt_spin_lock_key would be more robust imo.

Thanks,
Davidlohr

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

#10 lore raw
In reply to Davidlohr Bueso
Quoted 40 lines · Davidlohr Bueso
Quoted 5 lines · Wanpeng Li
Quoted 4 lines · Waiman Long
Quoted 2 lines · Davidlohr Bueso

On Thu, 19 Jul 2018, Waiman Long wrote:

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

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

Quoted 4 lines
Quoted 4 lines

code which has higher overhead on the unlock side than the native qspinlock code.

The xen_pvspin veriable is also turned off in this 1 vCPU case to

s/veriable
variable

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
Quoted 8 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 5 lines
arch/x86/kernel/kvm.c +2 -1
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

Quoted 1 line

How does this differ then from xen, then? I mean, same principle applies.

I am not saying this patch is wrong. I am just saying that this is not necessary.

In the xen case, they have a single variable that controls if pvqspinlock should be used and turn off all the knobs accordingly. There is no such equivalent in kvm. We had talked about that in the past, but didn't come to a conclusion. In the 1 vCPU case, the most important thing is to not use the pvqspinlock unlock path which add unneeded runtime overhead.

The others just have a slight boot time overhead. For me, they are optional. So I don't bother to add code to explicit turn them off as the result will be the same with or without them.

Quoted 9 lines
Quoted 5 lines

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Hmm I would think that my patch would be more appropiate as it actually does
what the comment says.

The static key controls the behavior of the locking slowpath which will not be executed at all. So it is essentially a no-op.

-Longman

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

#11 lore raw
In reply to Davidlohr Bueso
Quoted 40 lines · Davidlohr Bueso
Quoted 5 lines · Wanpeng Li
Quoted 4 lines · Waiman Long
Quoted 2 lines · Davidlohr Bueso

On Thu, 19 Jul 2018, Waiman Long wrote:

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

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

Quoted 4 lines
Quoted 4 lines

code which has higher overhead on the unlock side than the native qspinlock code.

The xen_pvspin veriable is also turned off in this 1 vCPU case to

s/veriable
variable

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
Quoted 8 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 5 lines
arch/x86/kernel/kvm.c +2 -1
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

Quoted 1 line

How does this differ then from xen, then? I mean, same principle applies.

I am not saying this patch is wrong. I am just saying that this is not necessary.

In the xen case, they have a single variable that controls if pvqspinlock should be used and turn off all the knobs accordingly. There is no such equivalent in kvm. We had talked about that in the past, but didn't come to a conclusion. In the 1 vCPU case, the most important thing is to not use the pvqspinlock unlock path which add unneeded runtime overhead.

The others just have a slight boot time overhead. For me, they are optional. So I don't bother to add code to explicit turn them off as the result will be the same with or without them.

Quoted 9 lines
Quoted 5 lines

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Hmm I would think that my patch would be more appropiate as it actually does
what the comment says.

The static key controls the behavior of the locking slowpath which will not be executed at all. So it is essentially a no-op.

-Longman

#12 lore raw
In reply to Wanpeng Li
Quoted 29 lines · Wanpeng Li
Quoted 13 lines · Waiman Long
Quoted 12 lines · Davidlohr Bueso
Quoted 8 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 15 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 13 lines
arch/x86/kernel/kvm.c +2 -1
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

Quoted 5 lines

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Regards,
Wanpeng Li

With only 1 vCPU, the slowpath will not be executed. It will be a deadlock if it happens. So we don't need to explicitly disable the static key here.

-Longman

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

#13 lore raw
In reply to Wanpeng Li
Quoted 29 lines · Wanpeng Li
Quoted 13 lines · Waiman Long
Quoted 12 lines · Davidlohr Bueso
Quoted 8 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

Quoted 15 lines

arch/x86/kernel/kvm.c static void __init sev_map_percpu_data(void) · line 463

Quoted 13 lines
arch/x86/kernel/kvm.c +2 -1
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)
 static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)
 {
    native_smp_prepare_cpus(max_cpus);
-    if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+    if (num_possible_cpus() == 1 ||
+        kvm_para_has_hint(KVM_HINTS_REALTIME))
        static_branch_disable(&virt_spin_lock_key);
 }

That doesn't really matter as the slowpath will never get executed in the 1 vCPU case.

Quoted 5 lines

So this is not needed in kvm tree?
https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?h=queue&id=3a792199004ec335346cc607d62600a399a7ee02

Regards,
Wanpeng Li

With only 1 vCPU, the slowpath will not be executed. It will be a deadlock if it happens. So we don't need to explicitly disable the static key here.

-Longman

#14 lore raw
In reply to Waiman Long
Quoted 8 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Wouldn't kvm also want this?

arch/x86/kernel/kvm.c +0 -0
index a37bda38d205..95aceb692010 100644
@@ -457,7 +457,8 @@ static void __init sev_map_percpu_data(void)

static void __init kvm_smp_prepare_cpus(unsigned int max_cpus)

{
	native_smp_prepare_cpus(max_cpus);
-	if (kvm_para_has_hint(KVM_HINTS_REALTIME))
+	if (num_possible_cpus() == 1 ||
+	    kvm_para_has_hint(KVM_HINTS_REALTIME))
		static_branch_disable(&virt_spin_lock_key);
}

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

reviewer Reviewed-by on v2 1/1
#15 lore raw
In reply to Waiman Long
Quoted 10 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Quoted 9 lines
---
 arch/x86/xen/spinlock.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/xen/spinlock.c +0 -0
index cd97a62..973f10e 100644

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

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

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

reviewer Reviewed-by on v2 1/1
#16 lore raw
In reply to Waiman Long
Quoted 10 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Quoted 19 lines
---
 arch/x86/xen/spinlock.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/xen/spinlock.c +4 -0
index cd97a62..973f10e 100644
@@ -130,6 +130,10 @@ void xen_uninit_lock_cpu(int cpu)
 void __init xen_init_spinlocks(void)
 {
 
+	/*  Don't need to use pvqspinlock code if there is only 1 vCPU. */
+	if (num_possible_cpus() == 1)
+		xen_pvspin = false;
+
 	if (!xen_pvspin) {
 		printk(KERN_DEBUG "xen: PV spinlocks disabled\n");
 		return;
reviewer Applied
#17 lore raw
In reply to Waiman Long
Quoted 10 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Applied to for-linus-4.19.

-boris

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

reviewer Applied
#18 lore raw
In reply to Waiman Long
Quoted 10 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.

The xen_pvspin veriable is also turned off in this 1 vCPU case to eliminate unneeded pvqspinlock initialization in xen_init_lock_cpu() which is run after xen_init_spinlocks().

Applied to for-linus-4.19.

-boris