Skip to contentSkip to conversation

x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU

PATCH Applied Wanpeng Li 2 participants 2 messages Feb 18, 2022

Subsystems (3)
lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH 1/1 x86/kvm: Don't use pv tlb/ipi/sched_yield if on 1 vCPU

From: Wanpeng Li <[email protected]>

Inspired by commit 3553ae5690a (x86/kvm: Don't use pvqspinlock code if only 1 vCPU), on a VM with only 1 vCPU, there is no need to enable pv tlb/ipi/sched_yield and we can save the memory for __pv_cpu_mask.

---
 arch/x86/kernel/kvm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/kvm.c +6 -3
index a438217cbfac..f734e3b0cfec 100644
@@ -462,19 +462,22 @@ static bool pv_tlb_flush_supported(void)
 {
 	return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
 		!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
-		kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
+		kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
+		(num_possible_cpus() != 1));
 }
 
 static bool pv_ipi_supported(void)
 {
-	return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI);
+	return (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI) &&
+	       (num_possible_cpus() != 1));
 }
 
 static bool pv_sched_yield_supported(void)
 {
 	return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&
 		!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
-	    kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
+	    kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
+	    (num_possible_cpus() != 1));
 }
 
 #define KVM_IPI_CLUSTER_SIZE	(2 * BITS_PER_LONG)
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 31 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

Inspired by commit 3553ae5690a (x86/kvm: Don't use pvqspinlock code if only 1 vCPU), on a VM with only 1 vCPU, there is no need to enable pv tlb/ipi/sched_yield and we can save the memory for __pv_cpu_mask.

---
  arch/x86/kernel/kvm.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/kvm.c +4 -2
index a438217cbfac..f734e3b0cfec 100644
@@ -462,19 +462,22 @@ static bool pv_tlb_flush_supported(void)
  {
  	return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
  		!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
-		kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
+		kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
+		(num_possible_cpus() != 1));
  }
 
  static bool pv_ipi_supported(void)
  {
-	return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI);
+	return (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI) &&
+	       (num_possible_cpus() != 1));
  }
 

arch/x86/kernel/kvm.c static bool pv_tlb_flush_supported(void) · line 483

Quoted 10 lines
arch/x86/kernel/kvm.c +2 -1
  static bool pv_sched_yield_supported(void)
  {
  	return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&
  		!kvm_para_has_hint(KVM_HINTS_REALTIME) &&
-	    kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
+	    kvm_para_has_feature(KVM_FEATURE_STEAL_TIME) &&
+	    (num_possible_cpus() != 1));
  }
 
  #define KVM_IPI_CLUSTER_SIZE	(2 * BITS_PER_LONG)

Queued, thanks.

Paolo