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

Re: [Xen-devel] [PATCH 12/13] vmx: Add a call-back to apply TSC scaling ratio to hardware



On Mon, Sep 28, 2015 at 12:02:08PM -0400, Boris Ostrovsky wrote:
> On 09/28/2015 03:13 AM, Haozhong Zhang wrote:
> >This patch adds a new call-back setup_tsc_scaling in struct
> >hvm_function_table to apply the TSC scaling ratio to hardware. For VMX,
> >it writes the TSC scaling ratio to VMCS field TSC_MULTIPLIER.
> >
> >Signed-off-by: Haozhong Zhang <haozhong.zhang@xxxxxxxxx>
> >---
> >  xen/arch/x86/hvm/hvm.c        | 1 +
> >  xen/arch/x86/hvm/svm/svm.c    | 5 +++++
> >  xen/arch/x86/hvm/vmx/vmx.c    | 8 ++++++++
> >  xen/include/asm-x86/hvm/hvm.h | 3 +++
> >  4 files changed, 17 insertions(+)
> >
> >diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> >index 3522d20..2d8a148 100644
> >--- a/xen/arch/x86/hvm/hvm.c
> >+++ b/xen/arch/x86/hvm/hvm.c
> >@@ -376,6 +376,7 @@ void hvm_setup_tsc_scaling(struct vcpu *v)
> >      }
> >      v->arch.tsc_scaling_ratio = ratio;
> >+    hvm_funcs.setup_tsc_scaling(v);
> >  }
> >  void hvm_set_guest_tsc_fixed(struct vcpu *v, u64 guest_tsc, u64 at_tsc)
> >diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
> >index 73bc863..d890c1f 100644
> >--- a/xen/arch/x86/hvm/svm/svm.c
> >+++ b/xen/arch/x86/hvm/svm/svm.c
> >@@ -2236,6 +2236,10 @@ static void svm_invlpg_intercept(unsigned long vaddr)
> >      svm_asid_g_invlpg(curr, vaddr);
> >  }
> >+static void svm_setup_tsc_scaling(struct vcpu *v)
> >+{
> >+}
> >+
> 
> Should this be wrmsrl(MSR_AMD64_TSC_RATIO, v->arch.tsc_scaling_ratio) ?
> 
> -boris
>

MSR_AMD64_TSC_RATIO is set in svm_ctxt_switch_to() before entering guest.

For VMX, the ratio is set to a VMCS field TSC_MULTIPLIER and it's not
necessary to set it every time entering guest. Therefore, I introduce
the call-back setup_tsc_scaling() to do this. For SVM, as the ratio is
set every time entering guest, I leave the SVM version of setup_tsc_scaling()
empty.

- Haozhong

> >  static struct hvm_function_table __initdata svm_function_table = {
> >      .name                 = "SVM",
> >      .cpu_up_prepare       = svm_cpu_up_prepare,
> >@@ -2289,6 +2293,7 @@ static struct hvm_function_table __initdata 
> >svm_function_table = {
> >      .max_tsc_scaling_ratio       = MAX_TSC_RATIO,
> >      .tsc_scaling_ratio_frac_bits = 32,
> >      .tsc_scaling_ratio_rsvd      = TSC_RATIO_RSVD_BITS,
> >+    .setup_tsc_scaling           = svm_setup_tsc_scaling,
> >  };
> >  void svm_vmexit_handler(struct cpu_user_regs *regs)
> >diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
> >index 163974d..c4a7b81 100644
> >--- a/xen/arch/x86/hvm/vmx/vmx.c
> >+++ b/xen/arch/x86/hvm/vmx/vmx.c
> >@@ -1100,6 +1100,13 @@ static void vmx_handle_cd(struct vcpu *v, unsigned 
> >long value)
> >      }
> >  }
> >+static void vmx_setup_tsc_scaling(struct vcpu *v)
> >+{
> >+    vmx_vmcs_enter(v);
> >+    __vmwrite(TSC_MULTIPLIER, v->arch.tsc_scaling_ratio);
> >+    vmx_vmcs_exit(v);
> >+}
> >+
> >  static void vmx_set_tsc_offset(struct vcpu *v, u64 offset, u64 at_tsc)
> >  {
> >      uint64_t host_tsc, guest_tsc;
> >@@ -1986,6 +1993,7 @@ static struct hvm_function_table __initdata 
> >vmx_function_table = {
> >      .max_tsc_scaling_ratio       = VMX_TSC_MULTIPLIER_MAX,
> >      .tsc_scaling_ratio_frac_bits = 48,
> >      .tsc_scaling_ratio_rsvd      = 0x0ULL,
> >+    .setup_tsc_scaling           = vmx_setup_tsc_scaling,
> >  };
> >  const struct hvm_function_table * __init start_vmx(void)
> >diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h
> >index f63fe93..9f8b6d5 100644
> >--- a/xen/include/asm-x86/hvm/hvm.h
> >+++ b/xen/include/asm-x86/hvm/hvm.h
> >@@ -226,6 +226,9 @@ struct hvm_function_table {
> >      void (*altp2m_vcpu_update_vmfunc_ve)(struct vcpu *v);
> >      bool_t (*altp2m_vcpu_emulate_ve)(struct vcpu *v);
> >      int (*altp2m_vcpu_emulate_vmfunc)(struct cpu_user_regs *regs);
> >+
> >+    /* setup TSC scaling */
> >+    void (*setup_tsc_scaling)(struct vcpu *v);
> >  };
> >  extern struct hvm_function_table hvm_funcs;
> 

_______________________________________________
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®.