From mboxrd@z Thu Jan 1 00:00:00 1970 From: Haozhong Zhang Subject: [PATCH 06/13] x86/hvm: Scale host TSC when setting/getting guest TSC Date: Mon, 28 Sep 2015 15:13:51 +0800 Message-ID: <1443424438-13404-7-git-send-email-haozhong.zhang@intel.com> References: <1443424438-13404-1-git-send-email-haozhong.zhang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1443424438-13404-1-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: xen-devel@lists.xen.org Cc: Haozhong Zhang , Kevin Tian , Wei Liu , Ian Campbell , Stefano Stabellini , Jun Nakajima , Andrew Cooper , Ian Jackson , Aravind Gopalakrishnan , Jan Beulich , Keir Fraser , Boris Ostrovsky , Suravee Suthikulpanit List-Id: xen-devel@lists.xenproject.org The existing hvm_set_guest_tsc_fixed() and hvm_get_guest_tsc_fixed() calculate the guest TSC by adding the TSC offset to the host TSC. When the TSC scaling is enabled, the host TSC should be scaled first. This patch adds the scaling logic to those two functions. Signed-off-by: Haozhong Zhang --- xen/arch/x86/hvm/hvm.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 2d55a36..568c9ef 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -388,13 +388,12 @@ void hvm_set_guest_tsc_fixed(struct vcpu *v, u64 guest_tsc, u64 at_tsc) tsc = hvm_get_guest_time_fixed(v, at_tsc); tsc = gtime_to_gtsc(v->domain, tsc); } - else if ( at_tsc ) - { - tsc = at_tsc; - } else { - tsc = rdtsc(); + tsc = at_tsc ? at_tsc : rdtsc(); + + if ( hvm_funcs.tsc_scaling_supported ) + tsc = hvm_scale_tsc(v, tsc); } delta_tsc = guest_tsc - tsc; @@ -422,13 +421,12 @@ u64 hvm_get_guest_tsc_fixed(struct vcpu *v, uint64_t at_tsc) tsc = hvm_get_guest_time_fixed(v, at_tsc); tsc = gtime_to_gtsc(v->domain, tsc); } - else if ( at_tsc ) - { - tsc = at_tsc; - } else { - tsc = rdtsc(); + tsc = at_tsc ? at_tsc : rdtsc(); + + if ( hvm_funcs.tsc_scaling_supported ) + tsc = hvm_scale_tsc(v, tsc); } return tsc + v->arch.hvm_vcpu.cache_tsc_offset; -- 2.4.8