[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 14/63] virtio: don't zero out memory region cache for indirect des
|
From: |
Michael S. Tsirkin |
|
Subject: |
[PULL 14/63] virtio: don't zero out memory region cache for indirect descriptors |
|
Date: |
Wed, 4 Oct 2023 04:43:53 -0400 |
From: Ilya Maximets <i.maximets@ovn.org>
Lots of virtio functions that are on a hot path in data transmission
are initializing indirect descriptor cache at the point of stack
allocation. It's a 112 byte structure that is getting zeroed out on
each call adding unnecessary overhead. It's going to be correctly
initialized later via special init function. The only reason to
actually initialize right away is the ability to safely destruct it.
Replacing a designated initializer with a function to only initialize
what is necessary.
Removal of the unnecessary stack initializations improves throughput
of virtio-net devices in terms of 64B packets per second by 6-14 %
depending on the case. Tested with a proposed af-xdp network backend
and a dpdk testpmd application in the guest, but should be beneficial
for other virtio devices as well.
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Message-Id: <20230811143423.3258788-1-i.maximets@ovn.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/exec/memory.h | 16 +++++++++++++---
hw/virtio/virtio.c | 20 +++++++++++++++-----
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index ef23d65afc..c99842d2fc 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2671,9 +2671,6 @@ struct MemoryRegionCache {
bool is_write;
};
-#define MEMORY_REGION_CACHE_INVALID ((MemoryRegionCache) { .mrs.mr = NULL })
-
-
/* address_space_ld*_cached: load from a cached #MemoryRegion
* address_space_st*_cached: store into a cached #MemoryRegion
*
@@ -2762,6 +2759,19 @@ int64_t address_space_cache_init(MemoryRegionCache
*cache,
hwaddr len,
bool is_write);
+/**
+ * address_space_cache_init_empty: Initialize empty #MemoryRegionCache
+ *
+ * @cache: The #MemoryRegionCache to operate on.
+ *
+ * Initializes #MemoryRegionCache structure without memory region attached.
+ * Cache initialized this way can only be safely destroyed, but not used.
+ */
+static inline void address_space_cache_init_empty(MemoryRegionCache *cache)
+{
+ cache->mrs.mr = NULL;
+}
+
/**
* address_space_cache_invalidate: complete a write to a #MemoryRegionCache
*
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 4577f3f5b3..d3a22e3d36 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1071,10 +1071,12 @@ static void virtqueue_split_get_avail_bytes(VirtQueue
*vq,
VirtIODevice *vdev = vq->vdev;
unsigned int idx;
unsigned int total_bufs, in_total, out_total;
- MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
+ MemoryRegionCache indirect_desc_cache;
int64_t len = 0;
int rc;
+ address_space_cache_init_empty(&indirect_desc_cache);
+
idx = vq->last_avail_idx;
total_bufs = in_total = out_total = 0;
@@ -1207,12 +1209,14 @@ static void virtqueue_packed_get_avail_bytes(VirtQueue
*vq,
VirtIODevice *vdev = vq->vdev;
unsigned int idx;
unsigned int total_bufs, in_total, out_total;
+ MemoryRegionCache indirect_desc_cache;
MemoryRegionCache *desc_cache;
- MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
int64_t len = 0;
VRingPackedDesc desc;
bool wrap_counter;
+ address_space_cache_init_empty(&indirect_desc_cache);
+
idx = vq->last_avail_idx;
wrap_counter = vq->last_avail_wrap_counter;
total_bufs = in_total = out_total = 0;
@@ -1487,7 +1491,7 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_t sz)
{
unsigned int i, head, max;
VRingMemoryRegionCaches *caches;
- MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
+ MemoryRegionCache indirect_desc_cache;
MemoryRegionCache *desc_cache;
int64_t len;
VirtIODevice *vdev = vq->vdev;
@@ -1498,6 +1502,8 @@ static void *virtqueue_split_pop(VirtQueue *vq, size_t sz)
VRingDesc desc;
int rc;
+ address_space_cache_init_empty(&indirect_desc_cache);
+
RCU_READ_LOCK_GUARD();
if (virtio_queue_empty_rcu(vq)) {
goto done;
@@ -1624,7 +1630,7 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t
sz)
{
unsigned int i, max;
VRingMemoryRegionCaches *caches;
- MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
+ MemoryRegionCache indirect_desc_cache;
MemoryRegionCache *desc_cache;
int64_t len;
VirtIODevice *vdev = vq->vdev;
@@ -1636,6 +1642,8 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t
sz)
uint16_t id;
int rc;
+ address_space_cache_init_empty(&indirect_desc_cache);
+
RCU_READ_LOCK_GUARD();
if (virtio_queue_packed_empty_rcu(vq)) {
goto done;
@@ -3970,13 +3978,15 @@ VirtioQueueElement
*qmp_x_query_virtio_queue_element(const char *path,
} else {
unsigned int head, i, max;
VRingMemoryRegionCaches *caches;
- MemoryRegionCache indirect_desc_cache = MEMORY_REGION_CACHE_INVALID;
+ MemoryRegionCache indirect_desc_cache;
MemoryRegionCache *desc_cache;
VRingDesc desc;
VirtioRingDescList *list = NULL;
VirtioRingDescList *node;
int rc; int ndescs;
+ address_space_cache_init_empty(&indirect_desc_cache);
+
RCU_READ_LOCK_GUARD();
max = vq->vring.num;
--
MST
- [PULL 04/63] hw/virtio/vhost-vdpa: Inline TARGET_PAGE_ALIGN() macro, (continued)
- [PULL 04/63] hw/virtio/vhost-vdpa: Inline TARGET_PAGE_ALIGN() macro, Michael S. Tsirkin, 2023/10/04
- [PULL 03/63] hw/virtio: Propagate page_mask to vhost_vdpa_section_end(), Michael S. Tsirkin, 2023/10/04
- [PULL 02/63] hw/virtio: Propagate page_mask to vhost_vdpa_listener_skipped_section(), Michael S. Tsirkin, 2023/10/04
- [PULL 06/63] hw/virtio: Build vhost-vdpa.o once, Michael S. Tsirkin, 2023/10/04
- [PULL 01/63] pci: SLT must be RO, Michael S. Tsirkin, 2023/10/04
- [PULL 05/63] hw/virtio/vhost-vdpa: Use target-agnostic qemu_target_page_mask(), Michael S. Tsirkin, 2023/10/04
- [PULL 07/63] hw/virtio/meson: Rename softmmu_virtio_ss[] -> system_virtio_ss[], Michael S. Tsirkin, 2023/10/04
- [PULL 11/63] virtio-net: Expose MAX_VLAN, Michael S. Tsirkin, 2023/10/04
- [PULL 09/63] hw/virtio: add config support to vhost-user-device, Michael S. Tsirkin, 2023/10/04
- [PULL 08/63] virtio: add vhost-user-base and a generic vhost-user-device, Michael S. Tsirkin, 2023/10/04
- [PULL 14/63] virtio: don't zero out memory region cache for indirect descriptors,
Michael S. Tsirkin <=
- [PULL 13/63] vdpa: Allow VIRTIO_NET_F_CTRL_VLAN in SVQ, Michael S. Tsirkin, 2023/10/04
- [PULL 10/63] virtio-net: do not reset vlan filtering at set_features, Michael S. Tsirkin, 2023/10/04
- [PULL 15/63] vdpa: use first queue SVQ state for CVQ default, Michael S. Tsirkin, 2023/10/04
- [PULL 17/63] vdpa: rename vhost_vdpa_net_load to vhost_vdpa_net_cvq_load, Michael S. Tsirkin, 2023/10/04
- [PULL 19/63] vdpa: remove net cvq migration blocker, Michael S. Tsirkin, 2023/10/04
- [PULL 12/63] vdpa: Restore vlan filtering state, Michael S. Tsirkin, 2023/10/04
- [PULL 16/63] vdpa: export vhost_vdpa_set_vring_ready, Michael S. Tsirkin, 2023/10/04
- [PULL 20/63] vhost: Add count argument to vhost_svq_poll(), Michael S. Tsirkin, 2023/10/04
- [PULL 22/63] qmp: update virtio feature maps, vhost-user-gpio introspection, Michael S. Tsirkin, 2023/10/04
- [PULL 24/63] vhost-user: strip superfluous whitespace, Michael S. Tsirkin, 2023/10/04