From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
Kevin Tian <kevin.tian@intel.com>, Wei Liu <wei.liu2@citrix.com>,
Ian Campbell <ian.campbell@citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Jun Nakajima <jun.nakajima@intel.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>,
Jan Beulich <jbeulich@suse.com>, Keir Fraser <keir@xen.org>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Subject: [PATCH 04/13] x86/hvm: Setup TSC scaling ratio
Date: Mon, 28 Sep 2015 15:13:49 +0800 [thread overview]
Message-ID: <1443424438-13404-5-git-send-email-haozhong.zhang@intel.com> (raw)
In-Reply-To: <1443424438-13404-1-git-send-email-haozhong.zhang@intel.com>
This patch adds a field tsc_scaling_ratio in struct arch_vcpu to
represent the TSC scaling ratio, and sets it up when tsc_set_info() is
called for a vcpu or a vcpu is restored or reset.
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
xen/arch/x86/hvm/hvm.c | 34 ++++++++++++++++++++++++++++++++++
xen/arch/x86/hvm/svm/svm.c | 2 ++
xen/arch/x86/time.c | 10 +++++++++-
xen/include/asm-x86/domain.h | 2 ++
xen/include/asm-x86/hvm/hvm.h | 2 ++
5 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 6afc344..63ce4de 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -297,6 +297,34 @@ int hvm_set_guest_pat(struct vcpu *v, u64 guest_pat)
return 1;
}
+void hvm_setup_tsc_scaling(struct vcpu *v)
+{
+ u64 ratio, khz;
+ s8 shift;
+
+ if ( !hvm_funcs.tsc_scaling_supported )
+ return;
+
+ khz = v->domain->arch.tsc_khz;
+ shift = (hvm_funcs.tsc_scaling_ratio_frac_bits <= 32) ?
+ hvm_funcs.tsc_scaling_ratio_frac_bits : 32;
+ ratio = khz << shift;
+ do_div(ratio, cpu_khz);
+ ratio <<= hvm_funcs.tsc_scaling_ratio_frac_bits - shift;
+
+ if ( ratio == 0 ||
+ ratio > hvm_funcs.max_tsc_scaling_ratio ||
+ ratio & hvm_funcs.tsc_scaling_ratio_rsvd )
+ {
+ printk(XENLOG_WARNING
+ "Invalid TSC scaling ratio - virtual tsc khz=%lu\n",
+ khz);
+ return;
+ }
+
+ v->arch.tsc_scaling_ratio = ratio;
+}
+
void hvm_set_guest_tsc_fixed(struct vcpu *v, u64 guest_tsc, u64 at_tsc)
{
uint64_t tsc;
@@ -2023,6 +2051,9 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
if ( hvm_funcs.load_cpu_ctxt(v, &ctxt) < 0 )
return -EINVAL;
+ if ( !v->domain->arch.vtsc && hvm_funcs.tsc_scaling_supported )
+ hvm_setup_tsc_scaling(v);
+
v->arch.hvm_vcpu.msr_tsc_aux = ctxt.msr_tsc_aux;
seg.limit = ctxt.idtr_limit;
@@ -5458,6 +5489,9 @@ void hvm_vcpu_reset_state(struct vcpu *v, uint16_t cs, uint16_t ip)
hvm_set_segment_register(v, x86_seg_gdtr, ®);
hvm_set_segment_register(v, x86_seg_idtr, ®);
+ if ( !v->domain->arch.vtsc && hvm_funcs.tsc_scaling_supported )
+ hvm_setup_tsc_scaling(v);
+
/* Sync AP's TSC with BSP's. */
v->arch.hvm_vcpu.cache_tsc_offset =
v->domain->vcpu[0]->arch.hvm_vcpu.cache_tsc_offset;
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 94b9618..a7465c6 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -1170,6 +1170,8 @@ static int svm_vcpu_initialise(struct vcpu *v)
svm_guest_osvw_init(v);
+ v->arch.tsc_scaling_ratio = DEFAULT_TSC_RATIO;
+
return 0;
}
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index 92dd8a1..64f4e31 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -1956,6 +1956,8 @@ void tsc_set_info(struct domain *d,
{
case TSC_MODE_NEVER_EMULATE:
d->arch.vtsc = 0;
+ if ( tsc_mode == TSC_MODE_NEVER_EMULATE )
+ d->arch.tsc_khz = cpu_khz;
break;
}
d->arch.vtsc = 1;
@@ -1981,8 +1983,14 @@ void tsc_set_info(struct domain *d,
if ( is_hvm_domain(d) )
{
hvm_set_rdtsc_exiting(d, d->arch.vtsc);
- if ( d->vcpu && d->vcpu[0] && incarnation == 0 )
+ if ( d->vcpu && d->vcpu[0] )
{
+ if ( !d->arch.vtsc && hvm_funcs.tsc_scaling_supported )
+ hvm_setup_tsc_scaling(d->vcpu[0]);
+
+ if ( incarnation )
+ return;
+
/*
* set_tsc_offset() is called from hvm_vcpu_initialise() before
* tsc_set_info(). New vtsc mode may require recomputing TSC
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index f0aeade..fffd519 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -533,6 +533,8 @@ struct arch_vcpu
XEN_GUEST_HANDLE(vcpu_time_info_t) time_info_guest;
struct arch_vm_event *vm_event;
+
+ uint64_t tsc_scaling_ratio;
};
smap_check_policy_t smap_policy_change(struct vcpu *v,
diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h
index 7dddfa0..55e7f64 100644
--- a/xen/include/asm-x86/hvm/hvm.h
+++ b/xen/include/asm-x86/hvm/hvm.h
@@ -261,6 +261,8 @@ void hvm_set_guest_tsc_fixed(struct vcpu *v, u64 guest_tsc, u64 at_tsc);
u64 hvm_get_guest_tsc_fixed(struct vcpu *v, u64 at_tsc);
#define hvm_get_guest_tsc(v) hvm_get_guest_tsc_fixed(v, 0)
+void hvm_setup_tsc_scaling(struct vcpu *v);
+
int hvm_set_mode(struct vcpu *v, int mode);
void hvm_init_guest_time(struct domain *d);
void hvm_set_guest_time(struct vcpu *v, u64 guest_time);
--
2.4.8
next prev parent reply other threads:[~2015-09-28 7:13 UTC|newest]
Thread overview: 117+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-28 7:13 [PATCH 00/13] Add VMX TSC scaling support Haozhong Zhang
2015-09-28 7:13 ` [PATCH 01/13] x86/time.c: Use system time to calculate elapsed_nsec in tsc_get_info() Haozhong Zhang
2015-10-09 6:51 ` Jan Beulich
2015-10-09 13:41 ` Boris Ostrovsky
2015-10-09 14:00 ` Haozhong Zhang
2015-10-09 15:11 ` Jan Beulich
2015-10-09 16:09 ` Boris Ostrovsky
2015-10-09 16:19 ` Jan Beulich
2015-10-09 16:31 ` Boris Ostrovsky
2015-10-09 16:51 ` Haozhong Zhang
2015-10-09 18:59 ` Boris Ostrovsky
2015-10-09 14:39 ` Jan Beulich
2015-10-09 15:37 ` Boris Ostrovsky
2015-10-09 16:39 ` Haozhong Zhang
2015-10-09 16:44 ` Boris Ostrovsky
2015-10-09 14:35 ` Haozhong Zhang
2015-10-09 14:43 ` Jan Beulich
2015-10-09 15:56 ` Boris Ostrovsky
2015-10-14 2:45 ` Haozhong Zhang
2015-10-14 9:40 ` Jan Beulich
2015-10-14 10:00 ` Haozhong Zhang
2015-10-14 10:20 ` Jan Beulich
2015-10-14 10:24 ` Haozhong Zhang
2015-09-28 7:13 ` [PATCH 02/13] x86/time.c: Get the correct guest TSC rate " Haozhong Zhang
2015-09-28 7:13 ` [PATCH 03/13] x86/hvm: Collect information of TSC scaling ratio Haozhong Zhang
2015-10-22 12:53 ` Jan Beulich
2015-10-22 14:40 ` Haozhong Zhang
2015-10-22 14:51 ` Jan Beulich
2015-10-22 15:57 ` Haozhong Zhang
2015-09-28 7:13 ` Haozhong Zhang [this message]
2015-10-22 13:13 ` [PATCH 04/13] x86/hvm: Setup " Jan Beulich
2015-10-22 15:55 ` Haozhong Zhang
2015-10-22 16:05 ` Jan Beulich
2015-10-22 16:39 ` Haozhong Zhang
2015-10-23 7:44 ` Haozhong Zhang
2015-10-23 7:59 ` Jan Beulich
2015-10-23 8:18 ` Haozhong Zhang
2015-10-23 8:31 ` Jan Beulich
2015-10-23 8:40 ` Haozhong Zhang
2015-10-23 9:18 ` Jan Beulich
2015-09-28 7:13 ` [PATCH 05/13] x86/hvm: Replace architecture TSC scaling by a common function Haozhong Zhang
2015-10-22 13:52 ` Jan Beulich
2015-10-23 0:49 ` Haozhong Zhang
2015-09-28 7:13 ` [PATCH 06/13] x86/hvm: Scale host TSC when setting/getting guest TSC Haozhong Zhang
2015-10-22 14:17 ` Jan Beulich
2015-10-22 15:44 ` Boris Ostrovsky
2015-10-22 16:23 ` Haozhong Zhang
2015-10-27 20:16 ` Aravind Gopalakrishnan
2015-10-28 1:51 ` Haozhong Zhang
2015-11-09 7:43 ` Haozhong Zhang
2015-11-12 13:50 ` George Dunlap
2015-10-22 16:03 ` Haozhong Zhang
2015-10-27 1:54 ` Haozhong Zhang
2015-10-27 8:15 ` Jan Beulich
2015-10-27 8:25 ` Haozhong Zhang
2015-10-27 8:44 ` Haozhong Zhang
2015-10-27 13:10 ` Boris Ostrovsky
2015-10-27 13:55 ` Boris Ostrovsky
2015-10-27 16:13 ` haozhong.zhang
2015-10-27 16:13 ` haozhong.zhang
2015-09-28 7:13 ` [PATCH 07/13] x86/hvm: Move saving/loading vcpu's TSC to common code Haozhong Zhang
2015-10-22 14:54 ` Jan Beulich
2015-09-28 7:13 ` [PATCH 08/13] x86/hvm: Detect TSC scaling through hvm_funcs in tsc_set_info() Haozhong Zhang
2015-10-22 15:01 ` Jan Beulich
2015-09-28 7:13 ` [PATCH 09/13] x86/time.c: Scale host TSC in pvclock properly Haozhong Zhang
2015-09-28 16:36 ` Boris Ostrovsky
2015-09-29 0:19 ` Haozhong Zhang
2015-10-22 15:50 ` Boris Ostrovsky
2015-10-22 16:44 ` Haozhong Zhang
2015-10-22 19:15 ` Boris Ostrovsky
2015-09-28 7:13 ` [PATCH 10/13] vmx: Detect and initialize VMX RDTSC(P) scaling Haozhong Zhang
2015-10-27 13:19 ` Jan Beulich
2015-10-27 16:17 ` Haozhong Zhang
2015-09-28 7:13 ` [PATCH 11/13] vmx: Use scaled host TSC to calculate TSC offset Haozhong Zhang
2015-10-22 15:55 ` Boris Ostrovsky
2015-10-22 17:12 ` Haozhong Zhang
2015-10-22 19:19 ` Boris Ostrovsky
2015-10-23 0:52 ` Haozhong Zhang
2015-10-27 13:29 ` Jan Beulich
2015-10-27 16:21 ` Haozhong Zhang
2015-09-28 7:13 ` [PATCH 12/13] vmx: Add a call-back to apply TSC scaling ratio to hardware Haozhong Zhang
2015-09-28 16:02 ` Boris Ostrovsky
2015-09-29 1:07 ` Haozhong Zhang
2015-09-29 9:33 ` Andrew Cooper
2015-09-29 10:02 ` Haozhong Zhang
2015-09-29 10:25 ` Andrew Cooper
2015-09-29 13:59 ` Haozhong Zhang
2015-10-27 13:33 ` Jan Beulich
2015-10-28 2:41 ` Haozhong Zhang
2015-09-28 7:13 ` [PATCH 13/13] tools/libxl: Add 'vtsc_khz' option to set guest TSC rate Haozhong Zhang
2015-09-28 11:47 ` Julien Grall
2015-09-28 12:11 ` Haozhong Zhang
2015-09-28 14:19 ` Wei Liu
2015-09-29 0:40 ` Haozhong Zhang
2015-09-29 9:20 ` Wei Liu
2015-09-29 9:50 ` Haozhong Zhang
2015-09-29 10:24 ` Julien Grall
2015-09-29 10:07 ` Ian Campbell
2015-09-29 10:33 ` Wei Liu
2015-09-29 12:57 ` Haozhong Zhang
2015-09-29 10:04 ` Ian Campbell
2015-09-29 10:13 ` Haozhong Zhang
2015-09-29 10:24 ` Andrew Cooper
2015-09-29 10:28 ` Ian Campbell
2015-09-29 10:31 ` Andrew Cooper
2015-09-29 13:53 ` Haozhong Zhang
2015-09-29 13:56 ` Andrew Cooper
2015-09-29 14:01 ` Haozhong Zhang
2015-09-29 14:37 ` Ian Campbell
2015-09-29 15:16 ` Haozhong Zhang
2015-09-28 10:51 ` [PATCH 00/13] Add VMX TSC scaling support Andrew Cooper
2015-09-28 13:48 ` Boris Ostrovsky
2015-11-22 17:54 ` Haozhong Zhang
2015-11-23 15:37 ` Boris Ostrovsky
2015-11-24 13:05 ` Haozhong Zhang
2015-11-24 14:19 ` Boris Ostrovsky
2015-11-24 14:25 ` Haozhong Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1443424438-13404-5-git-send-email-haozhong.zhang@intel.com \
--to=haozhong.zhang@intel.com \
--cc=Aravind.Gopalakrishnan@amd.com \
--cc=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=jun.nakajima@intel.com \
--cc=keir@xen.org \
--cc=kevin.tian@intel.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).