From patchwork Fri Apr 8 10:22:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ding, Xuan" X-Patchwork-Id: 109516 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 28FB8A0501; Fri, 8 Apr 2022 12:22:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 65A2940E64; Fri, 8 Apr 2022 12:22:24 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 4BE0D40E64 for ; Fri, 8 Apr 2022 12:22:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649413342; x=1680949342; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=h/Le2fHB2piPMWKhU6nK1FGjEVZNUsTG//OPsPzidRI=; b=YuEOj0Q6Ojc0BX0GbCbNhKyVl4Azdjcfyul7OhvD8EU/SXtnCJ6wM1Dq BnNnCCpWuUNVQGDM5Z1AwdS4W77gZ0/EEg8VTukbyIrFZon4m60V668oP 6FXQXTWatsCU+AqWDlEZ40RUsziTul1TAosNuPvLhaYkQIAhPOJfC+ldW 1rLfByPFMZ70wboh6Php2hTgZw+W5e8+h3Bl/mVg9S5FqmKUFqijUIldO ghEdQqi+wqUNNbcDVJjDiu5F86ouFaaci/l30BF/0OxNKMXqz7ivea6/L V1nnRHCuubO9tqgynqUchpMjoNE1hBrf9waC32WInZxBRO4mbWrBHhvKi A==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="261253244" X-IronPort-AV: E=Sophos;i="5.90,244,1643702400"; d="scan'208";a="261253244" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 03:22:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,244,1643702400"; d="scan'208";a="525324785" Received: from npg-dpdk-xuan-cbdma.sh.intel.com ([10.67.110.228]) by orsmga006.jf.intel.com with ESMTP; 08 Apr 2022 03:22:19 -0700 From: xuan.ding@intel.com To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, jiayu.hu@intel.com, cheng1.jiang@intel.com, sunil.pai.g@intel.com, Xuan Ding Subject: [PATCH v1 1/2] vhost: add unsafe API to check inflight packets Date: Fri, 8 Apr 2022 10:22:13 +0000 Message-Id: <20220408102214.11994-2-xuan.ding@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220408102214.11994-1-xuan.ding@intel.com> References: <20220408102214.11994-1-xuan.ding@intel.com> 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 From: Xuan Ding In async data path, when vring state changes or device is destroyed, it is necessary to know the number of inflight packets in DMA engine. This patch provides a thread unsafe API to return the number of inflight packets for a vhost queue without using any lock. Signed-off-by: Xuan Ding Reviewed-by: Maxime Coquelin --- doc/guides/prog_guide/vhost_lib.rst | 6 ++++++ doc/guides/rel_notes/release_22_07.rst | 4 ++++ lib/vhost/rte_vhost_async.h | 17 +++++++++++++++++ lib/vhost/version.map | 4 ++++ lib/vhost/vhost.c | 26 ++++++++++++++++++++++++++ 5 files changed, 57 insertions(+) diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst index 886f8f5e72..f287b76ebf 100644 --- a/doc/guides/prog_guide/vhost_lib.rst +++ b/doc/guides/prog_guide/vhost_lib.rst @@ -271,6 +271,12 @@ The following is an overview of some key Vhost API functions: This function returns the amount of in-flight packets for the vhost queue using async acceleration. + * ``rte_vhost_async_get_inflight_thread_unsafe(vid, queue_id)`` + + Get the number of inflight packets for a vhost queue without performing + any locking. It should only be used within the vhost ops, which already + holds the lock. + * ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count, dma_id, vchan_id)`` Clear inflight packets which are submitted to DMA engine in vhost async data diff --git a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst index 42a5f2d990..a0c5d9459b 100644 --- a/doc/guides/rel_notes/release_22_07.rst +++ b/doc/guides/rel_notes/release_22_07.rst @@ -55,6 +55,10 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added vhost API to get the number of inflight packets.** + + Added an API which can get the number of inflight packets in + vhost async data path without using lock. Removed Items ------------- diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index f1293c6a9d..70234debf9 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h @@ -139,6 +139,23 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id, __rte_experimental int rte_vhost_async_get_inflight(int vid, uint16_t queue_id); +/** + * This function is lock-free version to return the amount of in-flight + * packets for the vhost queue which uses async channel acceleration. + * + * @note This function does not perform any locking, it should only be + * used within the vhost ops, which already holds the lock. + * + * @param vid + * id of vhost device to enqueue data + * @param queue_id + * queue id to enqueue data + * @return + * the amount of in-flight packets on success; -1 on failure + */ +__rte_experimental +int rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id); + /** * This function checks async completion status and clear packets for * a specific vhost device queue. Packets which are inflight will be diff --git a/lib/vhost/version.map b/lib/vhost/version.map index 0a66c5840c..5841315386 100644 --- a/lib/vhost/version.map +++ b/lib/vhost/version.map @@ -87,6 +87,10 @@ EXPERIMENTAL { # added in 22.03 rte_vhost_async_dma_configure; + + # added in 22.07 + rte_vhost_async_get_inflight_thread_unsafe; + }; INTERNAL { diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 2f96a28dac..df0bb9d043 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1907,6 +1907,32 @@ rte_vhost_async_get_inflight(int vid, uint16_t queue_id) return ret; } +int +rte_vhost_async_get_inflight_thread_unsafe(int vid, uint16_t queue_id) +{ + struct vhost_virtqueue *vq; + struct virtio_net *dev = get_device(vid); + int ret = -1; + + if (dev == NULL) + return ret; + + if (queue_id >= VHOST_MAX_VRING) + return ret; + + vq = dev->virtqueue[queue_id]; + + if (vq == NULL) + return ret; + + if (!vq->async) + return ret; + + ret = vq->async->pkts_inflight_n; + + return ret; +} + int rte_vhost_get_monitor_addr(int vid, uint16_t queue_id, struct rte_vhost_power_monitor_cond *pmc) From patchwork Fri Apr 8 10:22:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ding, Xuan" X-Patchwork-Id: 109517 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 34CA6A0501; Fri, 8 Apr 2022 12:22:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 48FFE427EA; Fri, 8 Apr 2022 12:22:27 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 50DD3427EA for ; Fri, 8 Apr 2022 12:22:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649413345; x=1680949345; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=x3DbmVq+HWyhjHstE4XuTaXEllR1ttB2rsVet2NyoRI=; b=Bv+ningMtsfj70+CEVVTQpeoFvgy230n2JEEsKZ1U3qDdA60bQFjRXHx 0M26LBqPhJoC4nNjg0J0ljfVaGHGrwz2NxcXPuuoWkmbgLZ9R1gFx3MUj lvGbQhvCWYvm05MxvyTkJSBAawbmmsQYX+IqJaSO2kCQnhZDYacb7Yuv8 O/XQfZJXrRm25f1ieI02azobJUR9kZjHbZtuhF8lp1OMFqE3iA+V7CF1P vzuVZrbgy2yCbHTP8CFQAeu3HSDKjE6SibYbrSMU/Q7diQCR7hXKoAI+U 8fXc/i7vpOcMj2HTELqPbrIZJW5TyuHSG/o3WwKM4z6rAwDD7TbayD8Ls A==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="261253253" X-IronPort-AV: E=Sophos;i="5.90,244,1643702400"; d="scan'208";a="261253253" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2022 03:22:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,244,1643702400"; d="scan'208";a="525324795" Received: from npg-dpdk-xuan-cbdma.sh.intel.com ([10.67.110.228]) by orsmga006.jf.intel.com with ESMTP; 08 Apr 2022 03:22:22 -0700 From: xuan.ding@intel.com To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, jiayu.hu@intel.com, cheng1.jiang@intel.com, sunil.pai.g@intel.com, Xuan Ding Subject: [PATCH v1 2/2] examples/vhost: use API to check inflight packets Date: Fri, 8 Apr 2022 10:22:14 +0000 Message-Id: <20220408102214.11994-3-xuan.ding@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220408102214.11994-1-xuan.ding@intel.com> References: <20220408102214.11994-1-xuan.ding@intel.com> 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 From: Xuan Ding In async data path, call rte_vhost_async_get_inflight_thread_unsafe() API to directly return the number of inflight packets instead of maintaining a local variable. Signed-off-by: Xuan Ding Reviewed-by: Maxime Coquelin --- examples/vhost/main.c | 28 +++++++++++++++------------- examples/vhost/main.h | 1 - 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index d94fabb060..c4d46de1c5 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -994,10 +994,8 @@ complete_async_pkts(struct vhost_dev *vdev) complete_count = rte_vhost_poll_enqueue_completed(vdev->vid, VIRTIO_RXQ, p_cpl, MAX_PKT_BURST, dma_id, 0); - if (complete_count) { + if (complete_count) free_pkts(p_cpl, complete_count); - __atomic_sub_fetch(&vdev->pkts_inflight, complete_count, __ATOMIC_SEQ_CST); - } } @@ -1039,7 +1037,6 @@ drain_vhost(struct vhost_dev *vdev) complete_async_pkts(vdev); ret = rte_vhost_submit_enqueue_burst(vdev->vid, VIRTIO_RXQ, m, nr_xmit, dma_id, 0); - __atomic_add_fetch(&vdev->pkts_inflight, ret, __ATOMIC_SEQ_CST); enqueue_fail = nr_xmit - ret; if (enqueue_fail) @@ -1368,7 +1365,6 @@ drain_eth_rx(struct vhost_dev *vdev) complete_async_pkts(vdev); enqueue_count = rte_vhost_submit_enqueue_burst(vdev->vid, VIRTIO_RXQ, pkts, rx_count, dma_id, 0); - __atomic_add_fetch(&vdev->pkts_inflight, enqueue_count, __ATOMIC_SEQ_CST); enqueue_fail = rx_count - enqueue_count; if (enqueue_fail) @@ -1540,14 +1536,17 @@ destroy_device(int vid) if (dma_bind[vid].dmas[VIRTIO_RXQ].async_enabled) { uint16_t n_pkt = 0; + int pkts_inflight; int16_t dma_id = dma_bind[vid].dmas[VIRTIO_RXQ].dev_id; - struct rte_mbuf *m_cpl[vdev->pkts_inflight]; + pkts_inflight = rte_vhost_async_get_inflight_thread_unsafe(vid, VIRTIO_RXQ); + struct rte_mbuf *m_cpl[pkts_inflight]; - while (vdev->pkts_inflight) { + while (pkts_inflight) { n_pkt = rte_vhost_clear_queue_thread_unsafe(vid, VIRTIO_RXQ, - m_cpl, vdev->pkts_inflight, dma_id, 0); + m_cpl, pkts_inflight, dma_id, 0); free_pkts(m_cpl, n_pkt); - __atomic_sub_fetch(&vdev->pkts_inflight, n_pkt, __ATOMIC_SEQ_CST); + pkts_inflight = rte_vhost_async_get_inflight_thread_unsafe(vid, + VIRTIO_RXQ); } rte_vhost_async_channel_unregister(vid, VIRTIO_RXQ); @@ -1651,14 +1650,17 @@ vring_state_changed(int vid, uint16_t queue_id, int enable) if (dma_bind[vid].dmas[queue_id].async_enabled) { if (!enable) { uint16_t n_pkt = 0; + int pkts_inflight; + pkts_inflight = rte_vhost_async_get_inflight_thread_unsafe(vid, queue_id); int16_t dma_id = dma_bind[vid].dmas[VIRTIO_RXQ].dev_id; - struct rte_mbuf *m_cpl[vdev->pkts_inflight]; + struct rte_mbuf *m_cpl[pkts_inflight]; - while (vdev->pkts_inflight) { + while (pkts_inflight) { n_pkt = rte_vhost_clear_queue_thread_unsafe(vid, queue_id, - m_cpl, vdev->pkts_inflight, dma_id, 0); + m_cpl, pkts_inflight, dma_id, 0); free_pkts(m_cpl, n_pkt); - __atomic_sub_fetch(&vdev->pkts_inflight, n_pkt, __ATOMIC_SEQ_CST); + pkts_inflight = rte_vhost_async_get_inflight_thread_unsafe(vid, + queue_id); } } } diff --git a/examples/vhost/main.h b/examples/vhost/main.h index b4a453e77e..e7f395c3c9 100644 --- a/examples/vhost/main.h +++ b/examples/vhost/main.h @@ -52,7 +52,6 @@ struct vhost_dev { uint64_t features; size_t hdr_len; uint16_t nr_vrings; - uint16_t pkts_inflight; struct rte_vhost_memory *mem; struct device_statistics stats; TAILQ_ENTRY(vhost_dev) global_vdev_entry;