Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9830721ybi; Wed, 24 Jul 2019 10:41:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUSx62gjcRmKpULSbzq5ZjnuBwrkC41IWTzX7szvwgS75e2lm8xzS3Jdxu8V5Rbcu6OxXy X-Received: by 2002:a17:902:27e6:: with SMTP id i35mr86597119plg.190.1563990082268; Wed, 24 Jul 2019 10:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563990082; cv=none; d=google.com; s=arc-20160816; b=rIwpbF02j3EEQsQotP/QtId4NqynnICDYwWgZHS+bUhAEjVH1BkPcwb+s9+PY3wqCQ rS4aDecUnCthSyW69RoO+2zOrmc5LaawsdXejpUHv0E1tinR95p/LuCXqDsiHciaQyiO 7kOf5Et1Ds3luNpBt9K+nMoBb+OChbbE9BN3r9GkR+6653yZViFLksNbv2HC4nVxMekd 2dPM+uZd0Bcj6Xi8pmk1L1NliJgREAQC99bFO6Xa5aU6cet9VC0PucIT2iEm03v7asvC 0CmioLRGRIHSrJof4huMinsCIYncWaQ9vUSGew9Dxm3/wlHpuUM46GFSfjjZb/vmPODh fwaA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=+ajc9vZi2MqFJLit23a9ZCvYvRV5X2nerBYihNyosCo=; b=nrYLEWMCOt+eBSoKAbkasGB2dn98kXwUxLkCXcocuyRzlOiZ1z4nxHeLC/sbdPvvth A0VaCzi4tFCYw7f78K5lk/EukW2OuF5opttkyzZ1NpP1sjOfjl8SdWnXVthK5N+EVgr6 ezrG4mUdk8+MV7JpuhNgXcX0q0oYOFBzcVm5ru2n3mCVnuyNsOIVQcNXQ/TAkYxO95f8 k6GcuCKGrm1cIpjWkZ7oZ+MZKQAvLBaE1FoEfQ4EJTI6/Tp87K1ODY9p0dW78mOkF7Ui UtTSLmblANca2zYh6OcmCAkdfM8Xpg4rFKH7VuAyMBwxPWVZsWmJz2l+amA3xqiIyKzW M+hg== 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 r8si16492846pgr.243.2019.07.24.10.41.07; Wed, 24 Jul 2019 10:41:22 -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 S2387739AbfGXQs2 (ORCPT + 99 others); Wed, 24 Jul 2019 12:48:28 -0400 Received: from mga11.intel.com ([192.55.52.93]:51124 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387729AbfGXQs1 (ORCPT ); Wed, 24 Jul 2019 12:48:27 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jul 2019 09:48:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,303,1559545200"; d="scan'208";a="369355335" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.165]) by fmsmga006.fm.intel.com with ESMTP; 24 Jul 2019 09:48:26 -0700 Date: Wed, 24 Jul 2019 09:48:26 -0700 From: Sean Christopherson To: luferry@163.com Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: x86: init x2apic_enabled() once Message-ID: <20190724164826.GC25376@linux.intel.com> References: <20190723130608.26528-1-luferry@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190723130608.26528-1-luferry@163.com> 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, Jul 23, 2019 at 09:06:08PM +0800, luferry@163.com wrote: > From: luferry > > x2apic_eanbled() costs about 200 cycles > when guest trigger halt pretty high, pi ops in hotpath > > Signed-off-by: luferry > --- > arch/x86/kvm/vmx/vmx.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index d98eac371c0a..e17dbf011e47 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -186,6 +186,8 @@ static DEFINE_STATIC_KEY_FALSE(vmx_l1d_should_flush); > static DEFINE_STATIC_KEY_FALSE(vmx_l1d_flush_cond); > static DEFINE_MUTEX(vmx_l1d_flush_mutex); > > +static int __read_mostly host_x2apic_enabled; > + > /* Storage for pre module init parameter parsing */ > static enum vmx_l1d_flush_state __read_mostly vmentry_l1d_flush_param = VMENTER_L1D_FLUSH_AUTO; > > @@ -1204,7 +1206,7 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) > > dest = cpu_physical_id(cpu); > > - if (x2apic_enabled()) > + if (host_x2apic_enabled) Instead of caching x2apic_enabled(), this can be: if (x2apic_supported() && x2apic_mode) which will get compiled out if CONFIG_X86_X2APIC=n. It's quite suprising (to me) that 2apic_enabled() reads the MSR in the first place, but at a glance the other users of x2apic_enabled() do need to query the MSR and/or may be called before x2apic_mode is set. > new.ndst = dest; > else > new.ndst = (dest << 8) & 0xFF00; > @@ -7151,7 +7153,7 @@ static void __pi_post_block(struct kvm_vcpu *vcpu) > > dest = cpu_physical_id(vcpu->cpu); > > - if (x2apic_enabled()) > + if (host_x2apic_enabled) > new.ndst = dest; > else > new.ndst = (dest << 8) & 0xFF00; > @@ -7221,7 +7223,7 @@ static int pi_pre_block(struct kvm_vcpu *vcpu) > */ > dest = cpu_physical_id(vcpu->pre_pcpu); > > - if (x2apic_enabled()) > + if (host_x2apic_enabled) > new.ndst = dest; > else > new.ndst = (dest << 8) & 0xFF00; > @@ -7804,6 +7806,8 @@ static int __init vmx_init(void) > } > #endif > > + host_x2apic_enabled = x2apic_enabled(); > + > r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), > __alignof__(struct vcpu_vmx), THIS_MODULE); > if (r) > -- > 2.14.1.40.g8e62ba1 > >