KVM: x86: pass host_tsc to read_l1_tsc
authorMarcelo Tosatti <mtosatti@redhat.com>
Wed, 28 Nov 2012 01:28:58 +0000 (23:28 -0200)
committerMarcelo Tosatti <mtosatti@redhat.com>
Wed, 28 Nov 2012 01:29:11 +0000 (23:29 -0200)
Allow the caller to pass host tsc value to kvm_x86_ops->read_l1_tsc().

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/lapic.c
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c

index b2e11f4524354db111134fb28ef9dfd99f3edaee..d60535adec9839de4b339e5e4692a41b060bd1e1 100644 (file)
@@ -700,7 +700,7 @@ struct kvm_x86_ops {
        void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset);
 
        u64 (*compute_tsc_offset)(struct kvm_vcpu *vcpu, u64 target_tsc);
-       u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu);
+       u64 (*read_l1_tsc)(struct kvm_vcpu *vcpu, u64 host_tsc);
 
        void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2);
 
index 43e9fadca5d080a4e98a65735cbe071102742911..9392f527f107490b9fc8d036f971994c3823b31d 100644 (file)
@@ -1011,7 +1011,7 @@ static void start_apic_timer(struct kvm_lapic *apic)
                local_irq_save(flags);
 
                now = apic->lapic_timer.timer.base->get_time();
-               guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
+               guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu, native_read_tsc());
                if (likely(tscdeadline > guest_tsc)) {
                        ns = (tscdeadline - guest_tsc) * 1000000ULL;
                        do_div(ns, this_tsc_khz);
index e93908fabf46b3a9a56b264f37d668d34d881d59..94f5ceba7e1e266d7677d128ef8c16a734de0698 100644 (file)
@@ -3005,11 +3005,11 @@ static int cr8_write_interception(struct vcpu_svm *svm)
        return 0;
 }
 
-u64 svm_read_l1_tsc(struct kvm_vcpu *vcpu)
+u64 svm_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc)
 {
        struct vmcb *vmcb = get_host_vmcb(to_svm(vcpu));
        return vmcb->control.tsc_offset +
-               svm_scale_tsc(vcpu, native_read_tsc());
+               svm_scale_tsc(vcpu, host_tsc);
 }
 
 static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
index 6599e45f73f6bb7beba883d4aa372c54d2147a76..896efd4842e73edc71f3b48847bc9525a378c95a 100644 (file)
@@ -1839,11 +1839,10 @@ static u64 guest_read_tsc(void)
  * Like guest_read_tsc, but always returns L1's notion of the timestamp
  * counter, even if a nested guest (L2) is currently running.
  */
-u64 vmx_read_l1_tsc(struct kvm_vcpu *vcpu)
+u64 vmx_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc)
 {
-       u64 host_tsc, tsc_offset;
+       u64 tsc_offset;
 
-       rdtscll(host_tsc);
        tsc_offset = is_guest_mode(vcpu) ?
                to_vmx(vcpu)->nested.vmcs01_tsc_offset :
                vmcs_read64(TSC_OFFSET);
index 1dfe9d318734a47297005c6d322242145fb633e0..1155059c512ed1660e5292e9d6982ce34dd63ff9 100644 (file)
@@ -1150,7 +1150,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
 
        /* Keep irq disabled to prevent changes to the clock */
        local_irq_save(flags);
-       tsc_timestamp = kvm_x86_ops->read_l1_tsc(v);
+       tsc_timestamp = kvm_x86_ops->read_l1_tsc(v, native_read_tsc());
        kernel_ns = get_kernel_ns();
        this_tsc_khz = __get_cpu_var(cpu_tsc_khz);
        if (unlikely(this_tsc_khz == 0)) {
@@ -5338,7 +5338,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
        if (hw_breakpoint_active())
                hw_breakpoint_restore();
 
-       vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu);
+       vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu,
+                                                          native_read_tsc());
 
        vcpu->mode = OUTSIDE_GUEST_MODE;
        smp_wmb();