From patchwork Fri Feb 17 15:42:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 9580185 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 1FDF36043A for ; Fri, 17 Feb 2017 15:45:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 128132871F for ; Fri, 17 Feb 2017 15:45:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0772F28721; Fri, 17 Feb 2017 15:45:00 +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 B4CA328723 for ; Fri, 17 Feb 2017 15:44:59 +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 1cekgO-0001mR-HN; Fri, 17 Feb 2017 15:42:52 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cekgN-0001ls-AS for xen-devel@lists.xen.org; Fri, 17 Feb 2017 15:42:51 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id F0/93-24539-AF917A85; Fri, 17 Feb 2017 15:42:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42JxWrrBXven5PI Ig+5VvBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8byBafZC5r4Kma9Wc7cwHicq4uRk0NCwF/i wtkFbCA2m4CexMbZr5hAbBEBWYnVXXPYuxi5OJgFjjBKTF11hB0kISzgItG47yEriM0ioCpx5 eg2sAZeAVuJ0xf+skMMlZO4tO0LM4jNKWAnsfX3fzBbCKjm1+PHLBC2qsTrF7tYIHoFJU7OfA JmMwtISBx88YJ5AiPvLCSpWUhSCxiZVjFqFKcWlaUW6RpZ6CUVZaZnlOQmZuboGhqY6eWmFhc npqfmJCYV6yXn525iBIYPAxDsYDy/NvAQoyQHk5Io7yOu5RFCfEn5KZUZicUZ8UWlOanFhxhl ODiUJHgfSgDlBItS01Mr0jJzgIEMk5bg4FES4fUDBrMQb3FBYm5xZjpE6hSjopQ47z+QPgGQR EZpHlwbLHouMcpKCfMyAh0ixFOQWpSbWYIq/4pRnINRSZj3JcgUnsy8Erjpr4AWMwEt7oxYCr K4JBEhJdXAKPfq9zn/nR93qyeE7lfkZXnNcMLQKa5WZlfANamFFcXv/cPac+3jO82y89Z6Tv+ 67qtUlJHC6YCQBzozmb3yQjcX35afF6Q6TXSievZkn9ip/98vePbbqX8za8yrHO+Jz4ulr335 L9tz7JRi7zVPHZ2Ic3/P8jzl5BHli5glwb+jK1Nkd+AzJZbijERDLeai4kQAY1km+JkCAAA= X-Env-Sender: prvs=214538380=sergey.dyasli@citrix.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1487346166!77354806!2 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 38334 invoked from network); 17 Feb 2017 15:42:48 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-8.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 17 Feb 2017 15:42:48 -0000 X-IronPort-AV: E=Sophos;i="5.35,172,1484006400"; d="scan'208";a="416657564" From: Sergey Dyasli To: Date: Fri, 17 Feb 2017 15:42:32 +0000 Message-ID: <20170217154233.28514-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170217154233.28514-1-sergey.dyasli@citrix.com> References: <20170217154233.28514-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Jan Beulich , Jun Nakajima , Sergey Dyasli Subject: [Xen-devel] [PATCH v2 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 --- v1 --> v2: - a new patch, factored out from v1 1/2 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 49587d6..6c86147 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1347,17 +1347,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; @@ -1365,17 +1360,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;