aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorZachary Amsden <zamsden@gmail.com>2012-02-03 12:43:54 -0500
committerAvi Kivity <avi@redhat.com>2012-03-08 07:10:06 -0500
commit6f526ec5383dcd5fa5ffc7b3ac1d62099a0b46ad (patch)
tree3493dcd8ee803f1c8c77dd505d02816b2fc449e3 /arch/x86/kvm/x86.c
parentb183aa580a3a09b5d79224a9022418508532c778 (diff)
KVM: Add last_host_tsc tracking back to KVM
The variable last_host_tsc was removed from upstream code. I am adding it back for two reasons. First, it is unnecessary to use guest TSC computation to conclude information about the host TSC. The guest may set the TSC backwards (this case handled by the previous patch), but the computation of guest TSC (and fetching an MSR) is significanlty more work and complexity than simply reading the hardware counter. In addition, we don't actually need the guest TSC for any part of the computation, by always recomputing the offset, we can eliminate the need to deal with the current offset and any scaling factors that may apply. The second reason is that later on, we are going to be using the host TSC value to restore TSC offsets after a host S4 suspend, so we need to be reading the host values, not the guest values here. Signed-off-by: Zachary Amsden <zamsden@gmail.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2a59f76d96f1..39a57dac884a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2253,13 +2253,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
2253 2253
2254 kvm_x86_ops->vcpu_load(vcpu, cpu); 2254 kvm_x86_ops->vcpu_load(vcpu, cpu);
2255 if (unlikely(vcpu->cpu != cpu) || check_tsc_unstable()) { 2255 if (unlikely(vcpu->cpu != cpu) || check_tsc_unstable()) {
2256 /* Make sure TSC doesn't go backwards */ 2256 s64 tsc_delta = !vcpu->arch.last_host_tsc ? 0 :
2257 s64 tsc_delta; 2257 native_read_tsc() - vcpu->arch.last_host_tsc;
2258 u64 tsc;
2259
2260 tsc = kvm_x86_ops->read_l1_tsc(vcpu);
2261 tsc_delta = tsc - vcpu->arch.last_guest_tsc;
2262
2263 if (tsc_delta < 0) 2258 if (tsc_delta < 0)
2264 mark_tsc_unstable("KVM discovered backwards TSC"); 2259 mark_tsc_unstable("KVM discovered backwards TSC");
2265 if (check_tsc_unstable()) { 2260 if (check_tsc_unstable()) {
@@ -2282,7 +2277,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
2282{ 2277{
2283 kvm_x86_ops->vcpu_put(vcpu); 2278 kvm_x86_ops->vcpu_put(vcpu);
2284 kvm_put_guest_fpu(vcpu); 2279 kvm_put_guest_fpu(vcpu);
2285 vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu); 2280 vcpu->arch.last_host_tsc = native_read_tsc();
2286} 2281}
2287 2282
2288static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu, 2283static int kvm_vcpu_ioctl_get_lapic(struct kvm_vcpu *vcpu,