From: Haozhong Zhang Subject: Re: [PATCH v2 10/14] x86/hvm: Replace architecture TSC scaling by a common function Date: Tue, 8 Dec 2015 10:06:45 +0800 Message-ID: <20151208020645.GI3547@hz-desktop.sh.intel.com> References: <1449435529-12989-1-git-send-email-haozhong.zhang@intel.com> <1449435529-12989-11-git-send-email-haozhong.zhang@intel.com> <5665D611.5080809@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <5665D611.5080809@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Boris Ostrovsky Cc: Kevin Tian , Keir Fraser , Jan Beulich , Jun Nakajima , Andrew Cooper , xen-devel@lists.xen.org, Aravind Gopalakrishnan , Suravee Suthikulpanit List-Id: xen-devel@lists.xenproject.org On 12/07/15 13:55, Boris Ostrovsky wrote: > On 12/06/2015 03:58 PM, Haozhong Zhang wrote: > >This patch implements a common function hvm_scale_tsc() to scale TSC by > >using TSC scaling information collected by architecture code. > > > >Signed-off-by: Haozhong Zhang > >--- > > xen/arch/x86/hvm/hvm.c | 18 +++++++++-- > > xen/arch/x86/hvm/svm/svm.c | 12 -------- > > xen/arch/x86/time.c | 2 +- > > xen/include/asm-x86/hvm/hvm.h | 3 +- > > xen/include/asm-x86/math64.h | 70 +++++++++++++++++++++++++++++++++++++++++++ > > 5 files changed, 88 insertions(+), 17 deletions(-) > > > >diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c > >index 52a0ef8..1e3d89f 100644 > >--- a/xen/arch/x86/hvm/hvm.c > >+++ b/xen/arch/x86/hvm/hvm.c > >@@ -302,6 +302,20 @@ int hvm_set_guest_pat(struct vcpu *v, u64 guest_pat) > > return 1; > > } > >+u64 hvm_scale_tsc(const struct vcpu *v, u64 tsc) > >+{ > >+ u64 ratio = v->arch.hvm_vcpu.tsc_scaling_ratio; > >+ > >+ if ( !hvm_funcs.tsc_scaling_supported || > >+ ratio == hvm_funcs.default_tsc_scaling_ratio ) > >+ return tsc; > >+ > >+ BUG_ON(hvm_funcs.tsc_scaling_ratio_frac_bits >= 64 || > >+ hvm_funcs.tsc_scaling_ratio_frac_bits == 0); > > Since these values never change, I am not sure it's worth testing this. And > if you think it is then I'd do it somewhere in initialization code. > I'll remove this unnecessary check. > >+ > >+ return mul_u64_u64_shr(tsc, ratio, hvm_funcs.tsc_scaling_ratio_frac_bits); > >+} > >+ > > > > >diff --git a/xen/include/asm-x86/math64.h b/xen/include/asm-x86/math64.h > >index 9af6aee..c6a472b 100644 > >--- a/xen/include/asm-x86/math64.h > >+++ b/xen/include/asm-x86/math64.h > >@@ -27,4 +27,74 @@ static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor) > > return rl.ll; > > } > >+/* > >+ * Multiply two 64-bit unsigned integers a and b. The most and least > >+ * significant 64 bits of the 128-bit result are returned through hi > >+ * and lo respectively. > >+ */ > >+static inline void mul64(u64 *lo, u64 *hi, u64 a, u64 b) > > Please move these routines (as well as one in previous patch into a > standalone math patch (and provide attribution to wherever they came from). > I'll move them to a standalone patch and add comments for their source. Thanks, Haozhong