All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API
@ 2021-05-10 20:07 Philippe Mathieu-Daudé
  2021-05-10 20:07 ` [PATCH v3 1/2] bitops.h: Improve find_xxx_bit() documentation Philippe Mathieu-Daudé
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-10 20:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Sergio Lopez, Stefan Hajnoczi, qemu-block,
	Richard Henderson, Max Reitz, Chai Wen,
	Philippe Mathieu-Daudé

This series follow a suggestion from Stefan to use the bitops
API in virtio-blk:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg805139.html

Since v2:
- clear bitmap to avoid spurious interrupts! (Stefan)
- use 'further' in find_next docstring (Eric)
- added Richard R-b tag

Since v1:
- improved "bitops.h" docstring
- addressed Richard's review comments

Philippe Mathieu-Daudé (2):
  bitops.h: Improve find_xxx_bit() documentation
  virtio-blk: Convert QEMUBH callback to "bitops.h" API

 include/qemu/bitops.h           | 15 ++++++++++++---
 hw/block/dataplane/virtio-blk.c | 20 +++++---------------
 2 files changed, 17 insertions(+), 18 deletions(-)

-- 
2.26.3




^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/2] bitops.h: Improve find_xxx_bit() documentation
  2021-05-10 20:07 [PATCH v3 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
@ 2021-05-10 20:07 ` Philippe Mathieu-Daudé
  2021-05-10 20:07 ` [PATCH v3 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-10 20:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Sergio Lopez, Stefan Hajnoczi, qemu-block,
	Richard Henderson, Max Reitz, Chai Wen,
	Philippe Mathieu-Daudé

Document the following functions return the bitmap size
if no matching bit is found:

- find_first_bit
- find_next_bit
- find_last_bit
- find_first_zero_bit
- find_next_zero_bit

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 include/qemu/bitops.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index 3acbf3384c6..a72f69fea85 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -140,7 +140,8 @@ static inline int test_bit(long nr, const unsigned long *addr)
  * @addr: The address to start the search at
  * @size: The maximum size to search
  *
- * Returns the bit number of the first set bit, or size.
+ * Returns the bit number of the last set bit,
+ * or @size if there is no set bit in the bitmap.
  */
 unsigned long find_last_bit(const unsigned long *addr,
                             unsigned long size);
@@ -150,6 +151,9 @@ unsigned long find_last_bit(const unsigned long *addr,
  * @addr: The address to base the search on
  * @offset: The bitnumber to start searching at
  * @size: The bitmap size in bits
+ *
+ * Returns the bit number of the next set bit,
+ * or @size if there are no further set bits in the bitmap.
  */
 unsigned long find_next_bit(const unsigned long *addr,
                             unsigned long size,
@@ -160,6 +164,9 @@ unsigned long find_next_bit(const unsigned long *addr,
  * @addr: The address to base the search on
  * @offset: The bitnumber to start searching at
  * @size: The bitmap size in bits
+ *
+ * Returns the bit number of the next cleared bit,
+ * or @size if there are no further clear bits in the bitmap.
  */
 
 unsigned long find_next_zero_bit(const unsigned long *addr,
@@ -171,7 +178,8 @@ unsigned long find_next_zero_bit(const unsigned long *addr,
  * @addr: The address to start the search at
  * @size: The maximum size to search
  *
- * Returns the bit number of the first set bit.
+ * Returns the bit number of the first set bit,
+ * or @size if there is no set bit in the bitmap.
  */
 static inline unsigned long find_first_bit(const unsigned long *addr,
                                            unsigned long size)
@@ -194,7 +202,8 @@ static inline unsigned long find_first_bit(const unsigned long *addr,
  * @addr: The address to start the search at
  * @size: The maximum size to search
  *
- * Returns the bit number of the first cleared bit.
+ * Returns the bit number of the first cleared bit,
+ * or @size if there is no clear bit in the bitmap.
  */
 static inline unsigned long find_first_zero_bit(const unsigned long *addr,
                                                 unsigned long size)
-- 
2.26.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API
  2021-05-10 20:07 [PATCH v3 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
  2021-05-10 20:07 ` [PATCH v3 1/2] bitops.h: Improve find_xxx_bit() documentation Philippe Mathieu-Daudé
@ 2021-05-10 20:07 ` Philippe Mathieu-Daudé
  2021-05-21 17:37   ` Stefan Hajnoczi
  2021-05-11 10:11 ` [PATCH v3 0/2] " Stefan Hajnoczi
  2021-05-21 17:32 ` Stefan Hajnoczi
  3 siblings, 1 reply; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-10 20:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Sergio Lopez, Stefan Hajnoczi, qemu-block,
	Richard Henderson, Max Reitz, Chai Wen,
	Philippe Mathieu-Daudé

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>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/block/dataplane/virtio-blk.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index e9050c8987e..a31fa94ca33 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -60,24 +60,14 @@ 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);
     }
+    bitmap_clear(s->batch_notify_vqs, 0, nvqs);
 }
 
 /* Context: QEMU global mutex held */
-- 
2.26.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API
  2021-05-10 20:07 [PATCH v3 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
  2021-05-10 20:07 ` [PATCH v3 1/2] bitops.h: Improve find_xxx_bit() documentation Philippe Mathieu-Daudé
  2021-05-10 20:07 ` [PATCH v3 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
@ 2021-05-11 10:11 ` Stefan Hajnoczi
  2021-05-21 17:32 ` Stefan Hajnoczi
  3 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2021-05-11 10:11 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Sergio Lopez, qemu-block, Richard Henderson,
	qemu-devel, Max Reitz, Chai Wen

[-- Attachment #1: Type: text/plain, Size: 879 bytes --]

On Mon, May 10, 2021 at 10:07:56PM +0200, Philippe Mathieu-Daudé wrote:
> This series follow a suggestion from Stefan to use the bitops
> API in virtio-blk:
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg805139.html
> 
> Since v2:
> - clear bitmap to avoid spurious interrupts! (Stefan)
> - use 'further' in find_next docstring (Eric)
> - added Richard R-b tag
> 
> Since v1:
> - improved "bitops.h" docstring
> - addressed Richard's review comments
> 
> Philippe Mathieu-Daudé (2):
>   bitops.h: Improve find_xxx_bit() documentation
>   virtio-blk: Convert QEMUBH callback to "bitops.h" API
> 
>  include/qemu/bitops.h           | 15 ++++++++++++---
>  hw/block/dataplane/virtio-blk.c | 20 +++++---------------
>  2 files changed, 17 insertions(+), 18 deletions(-)
> 
> -- 
> 2.26.3
> 
> 

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API
  2021-05-10 20:07 [PATCH v3 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2021-05-11 10:11 ` [PATCH v3 0/2] " Stefan Hajnoczi
@ 2021-05-21 17:32 ` Stefan Hajnoczi
  3 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2021-05-21 17:32 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Sergio Lopez, qemu-block, Richard Henderson,
	qemu-devel, Max Reitz, Chai Wen

[-- Attachment #1: Type: text/plain, Size: 949 bytes --]

On Mon, May 10, 2021 at 10:07:56PM +0200, Philippe Mathieu-Daudé wrote:
> This series follow a suggestion from Stefan to use the bitops
> API in virtio-blk:
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg805139.html
> 
> Since v2:
> - clear bitmap to avoid spurious interrupts! (Stefan)
> - use 'further' in find_next docstring (Eric)
> - added Richard R-b tag
> 
> Since v1:
> - improved "bitops.h" docstring
> - addressed Richard's review comments
> 
> Philippe Mathieu-Daudé (2):
>   bitops.h: Improve find_xxx_bit() documentation
>   virtio-blk: Convert QEMUBH callback to "bitops.h" API
> 
>  include/qemu/bitops.h           | 15 ++++++++++++---
>  hw/block/dataplane/virtio-blk.c | 20 +++++---------------
>  2 files changed, 17 insertions(+), 18 deletions(-)

This series causes "make check" to hang. QEMU processes consume 100% CPU
in notify_guest_bh().

I have dropped this from my patch queue.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API
  2021-05-10 20:07 ` [PATCH v3 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
@ 2021-05-21 17:37   ` Stefan Hajnoczi
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2021-05-21 17:37 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Kevin Wolf, Sergio Lopez, qemu-block, Richard Henderson,
	qemu-devel, Max Reitz, Chai Wen

[-- Attachment #1: Type: text/plain, Size: 1460 bytes --]

On Mon, May 10, 2021 at 10:07:58PM +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>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  hw/block/dataplane/virtio-blk.c | 20 +++++---------------
>  1 file changed, 5 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
> index e9050c8987e..a31fa94ca33 100644
> --- a/hw/block/dataplane/virtio-blk.c
> +++ b/hw/block/dataplane/virtio-blk.c
> @@ -60,24 +60,14 @@ 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)) {

It needs to be find_next_bit(s->batch_notify_vqs, nvqs, i + 1).

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-21 17:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10 20:07 [PATCH v3 0/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
2021-05-10 20:07 ` [PATCH v3 1/2] bitops.h: Improve find_xxx_bit() documentation Philippe Mathieu-Daudé
2021-05-10 20:07 ` [PATCH v3 2/2] virtio-blk: Convert QEMUBH callback to "bitops.h" API Philippe Mathieu-Daudé
2021-05-21 17:37   ` Stefan Hajnoczi
2021-05-11 10:11 ` [PATCH v3 0/2] " Stefan Hajnoczi
2021-05-21 17:32 ` Stefan Hajnoczi

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.