From patchwork Sun Aug 14 14:04:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ding, Xuan" X-Patchwork-Id: 114950 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 6D85DA0548; Sun, 14 Aug 2022 16:05:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 580D2410E5; Sun, 14 Aug 2022 16:05:20 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id 947464113C for ; Sun, 14 Aug 2022 16:05:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660485918; x=1692021918; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=BX8DtoJvN5XSaz5g8rXqPmADEwgY79/9SvDIF3DH26w=; b=B9I6mOu3SS162F2dnxSb+O/wVt4qv0yFbkklAGZOrGe5tlBEcuBzSOdc PdjzWyqyE8wEAxhLRRp82svIr8LcXJ+3sz5WKdJD+2hY8+8PMECh/mk2m OTit6hu8bxMergICVHHaFld99LLcOF0JP8dN9Jb1h7iiDATxY0qM+bN6C 7HUuBH65UWT4CLwHYtl0ZQA7SBNR6luxPmKSPJ5sSfhhQbWF7UvEnnQN+ UKSk5fW+l+MD3Cy2PDCb8W2G3MYZJrvhH3w99zgQ3mbtJNl9E34vdZBIM m3NbVuNOr6w7bWJ6l6ZfPXGWZUAFTmP0M/9kbVGUgyAhWNto4FT4dtTzg w==; X-IronPort-AV: E=McAfee;i="6400,9594,10439"; a="272221091" X-IronPort-AV: E=Sophos;i="5.93,236,1654585200"; d="scan'208";a="272221091" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2022 07:04:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,236,1654585200"; d="scan'208";a="582597587" Received: from npg-dpdk-xuan-cbdma.sh.intel.com ([10.67.111.163]) by orsmga006.jf.intel.com with ESMTP; 14 Aug 2022 07:04:56 -0700 From: xuan.ding@intel.com To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, jiayu.hu@intel.com, xingguang.he@intel.com, yvonnex.yang@intel.com, cheng1.jiang@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, Xuan Ding Subject: [PATCH v1 1/2] vhost: introduce DMA vchannel unconfiguration Date: Sun, 14 Aug 2022 14:04:41 +0000 Message-Id: <20220814140442.82525-2-xuan.ding@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220814140442.82525-1-xuan.ding@intel.com> References: <20220814140442.82525-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 This patch adds a new API rte_vhost_async_dma_unconfigure() to unconfigure DMA vchannels in vhost async data path. Signed-off-by: Xuan Ding --- doc/guides/prog_guide/vhost_lib.rst | 5 ++++ doc/guides/rel_notes/release_22_11.rst | 2 ++ lib/vhost/rte_vhost_async.h | 17 ++++++++++++ lib/vhost/version.map | 3 +++ lib/vhost/vhost.c | 37 ++++++++++++++++++++++++++ 5 files changed, 64 insertions(+) diff --git a/doc/guides/prog_guide/vhost_lib.rst b/doc/guides/prog_guide/vhost_lib.rst index bad4d819e1..78b1943d29 100644 --- a/doc/guides/prog_guide/vhost_lib.rst +++ b/doc/guides/prog_guide/vhost_lib.rst @@ -323,6 +323,11 @@ The following is an overview of some key Vhost API functions: Get device type of vDPA device, such as VDPA_DEVICE_TYPE_NET, VDPA_DEVICE_TYPE_BLK. +* ``rte_vhost_async_dma_unconfigure(dma_id, vchan_id)`` + + Clear DMA vChannels finished to use. This function needs to + be called after async unregister. + Vhost-user Implementations -------------------------- diff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst index 8c021cf050..e94c006e39 100644 --- a/doc/guides/rel_notes/release_22_11.rst +++ b/doc/guides/rel_notes/release_22_11.rst @@ -55,6 +55,8 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added vhost API to unconfigure DMA vchannels.** + Added an API which helps to unconfigure DMA vchannels. Removed Items ------------- diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index 1db2a10124..0442e027fd 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h @@ -266,6 +266,23 @@ rte_vhost_async_try_dequeue_burst(int vid, uint16_t queue_id, struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count, int *nr_inflight, int16_t dma_id, uint16_t vchan_id); +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice. + * + * Unconfigure DMA vChannels in asynchronous data path. + * + * @param dma_id + * the identifier of DMA device + * @param vchan_id + * the identifier of virtual DMA channel + * @return + * 0 on success, and -1 on failure + */ +__rte_experimental +int +rte_vhost_async_dma_unconfigure(int16_t dma_id, uint16_t vchan_id); + #ifdef __cplusplus } #endif diff --git a/lib/vhost/version.map b/lib/vhost/version.map index 18574346d5..013a6bcc42 100644 --- a/lib/vhost/version.map +++ b/lib/vhost/version.map @@ -96,6 +96,9 @@ EXPERIMENTAL { rte_vhost_async_try_dequeue_burst; rte_vhost_driver_get_vdpa_dev_type; rte_vhost_clear_queue; + + # added in 22.11 + rte_vhost_async_dma_unconfigure; }; INTERNAL { diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 60cb05a0ff..d215c917a2 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1863,6 +1863,43 @@ rte_vhost_async_channel_unregister_thread_unsafe(int vid, uint16_t queue_id) return 0; } +int +rte_vhost_async_dma_unconfigure(int16_t dma_id, uint16_t vchan_id) +{ + struct rte_dma_info info; + void *pkts_cmpl_flag_addr; + + if (!rte_dma_is_valid(dma_id)) { + VHOST_LOG_CONFIG("dma", ERR, "DMA %d is not found.\n", dma_id); + return -1; + } + + if (rte_dma_info_get(dma_id, &info) != 0) { + VHOST_LOG_CONFIG("dma", ERR, "Fail to get DMA %d information.\n", dma_id); + return -1; + } + + if (vchan_id >= info.max_vchans) { + VHOST_LOG_CONFIG("dma", ERR, "Invalid DMA %d vChannel %u.\n", dma_id, vchan_id); + return -1; + } + + pkts_cmpl_flag_addr = dma_copy_track[dma_id].vchans[vchan_id].pkts_cmpl_flag_addr; + if (pkts_cmpl_flag_addr) { + rte_free(pkts_cmpl_flag_addr); + pkts_cmpl_flag_addr = NULL; + } + + if (dma_copy_track[dma_id].vchans) { + rte_free(dma_copy_track[dma_id].vchans); + dma_copy_track[dma_id].vchans = NULL; + } + + dma_copy_track[dma_id].nr_vchans--; + + return 0; +} + int rte_vhost_async_dma_configure(int16_t dma_id, uint16_t vchan_id) { From patchwork Sun Aug 14 14:04:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ding, Xuan" X-Patchwork-Id: 114951 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 26B18A0548; Sun, 14 Aug 2022 16:05:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B08742684; Sun, 14 Aug 2022 16:05:21 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id 46AD440697 for ; Sun, 14 Aug 2022 16:05:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660485919; x=1692021919; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=aj8Beyjwq/FV2hD1yW/SEnvrScjPxUJeB0feQs7erio=; b=fV20xfQcPd61KLmnbkhtIWbYwMWTwI/sIo8p8AHc2eYlZ+HwWUMPGnFI MlvWrDoQ6LWt+mvuuBo/iKv6lR1/TUzcO7dPPazUU7xJx6zMl8zEDJ21V kRJYimHQJ5cGwO+9nsXK4vevyNJ/YqprtIALrBqQaB4xpuJhUiTMShWPV 1pxcLh2MJ1UI6NHN+W3PNpNzf4h+VK2oPbmMswFF+fct70ZyZ/oMT4AjF eQzi3FTRpnZk2Nz1SWI50yYBtoez4MiGemJJ1L2xXsL+yVnHByC6ZoLZ4 TC95yn6r7Q9b+8QQjTkAUbJDL1yDbZ2uXupaHlQUGRpVJK3ihU/oIOTa4 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10439"; a="272221101" X-IronPort-AV: E=Sophos;i="5.93,236,1654585200"; d="scan'208";a="272221101" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2022 07:05:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,236,1654585200"; d="scan'208";a="582597615" Received: from npg-dpdk-xuan-cbdma.sh.intel.com ([10.67.111.163]) by orsmga006.jf.intel.com with ESMTP; 14 Aug 2022 07:04:59 -0700 From: xuan.ding@intel.com To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, jiayu.hu@intel.com, xingguang.he@intel.com, yvonnex.yang@intel.com, cheng1.jiang@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, Xuan Ding Subject: [PATCH v1 2/2] example/vhost: unconfigure DMA vchannel Date: Sun, 14 Aug 2022 14:04:42 +0000 Message-Id: <20220814140442.82525-3-xuan.ding@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220814140442.82525-1-xuan.ding@intel.com> References: <20220814140442.82525-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 This patch uses rte_vhost_async_dma_unconfigure() API to manually free 'dma_coy_track' array rather than wait for the program to finish before being freed. Signed-off-by: Xuan Ding --- examples/vhost/main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 7e1666f42a..1dba9724c2 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -2060,6 +2060,13 @@ main(int argc, char *argv[]) RTE_LCORE_FOREACH_WORKER(lcore_id) rte_eal_wait_lcore(lcore_id); + for (i = 0; i < dma_count; i++) { + if (rte_vhost_async_dma_unconfigure(dmas_id[i], 0) < 0) { + RTE_LOG(ERR, VHOST_PORT, "Failed to unconfigure DMA in vhost.\n"); + rte_exit(EXIT_FAILURE, "Cannot use given DMA device\n"); + } + } + /* clean up the EAL */ rte_eal_cleanup();