From mboxrd@z Thu Jan 1 00:00:00 1970 From: Haozhong Zhang Subject: Re: [PATCH v2 03/14] x86/time.c: Use correct guest TSC frequency in tsc_set_info() Date: Tue, 8 Dec 2015 08:30:41 +0800 Message-ID: <20151208003041.GD3547@hz-desktop.sh.intel.com> References: <1449435529-12989-1-git-send-email-haozhong.zhang@intel.com> <1449435529-12989-4-git-send-email-haozhong.zhang@intel.com> <5665BA5E.5000400@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <5665BA5E.5000400@oracle.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: Boris Ostrovsky Cc: Kevin Tian , Keir Fraser , Jan Beulich , Jun Nakajima , Andrew Cooper , xen-devel@lists.xen.org, Aravind Gopalakrishnan , Suravee Suthikulpanit List-Id: xen-devel@lists.xenproject.org On 12/07/15 11:57, Boris Ostrovsky wrote: > On 12/06/2015 03:58 PM, Haozhong Zhang wrote: > >When TSC_MODE_PVRDTSCP is used for a HVM container and TSC scaling is > >available, use the non-zero value of argument gtsc_khz of tsc_set_info() > >as the guest TSC frequency rather than using the host TSC > >frequency. Otherwise, TSC scaling will not be able get the correct ratio > >between the host and guest TSC frequencies. > > > >Signed-off-by: Haozhong Zhang > >--- > > xen/arch/x86/time.c | 11 +++++++++-- > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > >diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c > >index b5223cf..1091e69 100644 > >--- a/xen/arch/x86/time.c > >+++ b/xen/arch/x86/time.c > >@@ -1803,6 +1803,8 @@ void tsc_set_info(struct domain *d, > > uint32_t tsc_mode, uint64_t elapsed_nsec, > > uint32_t gtsc_khz, uint32_t incarnation) > > { > >+ bool_t enable_tsc_scaling; > >+ > > if ( is_idle_domain(d) || is_hardware_domain(d) ) > > { > > d->arch.vtsc = 0; > >@@ -1864,7 +1866,9 @@ void tsc_set_info(struct domain *d, > > case TSC_MODE_PVRDTSCP: > > d->arch.vtsc = !boot_cpu_has(X86_FEATURE_RDTSCP) || > > !host_tsc_is_safe(); > >- d->arch.tsc_khz = cpu_khz; > >+ enable_tsc_scaling = has_hvm_container_domain(d) && > >+ cpu_has_tsc_ratio && d->arch.vtsc; > >+ d->arch.tsc_khz = (enable_tsc_scaling && gtsc_khz) ? gtsc_khz : cpu_khz; > > set_time_scale(&d->arch.vtsc_to_ns, d->arch.tsc_khz * 1000 ); > > d->arch.ns_to_vtsc = scale_reciprocal(d->arch.vtsc_to_ns); > > if ( d->arch.vtsc ) > >@@ -1872,7 +1876,10 @@ void tsc_set_info(struct domain *d, > > else { > > /* when using native TSC, offset is nsec relative to power-on > > * of physical machine */ > >- d->arch.vtsc_offset = scale_delta(rdtsc(), &d->arch.vtsc_to_ns) - > >+ struct time_scale *scale = enable_tsc_scaling ? > > Do we need this test here? Per previous chunk, enable_tsc_scaling will be > zero since d->arch.vtsc is false. > > Actually, if you are trying to use (or, rather, account for) TSC scaling, > shouldn't it be !arch.vtsc there? > It really should be !arch.vtsc. Don't know why I missed ! here but my testing code did not. Thanks, Haozhong