diff options
author | Marcelo Tosatti <mtosatti@redhat.com> | 2008-09-24 19:28:34 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2008-10-15 08:25:28 -0400 |
commit | e48258009d941891fca35348986b8d280caf31cd (patch) | |
tree | 73d1fb56a9fc22c1e55160bb04e772bd6b2244fb /arch/x86/kvm | |
parent | 582801a95d2f2ceab841779e1dec0e11dfec44c0 (diff) |
KVM: PIC: enhance IPI avoidance
The PIC code makes little effort to avoid kvm_vcpu_kick(), resulting in
unnecessary guest exits in some conditions.
For example, if the timer interrupt is routed through the IOAPIC, IRR
for IRQ 0 will get set but not cleared, since the APIC is handling the
acks.
This means that everytime an interrupt < 16 is triggered, the priority
logic will find IRQ0 pending and send an IPI to vcpu0 (in case IRQ0 is
not masked, which is Linux's case).
Introduce a new variable isr_ack to represent the IRQ's for which the
guest has been signalled / cleared the ISR. Use it to avoid more than
one IPI per trigger-ack cycle, in addition to the avoidance when ISR is
set in get_priority().
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r-- | arch/x86/kvm/i8259.c | 17 | ||||
-rw-r--r-- | arch/x86/kvm/irq.h | 2 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 1 |
3 files changed, 18 insertions, 2 deletions
diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c index 71e3eeeccae8..17e41e165f1a 100644 --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c | |||
@@ -33,6 +33,14 @@ | |||
33 | static void pic_clear_isr(struct kvm_kpic_state *s, int irq) | 33 | static void pic_clear_isr(struct kvm_kpic_state *s, int irq) |
34 | { | 34 | { |
35 | s->isr &= ~(1 << irq); | 35 | s->isr &= ~(1 << irq); |
36 | s->isr_ack |= (1 << irq); | ||
37 | } | ||
38 | |||
39 | void kvm_pic_clear_isr_ack(struct kvm *kvm) | ||
40 | { | ||
41 | struct kvm_pic *s = pic_irqchip(kvm); | ||
42 | s->pics[0].isr_ack = 0xff; | ||
43 | s->pics[1].isr_ack = 0xff; | ||
36 | } | 44 | } |
37 | 45 | ||
38 | /* | 46 | /* |
@@ -213,6 +221,7 @@ void kvm_pic_reset(struct kvm_kpic_state *s) | |||
213 | s->irr = 0; | 221 | s->irr = 0; |
214 | s->imr = 0; | 222 | s->imr = 0; |
215 | s->isr = 0; | 223 | s->isr = 0; |
224 | s->isr_ack = 0xff; | ||
216 | s->priority_add = 0; | 225 | s->priority_add = 0; |
217 | s->irq_base = 0; | 226 | s->irq_base = 0; |
218 | s->read_reg_select = 0; | 227 | s->read_reg_select = 0; |
@@ -444,10 +453,14 @@ static void pic_irq_request(void *opaque, int level) | |||
444 | { | 453 | { |
445 | struct kvm *kvm = opaque; | 454 | struct kvm *kvm = opaque; |
446 | struct kvm_vcpu *vcpu = kvm->vcpus[0]; | 455 | struct kvm_vcpu *vcpu = kvm->vcpus[0]; |
456 | struct kvm_pic *s = pic_irqchip(kvm); | ||
457 | int irq = pic_get_irq(&s->pics[0]); | ||
447 | 458 | ||
448 | pic_irqchip(kvm)->output = level; | 459 | s->output = level; |
449 | if (vcpu) | 460 | if (vcpu && level && (s->pics[0].isr_ack & (1 << irq))) { |
461 | s->pics[0].isr_ack &= ~(1 << irq); | ||
450 | kvm_vcpu_kick(vcpu); | 462 | kvm_vcpu_kick(vcpu); |
463 | } | ||
451 | } | 464 | } |
452 | 465 | ||
453 | struct kvm_pic *kvm_create_pic(struct kvm *kvm) | 466 | struct kvm_pic *kvm_create_pic(struct kvm *kvm) |
diff --git a/arch/x86/kvm/irq.h b/arch/x86/kvm/irq.h index 479a3d2d5614..4748532fd1da 100644 --- a/arch/x86/kvm/irq.h +++ b/arch/x86/kvm/irq.h | |||
@@ -42,6 +42,7 @@ struct kvm_kpic_state { | |||
42 | u8 irr; /* interrupt request register */ | 42 | u8 irr; /* interrupt request register */ |
43 | u8 imr; /* interrupt mask register */ | 43 | u8 imr; /* interrupt mask register */ |
44 | u8 isr; /* interrupt service register */ | 44 | u8 isr; /* interrupt service register */ |
45 | u8 isr_ack; /* interrupt ack detection */ | ||
45 | u8 priority_add; /* highest irq priority */ | 46 | u8 priority_add; /* highest irq priority */ |
46 | u8 irq_base; | 47 | u8 irq_base; |
47 | u8 read_reg_select; | 48 | u8 read_reg_select; |
@@ -70,6 +71,7 @@ struct kvm_pic *kvm_create_pic(struct kvm *kvm); | |||
70 | void kvm_pic_set_irq(void *opaque, int irq, int level); | 71 | void kvm_pic_set_irq(void *opaque, int irq, int level); |
71 | int kvm_pic_read_irq(struct kvm *kvm); | 72 | int kvm_pic_read_irq(struct kvm *kvm); |
72 | void kvm_pic_update_irq(struct kvm_pic *s); | 73 | void kvm_pic_update_irq(struct kvm_pic *s); |
74 | void kvm_pic_clear_isr_ack(struct kvm *kvm); | ||
73 | 75 | ||
74 | static inline struct kvm_pic *pic_irqchip(struct kvm *kvm) | 76 | static inline struct kvm_pic *pic_irqchip(struct kvm *kvm) |
75 | { | 77 | { |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 1c5864ac0837..4cfdd1b6df0b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -3963,6 +3963,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, | |||
3963 | pr_debug("Set back pending irq %d\n", | 3963 | pr_debug("Set back pending irq %d\n", |
3964 | pending_vec); | 3964 | pending_vec); |
3965 | } | 3965 | } |
3966 | kvm_pic_clear_isr_ack(vcpu->kvm); | ||
3966 | } | 3967 | } |
3967 | 3968 | ||
3968 | kvm_set_segment(vcpu, &sregs->cs, VCPU_SREG_CS); | 3969 | kvm_set_segment(vcpu, &sregs->cs, VCPU_SREG_CS); |