Path: csiph.com!weretis.net!feeder4.news.weretis.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod From: Wanpeng Li Newsgroups: linux.kernel Subject: Re: [PATCH 3/3] KVM: LAPIC: Fix lapic timer injection delay Date: Sun, 02 Jul 2017 04:00:01 +0200 Message-ID: References: X-Original-To: Paolo Bonzini Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ZS/TJt2BLZUFFS1VDSnOkj20BunM4OeCvIFe2ItKDUA=; b=Y+NnfXscy8QEnXI6p3U4hsveB/y1LyRhP/dhu//dWfm0cHsQGeyOCULVFcIf8I7guQ zmnr98DbmiM55toG2iaex/JsApOWfj5k1/rkp5ACHVF40rNsG++gTHJ06tqPPFNJOR71 7b0/0ARW0vMslMkf779vrVUJd04h7ezkVdqqWLquJOVCdm1+E2MUKjvS+SbWl3BpUsu9 NegmsmzV6WhR3jqJdHvFeHNI/U6s6UJgw0Mc2lVKEjmbZTMdDYTknuGBgURf33C5L1z1 /DxX/MilL7BbLEaNP9wCTbXd6MLkpKzwwN11quEdxvW4o/3hFtCS92S3tG4BRsphNV0q gpSQ== X-Google-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ZS/TJt2BLZUFFS1VDSnOkj20BunM4OeCvIFe2ItKDUA=; b=N7JxNiWkPd13BP06qWL+jVxYxRHANVEEe8QNA4DylQPvqzMkHIxHp8y8qqSbfvBzC2 X4IV1NwQGS65gfFxr+rn2JANk4ScZtLW57Pj7dxmRFBUsZwyCDKaXcbAu3QsCzU8LudW vOco6chI6eAm+Kuuc+bGLIc6WTGWzsPPfynVDEzXvi+msLFELDOe8xQMB3s8rsouywzr tEmQo5KXkULuH4gUOgaIwVKUlY00Njjr/SwtEF5qfveLgPPw/ULBbbv+uihwW7s26j7M anNU97fSPHc7sQm51UF1mkpiFfZv28M5CuZ7ULISsaOvt3Y37avkR+ah6IJhp+0XneXV E+EA== X-Gm-Message-State: AKS2vOzDjSLPOdWl1Y1YiKnYetVtA9Ptr/CxsWbd2Ech7mBlLaejZ/Xx 6VoRCCcxDTuLUgYIdK42ahM76goFsg== X-Received: by 10.202.77.145 with SMTP id a139mr17721336oib.205.1498960577204; Sat, 01 Jul 2017 18:56:17 -0700 (PDT) MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 81 Organization: linux.* mail to news gateway X-Original-Cc: "linux-kernel@vger.kernel.org" , kvm , Radim Krcmar , Wanpeng Li X-Original-Date: Sun, 2 Jul 2017 09:56:16 +0800 X-Original-Message-ID: X-Original-References: <1498755501-39602-1-git-send-email-pbonzini@redhat.com> <1498755501-39602-4-git-send-email-pbonzini@redhat.com> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1679419 2017-07-02 9:35 GMT+08:00 Wanpeng Li : > 2017-06-30 0:58 GMT+08:00 Paolo Bonzini : >> From: Wanpeng Li >> >> 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 =3D=3D= 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 inte= rrupt >> immediately during the next vmentry if the TSC deadline timer is program= med >> really close to the deadline or even in the past. This saves ~1200 cycle= s on >> the tscdeadline_immed test of vmexit.flat. >> >> Cc: Paolo Bonzini >> Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 >> Signed-off-by: Wanpeng Li >> [Rebased on top of previous patch. - Paolo] >> Signed-off-by: Paolo Bonzini >> --- >> 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 f= or >> * simplicity, and the deadline will be recomputed on the next v= mexit. >> */ >> - if (!apic_lvtt_period(apic) && atomic_read(&ktimer->pending)) >> + if (!apic_lvtt_period(apic) && (r || atomic_read(&ktimer->pendin= g))) { >> + 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. Ah, I miss read it, the rebase is correct. Regards, Wanpeng Li > >> >> 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 *vcp= u, u64 guest_deadline_tsc) >> vmx->hv_deadline_tsc =3D tscl + delta_tsc; >> vmcs_set_bits(PIN_BASED_VM_EXEC_CONTROL, >> PIN_BASED_VMX_PREEMPTION_TIMER); >> - return 0; >> + >> + return delta_tsc =3D=3D 0; >> } >> >> static void vmx_cancel_hv_timer(struct kvm_vcpu *vcpu) >> -- >> 1.8.3.1 >>