From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Ostrovsky Subject: Re: [PATCH 12/13] vmx: Add a call-back to apply TSC scaling ratio to hardware Date: Mon, 28 Sep 2015 12:02:08 -0400 Message-ID: <56096480.6010007@oracle.com> References: <1443424438-13404-1-git-send-email-haozhong.zhang@intel.com> <1443424438-13404-13-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: <1443424438-13404-13-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 , Wei Liu , Ian Campbell , Stefano Stabellini , Jun Nakajima , Andrew Cooper , Ian Jackson , Aravind Gopalakrishnan , Jan Beulich , Keir Fraser , Suravee Suthikulpanit List-Id: xen-devel@lists.xenproject.org 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 > --- > 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 > 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;