2016-05-24 15:27-0700, Yunhong Jiang: > From: Yunhong Jiang <yunhong.jiang@xxxxxxxxx> > > Utilizing the VMX preemption timer for tsc deadline timer > virtualization. The VMX preemption timer is armed when the vCPU is > running, and a VMExit will happen if the virtual TSC deadline timer > expires. > > When the vCPU thread is scheduled out, the tsc deadline timer > virtualization will be switched to use the current solution, i.e. use > the timer for it. It's switched back to VMX preemption timer when the > vCPU thread is scheduled int. > > This solution avoids the complex OS's hrtimer system, and also the host > timer interrupt handling cost, with a preemption_timer VMexit. It fits > well for some NFV usage scenario, when the vCPU is bound to a pCPU and > the pCPU is isolated, or some similar scenario. > > However, it possibly has impact if the vCPU thread is scheduled in/out > very frequently, because it switches from/to the hrtimer emulation a lot. > > Signed-off-by: Yunhong Jiang <yunhong.jiang@xxxxxxxxx> > --- > arch/x86/kvm/lapic.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++-- > arch/x86/kvm/lapic.h | 11 ++++++ > arch/x86/kvm/trace.h | 22 ++++++++++++ > arch/x86/kvm/vmx.c | 8 +++++ > arch/x86/kvm/x86.c | 4 +++ > 5 files changed, 139 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > @@ -1343,6 +1343,85 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic) > +void kvm_lapic_arm_hv_timer(struct kvm_vcpu *vcpu) > +{ Preemption timer needs to be adjusted on every vmentry while hrtimer is set only once. After how many vmentries does preemption timer surpass the overhead of hrtimer? > + struct kvm_lapic *apic = vcpu->arch.apic; > + u64 tscdeadline, guest_tsc; > + > + if (apic->lapic_timer.hv_timer_state == HV_TIMER_NOT_USED) > + return; > + > + tscdeadline = apic->lapic_timer.tscdeadline; > + guest_tsc = kvm_read_l1_tsc(vcpu, rdtsc()); > + > + if (tscdeadline >= guest_tsc) > + kvm_x86_ops->set_hv_timer(vcpu, tscdeadline - guest_tsc); > + else > + kvm_x86_ops->set_hv_timer(vcpu, 0); Calling kvm_lapic_expired_hv_timer will avoid the useless immediate vmexit after a vmentry. Thanks. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html