x86/kvm: Don't use pvqspinlock code if only 1 vCPU
authorWaiman Long <longman@redhat.com>
Tue, 17 Jul 2018 21:59:27 +0000 (17:59 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 6 Aug 2018 15:59:04 +0000 (17:59 +0200)
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.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kernel/kvm.c

index 5b2300b818af9333f8d57f6b082f426b8556b606..575c9a51e6ba999711690e00472413b4b6df74e9 100644 (file)
@@ -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);