|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 12/23] vixen: paravirtualization TSC frequency calculation
From: Anthony Liguori <aliguori@xxxxxxxxxx>
Otherwise when time sharing a physical CPU, the calculation can
be bogus resulting in time drift for the guest due to improper
frequency within pvclock.
Signed-off-by: Anthony Liguori <aliguori@xxxxxxxxxx>
---
xen/arch/x86/guest/vixen.c | 22 ++++++++++++++++++++++
xen/arch/x86/time.c | 9 ++++++++-
xen/include/asm-x86/guest/vixen.h | 2 ++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/xen/arch/x86/guest/vixen.c b/xen/arch/x86/guest/vixen.c
index 1ad5bd7..a1614e0 100644
--- a/xen/arch/x86/guest/vixen.c
+++ b/xen/arch/x86/guest/vixen.c
@@ -120,3 +120,25 @@ void vixen_get_reserved_mem(unsigned long *start_pfn,
unsigned long *end_pfn)
/* This is part of the Xen ABI */
*end_pfn = 0x100000;
}
+
+u64 vixen_get_cpu_freq(void)
+{
+ volatile vcpu_time_info_t *timep = &global_si->native.vcpu_info[0].time;
+ vcpu_time_info_t time;
+ uint32_t version;
+ u64 imm;
+
+ do {
+ version = timep->version;
+ rmb();
+ time = *timep;
+ } while ((version & 1) || version != time.version);
+
+ imm = (1000000000ULL << 32) / time.tsc_to_system_mul;
+
+ if (time.tsc_shift < 0) {
+ return imm << -time.tsc_shift;
+ } else {
+ return imm >> time.tsc_shift;
+ }
+}
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index 2a87950..04c0fbb 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -36,6 +36,7 @@
#include <io_ports.h>
#include <asm/setup.h> /* for early_time_init */
#include <public/arch-x86/cpuid.h>
+#include <asm/guest/vixen.h>
/* opt_clocksource: Force clocksource to one of: pit, hpet, acpi. */
static char __initdata opt_clocksource[10];
@@ -1687,6 +1688,12 @@ void __init early_time_init(void)
preinit_pit();
tmp = init_platform_timer();
+
+ /* We cannot trust calibrated values when running under
+ * a hypervisor. */
+ if ( is_vixen() )
+ tmp = vixen_get_cpu_freq();
+
plt_tsc.frequency = tmp;
set_time_scale(&t->tsc_scale, tmp);
@@ -2014,7 +2021,7 @@ void tsc_set_info(struct domain *d,
uint32_t tsc_mode, uint64_t elapsed_nsec,
uint32_t gtsc_khz, uint32_t incarnation)
{
- if ( is_idle_domain(d) || is_hardware_domain(d) )
+ if ( is_idle_domain(d) || is_vixen() || is_hardware_domain(d) )
{
d->arch.vtsc = 0;
return;
diff --git a/xen/include/asm-x86/guest/vixen.h
b/xen/include/asm-x86/guest/vixen.h
index 0c040ee..e6b64f2 100644
--- a/xen/include/asm-x86/guest/vixen.h
+++ b/xen/include/asm-x86/guest/vixen.h
@@ -78,4 +78,6 @@ void __init init_vixen(void);
void __init early_vixen_init(void);
+u64 vixen_get_cpu_freq(void);
+
#endif
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |