KVM: VMX: Optimize tscdeadline timer latency
authorWanpeng Li <wanpengli@tencent.com>
Tue, 29 May 2018 06:53:17 +0000 (14:53 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 4 Jun 2018 15:51:59 +0000 (17:51 +0200)
commitc5ce8235cffa00c207e24210329094d7634bb467
tree9bc040bb9c249aa5792c06f869a1dedb51afa0db
parent71e9d9aeec7036ece9de8e51082f94d59c31be9a
KVM: VMX: Optimize tscdeadline timer latency

'Commit d0659d946be0 ("KVM: x86: add option to advance tscdeadline
hrtimer expiration")' advances the tscdeadline (the timer is emulated
by hrtimer) expiration in order that the latency which is incurred
by hypervisor (apic_timer_fn -> vmentry) can be avoided. This patch
adds the advance tscdeadline expiration support to which the tscdeadline
timer is emulated by VMX preemption timer to reduce the hypervisor
lantency (handle_preemption_timer -> vmentry). The guest can also
set an expiration that is very small (for example in Linux if an
hrtimer feeds a expiration in the past); in that case we set delta_tsc
to 0, leading to an immediately vmexit when delta_tsc is not bigger than
advance ns.

This patch can reduce ~63% latency (~4450 cycles to ~1660 cycles on
a haswell desktop) for kvm-unit-tests/tscdeadline_latency when testing
busy waits.

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>
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c