From nobody Sat Apr 27 16:16:25 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660837107639589.5959819062333; Thu, 18 Aug 2022 08:38:27 -0700 (PDT) Received: from localhost ([::1]:36488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOhbG-0000me-Am for importer2@patchew.org; Thu, 18 Aug 2022 11:38:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOhK3-00019J-1W for qemu-devel@nongnu.org; Thu, 18 Aug 2022 11:20:39 -0400 Received: from smtp236.sjtu.edu.cn ([202.120.2.236]:47488) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOhK0-00008W-HQ for qemu-devel@nongnu.org; Thu, 18 Aug 2022 11:20:38 -0400 Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 4C5FE1008B391; Thu, 18 Aug 2022 23:13:00 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 780512391A011; Thu, 18 Aug 2022 23:13:00 +0800 (CST) Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id qSkmh4vJ0xkC; Thu, 18 Aug 2022 23:13:00 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id A90832391A010; Thu, 18 Aug 2022 23:12:51 +0800 (CST) X-Virus-Scanned: amavisd-new at From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: qemu-devel@nongnu.org, Guo Zhi Subject: [RFC 1/2] virtio: expose used buffers Date: Thu, 18 Aug 2022 23:12:43 +0800 Message-Id: <20220818151244.2050-2-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220818151244.2050-1-qtxuning1999@sjtu.edu.cn> References: <20220818151244.2050-1-qtxuning1999@sjtu.edu.cn> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=202.120.2.236; envelope-from=qtxuning1999@sjtu.edu.cn; helo=smtp236.sjtu.edu.cn X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1660837108293100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Follow VIRTIO 1.1 spec, we can only writing out a single used ring for a batch of descriptors, and only notify guest when the batch of descriptors have all been used. We do that batch for tx, because the driver doesn't need to know the length of tx buffer, while for rx, we don't apply the batch strategy. Signed-off-by: Guo Zhi --- hw/net/virtio-net.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index dd0d056f..c8e83921 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2542,8 +2542,10 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) VirtIONet *n =3D q->n; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); VirtQueueElement *elem; + VirtQueueElement *elems[VIRTQUEUE_MAX_SIZE]; int32_t num_packets =3D 0; int queue_index =3D vq2q(virtio_get_queue_index(q->tx_vq)); + size_t j; if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { return num_packets; } @@ -2621,14 +2623,35 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *= q) } =20 drop: - virtqueue_push(q->tx_vq, elem, 0); - virtio_notify(vdev, q->tx_vq); - g_free(elem); + if (!virtio_vdev_has_feature(vdev, VIRTIO_F_IN_ORDER)) { + virtqueue_push(q->tx_vq, elem, 0); + virtio_notify(vdev, q->tx_vq); + g_free(elem); + } else { + elems[num_packets] =3D elem; + } =20 if (++num_packets >=3D n->tx_burst) { break; } } + + if (virtio_vdev_has_feature(vdev, VIRTIO_F_IN_ORDER) && num_packets) { + /** + * If in order feature negotiated, devices can notify the use of a= batch + * of buffers to the driver by only writing out a single used ring= entry + * with the id corresponding to the head entry of the descriptor c= hain + * describing the last buffer in the batch. + */ + virtqueue_fill(q->tx_vq, elems[num_packets - 1], 0, 0); + for (j =3D 0; j < num_packets; j++) { + g_free(elems[j]); + } + + virtqueue_flush(q->tx_vq, num_packets); + virtio_notify(vdev, q->tx_vq); + } + return num_packets; } =20 --=20 2.17.1 From nobody Sat Apr 27 16:16:25 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660837705944238.79583785861132; Thu, 18 Aug 2022 08:48:25 -0700 (PDT) Received: from localhost ([::1]:36378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOhkt-0001Gy-GC for importer2@patchew.org; Thu, 18 Aug 2022 11:48:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOhKb-0001u1-3G for qemu-devel@nongnu.org; Thu, 18 Aug 2022 11:21:13 -0400 Received: from smtp236.sjtu.edu.cn ([202.120.2.236]:35570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOhKZ-0000PO-32 for qemu-devel@nongnu.org; Thu, 18 Aug 2022 11:21:12 -0400 Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp236.sjtu.edu.cn (Postfix) with ESMTPS id 379FB1008B392; Thu, 18 Aug 2022 23:13:10 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id 7874C2391A025; Thu, 18 Aug 2022 23:13:10 +0800 (CST) Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id U7xg1c3srkZN; Thu, 18 Aug 2022 23:13:10 +0800 (CST) Received: from localhost.localdomain (unknown [202.120.40.82]) (Authenticated sender: qtxuning1999@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id CD8B32391A010; Thu, 18 Aug 2022 23:13:00 +0800 (CST) X-Virus-Scanned: amavisd-new at From: Guo Zhi To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com, mst@redhat.com Cc: qemu-devel@nongnu.org, Guo Zhi Subject: [RFC 2/2] virtio: enable f_in_order feature for virtio-net Date: Thu, 18 Aug 2022 23:12:44 +0800 Message-Id: <20220818151244.2050-3-qtxuning1999@sjtu.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220818151244.2050-1-qtxuning1999@sjtu.edu.cn> References: <20220818151244.2050-1-qtxuning1999@sjtu.edu.cn> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=202.120.2.236; envelope-from=qtxuning1999@sjtu.edu.cn; helo=smtp236.sjtu.edu.cn X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1660837707502100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In order feature is not a transparent feature in QEMU, only specific devices(eg, virtio-net) support it. Signed-off-by: Guo Zhi --- hw/net/virtio-net.c | 1 + include/hw/virtio/virtio.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index c8e83921..cf0b23d8 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -719,6 +719,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *v= dev, uint64_t features, features |=3D n->host_features; =20 virtio_add_feature(&features, VIRTIO_NET_F_MAC); + virtio_add_feature(&features, VIRTIO_F_IN_ORDER); =20 if (!peer_has_vnet_hdr(n)) { virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index db1c0ddf..578f22c8 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -291,7 +291,9 @@ typedef struct VirtIORNGConf VirtIORNGConf; DEFINE_PROP_BIT64("iommu_platform", _state, _field, \ VIRTIO_F_IOMMU_PLATFORM, false), \ DEFINE_PROP_BIT64("packed", _state, _field, \ - VIRTIO_F_RING_PACKED, false) + VIRTIO_F_RING_PACKED, false), \ + DEFINE_PROP_BIT64("in_order", _state, _field, \ + VIRTIO_F_IN_ORDER, false) =20 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n); bool virtio_queue_enabled_legacy(VirtIODevice *vdev, int n); --=20 2.17.1