Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8987407ybi; Tue, 23 Jul 2019 19:31:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmXdwXv8ItY/YDICpxEbTH14AJ6J06Fc2h47OfM7sDctK7zG+9Lm0rIuPRGxvz2gqhmPaa X-Received: by 2002:a17:90a:cb01:: with SMTP id z1mr84448838pjt.93.1563935514130; Tue, 23 Jul 2019 19:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563935514; cv=none; d=google.com; s=arc-20160816; b=uk3FARfH2dMwx+Gy29+A58sZ/TvR7Vd6tX2fVgQ9Ff+NQuLxmHZLgai8iteq3fOCAh GIxVeEjEroXr0DybWLqnx0VxfLDf9O77aYknyOdD+CQ+e2tb2lbJ43SG/cr5Np0Rddci dsk50ZBbUeeMraK4tXqSU9pXpinbBH3DzYsbqaCBv5TGOOZpG3pk+KLnzs0jrJRyWOii lNJzpOXc3nq5MhpJ13qS6jJ8YdI6KQm9bwjYbBJrLAkeYA0ONyP4smsv5Gp1MS8As9cB NGUBacLK7EA4uM4ujWVGP6I9MucrkJmqRldxTyao9/G50i+Djoey3bglI/oOn7anEWBS FBbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=jXLXRJ/Y6JfH9vX4QoNP0NAjE2AgrDuly2eL+QibNhM=; b=tBXPBy1phZFvZcJJxpI5DmRnuRACUigSI7MBq1fa9TrCBXbceaWvHlavd9mNLYSDZ5 lUG5sY33KYI/hdQBM5JcyCbZk320UiQMxCZXJ+DUTmgyg5MD/z0L2qG6D3TP05zCvsKK o39mFjVX7LNnpdjuMTPdAsaczMnxqTsR1A9TUq8fam9EFaMik2akllErcltcuuEfo+Bp 1PXZJj/ZytZg0KEpBnViJ5HvDqLjhTnSnywPc78z8+FPyuorawcwWvs+YPzV0e5MZeDM picgpqLgSt/cSITg5GBlFGMVysvskjdbe2jf/Hvr5RE1s1jJ6bS8YDzGrAjdQGDsjS+1 0vLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=VqyK1OKp; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g13si15512812pgo.274.2019.07.23.19.31.38; Tue, 23 Jul 2019 19:31:54 -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; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=VqyK1OKp; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392082AbfGWV24 (ORCPT + 99 others); Tue, 23 Jul 2019 17:28:56 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:37038 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728967AbfGWV2z (ORCPT ); Tue, 23 Jul 2019 17:28:55 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x6NLO9Ur031514; Tue, 23 Jul 2019 21:28:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=jXLXRJ/Y6JfH9vX4QoNP0NAjE2AgrDuly2eL+QibNhM=; b=VqyK1OKp7TR230/YHVBc0GtEfo9JHhY1dZLbJ6VYPvkgkjnID5sJgWr5e+PClmv+dNau xAJm6kFOUOaQwPnYrkrhWIKCG3qT0fYVS0C05oHn8V5dVB7+rZ6YdR3fGU8USIFnA/NX O0a0IV1s2w3ljnfv04vltT0hfIVYfakFjPTAfJv5PhuOchItpFaAqWlCCHQkAnvZEJHv B1BpbDZGw8TRRYT7e9M0HkhQRwjxN7I3JL2LPclkc93O/itlqfKkjoywx1s73P0RKeV7 7wnhYM++zelSqD+3lkA6cCm30B0dtgUq2uU6HwFA+/4yJjNaAdY1VgeoG77AGyGeJflJ OQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2tx61bsbub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Jul 2019 21:28:24 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x6NLRpRf082842; Tue, 23 Jul 2019 21:28:23 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2tx60xekek-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Jul 2019 21:28:23 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x6NLSJDo024157; Tue, 23 Jul 2019 21:28:19 GMT Received: from dhcp-10-132-91-225.usdhcp.oraclecorp.com (/10.132.91.225) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 23 Jul 2019 14:28:19 -0700 Subject: Re: [PATCH] KVM: x86: init x2apic_enabled() once To: luferry@163.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190723130608.26528-1-luferry@163.com> From: Krish Sadhukhan Message-ID: Date: Tue, 23 Jul 2019 14:28:18 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20190723130608.26528-1-luferry@163.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9327 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907230216 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9327 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907230216 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/23/2019 06:06 AM, 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) > 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) Reviewed-by: Krish Sadhukhan