All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wanpeng Li <kernellwp@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	kvm <kvm@vger.kernel.org>, Radim Krcmar <rkrcmar@redhat.com>,
	Wanpeng Li <wanpeng.li@hotmail.com>
Subject: Re: [PATCH 3/3] KVM: LAPIC: Fix lapic timer injection delay
Date: Sun, 2 Jul 2017 09:35:29 +0800	[thread overview]
Message-ID: <CANRm+CyD+CH=H1LFixyaqTa5j9GXMtDggseDtq+=WJ+QftvqBQ@mail.gmail.com> (raw)
In-Reply-To: <1498755501-39602-4-git-send-email-pbonzini@redhat.com>

2017-06-30 0:58 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
>
> If the TSC deadline timer is programmed really close to the deadline or
> even in the past, the computation in vmx_set_hv_timer will program the
> absolute target tsc value to vmcs preemption timer field w/ delta == 0.
> The next vmentry results in an immediate vmx preemption timer vmexit
> and the lapic timer injection is delayed due to this duration.  Actually
> the lapic timer which is emulated by hrtimer can handle this correctly.
>
> This patch fixes it by firing the lapic timer and injecting a timer interrupt
> immediately during the next vmentry if the TSC deadline timer is programmed
> really close to the deadline or even in the past. This saves ~1200 cycles on
> the tscdeadline_immed test of vmexit.flat.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> [Rebased on top of previous patch. - Paolo]
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/lapic.c | 5 ++++-
>  arch/x86/kvm/vmx.c   | 3 ++-
>  2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index a80e5a5d6f2f..2819d4c123eb 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1525,8 +1525,11 @@ static bool start_hv_timer(struct kvm_lapic *apic)
>          * the window.  For periodic timer, leave the hv timer running for
>          * simplicity, and the deadline will be recomputed on the next vmexit.
>          */
> -       if (!apic_lvtt_period(apic) && atomic_read(&ktimer->pending))
> +       if (!apic_lvtt_period(apic) && (r || atomic_read(&ktimer->pending))) {
> +               if (r)
> +                       apic_timer_expired(apic);
>                 return false;
> +       }

This logic is not the same as in my v4
http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1434040.html
. You return false for the expired timer and actually it will switch
to sw timer.

>
>         trace_kvm_hv_timer_state(apic->vcpu->vcpu_id, true);
>         return true;
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index e8b61ad84a8e..92ddea08f999 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -11147,7 +11147,8 @@ static int vmx_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc)
>         vmx->hv_deadline_tsc = tscl + delta_tsc;
>         vmcs_set_bits(PIN_BASED_VM_EXEC_CONTROL,
>                         PIN_BASED_VMX_PREEMPTION_TIMER);
> -       return 0;
> +
> +       return delta_tsc == 0;
>  }
>
>  static void vmx_cancel_hv_timer(struct kvm_vcpu *vcpu)
> --
> 1.8.3.1
>

  reply	other threads:[~2017-07-02  1:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29 16:58 [PATCH 0/3] KVM: lapic: optimize injection of already-expired timer Paolo Bonzini
2017-06-29 16:58 ` [PATCH 1/3] KVM: lapic: reorganize start_hv_timer Paolo Bonzini
2017-06-29 16:58 ` [PATCH 2/3] KVM: lapic: reorganize restart_apic_timer Paolo Bonzini
2017-06-29 16:58 ` [PATCH 3/3] KVM: LAPIC: Fix lapic timer injection delay Paolo Bonzini
2017-07-02  1:35   ` Wanpeng Li [this message]
2017-07-02  1:56     ` Wanpeng Li
2017-07-03  7:30       ` Paolo Bonzini
2017-07-03  8:08         ` Wanpeng Li
2017-07-03  8:16           ` Paolo Bonzini
2017-07-03  8:41             ` Wanpeng Li
2017-06-30  1:30 ` [PATCH 0/3] KVM: lapic: optimize injection of already-expired timer Wanpeng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANRm+CyD+CH=H1LFixyaqTa5j9GXMtDggseDtq+=WJ+QftvqBQ@mail.gmail.com' \
    --to=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=wanpeng.li@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.