qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Wei Yang <richard.weiyang@gmail.com>, jan.kiszka@siemens.com
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [Qemu-devel] [PATCH] kvm/irqchip: use bitmap utility for gsi tracking
Date: Mon, 7 Mar 2016 10:47:53 +0100	[thread overview]
Message-ID: <56DD4E49.1090608@redhat.com> (raw)
In-Reply-To: <1457229445-25954-1-git-send-email-richard.weiyang@gmail.com>

On 06/03/2016 02:57, Wei Yang wrote:
> 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 <richard.weiyang@gmail.com>
> ---
>  kvm-all.c | 34 ++++++++++------------------------
>  1 file changed, 10 insertions(+), 24 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index bd9e764..ed3f4a2 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -90,7 +90,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)
> 

Queued, thanks.  I will send a pull request today.

Paolo

  reply	other threads:[~2016-03-07  9:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-06  1:57 [Qemu-devel] [PATCH] kvm/irqchip: use bitmap utility for gsi tracking Wei Yang
2016-03-07  9:47 ` Paolo Bonzini [this message]
2016-03-07 13:53   ` Wei Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56DD4E49.1090608@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.weiyang@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).