Message ID | 1559729351-20244-3-git-send-email-wanpengli@tencent.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: LAPIC: Implement Exitless Timer | expand |
On 05/06/19 12:09, Wanpeng Li wrote: > +static void apic_timer_expired_pi(struct kvm_lapic *apic) > +{ > + struct kvm_timer *ktimer = &apic->lapic_timer; > + > + kvm_apic_local_deliver(apic, APIC_LVTT); > + if (apic_lvtt_tscdeadline(apic)) > + ktimer->tscdeadline = 0; > + if (apic_lvtt_oneshot(apic)) { > + ktimer->tscdeadline = 0; > + ktimer->target_expiration = 0; > + } > +} Please rename this function to kvm_apic_inject_pending_timer_irqs and call it from kvm_inject_apic_timer_irqs. Then apic_timer_expired can just do if (atomic_read(&apic->lapic_timer.pending)) return; + if (unlikely(posted_interrupt_inject_timer(apic->vcpu))) { + kvm_apic_inject_pending_timer_irqs(apic); + return; + } etc. Paolo
On Wed, 5 Jun 2019 at 20:30, Paolo Bonzini <pbonzini@redhat.com> wrote: > > On 05/06/19 12:09, Wanpeng Li wrote: > > +static void apic_timer_expired_pi(struct kvm_lapic *apic) > > +{ > > + struct kvm_timer *ktimer = &apic->lapic_timer; > > + > > + kvm_apic_local_deliver(apic, APIC_LVTT); > > + if (apic_lvtt_tscdeadline(apic)) > > + ktimer->tscdeadline = 0; > > + if (apic_lvtt_oneshot(apic)) { > > + ktimer->tscdeadline = 0; > > + ktimer->target_expiration = 0; > > + } > > +} > > Please rename this function to kvm_apic_inject_pending_timer_irqs and > call it from kvm_inject_apic_timer_irqs. > > Then apic_timer_expired can just do > > if (atomic_read(&apic->lapic_timer.pending)) > return; > > + if (unlikely(posted_interrupt_inject_timer(apic->vcpu))) { > + kvm_apic_inject_pending_timer_irqs(apic); > + return; > + } Do it in v2. Regards, Wanpeng Li
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 8c9c14d..e9db086 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1465,6 +1465,23 @@ static void apic_timer_expired(struct kvm_lapic *apic) } /* + * On APICv, lapic timer is injected by posted interrupt + * to dedicated instance. + */ +static void apic_timer_expired_pi(struct kvm_lapic *apic) +{ + struct kvm_timer *ktimer = &apic->lapic_timer; + + kvm_apic_local_deliver(apic, APIC_LVTT); + if (apic_lvtt_tscdeadline(apic)) + ktimer->tscdeadline = 0; + if (apic_lvtt_oneshot(apic)) { + ktimer->tscdeadline = 0; + ktimer->target_expiration = 0; + } +} + +/* * On APICv, this test will cause a busy wait * during a higher-priority task. */ @@ -2297,7 +2314,10 @@ static enum hrtimer_restart apic_timer_fn(struct hrtimer *data) struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer); struct kvm_lapic *apic = container_of(ktimer, struct kvm_lapic, lapic_timer); - apic_timer_expired(apic); + if (unlikely(posted_interrupt_inject_timer(apic->vcpu))) + apic_timer_expired_pi(apic); + else + apic_timer_expired(apic); if (lapic_is_periodic(apic)) { advance_periodic_target_expiration(apic);