From patchwork Thu Sep 9 06:58:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, YuanX" X-Patchwork-Id: 98409 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9DD13A0547; Thu, 9 Sep 2021 09:11:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 871C1406B4; Thu, 9 Sep 2021 09:11:46 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id C7AFC4003E for ; Thu, 9 Sep 2021 09:11:45 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10101"; a="306271621" X-IronPort-AV: E=Sophos;i="5.85,279,1624345200"; d="scan'208";a="306271621" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2021 00:11:44 -0700 X-IronPort-AV: E=Sophos;i="5.85,279,1624345200"; d="scan'208";a="504099068" Received: from unknown (HELO localhost.localdomain) ([10.240.183.50]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2021 00:11:40 -0700 From: Yuan Wang To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, chenbo.xia@intel.com, Sunil.Pai.G@intel.com, jiayu.hu@intel.com, xuan.ding@intel.com, cheng1.jiang@intel.com, wenwux.ma@intel.com, yvonnex.yang@intel.com, Yuan Wang Date: Thu, 9 Sep 2021 06:58:06 +0000 Message-Id: <20210909065807.812145-2-yuanx.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210909065807.812145-1-yuanx.wang@intel.com> References: <20210909065807.812145-1-yuanx.wang@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/2] vhost: support to clear in-flight packets for async dequeue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" rte_vhost_clear_queue_thread_unsafe() supports to clear in-flight packets for async enqueue only. But after supporting async dequeue, this API should support async dequeue too. Signed-off-by: Yuan Wang Tested-by: Yvonne Yang --- lib/vhost/virtio_net.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index e0159b53e3..7f6183a929 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -27,6 +27,11 @@ #define VHOST_ASYNC_BATCH_THRESHOLD 32 +static __rte_always_inline uint16_t +async_poll_dequeue_completed_split(struct virtio_net *dev, + struct vhost_virtqueue *vq, uint16_t queue_id, + struct rte_mbuf **pkts, uint16_t count, bool legacy_ol_flags); + static __rte_always_inline bool rxvq_is_mergeable(struct virtio_net *dev) { @@ -2119,11 +2124,6 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id, return 0; VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__); - if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->nr_vring))) { - VHOST_LOG_DATA(ERR, "(%d) %s: invalid virtqueue idx %d.\n", - dev->vid, __func__, queue_id); - return 0; - } vq = dev->virtqueue[queue_id]; @@ -2133,7 +2133,11 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id, return 0; } - n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count); + if ((queue_id % 2) == 0) + n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count); + else + n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id, pkts, count, + dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS); return n_pkts_cpl; } From patchwork Thu Sep 9 06:58:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, YuanX" X-Patchwork-Id: 98410 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 28725A0547; Thu, 9 Sep 2021 09:12:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 161BB406B4; Thu, 9 Sep 2021 09:12:43 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id D48A34003E for ; Thu, 9 Sep 2021 09:12:40 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10101"; a="220387038" X-IronPort-AV: E=Sophos;i="5.85,279,1624345200"; d="scan'208";a="220387038" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2021 00:12:40 -0700 X-IronPort-AV: E=Sophos;i="5.85,279,1624345200"; d="scan'208";a="504099377" Received: from unknown (HELO localhost.localdomain) ([10.240.183.50]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2021 00:12:36 -0700 From: Yuan Wang To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, chenbo.xia@intel.com, Sunil.Pai.G@intel.com, jiayu.hu@intel.com, xuan.ding@intel.com, cheng1.jiang@intel.com, wenwux.ma@intel.com, yvonnex.yang@intel.com, Yuan Wang Date: Thu, 9 Sep 2021 06:58:07 +0000 Message-Id: <20210909065807.812145-3-yuanx.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210909065807.812145-1-yuanx.wang@intel.com> References: <20210909065807.812145-1-yuanx.wang@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 2/2] vhost: support thread-safe API for clearing in-flight packets in async vhost X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds thread-safe version for clearing in-flight packets function. Signed-off-by: Yuan Wang Tested-by: Yvonne Yang --- lib/vhost/rte_vhost_async.h | 21 +++++++++++++++++++++ lib/vhost/version.map | 1 + lib/vhost/virtio_net.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index 5e2429ab70..a418e0a03d 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h @@ -261,6 +261,27 @@ int rte_vhost_async_get_inflight(int vid, uint16_t queue_id); __rte_experimental uint16_t rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count); + +/** + * This function checks async completion status and clear packets for + * a specific vhost device queue. Packets which are inflight will be + * returned in an array. + * + * @param vid + * ID of vhost device to clear data + * @param queue_id + * Queue id to clear data + * @param pkts + * Blank array to get return packet pointer + * @param count + * Size of the packet array + * @return + * Number of packets returned + */ +__rte_experimental +uint16_t rte_vhost_clear_queue(int vid, uint16_t queue_id, + struct rte_mbuf **pkts, uint16_t count); + /** * This function tries to receive packets from the guest with offloading * copies to the async channel. The packets that are transfer completed diff --git a/lib/vhost/version.map b/lib/vhost/version.map index 3d566a6d5f..f78cc89b58 100644 --- a/lib/vhost/version.map +++ b/lib/vhost/version.map @@ -88,4 +88,5 @@ EXPERIMENTAL { # added in 21.11 rte_vhost_async_try_dequeue_burst; + rte_vhost_clear_queue; }; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 7f6183a929..51693a7c35 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -2142,6 +2142,42 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id, return n_pkts_cpl; } +uint16_t +rte_vhost_clear_queue(int vid, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count) +{ + struct virtio_net *dev = get_device(vid); + struct vhost_virtqueue *vq; + uint16_t n_pkts_cpl; + + if (!dev) + return 0; + + VHOST_LOG_DATA(DEBUG, "(%d) %s\n", dev->vid, __func__); + + vq = dev->virtqueue[queue_id]; + + if (unlikely(!vq->async_registered)) { + VHOST_LOG_DATA(ERR, "(%d) %s: async not registered for queue id %d.\n", + dev->vid, __func__, queue_id); + return 0; + } + + if (!rte_spinlock_trylock(&vq->access_lock)) { + VHOST_LOG_CONFIG(ERR, "Failed to clear async queue, virt queue busy.\n"); + return 0; + } + + if ((queue_id % 2) == 0) + n_pkts_cpl = vhost_poll_enqueue_completed(dev, queue_id, pkts, count); + else + n_pkts_cpl = async_poll_dequeue_completed_split(dev, vq, queue_id, pkts, count, + dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS); + + rte_spinlock_unlock(&vq->access_lock); + + return n_pkts_cpl; +} + static __rte_always_inline uint32_t virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id, struct rte_mbuf **pkts, uint32_t count)