linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: luferry@163.com
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: init x2apic_enabled() once
Date: Wed, 24 Jul 2019 09:48:26 -0700	[thread overview]
Message-ID: <20190724164826.GC25376@linux.intel.com> (raw)
In-Reply-To: <20190723130608.26528-1-luferry@163.com>

On Tue, Jul 23, 2019 at 09:06:08PM +0800, luferry@163.com wrote:
> From: luferry <luferry@163.com>
> 
> x2apic_eanbled() costs about 200 cycles
> when guest trigger halt pretty high, pi ops in hotpath
> 
> Signed-off-by: luferry <luferry@163.com>
> ---
>  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
> 
> 

      parent reply	other threads:[~2019-07-24 16:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 13:06 [PATCH] KVM: x86: init x2apic_enabled() once luferry
2019-07-23 21:28 ` Krish Sadhukhan
2019-07-24 16:48 ` Sean Christopherson [this message]

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=20190724164826.GC25376@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luferry@163.com \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).