From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Ostrovsky Subject: Re: [PATCH v2 10/14] x86/hvm: Replace architecture TSC scaling by a common function Date: Mon, 7 Dec 2015 13:55:13 -0500 Message-ID: <5665D611.5080809@oracle.com> References: <1449435529-12989-1-git-send-email-haozhong.zhang@intel.com> <1449435529-12989-11-git-send-email-haozhong.zhang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1449435529-12989-11-git-send-email-haozhong.zhang@intel.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: Haozhong Zhang , xen-devel@lists.xen.org Cc: Kevin Tian , Keir Fraser , Jan Beulich , Jun Nakajima , Andrew Cooper , Aravind Gopalakrishnan , Suravee Suthikulpanit List-Id: xen-devel@lists.xenproject.org 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. > + > + 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). -boris