Add VMX TSC scaling support
v6 cover Add VMX TSC scaling support
This patchset adds support for VMX TSC scaling feature which is available on Intel Skylake Server CPU. The specification of VMX TSC scaling can be found at
http://www.intel.com/content/www/us/en/processors/timestamp-counter-scaling-virtualization-white-paper.html
VMX TSC scaling allows guest TSC which is read by guest rdtsc(p) instructions increases in a rate that is customized by the hypervisor and can be different than the host TSC frequency. Basically, VMX TSC scaling adds a 64-bit field called TSC multiplier in VMCS so that, if VMX TSC scaling is enabled, TSC read by guest rdtsc(p) instructions will be calculated by the following formula:
guest EDX:EAX = (Host TSC * TSC multiplier) >> 48 + VMX TSC Offset
where, Host TSC = Host MSR_IA32_TSC + Host MSR_IA32_TSC_ADJUST.
If the destination host supports VMX TSC scaling, this patchset allows guest programs in a HVM container in the default TSC mode or PVRDTSCP (native_paravirt) TSC mode to observe the same TSC frequency across the migration.
Changes in v6:
* v5 patch 1 has been committed so it's not included in v6.
* v5 patch 1 - 5 correspond to v4 patch 2 - 6.
* Adjust inline assembly in patch 1 and 2 per Jan's comments.
* Name and type adjustments in patch 1 and 4.
* Patch 3 and 5 are not changed.
Changes in v5:
* v4 patch 1 - 3 have been committed so they are not included in v5.
* v4 patch 5 "x86: Add functions for 64-bit integer arithmetic" is removed in v5. All math64 functions are inlined in v5.
* v5 patch 1 corresponds to v4 patch 4.
v5 patch 2 - 6 correspond to v4 patch 6 - 10.
* Other changes are logged in each patch respectively.
* Previous R-b and A-b (from Boris Ostrovsky, Jan Beulich and Kevin Tian) for all patches except patch 4 are removed because of above changes.
Changes in v4:
* v3 patch 1&2 have been committed so they are not included in v4.
* v3 patch 11 "x86/hvm: Detect TSC scaling through hvm_funcs" is merged early into v4 patch 4 "x86/hvm: Collect information of TSC scaling ratio".
* v4 patch 1 - 8 correspond to v3 patch 3 - 10.
v4 patch 9 - 10 correspond to v3 patch 12 - 13.
* Other changes are logged in each patch respectively.
Changes in v3:
* v2 patch 1&2 have been merged so they do not appear in v3.
* Patch 1 - 6 correspond to v2 patch 3 - 8. Patch 7 is new. Patch 8 - 13 correspond to v2 patch 9 - 14.
* Other changes are logged in each patch respectively.
Changes in v2:
* Remove unnecessary v1 patch 1&13.
* Add and move all bug-fix patches to the beginning of this series. (Patch 1 - 6)
* Update changes in tsc_set_info() and tsc_get_info() to make both functions consistent with each other. (Patch 2 - 4)
* Move a part of scaling logic out of [vmx|svm]_set_tsc_offset(). (Patch 7)
* Remove redundant hvm_funcs.tsc_scaling_ratio_rsvd. (Patch 8)
* Reimplement functions that calculate TSC ratio and scale TSC. (Patch 9&10)
* Merge setting VMX TSC multiplier into patch 13.
* Move initialing tsc_scaling_ratio in VMX ahead to vmx_vcpu_initialise() so as to make construct_vmcs() naturally use this field instead of a constant. (Patch 13)
* Update documents related to tsc_mode.
* Other code cleanup and style fixes.
Haozhong Zhang (5):
x86/hvm: Setup TSC scaling ratio
x86/hvm: Replace architecture TSC scaling by a common function x86/hvm: Move saving/loading vcpu's TSC to common code
vmx: Add VMX RDTSC(P) scaling support
docs: Add descriptions of TSC scaling in xl.cfg and tscmode.txt
docs/man/xl.cfg.pod.5 | 14 +++++++- docs/misc/tscmode.txt | 21 ++++++++++++ xen/arch/x86/hvm/hvm.c | 69 ++++++++++++++++++++++++++++++++++++-- xen/arch/x86/hvm/svm/svm.c | 15 +-------- xen/arch/x86/hvm/vmx/vmcs.c | 12 +++++-- xen/arch/x86/hvm/vmx/vmx.c | 22 +++++++++--- xen/arch/x86/time.c | 13 ++++--- xen/include/asm-x86/hvm/domain.h | 2 ++ xen/include/asm-x86/hvm/hvm.h | 12 ++++++- xen/include/asm-x86/hvm/svm/svm.h | 3 -- xen/include/asm-x86/hvm/vmx/vmcs.h | 7 ++++ 11 files changed, 157 insertions(+), 33 deletions(-)
Signature · 7 lines
2.7.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v6 1/5 x86/hvm: Setup TSC scaling ratio
This patch adds a field tsc_scaling_ratio in struct hvm_domain to record the per-domain TSC scaling ratio, and sets it in tsc_set_info().
Before setting the per-domain TSC scaling ratio, we check its validity in tsc_set_info(). If an invalid ratio is given, we will leave the default value in tsc_scaling_ratio (i.e. ratio = 1) and setup guest TSC as if no TSC scaling is used:
* For TSC_MODE_FAULT,
- if a user-specified TSC frequency is given, we will set the guest TSC frequency to it; otherwise, we set it to the host TSC frequency.
- if guest TSC frequency does not equal to host TSC frequency, we will emulate guest TSC (i.e. d->arch.vtsc is set to 1). In both cases, guest TSC runs in the guest TSC frequency.
* For TSC_MODE_PVRDTSCP,
- we set the guest TSC frequency to the host TSC frequency.
- guest rdtsc is executed natively in the host TSC frequency as before.
- if rdtscp is not available to guest, it will be emulated; otherwise, it will be executed natively. In both cases, guest rdtscp gets TSC in the host TSC frequency as before.
---
CC: Keir Fraser <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Aravind Gopalakrishnan <[email protected]>
CC: Kevin Tian <[email protected]>
---
Changes in v6:
For inline assembly in hvm_get_tsc_scaling_ratio():
* Add a check before inline assembly to avoid #DE from divq.
* Replace salq by shlq.
* Split inputs and outputs for dummy and ratio.
* Turn to named arguments.
* Put assembly and 'asm (' in the same line.
Misc:
* Rename macro hvm_vcpu_tsc_scaling_ratio() into hvm_tsc_scaling_ratio() and change its argument type to struct domain *.
--- xen/arch/x86/hvm/hvm.c | 38 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/svm/svm.c | 4 ++-- xen/arch/x86/time.c | 10 ++++++++-- xen/include/asm-x86/hvm/domain.h | 2 ++ xen/include/asm-x86/hvm/hvm.h | 8 ++++++++ xen/include/asm-x86/hvm/svm/svm.h | 3 --- 6 files changed, 58 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/hvm.c +38 -0
@@ -298,6 +298,41 @@ int hvm_set_guest_pat(struct vcpu *v, u64 guest_pat)return 1 ; } +/* +* Get the ratio to scale host TSC frequency to gtsc_khz. zero will be +* returned if TSC scaling is unavailable or ratio cannot be handled +* by host CPU. Otherwise, a non-zero ratio will be returned. +*/ +u64 hvm_get_tsc_scaling_ratio (u32 gtsc_khz) +{ +u8 ratio_frac_bits = hvm_funcs.tsc_scaling.ratio_frac_bits; +u64 max_ratio = hvm_funcs.tsc_scaling.max_ratio; +u64 ratio, dummy; + +if ( !hvm_tsc_scaling_supported ) +return 0 ; + +/* +* Return early if the quotient is too large to fit in the integral +* part of TSC scaling ratio. This also avoids #DE from the following +* divq when the quotient can not fit in a 64-bit integer. +*/ +if ( gtsc_khz / cpu_khz > (max_ratio >> ratio_frac_bits) ) +return 0 ; + +/* ratio = (gtsc_khz << hvm_funcs.tsc_scaling.ratio_frac_bits) / cpu_khz */ + asm ("shldq %[frac],%[gkhz],%[zero] ; " +"shlq %[frac],%[gkhz] ; " +"divq %[hkhz] " + :"=d" (dummy),"=a" (ratio) + : [frac]"c" (ratio_frac_bits), + [gkhz]"a" ((u64 ) gtsc_khz), + [zero]"d" (0ULL ), + [hkhz]"rm" ((u64 ) cpu_khz) ); + +return ratio > max_ratio ?0 : ratio; +} +void hvm_set_guest_tsc_fixed (struct vcpu *v,u64 guest_tsc,u64 at_tsc) {uint64_t tsc;
@@ -1641,6 +1676,9 @@ int hvm_domain_initialise(struct domain *d)register_portio_handler (d,0xe9 ,1 , hvm_print_line);register_portio_handler (d,0xcf8 ,4 , hvm_access_cf8); +if ( hvm_tsc_scaling_supported ) + d->arch.hvm_domain.tsc_scaling_ratio = hvm_default_tsc_scaling_ratio; + rc = hvm_funcs.domain_initialise (d);if ( rc !=0 ) goto fail2;
xen/arch/x86/hvm/svm/svm.c +2 -2
@@ -823,7 +823,7 @@ static uint64_t svm_scale_tsc(const struct vcpu *v, uint64_t tsc) {ASSERT (cpu_has_tsc_ratio && !v->domain->arch.vtsc); -return scale_tsc (tsc,vcpu_tsc_ratio (v)); +return scale_tsc (tsc,hvm_tsc_scaling_ratio (v->domain)); } static uint64_t svm_get_tsc_offset(uint64_t host_tsc, uint64_t guest_tsc,
@@ -1000,7 +1000,7 @@ static inline void svm_tsc_ratio_save(struct vcpu *v)static inline void svm_tsc_ratio_load (struct vcpu *v) {if ( cpu_has_tsc_ratio && !v->domain->arch.vtsc ) -wrmsrl (MSR_AMD64_TSC_RATIO ,vcpu_tsc_ratio (v)); +wrmsrl (MSR_AMD64_TSC_RATIO ,hvm_tsc_scaling_ratio (v->domain)); }static void svm_ctxt_switch_from (struct vcpu *v)
xen/arch/x86/time.c +8 -2
@@ -1865,7 +1865,8 @@ void tsc_set_info(struct domain *d,*/ if ( tsc_mode ==TSC_MODE_DEFAULT &&host_tsc_is_safe () && (has_hvm_container_domain (d) ? - d->arch.tsc_khz == cpu_khz || hvm_tsc_scaling_supported : + (d->arch.tsc_khz == cpu_khz || +hvm_get_tsc_scaling_ratio (d->arch.tsc_khz)) : incarnation ==0 ) ) {case TSC_MODE_NEVER_EMULATE :
@@ -1879,7 +1880,8 @@ void tsc_set_info(struct domain *d, d->arch.vtsc = !boot_cpu_has (X86_FEATURE_RDTSCP ) || !host_tsc_is_safe (); enable_tsc_scaling =has_hvm_container_domain (d) && - hvm_tsc_scaling_supported && !d->arch.vtsc; + !d->arch.vtsc && +hvm_get_tsc_scaling_ratio (gtsc_khz ?: cpu_khz); 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);
@@ -1897,6 +1899,10 @@ void tsc_set_info(struct domain *d, d->arch.incarnation = incarnation +1 ;if (has_hvm_container_domain (d) ) { +if ( hvm_tsc_scaling_supported && !d->arch.vtsc ) + d->arch.hvm_domain.tsc_scaling_ratio = +hvm_get_tsc_scaling_ratio (d->arch.tsc_khz); +hvm_set_rdtsc_exiting (d, d->arch.vtsc);if ( d->vcpu && d->vcpu[0 ] && incarnation ==0 ) {
xen/include/asm-x86/hvm/domain.h +2 -0
@@ -143,6 +143,8 @@ struct hvm_domain {*/ uint64_t sync_tsc; +uint64_t tsc_scaling_ratio; +unsigned long *io_bitmap;/* List of permanently write-mapped pages. */
xen/include/asm-x86/hvm/hvm.h +8 -0
@@ -272,6 +272,14 @@ u64 hvm_get_guest_tsc_fixed(struct vcpu *v, u64 at_tsc);#define hvm_tsc_scaling_supported \ (!!hvm_funcs.tsc_scaling.ratio_frac_bits) +#define hvm_default_tsc_scaling_ratio \ + (1ULL << hvm_funcs.tsc_scaling.ratio_frac_bits) + +#define hvm_tsc_scaling_ratio (d) \ + ((d)->arch.hvm_domain.tsc_scaling_ratio) + +u64 hvm_get_tsc_scaling_ratio (u32 gtsc_khz); +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);
xen/include/asm-x86/hvm/svm/svm.h +0 -3
@@ -97,9 +97,6 @@ extern u32 svm_feature_flags;/* TSC rate */ #define DEFAULT_TSC_RATIO 0x0000000100000000ULL#define TSC_RATIO_RSVD_BITS 0xffffff0000000000ULL -#define TSC_RATIO (g_khz, h_khz) ( (((u64)(g_khz)<<32)/(u64)(h_khz)) & \ - ~TSC_RATIO_RSVD_BITS ) -#define vcpu_tsc_ratio (v) TSC_RATIO((v)->domain->arch.tsc_khz, cpu_khz)extern void svm_host_osvw_reset (void );extern void svm_host_osvw_init (void );
Signature · 7 lines
2.7.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 1/5] x86/hvm: Setup TSC scaling ratio
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 28.02.16 at 13:54, <[email protected]> wrote:
This patch adds a field
tsc_scaling_ratioin structhvm_domainto record the per-domain TSC scaling ratio, and sets it intsc_set_info().Before setting the per-domain TSC scaling ratio, we check its validity in
tsc_set_info(). If an invalid ratio is given, we will leave the default value intsc_scaling_ratio(i.e. ratio = 1) and setup guest TSC as if no TSC scaling is used:
* ForTSC_MODE_FAULT,
- if a user-specified TSC frequency is given, we will set the guest TSC frequency to it; otherwise, we set it to the host TSC frequency.
- if guest TSC frequency does not equal to host TSC frequency, we will emulate guest TSC (i.e.d->arch.vtscis set to 1). In both cases, guest TSC runs in the guest TSC frequency.
* ForTSC_MODE_PVRDTSCP,
- we set the guest TSC frequency to the host TSC frequency.
- guest rdtsc is executed natively in the host TSC frequency as before.
- if rdtscp is not available to guest, it will be emulated; otherwise, it will be executed natively. In both cases, guest rdtscp gets TSC in the host TSC frequency as before.
Quoted 1 line
Signed-off-by Haozhong Zhang <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 1/5] x86/hvm: Setup TSC scaling ratio
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 28.02.16 at 13:54, <[email protected]> wrote:
This patch adds a field
tsc_scaling_ratioin structhvm_domainto record the per-domain TSC scaling ratio, and sets it intsc_set_info().Before setting the per-domain TSC scaling ratio, we check its validity in
tsc_set_info(). If an invalid ratio is given, we will leave the default value intsc_scaling_ratio(i.e. ratio = 1) and setup guest TSC as if no TSC scaling is used:
* ForTSC_MODE_FAULT,
s/TSC_MODE_FAULT/TSC_MODE_DEFAULT/
-boris
Quoted 13 lines
Quoted 13 lines
- if a user-specified TSC frequency is given, we will set the guest TSC frequency to it; otherwise, we set it to the host TSC frequency.
- if guest TSC frequency does not equal to host TSC frequency, we will emulate guest TSC (i.e.d->arch.vtscis set to 1). In both cases, guest TSC runs in the guest TSC frequency.
* ForTSC_MODE_PVRDTSCP,
- we set the guest TSC frequency to the host TSC frequency.
- guest rdtsc is executed natively in the host TSC frequency as before.
- if rdtscp is not available to guest, it will be emulated; otherwise, it will be executed natively. In both cases, guest rdtscp gets TSC in the host TSC frequency as before.
Quoted 3 lines
Quoted 1 line
Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 1/5] x86/hvm: Setup TSC scaling ratio
Quoted 5 lines · Boris Ostrovsky
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 28.02.16 at 13:54, <[email protected]> wrote:
This patch adds a field
tsc_scaling_ratioin structhvm_domainto record the per-domain TSC scaling ratio, and sets it intsc_set_info().
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Before setting the per-domain TSC scaling ratio, we check its validity in
tsc_set_info(). If an invalid ratio is given, we will leave the default value intsc_scaling_ratio(i.e. ratio = 1) and setup guest TSC as if no TSC scaling is used:
* ForTSC_MODE_FAULT,s/TSC_MODE_FAULT/TSC_MODE_DEFAULT/
will fix in the next version.
Thanks,
Haozhong
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 1/5] x86/hvm: Setup TSC scaling ratio
In reply to Boris OstrovskyQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 29.02.16 at 14:49, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 28.02.16 at 13:54, <[email protected]> wrote:
This patch adds a field
tsc_scaling_ratioin structhvm_domainto record the per-domain TSC scaling ratio, and sets it intsc_set_info().
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Before setting the per-domain TSC scaling ratio, we check its validity in
tsc_set_info(). If an invalid ratio is given, we will leave the default value intsc_scaling_ratio(i.e. ratio = 1) and setup guest TSC as if no TSC scaling is used:
* ForTSC_MODE_FAULT,s/TSC_MODE_FAULT/TSC_MODE_DEFAULT/
If that's the only issue, I would offer to fix it up while committing. Committing, though, requires the ack on the SVM changes to be given (again).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Boris Ostrovsky
Acked-byRe: [PATCH v6 1/5] x86/hvm: Setup TSC scaling ratio
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 29.02.16 at 14:49, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 28.02.16 at 13:54, <[email protected]> wrote:
This patch adds a field
tsc_scaling_ratioin structhvm_domainto record the per-domain TSC scaling ratio, and sets it intsc_set_info().Before setting the per-domain TSC scaling ratio, we check its validity in
tsc_set_info(). If an invalid ratio is given, we will leave the default value intsc_scaling_ratio(i.e. ratio = 1) and setup guest TSC as if no TSC scaling is used:
* ForTSC_MODE_FAULT,
Quoted 5 lines
Quoted 1 line
s/TSC_MODE_FAULT/TSC_MODE_DEFAULT/
If that's the only issue, I would offer to fix it up while committing. Committing, though, requires the ack on the SVM changes to be given (again).
For SVM bits:
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 2/5 x86/hvm: Replace architecture TSC scaling by a common function
In reply to Haozhong ZhangThis patch implements a common function hvm_scale_tsc() to scale TSC by using TSC scaling information collected by architecture code.
---
CC: Keir Fraser <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Aravind Gopalakrishnan <[email protected]>
CC: Kevin Tian <[email protected]>
---
Changes in v6:
* Turn to named arguments for inline assembly in hvm_scale_tsc().
* I don't take R-b from Jan Beulich and Kevin Tian because of above changes.
--- xen/arch/x86/hvm/hvm.c | 21 +++++++++++++++++++-- xen/arch/x86/hvm/svm/svm.c | 8 -------- xen/arch/x86/time.c | 3 +-- xen/include/asm-x86/hvm/hvm.h | 3 +-- 4 files changed, 21 insertions(+), 14 deletions(-)
xen/arch/x86/hvm/hvm.c +19 -2
@@ -333,6 +333,23 @@ u64 hvm_get_tsc_scaling_ratio(u32 gtsc_khz)return ratio > max_ratio ?0 : ratio; } +u64 hvm_scale_tsc (const struct domain *d,u64 tsc) +{ +u64 ratio = d->arch.hvm_domain.tsc_scaling_ratio; +u64 dummy; + +if ( ratio == hvm_default_tsc_scaling_ratio ) +return tsc; + +/* tsc = (tsc * ratio) >> hvm_funcs.tsc_scaling.ratio_frac_bits */ + asm ("mulq %[ratio]; shrdq %[frac],%%rdx,%[tsc]" + : [tsc]"+a" (tsc),"=d" (dummy) + : [frac]"c" (hvm_funcs.tsc_scaling.ratio_frac_bits), + [ratio]"rm" (ratio) ); + +return tsc; +} +void hvm_set_guest_tsc_fixed (struct vcpu *v,u64 guest_tsc,u64 at_tsc) {uint64_t tsc;
@@ -347,7 +364,7 @@ void hvm_set_guest_tsc_fixed(struct vcpu *v, u64 guest_tsc, u64 at_tsc) { tsc = at_tsc ?:rdtsc ();if ( hvm_tsc_scaling_supported ) - tsc = hvm_funcs.tsc_scaling.scale_tsc (v, tsc); + tsc =hvm_scale_tsc (v->domain, tsc); } delta_tsc = guest_tsc - tsc;
@@ -379,7 +396,7 @@ u64 hvm_get_guest_tsc_fixed(struct vcpu *v, uint64_t at_tsc) { tsc = at_tsc ?:rdtsc ();if ( hvm_tsc_scaling_supported ) - tsc = hvm_funcs.tsc_scaling.scale_tsc (v, tsc); + tsc =hvm_scale_tsc (v->domain, tsc); }return tsc + v->arch.hvm_vcpu.cache_tsc_offset;
xen/arch/x86/hvm/svm/svm.c +0 -8
@@ -819,13 +819,6 @@ static uint64_t scale_tsc(uint64_t host_tsc, uint64_t ratio)return scaled_host_tsc; } -static uint64_t svm_scale_tsc (const struct vcpu *v,uint64_t tsc) -{ -ASSERT (cpu_has_tsc_ratio && !v->domain->arch.vtsc); - -return scale_tsc (tsc,hvm_tsc_scaling_ratio (v->domain)); -} -static uint64_t svm_get_tsc_offset (uint64_t host_tsc,uint64_t guest_tsc,uint64_t ratio) {
@@ -2291,7 +2284,6 @@ static struct hvm_function_table __initdata svm_function_table = { .tsc_scaling = { .max_ratio = ~TSC_RATIO_RSVD_BITS, - .scale_tsc = svm_scale_tsc, }, };
xen/arch/x86/time.c +1 -2
@@ -816,8 +816,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int force) {if (has_hvm_container_domain (d) && hvm_tsc_scaling_supported ) { - tsc_stamp = - hvm_funcs.tsc_scaling.scale_tsc (v, t->local_tsc_stamp); + tsc_stamp =hvm_scale_tsc (d, t->local_tsc_stamp); _u.tsc_to_system_mul = d->arch.vtsc_to_ns.mul_frac; _u.tsc_shift = d->arch.vtsc_to_ns.shift; }
xen/include/asm-x86/hvm/hvm.h +1 -2
@@ -231,8 +231,6 @@ struct hvm_function_table {uint8_t ratio_frac_bits;/* maximum-allowed TSC scaling ratio */ uint64_t max_ratio; - -uint64_t (*scale_tsc)(const struct vcpu *v,uint64_t tsc); } tsc_scaling; };
@@ -278,6 +276,7 @@ u64 hvm_get_guest_tsc_fixed(struct vcpu *v, u64 at_tsc);#define hvm_tsc_scaling_ratio (d) \ ((d)->arch.hvm_domain.tsc_scaling_ratio) +u64 hvm_scale_tsc (const struct domain *d,u64 tsc);u64 hvm_get_tsc_scaling_ratio (u32 gtsc_khz);int hvm_set_mode (struct vcpu *v,int mode);
Signature · 7 lines
2.7.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 2/5] x86/hvm: Replace architecture TSC scaling by a common function
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.02.16 at 13:54, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +1
-0@@ -333,6 +333,23 @@ u64 hvm_get_tsc_scaling_ratio(u32 gtsc_khz)return ratio > max_ratio ?0 : ratio; } +u64 hvm_scale_tsc (const struct domain *d,u64 tsc)
xen/arch/x86/hvm/hvm.c u64 hvm_get_tsc_scaling_ratio(u32 gtsc_khz) · line 346
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+{ +u64 ratio = d->arch.hvm_domain.tsc_scaling_ratio; +u64 dummy; + +if ( ratio == hvm_default_tsc_scaling_ratio ) +return tsc; + +/* tsc = (tsc * ratio) >> hvm_funcs.tsc_scaling.ratio_frac_bits */ + asm ("mulq %[ratio]; shrdq %[frac],%%rdx,%[tsc]" + : [tsc] "+a" (tsc), "=d" (dummy)
Is mixing named and positional asm() operands supported by all gcc versions we care about? Also strictly speaking "=d" needs to be switched to "=&d".
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 2/5] x86/hvm: Replace architecture TSC scaling by a common function
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 28.02.16 at 13:54, <[email protected]> wrote:
xen/arch/x86/hvm/hvm.c +0
-0@@ -333,6 +333,23 @@ u64 hvm_get_tsc_scaling_ratio(u32 gtsc_khz)return ratio > max_ratio ?0 : ratio; }
Quoted 14 lines
xen/arch/x86/hvm/hvm.c u64 hvm_get_tsc_scaling_ratio(u32 gtsc_khz) · line 346
Quoted 11 lines
xen/arch/x86/hvm/hvm.c +11
-0+u64 hvm_scale_tsc (const struct domain *d,u64 tsc) +{ +u64 ratio = d->arch.hvm_domain.tsc_scaling_ratio; +u64 dummy; + +if ( ratio == hvm_default_tsc_scaling_ratio ) +return tsc; + +/* tsc = (tsc * ratio) >> hvm_funcs.tsc_scaling.ratio_frac_bits */ + asm ("mulq %[ratio]; shrdq %[frac],%%rdx,%[tsc]" + : [tsc] "+a" (tsc), "=d" (dummy)Is mixing named and positional
asm()operands supported by all gcc versions we care about?
I see in Config.mk the oldest version is gcc 4.1. I'll test on that version.
Quoted 2 lines
Also strictly speaking "=d" needs to be switched to "=&d".
I'll fix in the next version.
Thanks,
Haozhong
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 2/5] x86/hvm: Replace architecture TSC scaling by a common function
In reply to Haozhong ZhangQuoted 4 lines · Haozhong Zhang
This patch implements a common function
hvm_scale_tsc()to scale TSC by using TSC scaling information collected by architecture code.Signed-off-by Haozhong Zhang <[email protected]>
Quoted 8 lines
---
CC: Keir Fraser <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Aravind Gopalakrishnan <[email protected]>
CC: Kevin Tian <[email protected]>
SVM bits:
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v7 2/5 x86/hvm: Replace architecture TSC scaling by a common function
In reply to Haozhong ZhangThis patch implements a common function hvm_scale_tsc() to scale TSC by using TSC scaling information collected by architecture code.
---
CC: Keir Fraser <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Aravind Gopalakrishnan <[email protected]>
CC: Kevin Tian <[email protected]>
---
Mixing named and positional operands is tested with gcc 4.1.2. It can be compiled without any errors/warnings and provides the same result at runtime as that compiled by newer version of gcc (v4.8.4).
Changes in v7:
For inline assembly in hvm_scale_tsc():
* Add '&' to the restriction of output operand 'dummy'.
--- xen/arch/x86/hvm/hvm.c | 21 +++++++++++++++++++-- xen/arch/x86/hvm/svm/svm.c | 8 -------- xen/arch/x86/time.c | 3 +-- xen/include/asm-x86/hvm/hvm.h | 3 +-- 4 files changed, 21 insertions(+), 14 deletions(-)
xen/arch/x86/hvm/hvm.c +19 -2
@@ -333,6 +333,23 @@ u64 hvm_get_tsc_scaling_ratio(u32 gtsc_khz)return ratio > max_ratio ?0 : ratio; } +u64 hvm_scale_tsc (const struct domain *d,u64 tsc) +{ +u64 ratio = d->arch.hvm_domain.tsc_scaling_ratio; +u64 dummy; + +if ( ratio == hvm_default_tsc_scaling_ratio ) +return tsc; + +/* tsc = (tsc * ratio) >> hvm_funcs.tsc_scaling.ratio_frac_bits */ + asm ("mulq %[ratio]; shrdq %[frac],%%rdx,%[tsc]" + : [tsc]"+a" (tsc),"=&d" (dummy) + : [frac]"c" (hvm_funcs.tsc_scaling.ratio_frac_bits), + [ratio]"rm" (ratio) ); + +return tsc; +} +void hvm_set_guest_tsc_fixed (struct vcpu *v,u64 guest_tsc,u64 at_tsc) {uint64_t tsc;
@@ -347,7 +364,7 @@ void hvm_set_guest_tsc_fixed(struct vcpu *v, u64 guest_tsc, u64 at_tsc) { tsc = at_tsc ?:rdtsc ();if ( hvm_tsc_scaling_supported ) - tsc = hvm_funcs.tsc_scaling.scale_tsc (v, tsc); + tsc =hvm_scale_tsc (v->domain, tsc); } delta_tsc = guest_tsc - tsc;
@@ -379,7 +396,7 @@ u64 hvm_get_guest_tsc_fixed(struct vcpu *v, uint64_t at_tsc) { tsc = at_tsc ?:rdtsc ();if ( hvm_tsc_scaling_supported ) - tsc = hvm_funcs.tsc_scaling.scale_tsc (v, tsc); + tsc =hvm_scale_tsc (v->domain, tsc); }return tsc + v->arch.hvm_vcpu.cache_tsc_offset;
xen/arch/x86/hvm/svm/svm.c +0 -8
@@ -819,13 +819,6 @@ static uint64_t scale_tsc(uint64_t host_tsc, uint64_t ratio)return scaled_host_tsc; } -static uint64_t svm_scale_tsc (const struct vcpu *v,uint64_t tsc) -{ -ASSERT (cpu_has_tsc_ratio && !v->domain->arch.vtsc); - -return scale_tsc (tsc,hvm_tsc_scaling_ratio (v->domain)); -} -static uint64_t svm_get_tsc_offset (uint64_t host_tsc,uint64_t guest_tsc,uint64_t ratio) {
@@ -2291,7 +2284,6 @@ static struct hvm_function_table __initdata svm_function_table = { .tsc_scaling = { .max_ratio = ~TSC_RATIO_RSVD_BITS, - .scale_tsc = svm_scale_tsc, }, };
xen/arch/x86/time.c +1 -2
@@ -816,8 +816,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int force) {if (has_hvm_container_domain (d) && hvm_tsc_scaling_supported ) { - tsc_stamp = - hvm_funcs.tsc_scaling.scale_tsc (v, t->local_tsc_stamp); + tsc_stamp =hvm_scale_tsc (d, t->local_tsc_stamp); _u.tsc_to_system_mul = d->arch.vtsc_to_ns.mul_frac; _u.tsc_shift = d->arch.vtsc_to_ns.shift; }
xen/include/asm-x86/hvm/hvm.h +1 -2
@@ -231,8 +231,6 @@ struct hvm_function_table {uint8_t ratio_frac_bits;/* maximum-allowed TSC scaling ratio */ uint64_t max_ratio; - -uint64_t (*scale_tsc)(const struct vcpu *v,uint64_t tsc); } tsc_scaling; };
@@ -278,6 +276,7 @@ u64 hvm_get_guest_tsc_fixed(struct vcpu *v, u64 at_tsc);#define hvm_tsc_scaling_ratio (d) \ ((d)->arch.hvm_domain.tsc_scaling_ratio) +u64 hvm_scale_tsc (const struct domain *d,u64 tsc);u64 hvm_get_tsc_scaling_ratio (u32 gtsc_khz);int hvm_set_mode (struct vcpu *v,int mode);
Signature · 7 lines
2.4.8 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v7 2/5] x86/hvm: Replace architecture TSC scaling by a common function
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.03.16 at 02:39, <[email protected]> wrote:
This patch implements a common function
hvm_scale_tsc()to scale TSC by using TSC scaling information collected by architecture code.Signed-off-by Haozhong Zhang <[email protected]>
Quoted 4 lines
---
Mixing named and positional operands is tested with gcc 4.1.2. It can be compiled without any errors/warnings and provides the same result at runtime as that compiled by newer version of gcc (v4.8.4).
Thanks for making sure of this.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 3/5 x86/hvm: Move saving/loading vcpu's TSC to common code
In reply to Haozhong ZhangBoth VMX and SVM save/load vcpu's TSC when saving/loading vcpu's context, so this patch moves saving/loading vcpu's TSC to the common functions hvm_[save|load]_cpu_ctxt().
---
CC: Keir Fraser <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Suravee Suthikulpanit <[email protected]>
CC: Aravind Gopalakrishnan <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
--- xen/arch/x86/hvm/hvm.c | 4 ++++ xen/arch/x86/hvm/svm/svm.c | 5 ----- xen/arch/x86/hvm/vmx/vmx.c | 5 ----- 3 files changed, 4 insertions(+), 10 deletions(-)
xen/arch/x86/hvm/hvm.c +4 -0
@@ -1818,6 +1818,8 @@ static int hvm_save_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)/* Architecture-specific vmcs/vmcb bits */ hvm_funcs.save_cpu_ctxt (v, &ctxt); + ctxt.tsc =hvm_get_guest_tsc_fixed (v, d->arch.hvm_domain.sync_tsc); + ctxt.msr_tsc_aux =hvm_msr_tsc_aux (v);hvm_get_segment_register (v, x86_seg_idtr, &seg);
@@ -2123,6 +2125,8 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h) v->arch.hvm_vcpu.msr_tsc_aux = ctxt.msr_tsc_aux; +hvm_set_guest_tsc_fixed (v, ctxt.tsc, d->arch.hvm_domain.sync_tsc); + seg.limit = ctxt.idtr_limit; seg.base = ctxt.idtr_base;hvm_set_segment_register (v, x86_seg_idtr, &seg);
xen/arch/x86/hvm/svm/svm.c +0 -5
@@ -357,9 +357,6 @@ static void svm_save_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data) data->msr_syscall_mask = vmcb->sfmask; data->msr_efer = v->arch.hvm_vcpu.guest_efer; data->msr_flags =-1ULL ; - - data->tsc =hvm_get_guest_tsc_fixed (v, - v->domain->arch.hvm_domain.sync_tsc); }
@@ -374,8 +371,6 @@ static void svm_load_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data) vmcb->sfmask = data->msr_syscall_mask; v->arch.hvm_vcpu.guest_efer = data->msr_efer;svm_update_guest_efer (v); - -hvm_set_guest_tsc_fixed (v, data->tsc, v->domain->arch.hvm_domain.sync_tsc); }static void svm_save_vmcb_ctxt (struct vcpu *v,struct hvm_hw_cpu *ctxt)
xen/arch/x86/hvm/vmx/vmx.c +0 -5
@@ -604,9 +604,6 @@ static void vmx_save_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data) data->msr_lstar = guest_state->msrs[VMX_INDEX_MSR_LSTAR ]; data->msr_star = guest_state->msrs[VMX_INDEX_MSR_STAR ]; data->msr_syscall_mask = guest_state->msrs[VMX_INDEX_MSR_SYSCALL_MASK ]; - - data->tsc =hvm_get_guest_tsc_fixed (v, - v->domain->arch.hvm_domain.sync_tsc); }static void vmx_load_cpu_state (struct vcpu *v,struct hvm_hw_cpu *data)
@@ -621,8 +618,6 @@ static void vmx_load_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data) v->arch.hvm_vmx.cstar = data->msr_cstar; v->arch.hvm_vmx.shadow_gs = data->shadow_gs; - -hvm_set_guest_tsc_fixed (v, data->tsc, v->domain->arch.hvm_domain.sync_tsc); }
Signature · 7 lines
2.7.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v6 4/5 vmx: Add VMX RDTSC(P) scaling support
In reply to Haozhong ZhangThis patch adds the initialization and setup code for VMX TSC scaling.
---
CC: Keir Fraser <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Andrew Cooper <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
---
Changes in v6:
* Adapt to the macro renaming in patch 1.
* No functionality changes.
--- xen/arch/x86/hvm/hvm.c | 6 ++++++ xen/arch/x86/hvm/vmx/vmcs.c | 12 +++++++++--- xen/arch/x86/hvm/vmx/vmx.c | 17 +++++++++++++++++ xen/include/asm-x86/hvm/hvm.h | 3 +++ xen/include/asm-x86/hvm/vmx/vmcs.h | 7 +++++++ 5 files changed, 42 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/hvm.c +6 -0
@@ -2123,6 +2123,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 ( hvm_funcs.tsc_scaling.setup ) + hvm_funcs.tsc_scaling.setup (v); + v->arch.hvm_vcpu.msr_tsc_aux = ctxt.msr_tsc_aux;hvm_set_guest_tsc_fixed (v, ctxt.tsc, d->arch.hvm_domain.sync_tsc);
@@ -5638,6 +5641,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 ( hvm_funcs.tsc_scaling.setup ) + hvm_funcs.tsc_scaling.setup (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;
xen/arch/x86/hvm/vmx/vmcs.c +9 -3
@@ -149,6 +149,7 @@ static void __init vmx_display_features(void)P (cpu_has_vmx_vmfunc,"VM Functions" );P (cpu_has_vmx_virt_exceptions,"Virtualisation Exceptions" );P (cpu_has_vmx_pml,"Page Modification Logging" ); +P (cpu_has_vmx_tsc_scaling,"TSC Scaling" );#undef Pif ( !printed )
@@ -243,7 +244,8 @@ static int vmx_init_vmcs_config(void)SECONDARY_EXEC_ENABLE_VM_FUNCTIONS |SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS |SECONDARY_EXEC_XSAVES | - SECONDARY_EXEC_PCOMMIT); +SECONDARY_EXEC_PCOMMIT | + SECONDARY_EXEC_TSC_SCALING);rdmsrl (MSR_IA32_VMX_MISC , _vmx_misc_cap);if ( _vmx_misc_cap &VMX_MISC_VMWRITE_ALL ) opt |=SECONDARY_EXEC_ENABLE_VMCS_SHADOWING ;
@@ -1000,7 +1002,7 @@ static int construct_vmcs(struct vcpu *v)__vmwrite (PIN_BASED_VM_EXEC_CONTROL , vmx_pin_based_exec_control); v->arch.hvm_vmx.exec_control = vmx_cpu_based_exec_control; -if ( d->arch.vtsc ) +if ( d->arch.vtsc && !cpu_has_vmx_tsc_scaling ) v->arch.hvm_vmx.exec_control |=CPU_BASED_RDTSC_EXITING ; v->arch.hvm_vmx.secondary_exec_control = vmx_secondary_exec_control;
@@ -1288,6 +1290,9 @@ static int construct_vmcs(struct vcpu *v)if ( cpu_has_vmx_xsaves )__vmwrite (XSS_EXIT_BITMAP ,0 ); +if ( cpu_has_vmx_tsc_scaling ) +__vmwrite (TSC_MULTIPLIER , d->arch.hvm_domain.tsc_scaling_ratio); +vmx_vmcs_exit (v);/* PVH: paging mode is updated by arch_set_info_guest(). */
@@ -1870,7 +1875,8 @@ void vmcs_dump_vcpu(struct vcpu *v) vmr32(VM_EXIT_REASON), vmr(EXIT_QUALIFICATION));printk ("IDTVectoring: info=%08x errcode=%08x\n" ,vmr32 (IDT_VECTORING_INFO ),vmr32 (IDT_VECTORING_ERROR_CODE )); -printk ("TSC Offset = 0x%016lx\n" ,vmr (TSC_OFFSET )); +printk ("TSC Offset = 0x%016lx TSC Multiplier = 0x%016lx\n" , +vmr (TSC_OFFSET ),vmr (TSC_MULTIPLIER ));if ( (v->arch.hvm_vmx.exec_control &CPU_BASED_TPR_SHADOW ) || (vmx_pin_based_exec_control &PIN_BASED_POSTED_INTERRUPT ) ) printk("TPR Threshold = 0x%02x PostedIntrVec = 0x%02x\n",
xen/arch/x86/hvm/vmx/vmx.c +17 -0
@@ -1122,6 +1122,16 @@ static void vmx_handle_cd(struct vcpu *v, unsigned long value) } } +static void vmx_setup_tsc_scaling (struct vcpu *v) +{ +if ( !hvm_tsc_scaling_supported || v->domain->arch.vtsc ) +return ; + +vmx_vmcs_enter (v); +__vmwrite (TSC_MULTIPLIER ,hvm_tsc_scaling_ratio (v->domain)); +vmx_vmcs_exit (v); +} +static void vmx_set_tsc_offset (struct vcpu *v,u64 offset,u64 at_tsc) {vmx_vmcs_enter (v);
@@ -2016,6 +2026,10 @@ static struct hvm_function_table __initdata vmx_function_table = { .altp2m_vcpu_update_vmfunc_ve = vmx_vcpu_update_vmfunc_ve, .altp2m_vcpu_emulate_ve = vmx_vcpu_emulate_ve, .altp2m_vcpu_emulate_vmfunc = vmx_vcpu_emulate_vmfunc, + .tsc_scaling = { + .max_ratio = VMX_TSC_MULTIPLIER_MAX, + .setup = vmx_setup_tsc_scaling, + }, };/* Handle VT-d posted-interrupt when VCPU is running. */
@@ -2120,6 +2134,9 @@ const struct hvm_function_table * __init start_vmx(void) && cpu_has_vmx_secondary_exec_control ) vmx_function_table.pvh_supported =1 ; +if ( cpu_has_vmx_tsc_scaling ) + vmx_function_table.tsc_scaling.ratio_frac_bits =48 ; +setup_vmcs_dump ();return &vmx_function_table;
xen/include/asm-x86/hvm/hvm.h +3 -0
@@ -231,6 +231,9 @@ struct hvm_function_table {uint8_t ratio_frac_bits;/* maximum-allowed TSC scaling ratio */ uint64_t max_ratio; + +/* Architecture function to setup TSC scaling ratio */ +void (*setup)(struct vcpu *v); } tsc_scaling; };
xen/include/asm-x86/hvm/vmx/vmcs.h +7 -0
@@ -237,6 +237,7 @@ extern u32 vmx_vmentry_control;#define SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS 0x00040000#define SECONDARY_EXEC_XSAVES 0x00100000#define SECONDARY_EXEC_PCOMMIT 0x00200000 +#define SECONDARY_EXEC_TSC_SCALING 0x02000000extern u32 vmx_secondary_exec_control;#define VMX_EPT_EXEC_ONLY_SUPPORTED 0x00000001
@@ -259,6 +260,8 @@ extern u64 vmx_ept_vpid_cap;#define VMX_MISC_CR3_TARGET 0x01ff0000#define VMX_MISC_VMWRITE_ALL 0x20000000 +#define VMX_TSC_MULTIPLIER_MAX 0xffffffffffffffffULL +#define cpu_has_wbinvd_exiting \ (vmx_secondary_exec_control & SECONDARY_EXEC_WBINVD_EXITING)#define cpu_has_vmx_virtualize_apic_accesses \
@@ -306,6 +309,9 @@ extern u64 vmx_ept_vpid_cap; (vmx_secondary_exec_control & SECONDARY_EXEC_XSAVES)#define cpu_has_vmx_pcommit \ (vmx_secondary_exec_control & SECONDARY_EXEC_PCOMMIT) +#define cpu_has_vmx_tsc_scaling \ + (vmx_secondary_exec_control & SECONDARY_EXEC_TSC_SCALING) +#define VMCS_RID_TYPE_MASK 0x80000000/* GUEST_INTERRUPTIBILITY_INFO flags. */
@@ -380,6 +386,7 @@ enum vmcs_field {VMWRITE_BITMAP =0x00002028 ,VIRT_EXCEPTION_INFO =0x0000202a ,XSS_EXIT_BITMAP =0x0000202c , +TSC_MULTIPLIER =0x00002032 ,GUEST_PHYSICAL_ADDRESS =0x00002400 ,VMCS_LINK_POINTER =0x00002800 , GUEST_IA32_DEBUGCTL = 0x00002802,
Signature · 7 lines
2.7.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v6 5/5 docs: Add descriptions of TSC scaling in xl.cfg and tscmode.txt
In reply to Haozhong Zhang---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Keir Fraser <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Kevin Tian <[email protected]>
--- docs/man/xl.cfg.pod.5 | 14 +++++++++++++- docs/misc/tscmode.txt | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5 +13 -1
@@ -1313,9 +1313,17 @@ deprecated. Options are: =item B<"default"> -Guest rdtsc/p executed natively when monotonicity can be guaranteed +Guest rdtsc/p is executed natively when monotonicity can be guaranteed and emulated otherwise (with frequency scaled if necessary). +If a HVM container in B<default> TSC mode is created on a host that +provides constant host TSC, its guest TSC frequency will be the same +as the host. If it is later migrated to another host that provide +constant host TSC and supports Intel VMX TSC scaling/AMD SVM TSC +ratio, its guest TSC frequency will be the same before and after +migration, and guest rdtsc/p will be executed natively as well after +migration. + =item B<"always_emulate"> Guest rdtsc/p always emulated at 1GHz (kernel and user). Guest rdtsc/p
@@ -1337,6 +1345,10 @@ determine when a restore/migration has occurred and assumes guest obtains/uses pvclock-like mechanism to adjust for monotonicity and frequency changes. +If a HVM container in B<native_paravirt> TSC mode can execute both guest +rdtsc and guest rdtscp natively, then the guest TSC frequency will be +determined in the similar way to that of B<default> TSC mode. + =back Please see F<docs/misc/tscmode.txt> for more information on this option.
docs/misc/tscmode.txt +21 -0
@@ -297,3 +297,24 @@ and also much faster than nearly all OS-provided time mechanisms. While pvrtscp is too complex for most apps, certain enterprise TSC-sensitive high-TSC-frequency apps may find it useful to obtain a significant performance gain. + +Hardware TSC Scaling + +Intel VMX TSC scaling and AMD SVM TSC ratio allow the guest TSC read +by guest rdtsc/p increasing in a different frequency than the host +TSC frequency. + +If a HVM container in default TSC mode (tsc_mode=0) or PVRDTSCP mode +(tsc_mode=3) is created on a host that provides constant TSC, its +guest TSC frequency will be the same as the host. If it is later +migrated to another host that provides constant TSC and supports Intel +VMX TSC scaling/AMD SVM TSC ratio, its guest TSC frequency will be the +same before and after migration. + +For above HVM container in default TSC mode (tsc_mode=0), if above +hosts support rdtscp, both guest rdtsc and rdtscp instructions will be +executed natively before and after migration. + +For above HVM container in PVRDTSCP mode (tsc_mode=3), if the +destination host does not support rdtscp, the guest rdtscp instruction +will be emulated with the guest TSC frequency.
Signature · 7 lines
2.7.2 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v6 5/5] docs: Add descriptions of TSC scaling in xl.cfg and tscmode.txt
Haozhong Zhang writes ("[PATCH v6 5/5] docs: Add descriptions of TSC scaling in xl.cfg and tscmode.txt"):
Quoted 2 lines
Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Kevin Tian <[email protected]>
This seems relatively clear. I'm happy to take your word for it that this is the behaviour.
If anyone feels that the docs in this patch are wrong, they can send a followup. So:
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 5/5] docs: Add descriptions of TSC scaling in xl.cfg and tscmode.txt
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 01.03.16 at 15:09, <[email protected]> wrote:
Haozhong Zhang writes ("[PATCH v6 5/5] docs: Add descriptions of TSC scaling in xl.cfg and tscmode.txt"):
Quoted 2 lines
Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Kevin Tian <[email protected]>
Quoted 7 lines
This seems relatively clear. I'm happy to take your word for it that this is the behaviour.
If anyone feels that the docs in this patch are wrong, they can send a followup. So:
Committed-by Ian Jackson <[email protected]>
Oh, thanks. I was about to write a reply asking for a tools side ack on the xl doc change.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel