All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Sergio Lopez <slp@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Chai Wen <chaiwen@baidu.com>
Subject: Re: [PATCH v2 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API
Date: Mon, 10 May 2021 16:05:01 +0200	[thread overview]
Message-ID: <f66bfa6a-ec17-481e-c41e-5d8c59f220b1@redhat.com> (raw)
In-Reply-To: <YJk0Ybzgna/nPbGK@stefanha-x1.localdomain>

On 5/10/21 3:25 PM, Stefan Hajnoczi wrote:
> On Fri, May 07, 2021 at 07:06:34PM +0200, Philippe Mathieu-Daudé wrote:
>> By directly using find_first_bit() and find_next_bit from the
>> "bitops.h" API to iterate over the bitmap, we can remove the
>> bitmap[] variable-length array copy on the stack and the complex
>> manual bit testing/clearing logic.
>>
>> Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
>> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>  hw/block/dataplane/virtio-blk.c | 19 ++++---------------
>>  1 file changed, 4 insertions(+), 15 deletions(-)
>>
>> diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
>> index e9050c8987e..a7b5bda06fc 100644
>> --- a/hw/block/dataplane/virtio-blk.c
>> +++ b/hw/block/dataplane/virtio-blk.c
>> @@ -60,23 +60,12 @@ static void notify_guest_bh(void *opaque)
>>  {
>>      VirtIOBlockDataPlane *s = opaque;
>>      unsigned nvqs = s->conf->num_queues;
>> -    unsigned long bitmap[BITS_TO_LONGS(nvqs)];
>> -    unsigned j;
>>  
>> -    memcpy(bitmap, s->batch_notify_vqs, sizeof(bitmap));
>> -    memset(s->batch_notify_vqs, 0, sizeof(bitmap));
>> +    for (unsigned long i = find_first_bit(s->batch_notify_vqs, nvqs);
>> +             i < nvqs; i = find_next_bit(s->batch_notify_vqs, nvqs, i)) {
>> +        VirtQueue *vq = virtio_get_queue(s->vdev, i);
>>  
>> -    for (j = 0; j < nvqs; j += BITS_PER_LONG) {
>> -        unsigned long bits = bitmap[j / BITS_PER_LONG];
>> -
>> -        while (bits != 0) {
>> -            unsigned i = j + ctzl(bits);
>> -            VirtQueue *vq = virtio_get_queue(s->vdev, i);
>> -
>> -            virtio_notify_irqfd(s->vdev, vq);
>> -
>> -            bits &= bits - 1; /* clear right-most bit */
>> -        }
>> +        virtio_notify_irqfd(s->vdev, vq);
>>      }
>>  }
> 
> Bits in s->batch_notify_vqs[] must be cleared. Otherwise we may raise
> spurious irqs next time this function is called. The memset() can be
> moved after the loop.

Doh... good catch! I missed it when removing the previous
test_and_clear_bit() call (from v1).



      reply	other threads:[~2021-05-10 14:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 17:06 [PATCH v2 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
2021-05-07 17:06 ` [PATCH v2 1/2] bitops.h: Improve find_xxx_bit() documentation Philippe Mathieu-Daudé
2021-05-07 17:24   ` Richard Henderson
2021-05-07 17:38   ` Eric Blake
2021-05-07 17:06 ` [PATCH v2 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
2021-05-07 17:26   ` Richard Henderson
2021-05-10 13:25   ` Stefan Hajnoczi
2021-05-10 14:05     ` Philippe Mathieu-Daudé [this message]

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=f66bfa6a-ec17-481e-c41e-5d8c59f220b1@redhat.com \
    --to=philmd@redhat.com \
    --cc=chaiwen@baidu.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=slp@redhat.com \
    --cc=stefanha@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.