[patch 2/2] KVM: x86: standardize vcpu wakeup method for in-kernel irqchip

Marcelo Tosatti
2008-07-21T14:41:18Z

[-- Attachment #1: cleanup-lapic-mpstate --]
[-- Type: text/plain, Size: 2295 bytes --]

Now that halted->runnable promotion is handled in the vcpu's context, cleanup
wakers:

- If running outside of irq context, use kvm_vcpu_kick(vcpu)
- If running from irq context, wake_up_interruptible(vcpu->wq) (irq should
trigger on target vcpu).

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: kvm/arch/x86/kvm/i8254.c
===================================================================
--- kvm.orig/arch/x86/kvm/i8254.c
+++ kvm/arch/x86/kvm/i8254.c
@@ -200,10 +200,8 @@ static int __pit_timer_fn(struct kvm_kpi

if (!atomic_inc_and_test(&pt->pending))
set_bit(KVM_REQ_PENDING_TIMER, &vcpu0->requests);
- if (vcpu0 && waitqueue_active(&vcpu0->wq)) {
- vcpu0->arch.mp_state = KVM_MP_STATE_RUNNABLE;
+ if (vcpu0 && waitqueue_active(&vcpu0->wq))
wake_up_interruptible(&vcpu0->wq);
- }

pt->timer.expires = ktime_add_ns(pt->timer.expires, pt->period);
pt->scheduled = ktime_to_ns(pt->timer.expires);
Index: kvm/arch/x86/kvm/lapic.c
===================================================================
--- kvm.orig/arch/x86/kvm/lapic.c
+++ kvm/arch/x86/kvm/lapic.c
@@ -339,14 +339,7 @@ static int __apic_accept_irq(struct kvm_
} else
apic_clear_vector(vector, apic->regs + APIC_TMR);

- if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE)
- kvm_vcpu_kick(vcpu);
- else if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED) {
- vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
- if (waitqueue_active(&vcpu->wq))
- wake_up_interruptible(&vcpu->wq);
- }
-
+ kvm_vcpu_kick(vcpu);
result = (orig_irr == 0);
break;

@@ -384,8 +377,7 @@ static int __apic_accept_irq(struct kvm_
if (vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) {
vcpu->arch.sipi_vector = vector;
vcpu->arch.mp_state = KVM_MP_STATE_SIPI_RECEIVED;
- if (waitqueue_active(&vcpu->wq))
- wake_up_interruptible(&vcpu->wq);
+ kvm_vcpu_kick(vcpu);
}
break;

@@ -947,10 +939,9 @@ static int __apic_timer_fn(struct kvm_la

if(!atomic_inc_and_test(&apic->timer.pending))
set_bit(KVM_REQ_PENDING_TIMER, &apic->vcpu->requests);
- if (waitqueue_active(q)) {
- apic->vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
+ if (waitqueue_active(q))
wake_up_interruptible(q);
- }
+
if (apic_lvtt_period(apic)) {
result = 1;
apic->timer.dev.expires = ktime_add_ns(

--