Message ID | 1561110002-4438-5-git-send-email-wanpengli@tencent.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: LAPIC: Implement Exitless Timer | expand |
On 21/06/19 11:40, Wanpeng Li wrote: > From: Wanpeng Li <wanpengli@tencent.com> > > already-expired timer interrupt can be injected to guest when vCPU who > arms the lapic timer re-vmentry, don't posted inject in this case. > > Cc: Paolo Bonzini <pbonzini@redhat.com> > Cc: Radim Krčmář <rkrcmar@redhat.com> > Cc: Marcelo Tosatti <mtosatti@redhat.com> > Signed-off-by: Wanpeng Li <wanpengli@tencent.com> > --- > arch/x86/kvm/lapic.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index ae575c0..7cd95ea 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -1452,7 +1452,7 @@ static void kvm_apic_inject_pending_timer_irqs(struct kvm_lapic *apic) > } > } > > -static void apic_timer_expired(struct kvm_lapic *apic) > +static void apic_timer_expired(struct kvm_lapic *apic, bool can_pi_inject) > { > struct kvm_vcpu *vcpu = apic->vcpu; > struct swait_queue_head *q = &vcpu->wq; > @@ -1464,7 +1464,7 @@ static void apic_timer_expired(struct kvm_lapic *apic) > if (apic_lvtt_tscdeadline(apic) || ktimer->hv_timer_in_use) > ktimer->expired_tscdeadline = ktimer->tscdeadline; > > - if (posted_interrupt_inject_timer(apic->vcpu)) { > + if (can_pi_inject && posted_interrupt_inject_timer(apic->vcpu)) { Perhaps it should use a posted interrupt if kvm_arch_should_kick(vcpu), i.e. just add kvm_arch_vcpu_should_kick(apic->vcpu) to posted_interrupt_inject_timer? Paolo > if (apic->lapic_timer.timer_advance_ns) > kvm_wait_lapic_expire(vcpu, true); > kvm_apic_inject_pending_timer_irqs(apic); > @@ -1607,7 +1607,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic) > expire = ktime_sub_ns(expire, ktimer->timer_advance_ns); > hrtimer_start(&ktimer->timer, expire, HRTIMER_MODE_ABS); > } else > - apic_timer_expired(apic); > + apic_timer_expired(apic, false); > > local_irq_restore(flags); > } > @@ -1697,7 +1697,7 @@ static void start_sw_period(struct kvm_lapic *apic) > > if (ktime_after(ktime_get(), > apic->lapic_timer.target_expiration)) { > - apic_timer_expired(apic); > + apic_timer_expired(apic, false); > > if (apic_lvtt_oneshot(apic)) > return; > @@ -1759,7 +1759,7 @@ static bool start_hv_timer(struct kvm_lapic *apic) > if (atomic_read(&ktimer->pending)) { > cancel_hv_timer(apic); > } else if (expired) { > - apic_timer_expired(apic); > + apic_timer_expired(apic, false); > cancel_hv_timer(apic); > } > } > @@ -1809,7 +1809,7 @@ void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu) > goto out; > WARN_ON(swait_active(&vcpu->wq)); > cancel_hv_timer(apic); > - apic_timer_expired(apic); > + apic_timer_expired(apic, false); > > if (apic_lvtt_period(apic) && apic->lapic_timer.period) { > advance_periodic_target_expiration(apic); > @@ -2312,7 +2312,7 @@ 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); > + apic_timer_expired(apic, true); > > if (lapic_is_periodic(apic)) { > advance_periodic_target_expiration(apic); >
On 05/07/19 15:11, Wanpeng Li wrote: > On 7/5/19 8:40 PM, Paolo Bonzini wrote: > >> On 21/06/19 11:40, Wanpeng Li wrote: >>> From: Wanpeng Li <wanpengli@tencent.com> >>> >>> already-expired timer interrupt can be injected to guest when vCPU who >>> arms the lapic timer re-vmentry, don't posted inject in this case. >>> >>> Cc: Paolo Bonzini <pbonzini@redhat.com> >>> Cc: Radim Krčmář <rkrcmar@redhat.com> >>> Cc: Marcelo Tosatti <mtosatti@redhat.com> >>> Signed-off-by: Wanpeng Li <wanpengli@tencent.com> >>> --- >>> arch/x86/kvm/lapic.c | 14 +++++++------- >>> 1 file changed, 7 insertions(+), 7 deletions(-) >>> >>> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c >>> index ae575c0..7cd95ea 100644 >>> --- a/arch/x86/kvm/lapic.c >>> +++ b/arch/x86/kvm/lapic.c >>> @@ -1452,7 +1452,7 @@ static void kvm_apic_inject_pending_timer_irqs(struct kvm_lapic *apic) >>> } >>> } >>> >>> -static void apic_timer_expired(struct kvm_lapic *apic) >>> +static void apic_timer_expired(struct kvm_lapic *apic, bool can_pi_inject) >>> { >>> struct kvm_vcpu *vcpu = apic->vcpu; >>> struct swait_queue_head *q = &vcpu->wq; >>> @@ -1464,7 +1464,7 @@ static void apic_timer_expired(struct kvm_lapic *apic) >>> if (apic_lvtt_tscdeadline(apic) || ktimer->hv_timer_in_use) >>> ktimer->expired_tscdeadline = ktimer->tscdeadline; >>> >>> - if (posted_interrupt_inject_timer(apic->vcpu)) { >>> + if (can_pi_inject && posted_interrupt_inject_timer(apic->vcpu)) { >> Perhaps it should use a posted interrupt if kvm_arch_should_kick(vcpu), >> i.e. just add kvm_arch_vcpu_should_kick(apic->vcpu) to >> posted_interrupt_inject_timer? > > So do you mean not nohz_full setup? An external interrupt is incurred > here and preemption timer is better. No, I mean instead of adding can_pi_inject, just test kvm_arch_should_kick in posted_interrupt_inject_timer, skipping the PI if the vCPU is not running. Instead just go down the normal path and the guest will get the interrupt by checking the timer-pending flag. Paolo
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index ae575c0..7cd95ea 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1452,7 +1452,7 @@ static void kvm_apic_inject_pending_timer_irqs(struct kvm_lapic *apic) } } -static void apic_timer_expired(struct kvm_lapic *apic) +static void apic_timer_expired(struct kvm_lapic *apic, bool can_pi_inject) { struct kvm_vcpu *vcpu = apic->vcpu; struct swait_queue_head *q = &vcpu->wq; @@ -1464,7 +1464,7 @@ static void apic_timer_expired(struct kvm_lapic *apic) if (apic_lvtt_tscdeadline(apic) || ktimer->hv_timer_in_use) ktimer->expired_tscdeadline = ktimer->tscdeadline; - if (posted_interrupt_inject_timer(apic->vcpu)) { + if (can_pi_inject && posted_interrupt_inject_timer(apic->vcpu)) { if (apic->lapic_timer.timer_advance_ns) kvm_wait_lapic_expire(vcpu, true); kvm_apic_inject_pending_timer_irqs(apic); @@ -1607,7 +1607,7 @@ static void start_sw_tscdeadline(struct kvm_lapic *apic) expire = ktime_sub_ns(expire, ktimer->timer_advance_ns); hrtimer_start(&ktimer->timer, expire, HRTIMER_MODE_ABS); } else - apic_timer_expired(apic); + apic_timer_expired(apic, false); local_irq_restore(flags); } @@ -1697,7 +1697,7 @@ static void start_sw_period(struct kvm_lapic *apic) if (ktime_after(ktime_get(), apic->lapic_timer.target_expiration)) { - apic_timer_expired(apic); + apic_timer_expired(apic, false); if (apic_lvtt_oneshot(apic)) return; @@ -1759,7 +1759,7 @@ static bool start_hv_timer(struct kvm_lapic *apic) if (atomic_read(&ktimer->pending)) { cancel_hv_timer(apic); } else if (expired) { - apic_timer_expired(apic); + apic_timer_expired(apic, false); cancel_hv_timer(apic); } } @@ -1809,7 +1809,7 @@ void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu) goto out; WARN_ON(swait_active(&vcpu->wq)); cancel_hv_timer(apic); - apic_timer_expired(apic); + apic_timer_expired(apic, false); if (apic_lvtt_period(apic) && apic->lapic_timer.period) { advance_periodic_target_expiration(apic); @@ -2312,7 +2312,7 @@ 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); + apic_timer_expired(apic, true); if (lapic_is_periodic(apic)) { advance_periodic_target_expiration(apic);