virtio_net_flush_tx() has two large iovec arrays that are populated
as needed. Entries are initialized explicitly or through iov_copy(),
and out_num bounds the entries subsequently consumed through out_sg.
Zero-initializing the entire arrays is therefore unnecessary.
Similar arrays in virtio_net_receive_rcu() already use
QEMU_UNINITIALIZED to avoid automatic zero-initialization overhead.
Apply the same optimization to the TX path.
Performance was measured with iperf3 TCP_STREAM and netperf UDP_STREAM
using a single-vCPU RISC-V KVM guest with QEMU user networking
(-netdev user). Six interleaved baseline/patched runs were performed
per workload, with 30 seconds of measurement after warm-up.
Median guest-to-host throughput (Mbit/s):
Before After Change
UDP_STREAM 64B 40.26 46.95 +16.6%
UDP_STREAM 256B 163.17 185.21 +13.5%
TCP_STREAM 480.02 484.83 +1.0%
Median QEMU process instructions during the perf sampling windows
decreased by 23.1% and 24.5% for the 64-byte and 256-byte UDP
workloads, respectively.
Signed-off-by: Tan Chi <[email protected]>
---
Changes in v2:
- Add performance results and perf instruction-count measurements.
- No code changes.
hw/net/virtio-net.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 54e42cfec9..76e3281831 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -2783,7 +2783,9 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
for (;;) {
ssize_t ret;
unsigned int out_num;
- struct iovec sg[VIRTQUEUE_MAX_SIZE], sg2[VIRTQUEUE_MAX_SIZE + 1],
*out_sg;
+ QEMU_UNINITIALIZED struct iovec sg[VIRTQUEUE_MAX_SIZE];
+ QEMU_UNINITIALIZED struct iovec sg2[VIRTQUEUE_MAX_SIZE + 1];
+ struct iovec *out_sg;
struct virtio_net_hdr vhdr;
elem = virtqueue_pop(q->tx_vq, sizeof(VirtQueueElement));
--
2.53.0