]> git.karo-electronics.de Git - linux-beck.git/commitdiff
KVM: Migrate lapic hrtimer when vcpu moves to another cpu
authorEddie Dong <eddie.dong@intel.com>
Mon, 3 Sep 2007 13:15:12 +0000 (16:15 +0300)
committerAvi Kivity <avi@qumranet.com>
Sat, 13 Oct 2007 08:18:26 +0000 (10:18 +0200)
This reduces overhead by accessing cachelines from the wrong node, as well
as simplifying locking.

[Qing: fix for inactive or expired one-shot timer]

Signed-off-by: Yaozu (Eddie) Dong <Eddie.Dong@intel.com>
Signed-off-by: Qing He <qing.he@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
drivers/kvm/irq.h
drivers/kvm/lapic.c
drivers/kvm/svm.c
drivers/kvm/vmx.c

index 87baf7e69ea2ea1327566f83568f2817835d5237..f324cfb40084cd67f1e3316635c6f4836f733fc2 100644 (file)
@@ -158,5 +158,6 @@ void kvm_apic_timer_intr_post(struct kvm_vcpu *vcpu, int vec);
 void kvm_timer_intr_post(struct kvm_vcpu *vcpu, int vec);
 void kvm_inject_pending_timer_irqs(struct kvm_vcpu *vcpu);
 void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu);
+void kvm_migrate_apic_timer(struct kvm_vcpu *vcpu);
 
 #endif
index 490d4939dba7b6060d0e0676f384a1f345f2cc12..2706ec36c2586e24b32a2d95f2b64b0d9269904f 100644 (file)
@@ -979,3 +979,17 @@ void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu)
        update_divide_count(apic);
        start_apic_timer(apic);
 }
+
+void kvm_migrate_apic_timer(struct kvm_vcpu *vcpu)
+{
+       struct kvm_lapic *apic = vcpu->apic;
+       struct hrtimer *timer;
+
+       if (!apic)
+               return;
+
+       timer = &apic->timer.dev;
+       if (hrtimer_cancel(timer))
+               hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS);
+}
+EXPORT_SYMBOL_GPL(kvm_migrate_apic_timer);
index 00119ec4166985fe5447a47188c77592d9e74f35..3de9ec35ebf9d899e777d0b7fd29bacad080d6d8 100644 (file)
@@ -633,6 +633,7 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
                delta = vcpu->host_tsc - tsc_this;
                svm->vmcb->control.tsc_offset += delta;
                vcpu->cpu = cpu;
+               kvm_migrate_apic_timer(vcpu);
        }
 
        for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++)
index eeecadf5da4670b36a058973fe7defc89ba0a369..f4618b9edf9c7ce364d1112fcc4779c3ef86fb43 100644 (file)
@@ -441,8 +441,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
        u64 phys_addr = __pa(vmx->vmcs);
        u64 tsc_this, delta;
 
-       if (vcpu->cpu != cpu)
+       if (vcpu->cpu != cpu) {
                vcpu_clear(vmx);
+               kvm_migrate_apic_timer(vcpu);
+       }
 
        if (per_cpu(current_vmcs, cpu) != vmx->vmcs) {
                u8 error;