From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 01CE04327C; Fri, 3 Nov 2023 19:30:36 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E15B2402D1; Fri, 3 Nov 2023 19:30:35 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 8FE164029E for ; Fri, 3 Nov 2023 19:30:34 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A3GtKvZ005006; Fri, 3 Nov 2023 11:30:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=ykGlB7wDSx1c476AiBvyNVCQufWv6r7FmhctPmV0YMo=; b=eBSEE388C0tYzDMcXUxatQY6l+0yQxU1AXYBvGRij6GaRkREN4L0J17KtNdZoBPqJETy 794PAVU5//UywYx+sQKoxhsLYfxqS8lz6OkHCgobfubGb3JiHHzMDFppkagEGUbT5/vh BeH+7cns2DIeIlYogSXTJCE8Hh5Yj65+C/eEjoPSLH3GuStzXyXEu0u4wijeQQzewOTP 7ctt/1GH3wf+c+Awk3QWOv33PkSnivNXqMI6+SDezQv5/QzIljhCIJ/hkjTup7072cW/ cg3uo62cXgkORpG6pTJI6QpFpjSYOA+1S5BLmFBo26AfoCje+B1Oiqzu2ccPbwITQlj/ Xg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3u4upkj3m2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 11:30:33 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 3 Nov 2023 11:30:32 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 3 Nov 2023 11:30:32 -0700 Received: from localhost.localdomain (unknown [10.28.36.157]) by maili.marvell.com (Postfix) with ESMTP id BD4803F70C1; Fri, 3 Nov 2023 11:30:27 -0700 (PDT) From: Amit Prakash Shukla To: Chengwen Feng , Kevin Laatz , Bruce Richardson CC: , , , , , , , , , , , Amit Prakash Shukla Subject: [PATCH v2] test/dma: fix for buffer auto free Date: Sat, 4 Nov 2023 00:00:17 +0530 Message-ID: <20231103183017.3888467-1-amitprakashs@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231101101809.3546500-1-amitprakashs@marvell.com> References: <20231101101809.3546500-1-amitprakashs@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: fVUc0xHUiSTYigvqdHpKX0g8aKSB_5jj X-Proofpoint-GUID: fVUc0xHUiSTYigvqdHpKX0g8aKSB_5jj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-03_18,2023-11-02_03,2023-05-22_02 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 Buffer auto free test failed for more than 1 dma device as the device initialization for the test was been done only for the first dma device. This changeset fixes the same and also fixes the freeing of the uninitialised source buffer in error condition. Fixes: 877cb3e37426 ("dmadev: add buffer auto free offload") Signed-off-by: Amit Prakash Shukla --- v2: - Incorporated review suggestion from Chengwen. app/test/test_dmadev.c | 81 ++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/app/test/test_dmadev.c b/app/test/test_dmadev.c index 216f84b6bb..7581fc2b4c 100644 --- a/app/test/test_dmadev.c +++ b/app/test/test_dmadev.c @@ -827,65 +827,35 @@ static int test_m2d_auto_free(int16_t dev_id, uint16_t vchan) { #define NR_MBUF 256 - struct rte_mbuf *src[NR_MBUF], *dst[NR_MBUF]; - const struct rte_dma_vchan_conf qconf = { - .direction = RTE_DMA_DIR_MEM_TO_DEV, - .nb_desc = TEST_RINGSIZE, - .auto_free.m2d.pool = pool, - .dst_port.port_type = RTE_DMA_PORT_PCIE, - .dst_port.pcie.coreid = 0, - }; + struct rte_mempool_cache *cache; + struct rte_mbuf *src[NR_MBUF]; uint32_t buf_cnt1, buf_cnt2; struct rte_mempool_ops *ops; - static bool dev_init; uint16_t nb_done = 0; bool dma_err = false; int retry = 100; int i, ret = 0; + rte_iova_t dst; - if (!dev_init) { - /* Stop the device to reconfigure vchan. */ - if (rte_dma_stop(dev_id) < 0) - ERR_RETURN("Error stopping device %u\n", dev_id); - - if (rte_dma_vchan_setup(dev_id, vchan, &qconf) < 0) - ERR_RETURN("Error with queue configuration\n"); - - if (rte_dma_start(dev_id) != 0) - ERR_RETURN("Error with rte_dma_start()\n"); - - dev_init = true; - } - - if (rte_pktmbuf_alloc_bulk(pool, dst, NR_MBUF) != 0) - ERR_RETURN("alloc dst mbufs failed.\n"); - - for (i = 0; i < NR_MBUF; i++) { - /* Using mbuf structure to hold remote iova address. */ - rte_mbuf_iova_set(dst[i], (rte_iova_t)env_test_param[TEST_PARAM_REMOTE_ADDR]); - dst[i]->data_off = 0; - } + dst = (rte_iova_t)env_test_param[TEST_PARAM_REMOTE_ADDR]; /* Capture buffer count before allocating source buffer. */ + cache = rte_mempool_default_cache(pool, rte_lcore_id()); ops = rte_mempool_get_ops(pool->ops_index); - buf_cnt1 = ops->get_count(pool); + buf_cnt1 = ops->get_count(pool) + cache->len; - if (rte_pktmbuf_alloc_bulk(pool, src, NR_MBUF) != 0) { - printf("alloc src mbufs failed.\n"); - ret = -1; - goto done; - } + if (rte_pktmbuf_alloc_bulk(pool, src, NR_MBUF) != 0) + ERR_RETURN("alloc src mbufs failed.\n"); - if ((buf_cnt1 - NR_MBUF) != ops->get_count(pool)) { + if ((buf_cnt1 - NR_MBUF) != (ops->get_count(pool) + cache->len)) { printf("Buffer count check failed.\n"); ret = -1; goto done; } for (i = 0; i < NR_MBUF; i++) { - ret = rte_dma_copy(dev_id, vchan, rte_mbuf_data_iova(src[i]), - rte_mbuf_data_iova(dst[i]), COPY_LEN, - RTE_DMA_OP_FLAG_AUTO_FREE); + ret = rte_dma_copy(dev_id, vchan, rte_mbuf_data_iova(src[i]), dst, + COPY_LEN, RTE_DMA_OP_FLAG_AUTO_FREE); if (ret < 0) { printf("rte_dma_copy returned error.\n"); @@ -902,14 +872,13 @@ test_m2d_auto_free(int16_t dev_id, uint16_t vchan) rte_delay_us_sleep(1000); } while (retry-- && (nb_done < NR_MBUF)); - buf_cnt2 = ops->get_count(pool); + buf_cnt2 = ops->get_count(pool) + cache->len; if ((buf_cnt1 != buf_cnt2) || dma_err) { printf("Free mem to dev buffer test failed.\n"); ret = -1; } done: - rte_pktmbuf_free_bulk(dst, NR_MBUF); /* If the test passes source buffer will be freed in hardware. */ if (ret < 0) rte_pktmbuf_free_bulk(&src[nb_done], (NR_MBUF - nb_done)); @@ -917,6 +886,30 @@ test_m2d_auto_free(int16_t dev_id, uint16_t vchan) return ret; } +static int +prepare_m2d_auto_free(int16_t dev_id, uint16_t vchan) +{ + const struct rte_dma_vchan_conf qconf = { + .direction = RTE_DMA_DIR_MEM_TO_DEV, + .nb_desc = TEST_RINGSIZE, + .auto_free.m2d.pool = pool, + .dst_port.port_type = RTE_DMA_PORT_PCIE, + .dst_port.pcie.coreid = 0, + }; + + /* Stop the device to reconfigure vchan. */ + if (rte_dma_stop(dev_id) < 0) + ERR_RETURN("Error stopping device %u\n", dev_id); + + if (rte_dma_vchan_setup(dev_id, vchan, &qconf) < 0) + ERR_RETURN("Error with queue configuration\n"); + + if (rte_dma_start(dev_id) != 0) + ERR_RETURN("Error with rte_dma_start()\n"); + + return 0; +} + static int test_dmadev_instance(int16_t dev_id) { @@ -1011,6 +1004,8 @@ test_dmadev_instance(int16_t dev_id) if ((info.dev_capa & RTE_DMA_CAPA_M2D_AUTO_FREE) && dma_add_test[TEST_M2D_AUTO_FREE].enabled == true) { + if (prepare_m2d_auto_free(dev_id, vchan) != 0) + goto err; if (runtest("m2d_auto_free", test_m2d_auto_free, 128, dev_id, vchan, CHECK_ERRS) < 0) goto err; -- 2.25.1