1 Star 0 Fork 121

ctyunsystem/qemu

forked from src-openEuler/qemu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
virtio-net-update-the-default-and-max-of-rx-tx_queue.patch 3.97 KB
一键复制 编辑 原始数据 按行查看 历史
From 88dfb4236c735c608f8ca91cfbfb5ac424d654aa Mon Sep 17 00:00:00 2001
From: Jinhua Cao <caojinhua1@huawei.com>
Date: Thu, 10 Feb 2022 17:28:49 +0800
Subject: [PATCH] virtio-net: update the default and max of rx/tx_queue_size
Set the max of tx_queue_size to 4096 even if the backends
are not vhost-user.
Set the default of rx/tx_queue_size to 2048 if the backends
are vhost-user, otherwise to 4096.
Signed-off-by: Jinhua Cao <caojinhua1@huawei.com>
---
hw/net/virtio-net.c | 41 +++++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 009dc9f3d1..e887589a30 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -51,12 +51,11 @@
#define MAX_VLAN (1 << 12) /* Per 802.1Q definition */
/* previously fixed value */
-#define VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE 256
-#define VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE 256
+#define VIRTIO_NET_VHOST_USER_DEFAULT_SIZE 2048
/* for now, only allow larger queue_pairs; with virtio-1, guest can downsize */
-#define VIRTIO_NET_RX_QUEUE_MIN_SIZE VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE
-#define VIRTIO_NET_TX_QUEUE_MIN_SIZE VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE
+#define VIRTIO_NET_RX_QUEUE_MIN_SIZE 256
+#define VIRTIO_NET_TX_QUEUE_MIN_SIZE 256
#define VIRTIO_NET_IP4_ADDR_SIZE 8 /* ipv4 saddr + daddr */
@@ -622,6 +621,28 @@ static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs,
}
}
+static void virtio_net_set_default_queue_size(VirtIONet *n)
+{
+ NetClientState *peer = n->nic_conf.peers.ncs[0];
+
+ /* Default value is 0 if not set */
+ if (n->net_conf.rx_queue_size == 0) {
+ if (peer && peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
+ n->net_conf.rx_queue_size = VIRTIO_NET_VHOST_USER_DEFAULT_SIZE;
+ } else {
+ n->net_conf.rx_queue_size = VIRTIO_NET_VQ_MAX_SIZE;
+ }
+ }
+
+ if (n->net_conf.tx_queue_size == 0) {
+ if (peer && peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
+ n->net_conf.tx_queue_size = VIRTIO_NET_VHOST_USER_DEFAULT_SIZE;
+ } else {
+ n->net_conf.tx_queue_size = VIRTIO_NET_VQ_MAX_SIZE;
+ }
+ }
+}
+
static int virtio_net_max_tx_queue_size(VirtIONet *n)
{
NetClientState *peer = n->nic_conf.peers.ncs[0];
@@ -630,11 +651,11 @@ static int virtio_net_max_tx_queue_size(VirtIONet *n)
* Backends other than vhost-user don't support max queue size.
*/
if (!peer) {
- return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE;
+ return VIRTIO_NET_VQ_MAX_SIZE;
}
if (peer->info->type != NET_CLIENT_DRIVER_VHOST_USER) {
- return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE;
+ return VIRTIO_NET_VQ_MAX_SIZE;
}
return VIRTIO_NET_VQ_MAX_SIZE;
@@ -3388,6 +3409,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
virtio_net_set_config_size(n, n->host_features);
virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
+ virtio_net_set_default_queue_size(n);
+
/*
* We set a lower limit on RX queue size to what it always was.
* Guests that want a smaller ring can always resize it without
@@ -3679,10 +3702,8 @@ static Property virtio_net_properties[] = {
TX_TIMER_INTERVAL),
DEFINE_PROP_INT32("x-txburst", VirtIONet, net_conf.txburst, TX_BURST),
DEFINE_PROP_STRING("tx", VirtIONet, net_conf.tx),
- DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size,
- VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE),
- DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size,
- VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE),
+ DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, 0),
+ DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size, 0),
DEFINE_PROP_UINT16("host_mtu", VirtIONet, net_conf.mtu, 0),
DEFINE_PROP_BOOL("x-mtu-bypass-backend", VirtIONet, mtu_bypass_backend,
true),
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ctyunsystem/qemu.git
git@gitee.com:ctyunsystem/qemu.git
ctyunsystem
qemu
qemu
master

搜索帮助