Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2217726/?format=api
{ "id": 2217726, "url": "http://patchwork.ozlabs.org/api/patches/2217726/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260330122917.468225-1-kdutta@redhat.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260330122917.468225-1-kdutta@redhat.com>", "list_archive_url": null, "date": "2026-03-30T12:29:17", "name": "[v4] hw/net/virtio-net: add support for notification coalescing", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "7d74938bfde46ee7e5f1872efdec3f2ba58f3931", "submitter": { "id": 92694, "url": "http://patchwork.ozlabs.org/api/people/92694/?format=api", "name": "Koushik Dutta", "email": "kdutta@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260330122917.468225-1-kdutta@redhat.com/mbox/", "series": [ { "id": 498018, "url": "http://patchwork.ozlabs.org/api/series/498018/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=498018", "date": "2026-03-30T12:29:17", "name": "[v4] hw/net/virtio-net: add support for notification coalescing", "version": 4, "mbox": "http://patchwork.ozlabs.org/series/498018/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2217726/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2217726/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=ZZYrz9xw;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fkrF15JDSz1y1q\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 30 Mar 2026 23:30:29 +1100 (AEDT)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1w7BkR-0000ZJ-OK; Mon, 30 Mar 2026 08:29:41 -0400", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <kdutta@redhat.com>) id 1w7BkK-0000Yf-38\n for qemu-devel@nongnu.org; Mon, 30 Mar 2026 08:29:33 -0400", "from us-smtp-delivery-124.mimecast.com ([170.10.129.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <kdutta@redhat.com>) id 1w7BkF-0004kj-VC\n for qemu-devel@nongnu.org; Mon, 30 Mar 2026 08:29:31 -0400", "from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-323-l7qTyIGDMyiU6Tx9SP-iaA-1; Mon,\n 30 Mar 2026 08:29:23 -0400", "from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id CC0091955D8B\n for <qemu-devel@nongnu.org>; Mon, 30 Mar 2026 12:29:22 +0000 (UTC)", "from kdutta-thinkpadp1gen7.bengluru.csb (unknown [10.74.64.235])\n by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 055A130001A2; Mon, 30 Mar 2026 12:29:19 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1774873764;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding;\n bh=d09OnqQttl2o/9T3TEgKhyfsEQgk4MnQ9HxKJ0C8/iM=;\n b=ZZYrz9xw/qsponSOwg42+KQtcW2geE7TPPRQEQURNah7EDySiMnMJTBEPhyLN4ZxpxIMy7\n jW9xU3j2pqj4YY5HE2qXzjYvFV2WnBRIJkmZ+rQKeyA3NnIhwsBjOQFvfJqtAfMoPd5lMS\n dKwWwyB7L8pr6yQynp6xCxIqzeIr/QA=", "X-MC-Unique": "l7qTyIGDMyiU6Tx9SP-iaA-1", "X-Mimecast-MFC-AGG-ID": "l7qTyIGDMyiU6Tx9SP-iaA_1774873762", "From": "Koushik Dutta <kdutta@redhat.com>", "To": "qemu-devel@nongnu.org", "Cc": "\"Michael S. Tsirkin\" <mst@redhat.com>,\n Stefano Garzarella <sgarzare@redhat.com>, Jason Wang <jasowang@redhat.com>,\n\t=?utf-8?q?Eugenio_P=C3=A9rez?= <eperezma@redhat.com>", "Subject": "[PATCH v4] hw/net/virtio-net: add support for notification coalescing", "Date": "Mon, 30 Mar 2026 17:59:17 +0530", "Message-ID": "<20260330122917.468225-1-kdutta@redhat.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.4", "Received-SPF": "pass client-ip=170.10.129.124; envelope-from=kdutta@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com", "X-Spam_score_int": "27", "X-Spam_score": "2.7", "X-Spam_bar": "++", "X-Spam_report": "(2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335,\n RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=1, RCVD_IN_VALIDITY_RPBL_BLOCKED=1,\n SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no", "X-Spam_action": "no action", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "qemu development <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "Implement VirtIO Network Notification Coalescing (Bit 53).\nThis allows the guest to manage interrupt frequency using ethtool\n-C for both RX and TX paths.\n\n- Added VIRTIO_NET_F_NOTF_COAL to host features.\n- Implemented VIRTIO_NET_CTRL_NOTF_COAL class handling in\n virtio_net_handle_ctrl_iov.\n- Added logic to store and apply rx/tx usecs and max_packets.\n- Added packet counters and threshold logic for both RX and TX data paths.\n- Dynamic Dispatcher: Implemented a dispatcher mechanism that\n dynamically switches/activates the notification callback logic\n only after the guest enables TX coalescing via ethtool.\n\nvhost-vdpa: add support for SVQ interrupt coalescing.\n\nThis reduces interrupt overhead by batching notifications based on\neither a packet count or a time-based threshold.\n\nSigned-off-by: Koushik Dutta <kdutta@redhat.com>\n---\n hw/net/virtio-net.c | 137 +++++++++++++++++++++++++++++----\n include/hw/virtio/virtio-net.h | 8 ++\n net/vhost-vdpa.c | 2 +\n 3 files changed, 131 insertions(+), 16 deletions(-)", "diff": "diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c\nindex eccb48ad42..16f197cbdb 100644\n--- a/hw/net/virtio-net.c\n+++ b/hw/net/virtio-net.c\n@@ -131,6 +131,8 @@ static const VirtIOConfigSizeParams cfg_size_params = {\n .feature_sizes = feature_sizes\n };\n \n+static void virtio_net_tx_timer(void *opaque);\n+\n static VirtIONetQueue *virtio_net_get_subqueue(NetClientState *nc)\n {\n VirtIONet *n = qemu_get_nic_opaque(nc);\n@@ -157,6 +159,15 @@ static void flush_or_purge_queued_packets(NetClientState *nc)\n * - we could suppress RX interrupt if we were so inclined.\n */\n \n+static void virtio_net_rx_notify(void *opaque)\n+{\n+ VirtIONet *n = opaque;\n+ VirtIODevice *vdev = VIRTIO_DEVICE(n);\n+\n+ n->rx_pkt_cnt = 0;\n+ virtio_notify(vdev, n->vqs[0].rx_vq);\n+}\n+\n static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)\n {\n VirtIONet *n = VIRTIO_NET(vdev);\n@@ -1081,6 +1092,43 @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,\n }\n }\n \n+static int virtio_net_handle_coal(VirtIONet *n, uint8_t cmd,\n+ struct iovec *iov, unsigned int iov_cnt)\n+{\n+ struct virtio_net_ctrl_coal coal;\n+ VirtIONetQueue *q;\n+ size_t s;\n+ int i;\n+\n+ s = iov_to_buf(iov, iov_cnt, 0, &coal, sizeof(coal));\n+ if (s != sizeof(coal)) {\n+ return VIRTIO_NET_ERR;\n+ }\n+\n+ if (cmd == VIRTIO_NET_CTRL_NOTF_COAL_RX_SET) {\n+ n->rx_coal_usecs = le32_to_cpu(coal.max_usecs);\n+ n->rx_coal_packets = le32_to_cpu(coal.max_packets);\n+ if (!n->rx_index_timer) {\n+ n->rx_index_timer = timer_new_us(QEMU_CLOCK_VIRTUAL,\n+ virtio_net_rx_notify, n);\n+ }\n+ } else if (cmd == VIRTIO_NET_CTRL_NOTF_COAL_TX_SET) {\n+ n->tx_coal_usecs = le32_to_cpu(coal.max_usecs);\n+ n->tx_coal_packets = le32_to_cpu(coal.max_packets);\n+ n->tx_timeout = n->tx_coal_usecs * 1000;\n+ for (i = 0; i < n->max_queue_pairs; i++) {\n+ q = &n->vqs[i];\n+ if (!q->tx_timer) {\n+ q->tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,\n+ virtio_net_tx_timer,\n+ q);\n+ }\n+ }\n+ }\n+\n+ return VIRTIO_NET_OK;\n+}\n+\n static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,\n struct iovec *iov, unsigned int iov_cnt)\n {\n@@ -1582,6 +1630,8 @@ size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev,\n status = virtio_net_handle_mq(n, ctrl.cmd, iov, out_num);\n } else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) {\n status = virtio_net_handle_offloads(n, ctrl.cmd, iov, out_num);\n+ } else if (ctrl.class == VIRTIO_NET_CTRL_NOTF_COAL) {\n+ status = virtio_net_handle_coal(n, ctrl.cmd, iov, out_num);\n }\n \n s = iov_from_buf(in_sg, in_num, 0, &status, sizeof(status));\n@@ -2041,7 +2091,22 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,\n }\n \n virtqueue_flush(q->rx_vq, i);\n- virtio_notify(vdev, q->rx_vq);\n+\n+ /* rx coalescing */\n+ n->rx_pkt_cnt += i;\n+ if (n->rx_coal_usecs == 0 || n->rx_pkt_cnt >= n->rx_coal_packets) {\n+ if (n->rx_index_timer) {\n+ timer_del(n->rx_index_timer);\n+ }\n+ virtio_net_rx_notify(n);\n+ } else {\n+ if (n->rx_index_timer) {\n+ if (!timer_pending(n->rx_index_timer)) {\n+ timer_mod(n->rx_index_timer,\n+ qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + n->rx_coal_usecs);\n+ }\n+ }\n+ }\n \n return size;\n \n@@ -2818,7 +2883,6 @@ detach:\n return -EINVAL;\n }\n \n-static void virtio_net_tx_timer(void *opaque);\n \n static void virtio_net_handle_tx_timer(VirtIODevice *vdev, VirtQueue *vq)\n {\n@@ -2900,6 +2964,12 @@ static void virtio_net_tx_timer(void *opaque)\n if (ret == -EBUSY || ret == -EINVAL) {\n return;\n }\n+ if (n->tx_pkt_cnt < ret) {\n+ n->tx_pkt_cnt = 0;\n+ } else {\n+ n->tx_pkt_cnt -= ret;\n+ }\n+\n /*\n * If we flush a full burst of packets, assume there are\n * more coming and immediately rearm\n@@ -2919,6 +2989,7 @@ static void virtio_net_tx_timer(void *opaque)\n ret = virtio_net_flush_tx(q);\n if (ret > 0) {\n virtio_queue_set_notification(q->tx_vq, 0);\n+ n->tx_pkt_cnt -= ret;\n q->tx_waiting = 1;\n timer_mod(q->tx_timer,\n qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + n->tx_timeout);\n@@ -2974,6 +3045,32 @@ static void virtio_net_tx_bh(void *opaque)\n }\n }\n \n+static void virtio_net_handle_tx_dispatch(VirtIODevice *vdev, VirtQueue *vq)\n+{\n+ VirtIONet *n = VIRTIO_NET(vdev);\n+ VirtIONetQueue *q = &n->vqs[vq2q(virtio_get_queue_index(vq))];\n+ bool use_timer = n->tx_timer_activate || n->tx_coal_usecs > 0 ||\n+ n->tx_coal_packets > 0;\n+ bool pkt_limit = (n->tx_coal_packets > 0);\n+\n+ if (use_timer) {\n+ n->tx_pkt_cnt++;\n+ if (!pkt_limit || n->tx_pkt_cnt < n->tx_coal_packets) {\n+ if (q->tx_timer) {\n+ virtio_net_handle_tx_timer(vdev, vq);\n+ return;\n+ }\n+ }\n+ n->tx_pkt_cnt = 0;\n+ if (q->tx_timer) {\n+ timer_del(q->tx_timer);\n+ }\n+ virtio_net_handle_tx_bh(vdev, vq);\n+ } else {\n+ virtio_net_handle_tx_bh(vdev, vq);\n+ }\n+}\n+\n static void virtio_net_add_queue(VirtIONet *n, int index)\n {\n VirtIODevice *vdev = VIRTIO_DEVICE(n);\n@@ -2981,20 +3078,15 @@ static void virtio_net_add_queue(VirtIONet *n, int index)\n n->vqs[index].rx_vq = virtio_add_queue(vdev, n->net_conf.rx_queue_size,\n virtio_net_handle_rx);\n \n- if (n->net_conf.tx && !strcmp(n->net_conf.tx, \"timer\")) {\n- n->vqs[index].tx_vq =\n- virtio_add_queue(vdev, n->net_conf.tx_queue_size,\n- virtio_net_handle_tx_timer);\n- n->vqs[index].tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,\n- virtio_net_tx_timer,\n- &n->vqs[index]);\n- } else {\n- n->vqs[index].tx_vq =\n- virtio_add_queue(vdev, n->net_conf.tx_queue_size,\n- virtio_net_handle_tx_bh);\n- n->vqs[index].tx_bh = qemu_bh_new_guarded(virtio_net_tx_bh, &n->vqs[index],\n- &DEVICE(vdev)->mem_reentrancy_guard);\n- }\n+ n->vqs[index].tx_vq =\n+ virtio_add_queue(vdev,\n+ n->net_conf.tx_queue_size,\n+ virtio_net_handle_tx_dispatch);\n+\n+ n->vqs[index].tx_bh =\n+ qemu_bh_new_guarded(virtio_net_tx_bh,\n+ &n->vqs[index],\n+ &DEVICE(vdev)->mem_reentrancy_guard);\n \n n->vqs[index].tx_waiting = 0;\n n->vqs[index].n = n;\n@@ -3972,6 +4064,10 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)\n error_printf(\"Defaulting to \\\"bh\\\"\");\n }\n \n+ if (n->net_conf.tx && strcmp(n->net_conf.tx, \"timer\")) {\n+ n->tx_timer_activate = true;\n+ }\n+\n n->net_conf.tx_queue_size = MIN(virtio_net_max_tx_queue_size(n),\n n->net_conf.tx_queue_size);\n \n@@ -4048,6 +4144,13 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)\n n->rss_data.specified_hash_types.on_bits |\n n->rss_data.specified_hash_types.auto_bits;\n }\n+ n->rx_pkt_cnt = 0;\n+ n->tx_pkt_cnt = 0;\n+ n->rx_coal_usecs = 0;\n+ n->tx_coal_usecs = 0;\n+ n->rx_coal_packets = 0;\n+ n->tx_coal_packets = 0;\n+ n->rx_index_timer = NULL;\n }\n \n static void virtio_net_device_unrealize(DeviceState *dev)\n@@ -4262,6 +4365,8 @@ static const Property virtio_net_properties[] = {\n VIRTIO_NET_F_GUEST_USO6, true),\n DEFINE_PROP_BIT64(\"host_uso\", VirtIONet, host_features,\n VIRTIO_NET_F_HOST_USO, true),\n+ DEFINE_PROP_BIT64(\"vq_notf_coal\", VirtIONet, host_features,\n+ VIRTIO_NET_F_NOTF_COAL, true),\n DEFINE_PROP_ON_OFF_AUTO_BIT64(\"hash-ipv4\", VirtIONet,\n rss_data.specified_hash_types,\n VIRTIO_NET_HASH_REPORT_IPv4 - 1,\ndiff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h\nindex 5b8ab7bda7..024501ed37 100644\n--- a/include/hw/virtio/virtio-net.h\n+++ b/include/hw/virtio/virtio-net.h\n@@ -231,6 +231,14 @@ struct VirtIONet {\n struct EBPFRSSContext ebpf_rss;\n uint32_t nr_ebpf_rss_fds;\n char **ebpf_rss_fds;\n+ QEMUTimer *rx_index_timer;\n+ uint32_t rx_coal_usecs;\n+ uint32_t rx_coal_packets;\n+ uint32_t rx_pkt_cnt;\n+ uint32_t tx_coal_usecs;\n+ uint32_t tx_coal_packets;\n+ uint32_t tx_pkt_cnt;\n+ bool tx_timer_activate;\n };\n \n size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev,\ndiff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c\nindex 3df6091274..a20db78b81 100644\n--- a/net/vhost-vdpa.c\n+++ b/net/vhost-vdpa.c\n@@ -70,6 +70,7 @@ static const int vdpa_feature_bits[] = {\n VIRTIO_NET_F_CTRL_RX,\n VIRTIO_NET_F_CTRL_RX_EXTRA,\n VIRTIO_NET_F_CTRL_VLAN,\n+ VIRTIO_NET_F_NOTF_COAL,\n VIRTIO_NET_F_CTRL_VQ,\n VIRTIO_NET_F_GSO,\n VIRTIO_NET_F_GUEST_CSUM,\n@@ -115,6 +116,7 @@ static const uint64_t vdpa_svq_device_features =\n BIT_ULL(VIRTIO_NET_F_HOST_UFO) |\n BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) |\n BIT_ULL(VIRTIO_NET_F_STATUS) |\n+ BIT_ULL(VIRTIO_NET_F_NOTF_COAL) |\n BIT_ULL(VIRTIO_NET_F_CTRL_VQ) |\n BIT_ULL(VIRTIO_NET_F_GSO) |\n BIT_ULL(VIRTIO_NET_F_CTRL_RX) |\n", "prefixes": [ "v4" ] }