Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1677799
| Path | csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Paolo Bonzini <pbonzini@redhat.com> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v4] KVM: LAPIC: Fix lapic timer injection delay |
| Date | Thu, 29 Jun 2017 16:30:02 +0200 |
| Message-ID | <tXICe-eR-9@gated-at.bofh.it> (permalink) |
| References | <tXHGa-87n-19@gated-at.bofh.it> |
| X-Original-To | Wanpeng Li <kernellwp@gmail.com>, linux-kernel@vger.kernel.org, kvm@vger.kernel.org |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=mjkeVzpfnMvsNu6FHsz6oH5H5DqxHnI54bh/npmcb4g=; b=ofJ3TyDdvq7h4pOLya5d4LtyRz+Fb7giXX3DP05yiQyPIKdUZqQP/DZczxOnHyGYwe BdsW3NeL4VORiFVz015u+FKV+mg5XhV79U5bWxZpspJB/384tbYURGQ5NP0MWNOF8/x3 SzOyLH6zRgjUK+qAGzSBm9GOG4/j8GKgJTm6xMz1Px9WhZKk/OApo+kVDQRU69s2hFvc YK3seL7DBwGc5UYlt9PzbE1rRt2yBW+XFKHNpf7JDnYtz1QZ1n8vntc0cywAWJC5ycmR rMqLPI19ySMS5Lnk2hpmNAjsRSrHOUxd7fwcPG5Zm7hnJJENZ+c5e0QZiE/k/T98cFn9 fQLg== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=mjkeVzpfnMvsNu6FHsz6oH5H5DqxHnI54bh/npmcb4g=; b=txebDQbYHPAEKbeidIpPjA+UDUPH0WIqGnqjmNlGBr2Dz3JklEakSSIvK+cpDisxWJ 90MjxReDFJBlcePLZ6MKN/iQFr0WTH8hno6WxxxuhivLGXecaG8Wq5IbdXn56eFFIiEP 4UJmoNd0roV7mq0xSDsVqXO1iZJy1wbHmXflrpVw50Kj0aVPGgfGfpuAR9r9tGi+m2eo xjyQePjpE9DKdpwSarCn+l1lba8p08BzYdoIsZejUgvpa1IW6wU7cOuq15jdnQecrC5U qkIlHzeocRVLs6OWSve1rVOu6zP3/MV+HAa0txub6pZ1tGbKqS+mHDM2JbVu2pkbp3Go BNSw== |
| X-Gm-Message-State | AKS2vOx7OM/wBw8X8l2uPQHKtB3zYJj0plseDb/1uwOsf20PUutVh9pq wCTOr7MwzGwTNw== |
| X-Received | by 10.80.131.6 with SMTP id 6mr2001275edh.178.1498746573493; Thu, 29 Jun 2017 07:29:33 -0700 (PDT) |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Language | en-US |
| Content-Transfer-Encoding | 8bit |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 107 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Radim Krčmář <rkrcmar@redhat.com>, Wanpeng Li <wanpeng.li@hotmail.com> |
| X-Original-Date | Thu, 29 Jun 2017 16:29:31 +0200 |
| X-Original-Message-ID | <2ea28e01-08e2-c2c9-144d-60e930ba14ee@redhat.com> |
| X-Original-References | <1498742889-10080-1-git-send-email-wanpeng.li@hotmail.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1677799 |
Show key headers only | View raw
On 29/06/2017 15:28, Wanpeng Li wrote:
> 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,
> then plays a vmentry and an upcoming vmx preemption timer fire vmexit
> dance, 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 ~300 cycles on
> the tsc_deadline_timer test of apic.flat.
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
Thanks, looks good. I'll post another refactoring of start_hv_timer for comments.
And unrelated to your patch, I think we need this:
@@ -1567,8 +1575,7 @@ void kvm_lapic_switch_to_sw_timer(struct kvm_vcpu *vcpu)
return;
cancel_hv_timer(apic);
-
- if (atomic_read(&apic->lapic_timer.pending))
+ if (atomic_read(&apic->lapic_timer.pending) && !apic_lvtt_period(apic))
return;
if (apic_lvtt_period(apic) || apic_lvtt_oneshot(apic))
Paolo
> ---
> arch/x86/kvm/lapic.c | 33 ++++++++++++++++++++-------------
> arch/x86/kvm/vmx.c | 6 +++++-
> 2 files changed, 25 insertions(+), 14 deletions(-)
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index d24c874..40ad729 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1504,21 +1504,28 @@ static void cancel_hv_timer(struct kvm_lapic *apic)
> static bool start_hv_timer(struct kvm_lapic *apic)
> {
> u64 tscdeadline = apic->lapic_timer.tscdeadline;
> + bool need_cancel = apic->lapic_timer.hv_timer_in_use;
> + if (!atomic_read(&apic->lapic_timer.pending) || apic_lvtt_period(apic)) {
> + int r = kvm_x86_ops->set_hv_timer(apic->vcpu, tscdeadline);
> + if (r >= 0) {
> + need_cancel = false;
> + apic->lapic_timer.hv_timer_in_use = true;
> + hrtimer_cancel(&apic->lapic_timer.timer);
> +
> + /* In case the sw timer triggered in the window */
> + if (!apic_lvtt_period(apic)) {
> + if (r || atomic_read(&apic->lapic_timer.pending)) {
> + need_cancel = true;
> + if (r)
> + apic_timer_expired(apic);
> + }
> + }
> + }
> + }
>
> - if ((atomic_read(&apic->lapic_timer.pending) &&
> - !apic_lvtt_period(apic)) ||
> - kvm_x86_ops->set_hv_timer(apic->vcpu, tscdeadline)) {
> - if (apic->lapic_timer.hv_timer_in_use)
> - cancel_hv_timer(apic);
> - } else {
> - apic->lapic_timer.hv_timer_in_use = true;
> - hrtimer_cancel(&apic->lapic_timer.timer);
> + if (need_cancel)
> + cancel_hv_timer(apic);
>
> - /* In case the sw timer triggered in the window */
> - if (atomic_read(&apic->lapic_timer.pending) &&
> - !apic_lvtt_period(apic))
> - cancel_hv_timer(apic);
> - }
> trace_kvm_hv_timer_state(apic->vcpu->vcpu_id,
> apic->lapic_timer.hv_timer_in_use);
> return apic->lapic_timer.hv_timer_in_use;
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 4263860..f8ccf8b 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -11158,7 +11158,11 @@ 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;
> +
> + if (delta_tsc == 0)
> + return 1;
> + else
> + return 0;
> }
>
> static void vmx_cancel_hv_timer(struct kvm_vcpu *vcpu)
>
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH v4] KVM: LAPIC: Fix lapic timer injection delay Wanpeng Li <kernellwp@gmail.com> - 2017-06-29 15:30 +0200 Re: [PATCH v4] KVM: LAPIC: Fix lapic timer injection delay Paolo Bonzini <pbonzini@redhat.com> - 2017-06-29 16:30 +0200
csiph-web