Skip to content

Commit 7150629

Browse files
Wanpeng Libonzini
authored andcommitted
KVM: X86: Implement PV sched yield hypercall
The target vCPUs are in runnable state after vcpu_kick and suitable as a yield target. This patch implements the sched yield hypercall. 17% performance increasement of ebizzy benchmark can be observed in an over-subscribe environment. (w/ kvm-pv-tlb disabled, testing TLB flush call-function IPI-many since call-function is not easy to be trigged by userspace workload). Cc: Paolo Bonzini <[email protected]> Cc: Radim Krčmář <[email protected]> Cc: Liran Alon <[email protected]> Signed-off-by: Wanpeng Li <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent f85f6e7 commit 7150629

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

arch/x86/kvm/x86.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7193,6 +7193,23 @@ void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu)
71937193
kvm_x86_ops->refresh_apicv_exec_ctrl(vcpu);
71947194
}
71957195

7196+
static void kvm_sched_yield(struct kvm *kvm, unsigned long dest_id)
7197+
{
7198+
struct kvm_vcpu *target = NULL;
7199+
struct kvm_apic_map *map;
7200+
7201+
rcu_read_lock();
7202+
map = rcu_dereference(kvm->arch.apic_map);
7203+
7204+
if (likely(map) && dest_id <= map->max_apic_id && map->phys_map[dest_id])
7205+
target = map->phys_map[dest_id]->vcpu;
7206+
7207+
rcu_read_unlock();
7208+
7209+
if (target)
7210+
kvm_vcpu_yield_to(target);
7211+
}
7212+
71967213
int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
71977214
{
71987215
unsigned long nr, a0, a1, a2, a3, ret;
@@ -7239,6 +7256,10 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
72397256
case KVM_HC_SEND_IPI:
72407257
ret = kvm_pv_send_ipi(vcpu->kvm, a0, a1, a2, a3, op_64_bit);
72417258
break;
7259+
case KVM_HC_SCHED_YIELD:
7260+
kvm_sched_yield(vcpu->kvm, a0);
7261+
ret = 0;
7262+
break;
72427263
default:
72437264
ret = -KVM_ENOSYS;
72447265
break;

0 commit comments

Comments
 (0)