diff options
author | Avi Kivity <avi@redhat.com> | 2009-12-28 07:08:30 -0500 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2010-03-01 10:35:46 -0500 |
commit | 46a929bc15fcd48e1e0e770a44040a6949cae133 (patch) | |
tree | 5351d75586821e74d82c59f1e1cde10806a25237 /virt/kvm | |
parent | f4c9e87c83a9f5bc1800db27dbb39e5cd1254c0a (diff) |
KVM: avoid taking ioapic mutex for non-ioapic EOIs
When the guest acknowledges an interrupt, it sends an EOI message to the local
apic, which broadcasts it to the ioapic. To handle the EOI, we need to take
the ioapic mutex.
On large guests, this causes a lot of contention on this mutex. Since large
guests usually don't route interrupts via the ioapic (they use msi instead),
this is completely unnecessary.
Avoid taking the mutex by introducing a handled_vectors bitmap. Before taking
the mutex, check if the ioapic was actually responsible for the acked vector.
If not, we can return early.
Signed-off-by: Avi Kivity <avi@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt/kvm')
-rw-r--r-- | virt/kvm/ioapic.c | 19 | ||||
-rw-r--r-- | virt/kvm/ioapic.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index f01392f51e8..a2edfd177fa 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c | |||
@@ -100,6 +100,19 @@ static int ioapic_service(struct kvm_ioapic *ioapic, unsigned int idx) | |||
100 | return injected; | 100 | return injected; |
101 | } | 101 | } |
102 | 102 | ||
103 | static void update_handled_vectors(struct kvm_ioapic *ioapic) | ||
104 | { | ||
105 | DECLARE_BITMAP(handled_vectors, 256); | ||
106 | int i; | ||
107 | |||
108 | memset(handled_vectors, 0, sizeof(handled_vectors)); | ||
109 | for (i = 0; i < IOAPIC_NUM_PINS; ++i) | ||
110 | __set_bit(ioapic->redirtbl[i].fields.vector, handled_vectors); | ||
111 | memcpy(ioapic->handled_vectors, handled_vectors, | ||
112 | sizeof(handled_vectors)); | ||
113 | smp_wmb(); | ||
114 | } | ||
115 | |||
103 | static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val) | 116 | static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val) |
104 | { | 117 | { |
105 | unsigned index; | 118 | unsigned index; |
@@ -134,6 +147,7 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val) | |||
134 | e->bits |= (u32) val; | 147 | e->bits |= (u32) val; |
135 | e->fields.remote_irr = 0; | 148 | e->fields.remote_irr = 0; |
136 | } | 149 | } |
150 | update_handled_vectors(ioapic); | ||
137 | mask_after = e->fields.mask; | 151 | mask_after = e->fields.mask; |
138 | if (mask_before != mask_after) | 152 | if (mask_before != mask_after) |
139 | kvm_fire_mask_notifiers(ioapic->kvm, index, mask_after); | 153 | kvm_fire_mask_notifiers(ioapic->kvm, index, mask_after); |
@@ -241,6 +255,9 @@ void kvm_ioapic_update_eoi(struct kvm *kvm, int vector, int trigger_mode) | |||
241 | { | 255 | { |
242 | struct kvm_ioapic *ioapic = kvm->arch.vioapic; | 256 | struct kvm_ioapic *ioapic = kvm->arch.vioapic; |
243 | 257 | ||
258 | smp_rmb(); | ||
259 | if (!test_bit(vector, ioapic->handled_vectors)) | ||
260 | return; | ||
244 | mutex_lock(&ioapic->lock); | 261 | mutex_lock(&ioapic->lock); |
245 | __kvm_ioapic_update_eoi(ioapic, vector, trigger_mode); | 262 | __kvm_ioapic_update_eoi(ioapic, vector, trigger_mode); |
246 | mutex_unlock(&ioapic->lock); | 263 | mutex_unlock(&ioapic->lock); |
@@ -352,6 +369,7 @@ void kvm_ioapic_reset(struct kvm_ioapic *ioapic) | |||
352 | ioapic->ioregsel = 0; | 369 | ioapic->ioregsel = 0; |
353 | ioapic->irr = 0; | 370 | ioapic->irr = 0; |
354 | ioapic->id = 0; | 371 | ioapic->id = 0; |
372 | update_handled_vectors(ioapic); | ||
355 | } | 373 | } |
356 | 374 | ||
357 | static const struct kvm_io_device_ops ioapic_mmio_ops = { | 375 | static const struct kvm_io_device_ops ioapic_mmio_ops = { |
@@ -401,6 +419,7 @@ int kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state) | |||
401 | 419 | ||
402 | mutex_lock(&ioapic->lock); | 420 | mutex_lock(&ioapic->lock); |
403 | memcpy(ioapic, state, sizeof(struct kvm_ioapic_state)); | 421 | memcpy(ioapic, state, sizeof(struct kvm_ioapic_state)); |
422 | update_handled_vectors(ioapic); | ||
404 | mutex_unlock(&ioapic->lock); | 423 | mutex_unlock(&ioapic->lock); |
405 | return 0; | 424 | return 0; |
406 | } | 425 | } |
diff --git a/virt/kvm/ioapic.h b/virt/kvm/ioapic.h index 419c43b667a..a505ce9054f 100644 --- a/virt/kvm/ioapic.h +++ b/virt/kvm/ioapic.h | |||
@@ -46,6 +46,7 @@ struct kvm_ioapic { | |||
46 | struct kvm *kvm; | 46 | struct kvm *kvm; |
47 | void (*ack_notifier)(void *opaque, int irq); | 47 | void (*ack_notifier)(void *opaque, int irq); |
48 | struct mutex lock; | 48 | struct mutex lock; |
49 | DECLARE_BITMAP(handled_vectors, 256); | ||
49 | }; | 50 | }; |
50 | 51 | ||
51 | #ifdef DEBUG | 52 | #ifdef DEBUG |