From patchwork Thu Feb 23 09:33:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9587977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CC0D601AE for ; Thu, 23 Feb 2017 09:36:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 619DD286AA for ; Thu, 23 Feb 2017 09:36:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5662B286EC; Thu, 23 Feb 2017 09:36:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4BECE286EC for ; Thu, 23 Feb 2017 09:36:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgpmL-0007ah-Jo; Thu, 23 Feb 2017 09:33:37 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgpmK-0007a4-8P for xen-devel@lists.xen.org; Thu, 23 Feb 2017 09:33:36 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 95/5C-23854-F6CAEA85; Thu, 23 Feb 2017 09:33:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42JxWrrBXjd/zbo Ig45ZHBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bGI31MBQf4Kqb8vcfewNjM3cXIySEh4C+x 7Eg3C4jNJqAnsXH2KyYQW0RAVmJ11xz2LkYuDmaBI4wSU1cdAXI4OIQFXCSm/gOrYRFQlTh+7 CUziM0rYCvxaO9lNoiZchKXtn0Bi3MK2Em8WncJLC4EVPN5yWsoW1Xi9YtdLBC9ghInZz4Bs5 kFJCQOvnjBPIGRdxaS1CwkqQWMTKsYNYpTi8pSi3SNjPSSijLTM0pyEzNzdA0NjPVyU4uLE9N TcxKTivWS83M3MQKDp56BgXEH49QTfocYJTmYlER52VauixDiS8pPqcxILM6ILyrNSS0+xCjD waEkwcsADEYhwaLU9NSKtMwcYBjDpCU4eJREeBVA0rzFBYm5xZnpEKlTjIpS4rwsIAkBkERGa R5cGyx2LjHKSgnzMjIwMAjxFKQW5WaWoMq/YhTnYFQS5t2yGmgKT2ZeCdz0V0CLmYAWWzqvBV lckoiQkmpg1M87JXZzcvrxWImaRuO/u0t6fuu6aWpvYzv8Ipon4xNjZOzr/aZLGZUO/bp2gH8 L5yynf++bU2cbzZghJ5KyRG3+s9UOfj+DRB1lWTvuheYqCjm8Eefu2r7vqMMsG117z4sx31cI yM5XYMt3z3ha8qm/548659ZNM3SeeN404Ni3MDcl84WVEktxRqKhFnNRcSIA9MouJZgCAAA= X-Env-Sender: prvs=22001adc4=sergey.dyasli@citrix.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1487842413!70247224!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 2693 invoked from network); 23 Feb 2017 09:33:34 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-12.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 23 Feb 2017 09:33:34 -0000 X-IronPort-AV: E=Sophos;i="5.35,197,1484006400"; d="scan'208";a="418009704" From: Sergey Dyasli To: Date: Thu, 23 Feb 2017 09:33:26 +0000 Message-ID: <20170223093327.23493-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170223093327.23493-1-sergey.dyasli@citrix.com> References: <20170223093327.23493-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Jan Beulich , Jun Nakajima , Sergey Dyasli Subject: [Xen-devel] [PATCH v3 2/3] x86/vmx: optimize vmx_read/write_guest_msr() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Replace linear scan with vmx_find_msr(). This way the time complexity of searching for required MSR reduces from linear to logarithmic. Signed-off-by: Sergey Dyasli Acked-by: Kevin Tian Reviewed-by: Jan Beulich --- v2 --> v3: - no changes xen/arch/x86/hvm/vmx/vmcs.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 977106f..0dcb938 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1360,17 +1360,12 @@ struct vmx_msr_entry *vmx_find_msr(u32 msr, int type) int vmx_read_guest_msr(u32 msr, u64 *val) { - struct vcpu *curr = current; - unsigned int i, msr_count = curr->arch.hvm_vmx.msr_count; - const struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area; + struct vmx_msr_entry *ent; - for ( i = 0; i < msr_count; i++ ) + if ( (ent = vmx_find_msr(msr, VMX_GUEST_MSR)) != NULL ) { - if ( msr_area[i].index == msr ) - { - *val = msr_area[i].data; - return 0; - } + *val = ent->data; + return 0; } return -ESRCH; @@ -1378,17 +1373,12 @@ int vmx_read_guest_msr(u32 msr, u64 *val) int vmx_write_guest_msr(u32 msr, u64 val) { - struct vcpu *curr = current; - unsigned int i, msr_count = curr->arch.hvm_vmx.msr_count; - struct vmx_msr_entry *msr_area = curr->arch.hvm_vmx.msr_area; + struct vmx_msr_entry *ent; - for ( i = 0; i < msr_count; i++ ) + if ( (ent = vmx_find_msr(msr, VMX_GUEST_MSR)) != NULL ) { - if ( msr_area[i].index == msr ) - { - msr_area[i].data = val; - return 0; - } + ent->data = val; + return 0; } return -ESRCH;