diff options
author | Qing He <qing.he@intel.com> | 2007-09-17 02:47:13 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2007-10-13 04:18:26 -0400 |
commit | 40487c680d5855459dfdce340df13d40071bb774 (patch) | |
tree | abc0ec56ecb1b6d1533b918621c060a1d38fccef | |
parent | 5cd4f6fd8506f59cb8a232f364c54f6bd8e5150a (diff) |
KVM: deliver PIC interrupt only to vcpu0
This patch changes the PIC interrupts delivery. Now it is only delivered
to vcpu0 when either condition is met (on vcpu0):
1. local APIC is hardware disabled
2. LVT0 is unmasked and configured to delivery mode ExtInt
It fixes the 2x faster wall clock on x86_64 and SMP i386 Linux guests
Signed-off-by: Eddie (Yaozu) Dong <eddie.dong@intel.com>
Signed-off-by: Qing He <qing.he@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r-- | drivers/kvm/irq.c | 15 | ||||
-rw-r--r-- | drivers/kvm/irq.h | 1 | ||||
-rw-r--r-- | drivers/kvm/lapic.c | 17 |
3 files changed, 28 insertions, 5 deletions
diff --git a/drivers/kvm/irq.c b/drivers/kvm/irq.c index b88e50115588..7628c7ff628f 100644 --- a/drivers/kvm/irq.c +++ b/drivers/kvm/irq.c | |||
@@ -33,8 +33,11 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v) | |||
33 | struct kvm_pic *s; | 33 | struct kvm_pic *s; |
34 | 34 | ||
35 | if (kvm_apic_has_interrupt(v) == -1) { /* LAPIC */ | 35 | if (kvm_apic_has_interrupt(v) == -1) { /* LAPIC */ |
36 | s = pic_irqchip(v->kvm); /* PIC */ | 36 | if (kvm_apic_accept_pic_intr(v)) { |
37 | return s->output; | 37 | s = pic_irqchip(v->kvm); /* PIC */ |
38 | return s->output; | ||
39 | } else | ||
40 | return 0; | ||
38 | } | 41 | } |
39 | return 1; | 42 | return 1; |
40 | } | 43 | } |
@@ -50,9 +53,11 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v) | |||
50 | 53 | ||
51 | vector = kvm_get_apic_interrupt(v); /* APIC */ | 54 | vector = kvm_get_apic_interrupt(v); /* APIC */ |
52 | if (vector == -1) { | 55 | if (vector == -1) { |
53 | s = pic_irqchip(v->kvm); | 56 | if (kvm_apic_accept_pic_intr(v)) { |
54 | s->output = 0; /* PIC */ | 57 | s = pic_irqchip(v->kvm); |
55 | vector = kvm_pic_read_irq(s); | 58 | s->output = 0; /* PIC */ |
59 | vector = kvm_pic_read_irq(s); | ||
60 | } | ||
56 | } | 61 | } |
57 | return vector; | 62 | return vector; |
58 | } | 63 | } |
diff --git a/drivers/kvm/irq.h b/drivers/kvm/irq.h index f324cfb40084..ec46a09e2135 100644 --- a/drivers/kvm/irq.h +++ b/drivers/kvm/irq.h | |||
@@ -135,6 +135,7 @@ do { \ | |||
135 | 135 | ||
136 | void kvm_vcpu_kick(struct kvm_vcpu *vcpu); | 136 | void kvm_vcpu_kick(struct kvm_vcpu *vcpu); |
137 | int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu); | 137 | int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu); |
138 | int kvm_apic_accept_pic_intr(struct kvm_vcpu *vcpu); | ||
138 | int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu); | 139 | int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu); |
139 | int kvm_create_lapic(struct kvm_vcpu *vcpu); | 140 | int kvm_create_lapic(struct kvm_vcpu *vcpu); |
140 | void kvm_free_apic(struct kvm_lapic *apic); | 141 | void kvm_free_apic(struct kvm_lapic *apic); |
diff --git a/drivers/kvm/lapic.c b/drivers/kvm/lapic.c index 2706ec36c258..01e769672dcc 100644 --- a/drivers/kvm/lapic.c +++ b/drivers/kvm/lapic.c | |||
@@ -788,6 +788,8 @@ static void lapic_reset(struct kvm_vcpu *vcpu) | |||
788 | 788 | ||
789 | for (i = 0; i < APIC_LVT_NUM; i++) | 789 | for (i = 0; i < APIC_LVT_NUM; i++) |
790 | apic_set_reg(apic, APIC_LVTT + 0x10 * i, APIC_LVT_MASKED); | 790 | apic_set_reg(apic, APIC_LVTT + 0x10 * i, APIC_LVT_MASKED); |
791 | apic_set_reg(apic, APIC_LVT0, | ||
792 | SET_APIC_DELIVERY_MODE(0, APIC_MODE_EXTINT)); | ||
791 | 793 | ||
792 | apic_set_reg(apic, APIC_DFR, 0xffffffffU); | 794 | apic_set_reg(apic, APIC_DFR, 0xffffffffU); |
793 | apic_set_reg(apic, APIC_SPIV, 0xff); | 795 | apic_set_reg(apic, APIC_SPIV, 0xff); |
@@ -932,6 +934,21 @@ int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu) | |||
932 | return highest_irr; | 934 | return highest_irr; |
933 | } | 935 | } |
934 | 936 | ||
937 | int kvm_apic_accept_pic_intr(struct kvm_vcpu *vcpu) | ||
938 | { | ||
939 | u32 lvt0 = apic_get_reg(vcpu->apic, APIC_LVT0); | ||
940 | int r = 0; | ||
941 | |||
942 | if (vcpu->vcpu_id == 0) { | ||
943 | if (!apic_hw_enabled(vcpu->apic)) | ||
944 | r = 1; | ||
945 | if ((lvt0 & APIC_LVT_MASKED) == 0 && | ||
946 | GET_APIC_DELIVERY_MODE(lvt0) == APIC_MODE_EXTINT) | ||
947 | r = 1; | ||
948 | } | ||
949 | return r; | ||
950 | } | ||
951 | |||
935 | void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu) | 952 | void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu) |
936 | { | 953 | { |
937 | struct kvm_lapic *apic = vcpu->apic; | 954 | struct kvm_lapic *apic = vcpu->apic; |