qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio: use shadow_avail_idx while checking number of heads
@ 2023-08-25 17:04 Ilya Maximets
  2023-09-25 11:20 ` Ilya Maximets
  2023-09-25 14:23 ` Stefan Hajnoczi
  0 siblings, 2 replies; 12+ messages in thread
From: Ilya Maximets @ 2023-08-25 17:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jason Wang, Stefan Hajnoczi, Michael S. Tsirkin, Ilya Maximets

We do not need the most up to date number of heads, we only want to
know if there is at least one.

Use shadow variable as long as it is not equal to the last available
index checked.  This avoids expensive qatomic dereference of the
RCU-protected memory region cache as well as the memory access itself
and the subsequent memory barrier.

The change improves performance of the af-xdp network backend by 2-3%.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 hw/virtio/virtio.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 309038fd46..04bf7cc977 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -999,7 +999,15 @@ void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
 /* Called within rcu_read_lock().  */
 static int virtqueue_num_heads(VirtQueue *vq, unsigned int idx)
 {
-    uint16_t num_heads = vring_avail_idx(vq) - idx;
+    uint16_t num_heads;
+
+    if (vq->shadow_avail_idx != idx) {
+        num_heads = vq->shadow_avail_idx - idx;
+
+        return num_heads;
+    }
+
+    num_heads = vring_avail_idx(vq) - idx;
 
     /* Check it isn't doing very strange things with descriptor numbers. */
     if (num_heads > vq->vring.num) {
-- 
2.40.1



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

end of thread, other threads:[~2023-09-27 14:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-25 17:04 [PATCH] virtio: use shadow_avail_idx while checking number of heads Ilya Maximets
2023-09-25 11:20 ` Ilya Maximets
2023-09-25 14:23 ` Stefan Hajnoczi
2023-09-25 15:02   ` Ilya Maximets
2023-09-25 15:12     ` Stefan Hajnoczi
2023-09-25 15:36       ` Ilya Maximets
2023-09-25 15:38         ` Stefan Hajnoczi
2023-09-25 20:58           ` Ilya Maximets
2023-09-25 21:24             ` Michael S. Tsirkin
2023-09-25 22:13               ` Ilya Maximets
2023-09-25 22:24                 ` Michael S. Tsirkin
2023-09-27 14:01                   ` Ilya Maximets

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).