[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 10/14] x86/hvm: Replace architecture TSC scaling by a common function



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 <haozhong.zhang@xxxxxxxxx>
---
  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


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.