Skip to content

Commit 266e85a

Browse files
Wanpeng Libonzini
authored andcommitted
KVM: X86: Boost queue head vCPU to mitigate lock waiter preemption
Commit 11752ad (locking/pvqspinlock: Implement hybrid PV queued/unfair locks) introduces hybrid PV queued/unfair locks - queued mode (no starvation) - unfair mode (good performance on not heavily contended lock) The lock waiter goes into the unfair mode especially in VMs with over-commit vCPUs since increaing over-commitment increase the likehood that the queue head vCPU may have been preempted and not actively spinning. However, reschedule queue head vCPU timely to acquire the lock still can get better performance than just depending on lock stealing in over-subscribe scenario. Testing on 80 HT 2 socket Xeon Skylake server, with 80 vCPUs VM 80GB RAM: ebizzy -M vanilla boosting improved 1VM 23520 25040 6% 2VM 8000 13600 70% 3VM 3100 5400 74% The lock holder vCPU yields to the queue head vCPU when unlock, to boost queue head vCPU which is involuntary preemption or the one which is voluntary halt due to fail to acquire the lock after a short spin in the guest. Cc: Waiman Long <longman@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Radim Krčmář <rkrcmar@redhat.com> Signed-off-by: Wanpeng Li <wanpengli@tencent.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 2f5947d commit 266e85a

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎arch/x86/kvm/x86.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7206,7 +7206,7 @@ static void kvm_sched_yield(struct kvm *kvm, unsigned long dest_id)
72067206

72077207
rcu_read_unlock();
72087208

7209-
if (target)
7209+
if (target && READ_ONCE(target->ready))
72107210
kvm_vcpu_yield_to(target);
72117211
}
72127212

@@ -7246,6 +7246,7 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
72467246
break;
72477247
case KVM_HC_KICK_CPU:
72487248
kvm_pv_kick_cpu_op(vcpu->kvm, a0, a1);
7249+
kvm_sched_yield(vcpu->kvm, a1);
72497250
ret = 0;
72507251
break;
72517252
#ifdef CONFIG_X86_64

0 commit comments

Comments
 (0)