mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
x86/time: use correct guest TSC frequency in tsc_set_info()
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 <haozhong.zhang@intel.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
This commit is contained in:
1 parent
9754544a55
commit
0a449aa43d
2 files changed
+13
-5
No files matched your search
+7
-2
@@ -1838,6 +1838,8 @@ void tsc_set_info(struct domain *d,
|
||||
|
||||
switch ( d->arch.tsc_mode = tsc_mode )
|
||||
{
|
||||
bool_t enable_tsc_scaling;
|
||||
|
||||
case TSC_MODE_DEFAULT:
|
||||
case TSC_MODE_ALWAYS_EMULATE:
|
||||
d->arch.vtsc_offset = get_s_time() - elapsed_nsec;
|
||||
@@ -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,8 @@ 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) -
|
||||
d->arch.vtsc_offset = scale_delta(rdtsc(),
|
||||
&this_cpu(cpu_time).tsc_scale) -
|
||||
elapsed_nsec;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -347,9 +347,12 @@ struct arch_domain
|
||||
s_time_t vtsc_last; /* previous TSC value (guarantee monotonicity) */
|
||||
spinlock_t vtsc_lock;
|
||||
uint64_t vtsc_offset; /* adjustment for save/restore/migrate */
|
||||
uint32_t tsc_khz; /* cached khz for certain emulated cases */
|
||||
struct time_scale vtsc_to_ns; /* scaling for certain emulated cases */
|
||||
struct time_scale ns_to_vtsc; /* scaling for certain emulated cases */
|
||||
uint32_t tsc_khz; /* cached guest khz for certain emulated or
|
||||
hardware TSC scaling cases */
|
||||
struct time_scale vtsc_to_ns; /* scaling for certain emulated or
|
||||
hardware TSC scaling cases */
|
||||
struct time_scale ns_to_vtsc; /* scaling for certain emulated or
|
||||
hardware TSC scaling cases */
|
||||
uint32_t incarnation; /* incremented every restore or live migrate
|
||||
(possibly other cases in the future */
|
||||
#if !defined(NDEBUG) || defined(PERF_COUNTERS)
|
||||
|
||||