From patchwork Tue Sep 28 15:55:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ding, Xuan" X-Patchwork-Id: 99934 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 519D5A0C41; Tue, 28 Sep 2021 18:05:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6C2D5410DF; Tue, 28 Sep 2021 18:05:47 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id A5F3E40E3C for ; Tue, 28 Sep 2021 18:05:45 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10121"; a="288400281" X-IronPort-AV: E=Sophos;i="5.85,329,1624345200"; d="scan'208";a="288400281" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 09:03:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,329,1624345200"; d="scan'208";a="519097277" Received: from dpdk-xuanding-dev2.sh.intel.com ([10.67.119.250]) by fmsmga008.fm.intel.com with ESMTP; 28 Sep 2021 09:03:05 -0700 From: Xuan Ding To: dev@dpdk.org, maxime.coquelin@redhat.com, chenbo.xia@intel.com, ktraynor@redhat.com Cc: jiayu.hu@intel.com, cheng1.jiang@intel.com, bruce.richardson@intel.com, sunil.pai.g@intel.com, yinan.wang@intel.com, YvonneX.Yang@intel.com, Xuan Ding Date: Tue, 28 Sep 2021 15:55:08 +0000 Message-Id: <20210928155509.73762-2-xuan.ding@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210928155509.73762-1-xuan.ding@intel.com> References: <20210909055758.106588-1-xuan.ding@intel.com> <20210928155509.73762-1-xuan.ding@intel.com> Subject: [dpdk-dev] [PATCH v6 1/2] vhost: add unsafe API to check inflight packets 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" 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 --- doc/guides/prog_guide/vhost_lib.rst | 5 +++++ doc/guides/rel_notes/release_21_11.rst | 5 +++++ lib/vhost/rte_vhost_async.h | 14 ++++++++++++++ lib/vhost/version.map | 3 +++ lib/vhost/vhost.c | 26 ++++++++++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst index 171e0096f6..73a4e24640 100644 --- a/doc/guides/prog_guide/vhost_lib.rst +++ b/doc/guides/prog_guide/vhost_lib.rst @@ -298,6 +298,11 @@ 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. + * ``rte_vhost_clear_queue_thread_unsafe(vid, queue_id, **pkts, count)`` Clear inflight packets which are submitted to DMA engine in vhost async data diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index ad7c1afec0..fd821b29d3 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -55,6 +55,11 @@ 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. + * **Enabled new devargs parser.** * Enabled devargs syntax diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index ad71555a7f..1f0708378b 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h @@ -234,6 +234,20 @@ 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. + * + * @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 8ebde3f694..ed6cb53a99 100644 --- a/lib/vhost/version.map +++ b/lib/vhost/version.map @@ -85,4 +85,7 @@ EXPERIMENTAL { rte_vhost_async_channel_register_thread_unsafe; rte_vhost_async_channel_unregister_thread_unsafe; rte_vhost_clear_queue_thread_unsafe; + + #added in 21.11 + rte_vhost_async_get_inflight_thread_unsafe; }; diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 996287c3c2..c16c6bc2bb 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1884,5 +1884,31 @@ int 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_registered) + return ret; + + ret = vq->async_pkts_inflight_n; + + return ret; +} + RTE_LOG_REGISTER_SUFFIX(vhost_config_log_level, config, INFO); RTE_LOG_REGISTER_SUFFIX(vhost_data_log_level, data, WARNING); From patchwork Tue Sep 28 15:55:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ding, Xuan" X-Patchwork-Id: 99935 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 03F4EA0C41; Tue, 28 Sep 2021 18:06:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E310E410E6; Tue, 28 Sep 2021 18:06:02 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id CF8D2410E5 for ; Tue, 28 Sep 2021 18:06:00 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10121"; a="288400355" X-IronPort-AV: E=Sophos;i="5.85,329,1624345200"; d="scan'208";a="288400355" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 09:03:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,329,1624345200"; d="scan'208";a="519097323" Received: from dpdk-xuanding-dev2.sh.intel.com ([10.67.119.250]) by fmsmga008.fm.intel.com with ESMTP; 28 Sep 2021 09:03:10 -0700 From: Xuan Ding To: dev@dpdk.org, maxime.coquelin@redhat.com, chenbo.xia@intel.com, ktraynor@redhat.com Cc: jiayu.hu@intel.com, cheng1.jiang@intel.com, bruce.richardson@intel.com, sunil.pai.g@intel.com, yinan.wang@intel.com, YvonneX.Yang@intel.com, Xuan Ding Date: Tue, 28 Sep 2021 15:55:09 +0000 Message-Id: <20210928155509.73762-3-xuan.ding@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210928155509.73762-1-xuan.ding@intel.com> References: <20210909055758.106588-1-xuan.ding@intel.com> <20210928155509.73762-1-xuan.ding@intel.com> Subject: [dpdk-dev] [PATCH v6 2/2] examples/vhost: use API to check inflight packets 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" 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 --- examples/vhost/main.c | 31 +++++++++++++++++-------------- examples/vhost/main.h | 1 - 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index d0bf1f31e3..7a5d97cef6 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -842,11 +842,8 @@ complete_async_pkts(struct vhost_dev *vdev) complete_count = rte_vhost_poll_enqueue_completed(vdev->vid, VIRTIO_RXQ, p_cpl, MAX_PKT_BURST); - if (complete_count) { + if (complete_count) free_pkts(p_cpl, complete_count); - __atomic_sub_fetch(&vdev->pkts_inflight, complete_count, __ATOMIC_SEQ_CST); - } - } static __rte_always_inline void @@ -886,7 +883,6 @@ drain_vhost(struct vhost_dev *vdev) complete_async_pkts(vdev); ret = rte_vhost_submit_enqueue_burst(vdev->vid, VIRTIO_RXQ, m, nr_xmit); - __atomic_add_fetch(&vdev->pkts_inflight, ret, __ATOMIC_SEQ_CST); enqueue_fail = nr_xmit - ret; if (enqueue_fail) @@ -1212,7 +1208,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); - __atomic_add_fetch(&vdev->pkts_inflight, enqueue_count, __ATOMIC_SEQ_CST); enqueue_fail = rx_count - enqueue_count; if (enqueue_fail) @@ -1384,13 +1379,17 @@ destroy_device(int vid) if (async_vhost_driver) { uint16_t n_pkt = 0; - struct rte_mbuf *m_cpl[vdev->pkts_inflight]; + int pkts_inflight; - while (vdev->pkts_inflight) { + pkts_inflight = rte_vhost_async_get_inflight_thread_unsafe(vid, VIRTIO_RXQ); + struct rte_mbuf *m_cpl[pkts_inflight]; + + while (pkts_inflight) { n_pkt = rte_vhost_clear_queue_thread_unsafe(vid, VIRTIO_RXQ, - m_cpl, vdev->pkts_inflight); + m_cpl, pkts_inflight); 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); @@ -1500,13 +1499,17 @@ vring_state_changed(int vid, uint16_t queue_id, int enable) if (async_vhost_driver) { if (!enable) { uint16_t n_pkt = 0; - struct rte_mbuf *m_cpl[vdev->pkts_inflight]; + int pkts_inflight; + + pkts_inflight = rte_vhost_async_get_inflight_thread_unsafe(vid, queue_id); + 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); + m_cpl, pkts_inflight); 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 e7b1ac60a6..0ccdce4b4a 100644 --- a/examples/vhost/main.h +++ b/examples/vhost/main.h @@ -51,7 +51,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;