Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > fc11cd6e1c513a17304da94a5390f3cd > files > 3830

kernel-2.6.18-194.11.1.el5.src.rpm

From: Glauber Costa <glommer@redhat.com>
Date: Mon, 24 May 2010 20:08:09 -0400
Subject: [virt] don't compute pvclock adjustments if we trust tsc
Message-id: <1274731689-21363-6-git-send-email-glommer@redhat.com>
Patchwork-id: 25797
O-Subject: [PATCH RHEL5.6/5.5.z v2 5/5] don't compute pvclock adjustments if we
	trust the tsc
Bugzilla: 570824
RH-Acked-by: Zachary Amsden <zamsden@redhat.com>
RH-Acked-by: Rik van Riel <riel@redhat.com>
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>

RH-Author: Glauber Costa <glommer@redhat.com>
RH-Bugzilla: 570824 and many, many others
RH-Upstream-status: kvm/master

If the HV told us we can fully trust the TSC, skip any
correction

Signed-off-by: Glauber Costa <glommer@redhat.com>

diff --git a/arch/i386/kernel/kvmclock.c b/arch/i386/kernel/kvmclock.c
index 4c96682..2515039 100644
--- a/arch/i386/kernel/kvmclock.c
+++ b/arch/i386/kernel/kvmclock.c
@@ -147,5 +147,7 @@ void __cpuinit kvmclock_init(void)
 #ifdef CONFIG_X86_32
 		clocksource_register(&kvm_clock);
 #endif
+		if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT))
+			pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT);
 	}
 }
diff --git a/arch/i386/kernel/pvclock.c b/arch/i386/kernel/pvclock.c
index 89f74c5..2bd45a9 100644
--- a/arch/i386/kernel/pvclock.c
+++ b/arch/i386/kernel/pvclock.c
@@ -141,6 +141,10 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
 		barrier();
 	} while (version != src->version);
 
+	if ((valid_flags & PVCLOCK_TSC_STABLE_BIT) &&
+		(shadow.flags & PVCLOCK_TSC_STABLE_BIT))
+		return ret;
+
 	/*
 	 * Assumption here is that last_value, a global accumulator, always goes
 	 * forward. If we are less than that, we should not be much smaller.
diff --git a/include/asm-i386/kvm_para.h b/include/asm-i386/kvm_para.h
index a34d09e..31b47cc 100644
--- a/include/asm-i386/kvm_para.h
+++ b/include/asm-i386/kvm_para.h
@@ -14,6 +14,11 @@
 #define KVM_FEATURE_NOP_IO_DELAY	1
 #define KVM_FEATURE_MMU_OP		2
 
+/* The last 8 bits are used to indicate how to interpret the flags field
+ * in pvclock structure. If no bits are set, all flags are ignored.
+ */
+#define KVM_FEATURE_CLOCKSOURCE_STABLE_BIT	24
+
 #define MSR_KVM_WALL_CLOCK  0x11
 #define MSR_KVM_SYSTEM_TIME 0x12
 
diff --git a/include/asm-i386/pvclock-abi.h b/include/asm-i386/pvclock-abi.h
index ec5c41a..35f2d19 100644
--- a/include/asm-i386/pvclock-abi.h
+++ b/include/asm-i386/pvclock-abi.h
@@ -39,5 +39,6 @@ struct pvclock_wall_clock {
 	u32   nsec;
 } __attribute__((__packed__));
 
+#define PVCLOCK_TSC_STABLE_BIT	(1 << 0)
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_X86_PVCLOCK_ABI_H */
diff --git a/include/asm-x86_64/kvm_para.h b/include/asm-x86_64/kvm_para.h
index f680ef1..3de1993 100644
--- a/include/asm-x86_64/kvm_para.h
+++ b/include/asm-x86_64/kvm_para.h
@@ -14,6 +14,11 @@
 #define KVM_FEATURE_NOP_IO_DELAY	1
 #define KVM_FEATURE_MMU_OP		2
 
+/* The last 8 bits are used to indicate how to interpret the flags field
+ * in pvclock structure. If no bits are set, all flags are ignored.
+ */
+#define KVM_FEATURE_CLOCKSOURCE_STABLE_BIT	24
+
 #define MSR_KVM_WALL_CLOCK  0x11
 #define MSR_KVM_SYSTEM_TIME 0x12
 
diff --git a/include/asm-x86_64/pvclock-abi.h b/include/asm-x86_64/pvclock-abi.h
index ec5c41a..35f2d19 100644
--- a/include/asm-x86_64/pvclock-abi.h
+++ b/include/asm-x86_64/pvclock-abi.h
@@ -39,5 +39,6 @@ struct pvclock_wall_clock {
 	u32   nsec;
 } __attribute__((__packed__));
 
+#define PVCLOCK_TSC_STABLE_BIT	(1 << 0)
 #endif /* __ASSEMBLY__ */
 #endif /* _ASM_X86_PVCLOCK_ABI_H */