From mboxrd@z Thu Jan 1 00:00:00 1970 From: Haozhong Zhang Subject: Re: [PATCH] kvm: x86: Update tsc multiplier on change. Date: Wed, 2 Mar 2016 09:39:07 +0800 Message-ID: <20160302013907.GA4004@hz-desktop.sh.intel.com> References: <1456868173-444-1-git-send-email-osh@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: , Paolo Bonzini To: Owen Hofmann Return-path: Received: from mga04.intel.com ([192.55.52.120]:30870 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751935AbcCBBjK (ORCPT ); Tue, 1 Mar 2016 20:39:10 -0500 Content-Disposition: inline In-Reply-To: <1456868173-444-1-git-send-email-osh@google.com> Sender: kvm-owner@vger.kernel.org List-ID: On 03/01/16 13:36, Owen Hofmann wrote: > vmx.c writes the TSC_MULTIPLIER field in vmx_vcpu_load, but only when a > vcpu has migrated physical cpus. Record the last value written and > update in vmx_vcpu_load on any change, otherwise a cpu migration must > occur for TSC frequency scaling to take effect. > > Fixes: ff2c3a1803775cc72dc6f624b59554956396b0ee > Signed-off-by: Owen Hofmann looks good for me. Reviewed-by: Haozhong Zhang > --- > arch/x86/kvm/vmx.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index e2951b6..0ff4537 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -596,6 +596,8 @@ struct vcpu_vmx { > /* Support for PML */ > #define PML_ENTITY_NUM 512 > struct page *pml_pg; > + > + u64 current_tsc_ratio; > }; > > enum segment_cache_field { > @@ -2127,14 +2129,16 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) > rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp); > vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */ > > - /* Setup TSC multiplier */ > - if (cpu_has_vmx_tsc_scaling()) > - vmcs_write64(TSC_MULTIPLIER, > - vcpu->arch.tsc_scaling_ratio); > - > vmx->loaded_vmcs->cpu = cpu; > } > > + /* Setup TSC multiplier */ > + if (kvm_has_tsc_control && > + vmx->current_tsc_ratio != vcpu->arch.tsc_scaling_ratio) { > + vmx->current_tsc_ratio = vcpu->arch.tsc_scaling_ratio; > + vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio); > + } > + > vmx_vcpu_pi_load(vcpu, cpu); > } > > -- > 2.7.0.rc3.207.g0ac5344 >