From patchwork Sun Jan 17 21:58:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 8051051 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 74576BEEE5 for ; Sun, 17 Jan 2016 22:04:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8A36B205DC for ; Sun, 17 Jan 2016 22:04:36 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 09455205FC for ; Sun, 17 Jan 2016 22:03:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aKvMz-0003OW-O2; Sun, 17 Jan 2016 22:00:21 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aKvMx-0003O3-Ne for xen-devel@lists.xen.org; Sun, 17 Jan 2016 22:00:19 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id D2/E8-14900-2FE0C965; Sun, 17 Jan 2016 22:00:18 +0000 X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1453068017!16335561!1 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58040 invoked from network); 17 Jan 2016 22:00:18 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-10.tower-31.messagelabs.com with SMTP; 17 Jan 2016 22:00:18 -0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 17 Jan 2016 14:00:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,309,1449561600"; d="scan'208";a="635191723" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.26]) by FMSMGA003.fm.intel.com with ESMTP; 17 Jan 2016 14:00:15 -0800 From: Haozhong Zhang To: xen-devel@lists.xen.org, Jan Beulich , Boris Ostrovsky , Kevin Tian Date: Mon, 18 Jan 2016 05:58:52 +0800 Message-Id: <1453067939-9121-4-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1453067939-9121-1-git-send-email-haozhong.zhang@intel.com> References: <1453067939-9121-1-git-send-email-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Keir Fraser , Suravee Suthikulpanit , Andrew Cooper , Aravind Gopalakrishnan , Jun Nakajima Subject: [Xen-devel] [PATCH v4 03/10] svm: Remove redundant TSC scaling in svm_set_tsc_offset() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now every caller passes an already scaled offset to svm_set_tsc_offset(), so it's not necessary to recalculate a scaled TSC offset in svm_set_tsc_offset(). Signed-off-by: Haozhong Zhang Reviewed-by: Boris Ostrovsky --- Changes in v4: (addressing Jan Beulich's comments) * Fix code style. xen/arch/x86/hvm/svm/svm.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index a46bc98..953e0b5 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -823,19 +823,6 @@ static void svm_set_tsc_offset(struct vcpu *v, u64 offset, u64 at_tsc) struct vmcb_struct *n1vmcb, *n2vmcb; uint64_t n2_tsc_offset = 0; struct domain *d = v->domain; - uint64_t host_tsc, guest_tsc; - - guest_tsc = hvm_get_guest_tsc_fixed(v, at_tsc); - - /* Re-adjust the offset value when TSC_RATIO is available */ - if ( cpu_has_tsc_ratio && !d->arch.vtsc ) - { - if ( at_tsc ) - host_tsc = at_tsc; - else - host_tsc = rdtsc(); - offset = svm_get_tsc_offset(host_tsc, guest_tsc, vcpu_tsc_ratio(v)); - } if ( !nestedhvm_enabled(d) ) { vmcb_set_tsc_offset(vmcb, offset); @@ -849,10 +836,13 @@ static void svm_set_tsc_offset(struct vcpu *v, u64 offset, u64 at_tsc) struct nestedsvm *svm = &vcpu_nestedsvm(v); n2_tsc_offset = vmcb_get_tsc_offset(n2vmcb) - - vmcb_get_tsc_offset(n1vmcb); + vmcb_get_tsc_offset(n1vmcb); if ( svm->ns_tscratio != DEFAULT_TSC_RATIO ) { + uint64_t guest_tsc = hvm_get_guest_tsc_fixed(v, at_tsc); + n2_tsc_offset = svm_get_tsc_offset(guest_tsc, - guest_tsc + n2_tsc_offset, svm->ns_tscratio); + guest_tsc + n2_tsc_offset, + svm->ns_tscratio); } vmcb_set_tsc_offset(n1vmcb, offset); }