]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
KVM: migrate PIT timer
authorMarcelo Tosatti <mtosatti@redhat.com>
Tue, 27 May 2008 15:10:20 +0000 (12:10 -0300)
committerAvi Kivity <avi@qumranet.com>
Fri, 6 Jun 2008 18:25:51 +0000 (21:25 +0300)
Migrate the PIT timer to the physical CPU which vcpu0 is scheduled on,
similarly to what is done for the LAPIC timers, otherwise PIT interrupts
will be delayed until an unrelated event causes an exit.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
arch/x86/kvm/i8254.c
arch/x86/kvm/irq.c
arch/x86/kvm/irq.h
arch/x86/kvm/svm.c
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c
include/linux/kvm_host.h

index 7c077a9d97770c8faee45123b9c049eeb8b33465..f2f5d260874e96117ee0dbcbc3152a594fc96033 100644 (file)
@@ -200,7 +200,6 @@ int __pit_timer_fn(struct kvm_kpit_state *ps)
 
        atomic_inc(&pt->pending);
        smp_mb__after_atomic_inc();
-       /* FIXME: handle case where the guest is in guest mode */
        if (vcpu0 && waitqueue_active(&vcpu0->wq)) {
                vcpu0->arch.mp_state = KVM_MP_STATE_RUNNABLE;
                wake_up_interruptible(&vcpu0->wq);
@@ -237,6 +236,19 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
                return HRTIMER_NORESTART;
 }
 
+void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
+{
+       struct kvm_pit *pit = vcpu->kvm->arch.vpit;
+       struct hrtimer *timer;
+
+       if (vcpu->vcpu_id != 0 || !pit)
+               return;
+
+       timer = &pit->pit_state.pit_timer.timer;
+       if (hrtimer_cancel(timer))
+               hrtimer_start(timer, timer->expires, HRTIMER_MODE_ABS);
+}
+
 static void destroy_pit_timer(struct kvm_kpit_timer *pt)
 {
        pr_debug("pit: execute del timer!\n");
index ce1f583459b1f4875db0d3eeea72d728aa0a9873..76d736b5f66464372a95979c0ada398f6f109a1d 100644 (file)
@@ -94,3 +94,9 @@ void kvm_timer_intr_post(struct kvm_vcpu *vcpu, int vec)
        /* TODO: PIT, RTC etc. */
 }
 EXPORT_SYMBOL_GPL(kvm_timer_intr_post);
+
+void __kvm_migrate_timers(struct kvm_vcpu *vcpu)
+{
+       __kvm_migrate_apic_timer(vcpu);
+       __kvm_migrate_pit_timer(vcpu);
+}
index 1802134b836fc352529f59e6fd7b82b81ef28e95..2a15be2275c0e1d84eb3b0ce1c8a24d1e1986072 100644 (file)
@@ -84,6 +84,8 @@ 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);
+void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu);
+void __kvm_migrate_timers(struct kvm_vcpu *vcpu);
 
 int pit_has_pending_timer(struct kvm_vcpu *vcpu);
 int apic_has_pending_timer(struct kvm_vcpu *vcpu);
index ab22615eee896be9128ec6b047bd786bb004acf8..6b0d5fa5bab3e7e3a395dd5c3133b0c5f0791b31 100644 (file)
@@ -688,7 +688,7 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
                delta = vcpu->arch.host_tsc - tsc_this;
                svm->vmcb->control.tsc_offset += delta;
                vcpu->cpu = cpu;
-               kvm_migrate_apic_timer(vcpu);
+               kvm_migrate_timers(vcpu);
        }
 
        for (i = 0; i < NR_HOST_SAVE_USER_MSRS; i++)
index bfe4db11989c08b79e63acb623a7289f1a2974dc..96445f341519c5933e899d1aa21039501d1b0588 100644 (file)
@@ -608,7 +608,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 
        if (vcpu->cpu != cpu) {
                vcpu_clear(vmx);
-               kvm_migrate_apic_timer(vcpu);
+               kvm_migrate_timers(vcpu);
                vpid_sync_vcpu_all(vmx);
        }
 
index 21338bdb28ff88a2577fb22d79aadfd9fee3cf39..00acf1301a151663beb43151a569f2022d6e9dde 100644 (file)
@@ -2758,7 +2758,7 @@ again:
 
        if (vcpu->requests) {
                if (test_and_clear_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests))
-                       __kvm_migrate_apic_timer(vcpu);
+                       __kvm_migrate_timers(vcpu);
                if (test_and_clear_bit(KVM_REQ_REPORT_TPR_ACCESS,
                                       &vcpu->requests)) {
                        kvm_run->exit_reason = KVM_EXIT_TPR_ACCESS;
index 398978972b7a639cb6cf0b14b974971db0addd76..092b1b25291daffb16f3de899e446f1adc24274a 100644 (file)
@@ -297,7 +297,7 @@ static inline gpa_t gfn_to_gpa(gfn_t gfn)
        return (gpa_t)gfn << PAGE_SHIFT;
 }
 
-static inline void kvm_migrate_apic_timer(struct kvm_vcpu *vcpu)
+static inline void kvm_migrate_timers(struct kvm_vcpu *vcpu)
 {
        set_bit(KVM_REQ_MIGRATE_TIMER, &vcpu->requests);
 }