[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/15] kvm/irqchip: use bitmap utility for gsi tracki
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 14/15] kvm/irqchip: use bitmap utility for gsi tracking |
Date: |
Mon, 7 Mar 2016 18:37:00 +0100 |
From: Wei Yang <address@hidden>
By using utilities in bitops and bitmap, this patch tries to make it more
friendly to audience. No functional change.
Signed-off-by: Wei Yang <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
kvm-all.c | 34 ++++++++++------------------------
1 file changed, 10 insertions(+), 24 deletions(-)
diff --git a/kvm-all.c b/kvm-all.c
index 161200e..44c0464 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -89,7 +89,7 @@ struct KVMState
#ifdef KVM_CAP_IRQ_ROUTING
struct kvm_irq_routing *irq_routes;
int nr_allocated_irq_routes;
- uint32_t *used_gsi_bitmap;
+ unsigned long *used_gsi_bitmap;
unsigned int gsi_count;
QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
#endif
@@ -951,12 +951,12 @@ typedef struct KVMMSIRoute {
static void set_gsi(KVMState *s, unsigned int gsi)
{
- s->used_gsi_bitmap[gsi / 32] |= 1U << (gsi % 32);
+ set_bit(gsi, s->used_gsi_bitmap);
}
static void clear_gsi(KVMState *s, unsigned int gsi)
{
- s->used_gsi_bitmap[gsi / 32] &= ~(1U << (gsi % 32));
+ clear_bit(gsi, s->used_gsi_bitmap);
}
void kvm_init_irq_routing(KVMState *s)
@@ -965,17 +965,9 @@ void kvm_init_irq_routing(KVMState *s)
gsi_count = kvm_check_extension(s, KVM_CAP_IRQ_ROUTING) - 1;
if (gsi_count > 0) {
- unsigned int gsi_bits, i;
-
/* Round up so we can search ints using ffs */
- gsi_bits = ALIGN(gsi_count, 32);
- s->used_gsi_bitmap = g_malloc0(gsi_bits / 8);
+ s->used_gsi_bitmap = bitmap_new(gsi_count);
s->gsi_count = gsi_count;
-
- /* Mark any over-allocated bits as already in use */
- for (i = gsi_count; i < gsi_bits; i++) {
- set_gsi(s, i);
- }
}
s->irq_routes = g_malloc0(sizeof(*s->irq_routes));
@@ -1105,9 +1097,7 @@ static void kvm_flush_dynamic_msi_routes(KVMState *s)
static int kvm_irqchip_get_virq(KVMState *s)
{
- uint32_t *word = s->used_gsi_bitmap;
- int max_words = ALIGN(s->gsi_count, 32) / 32;
- int i, zeroes;
+ int next_virq;
/*
* PIC and IOAPIC share the first 16 GSI numbers, thus the available
@@ -1120,16 +1110,12 @@ static int kvm_irqchip_get_virq(KVMState *s)
}
/* Return the lowest unused GSI in the bitmap */
- for (i = 0; i < max_words; i++) {
- zeroes = ctz32(~word[i]);
- if (zeroes == 32) {
- continue;
- }
-
- return zeroes + i * 32;
+ next_virq = find_first_zero_bit(s->used_gsi_bitmap, s->gsi_count);
+ if (next_virq >= s->gsi_count) {
+ return -ENOSPC;
+ } else {
+ return next_virq;
}
- return -ENOSPC;
-
}
static KVMMSIRoute *kvm_lookup_msi_route(KVMState *s, MSIMessage msg)
--
2.5.0
- [Qemu-devel] [PULL 03/15] exec: Return RAMBlock pointer from allocating functions, (continued)
- [Qemu-devel] [PULL 03/15] exec: Return RAMBlock pointer from allocating functions, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 04/15] memory: Move assignment to ram_block to memory_region_init_*, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 05/15] memory: Implement memory_region_get_ram_addr with mr->ram_block, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 06/15] memory: Drop MemoryRegion.ram_addr, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 07/15] exec: Pass RAMBlock pointer to qemu_ram_free, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 08/15] exec: Factor out section_covers_addr, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 11/15] doc/memory.txt: correct a logic error, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 09/15] exec: Introduce AddressSpaceDispatch.mru_section, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 12/15] doc/memory.txt: correct description of MemoryRegionOps fields, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 13/15] MAINTAINERS: Add entry for include/sysemu/kvm*.h, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 14/15] kvm/irqchip: use bitmap utility for gsi tracking,
Paolo Bonzini <=
- [Qemu-devel] [PULL 15/15] scsi-bus: Remove tape command from scsi_req_xfer, Paolo Bonzini, 2016/03/07
- [Qemu-devel] [PULL 10/15] icount: possible options for sleep are on or off, Paolo Bonzini, 2016/03/07
- Re: [Qemu-devel] [PULL 00/15] Memory changes and misc bug fixes for 2016-03-07, Peter Maydell, 2016/03/08