Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4578285ybi; Tue, 11 Jun 2019 08:54:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcreVGsp9EUU+VgPNkQ5FJLz6My+VHeeU63XWxXpLDGJLZQXXxJp9vwS+O8K3NqTFoEKq+ X-Received: by 2002:aa7:8ecb:: with SMTP id b11mr41262815pfr.220.1560268485099; Tue, 11 Jun 2019 08:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560268485; cv=none; d=google.com; s=arc-20160816; b=ueX5BDTGjG0T67Bm8mxSxiKyvD3Sp8Q8LQlsuyEsIrY57+2UiyzCTeE/Z0AxIjGsUx aldyzx3kCtdySl/BdbDXlaH3vULy0MMFRtcJC06/LYEogLDQoLImah8wRnLl+PktAdO8 dgHtwgsTBmguwOxQJdL5K8f6PYixZRIS6AVqLsYHSBgR7ItAlQKZdlGsCJlK+PIH+KhE Q14O4ymJedmy91UAbE+wUS12VypnO28z9R502pLFWRaMX8QvK1lcImIFS/j+QEwmbN1i sBYa86Nran4h5UsY0v6WpV7VX0TRPfealHlMEdVQQtHMROZxlJayW75R6bioguaDUWwK Mo2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=tYvNhBsl81Szz5lpX12vzBlURtPV5HvGMh+XVCvP6Z8=; b=qIorPh2iz7YD10SpJL86xR8+J/doW4J6mSKzyPPr4kGBpyKPMvU4qgG/396kqieD7I e+ONbY6/YWgX6KgvspsJu3AQ8dTqGblKb2arWeaG283uEvHk+0apIItFdSecIMcZi+BG sHt2dg9t9jTiln5bkw2hDRtocI5ZfFsj/qAflhTk7mmhUScy95Y2eonQUFVu2L1+9k+i cssJ4EGz4Zda4rqOetXixstdH89iqoSbx/LcTktLG0sczzZl1EPlO9UDIUEqQKFJwaam CB4ATcORSFIk1ofiqUIri2+XHTz0/7fd3E49r2RpqKm8mlF4KKqjubHeOqEUbyrppk0e cIJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s15si12865080pgj.350.2019.06.11.08.54.29; Tue, 11 Jun 2019 08:54:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404399AbfFKPKS (ORCPT + 99 others); Tue, 11 Jun 2019 11:10:18 -0400 Received: from mga07.intel.com ([134.134.136.100]:52617 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404326AbfFKPKS (ORCPT ); Tue, 11 Jun 2019 11:10:18 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jun 2019 08:10:15 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by FMSMGA003.fm.intel.com with ESMTP; 11 Jun 2019 08:10:14 -0700 Date: Tue, 11 Jun 2019 08:10:14 -0700 From: Sean Christopherson To: Wanpeng Li Cc: LKML , kvm , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: [PATCH v2 1/2] KVM: LAPIC: Optimize timer latency consider world switch time Message-ID: <20190611151014.GA3416@linux.intel.com> References: <1559284814-20378-1-git-send-email-wanpengli@tencent.com> <20190611012118.GC24835@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 11, 2019 at 09:38:18AM +0800, Wanpeng Li wrote: > On Tue, 11 Jun 2019 at 09:21, Sean Christopherson > wrote: > > > > On Fri, May 31, 2019 at 02:40:13PM +0800, Wanpeng Li wrote: > > > From: Wanpeng Li > > > > > > Advance lapic timer tries to hidden the hypervisor overhead between the > > > host emulated timer fires and the guest awares the timer is fired. However, > > > even though after more sustaining optimizations, kvm-unit-tests/tscdeadline_latency > > > still awares ~1000 cycles latency since we lost the time between the end of > > > wait_lapic_expire and the guest awares the timer is fired. There are > > > codes between the end of wait_lapic_expire and the world switch, furthermore, > > > the world switch itself also has overhead. Actually the guest_tsc is equal > > > to the target deadline time in wait_lapic_expire is too late, guest will > > > aware the latency between the end of wait_lapic_expire() and after vmentry > > > to the guest. This patch takes this time into consideration. > > > > > > The vmentry_lapic_timer_advance_ns module parameter should be well tuned by > > > host admin, setting bit 0 to 1 to finally cache parameter in KVM. This patch > > > can reduce average cyclictest latency from 3us to 2us on Skylake server. > > > (guest w/ nohz=off, idle=poll, host w/ preemption_timer=N, the cyclictest > > > latency is not too sensitive when preemption_timer=Y for this optimization in > > > my testing), kvm-unit-tests/tscdeadline_latency can reach 0. > > > > > > Cc: Paolo Bonzini > > > Cc: Radim Krčmář > > > Cc: Sean Christopherson > > > Signed-off-by: Wanpeng Li > > > --- > > > NOTE: rebase on https://lkml.org/lkml/2019/5/20/449 > > > v1 -> v2: > > > * rename get_vmentry_advance_delta to get_vmentry_advance_cycles > > > * cache vmentry_advance_cycles by setting param bit 0 > > > * add param max limit > > > > > > arch/x86/kvm/lapic.c | 38 +++++++++++++++++++++++++++++++++++--- > > > arch/x86/kvm/lapic.h | 3 +++ > > > arch/x86/kvm/vmx/vmx.c | 2 +- > > > arch/x86/kvm/x86.c | 9 +++++++++ > > > arch/x86/kvm/x86.h | 2 ++ > > > 5 files changed, 50 insertions(+), 4 deletions(-) > > > > > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > > > index fcf42a3..60587b5 100644 > > > --- a/arch/x86/kvm/lapic.c > > > +++ b/arch/x86/kvm/lapic.c > > > @@ -1531,6 +1531,38 @@ static inline void adjust_lapic_timer_advance(struct kvm_vcpu *vcpu, > > > apic->lapic_timer.timer_advance_ns = timer_advance_ns; > > > } > > > > > > +#define MAX_VMENTRY_ADVANCE_NS 1000 > > > + > > > +u64 compute_vmentry_advance_cycles(struct kvm_vcpu *vcpu) > > > > This can be static, unless get_vmentry_advance_cycles() is moved to > > lapic.h, in which case compute_vmentry_advance_cycles() would need to be > > exported. > > Thanks for the review, Sean. I think Paolo has already drop this one. > https://lkml.org/lkml/2019/5/31/210 I couldn't tell if Paolo's response was "no, don't do that" or "let's be careful". :-)