From patchwork Mon Apr 1 10:34:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahaf Shuler X-Patchwork-Id: 51969 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1DDB32B99; Mon, 1 Apr 2019 12:34:29 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id D7A262B99 for ; Mon, 1 Apr 2019 12:34:27 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 1 Apr 2019 13:34:23 +0300 Received: from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx [10.7.12.62]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x31AYM8u014978; Mon, 1 Apr 2019 13:34:22 +0300 From: Shahaf Shuler To: wenzhuo.lu@intel.com, jingjing.wu@intel.com, bernard.iremonger@intel.com Cc: dev@dpdk.org, rasland@mellanox.com, thomas@monjalon.net, ferruh.yigit@intel.com, stable@dpdk.org Date: Mon, 1 Apr 2019 13:34:04 +0300 Message-Id: <8e193bdeef1080877dc503ccc34ea1fd861dc3d2.1554114165.git.shahafs@mellanox.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/3] app/testpmd: fix mempool free on exit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Allocated mempools were never free. it is bad practice. Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org Signed-off-by: Shahaf Shuler --- app/test-pmd/testpmd.c | 24 ++++++++++++++++++------ app/test-pmd/testpmd.h | 2 ++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 40c873b972..7ea6c1d7e0 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -188,6 +188,8 @@ struct fwd_engine * fwd_engines[] = { NULL, }; +struct rte_mempool *mempools[RTE_MAX_NUMA_NODES]; + struct fwd_config cur_fwd_config; struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */ uint32_t retry_enabled; @@ -835,7 +837,7 @@ setup_extmem(uint32_t nb_mbufs, uint32_t mbuf_sz, bool huge) /* * Configuration initialisation done once at init time. */ -static void +static struct rte_mempool * mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf, unsigned int socket_id) { @@ -904,6 +906,7 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf, rte_exit(EXIT_FAILURE, "Invalid mempool creation mode\n"); } } + return rte_mp; err: if (rte_mp == NULL) { @@ -913,6 +916,7 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf, } else if (verbose_level > 0) { rte_mempool_dump(stdout, rte_mp); } + return NULL; } /* @@ -1130,14 +1134,18 @@ init_config(void) uint8_t i; for (i = 0; i < num_sockets; i++) - mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, - socket_ids[i]); + mempools[i] = mbuf_pool_create(mbuf_data_size, + nb_mbuf_per_pool, + socket_ids[i]); } else { if (socket_num == UMA_NO_CONFIG) - mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 0); + mempools[0] = mbuf_pool_create(mbuf_data_size, + nb_mbuf_per_pool, 0); else - mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, - socket_num); + mempools[socket_num] = mbuf_pool_create + (mbuf_data_size, + nb_mbuf_per_pool, + socket_num); } init_port_config(); @@ -2396,6 +2404,7 @@ pmd_test_exit(void) struct rte_device *device; portid_t pt_id; int ret; + int i; if (test_done == 0) stop_packet_forwarding(); @@ -2449,6 +2458,9 @@ pmd_test_exit(void) return; } } + for (i = 0 ; i < RTE_MAX_NUMA_NODES ; i++) + if (mempools[i]) + rte_mempool_free(mempools[i]); printf("\nBye...\n"); } diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index a45988ebc5..84ce8ffa2f 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -264,6 +264,8 @@ extern struct fwd_engine ieee1588_fwd_engine; extern struct fwd_engine * fwd_engines[]; /**< NULL terminated array. */ +extern struct rte_mempool *mempools[RTE_MAX_NUMA_NODES]; + /** * Forwarding Configuration * From patchwork Mon Apr 1 10:34:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahaf Shuler X-Patchwork-Id: 51971 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 708C14C90; Mon, 1 Apr 2019 12:34:33 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id DB52A343C for ; Mon, 1 Apr 2019 12:34:27 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 1 Apr 2019 13:34:23 +0300 Received: from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx [10.7.12.62]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x31AYM8v014978; Mon, 1 Apr 2019 13:34:22 +0300 From: Shahaf Shuler To: wenzhuo.lu@intel.com, jingjing.wu@intel.com, bernard.iremonger@intel.com Cc: dev@dpdk.org, rasland@mellanox.com, thomas@monjalon.net, ferruh.yigit@intel.com Date: Mon, 1 Apr 2019 13:34:05 +0300 Message-Id: X-Mailer: git-send-email 2.12.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/3] app/testpmd: support creation of no IOVA contig mempools X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" providing a command line parameter to set the mempool flags accordingly. This mode is relevant only when creating an empty mempool and then populating with memory. Signed-off-by: Shahaf Shuler --- app/test-pmd/parameters.c | 5 +++++ app/test-pmd/testpmd.c | 3 ++- app/test-pmd/testpmd.h | 2 ++ doc/guides/testpmd_app_ug/run_app.rst | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 7b6b60905d..ce0056b0bd 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -202,6 +202,8 @@ usage(char* progname) printf(" --noisy-lkup-num-writes=N: do N random writes per packet\n"); printf(" --noisy-lkup-num-reads=N: do N random reads per packet\n"); printf(" --noisy-lkup-num-writes=N: do N random reads and writes per packet\n"); + printf(" --no-iova-contig: mempool memory can be IOVA non contiguous. " + "valid only with --mp-alloc=anon\n"); } #ifdef RTE_LIBRTE_CMDLINE @@ -651,6 +653,7 @@ launch_args_parse(int argc, char** argv) { "noisy-lkup-num-writes", 1, 0, 0 }, { "noisy-lkup-num-reads", 1, 0, 0 }, { "noisy-lkup-num-reads-writes", 1, 0, 0 }, + { "no-iova-contig", 0, 0, 0 }, { 0, 0, 0, 0 }, }; @@ -1242,6 +1245,8 @@ launch_args_parse(int argc, char** argv) rte_exit(EXIT_FAILURE, "noisy-lkup-num-reads-writes must be >= 0\n"); } + if (!strcmp(lgopts[opt_idx].name, "no-iova-contig")) + mempool_flags = MEMPOOL_F_NO_IOVA_CONTIG; break; case 'h': usage(argv[0]); diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 7ea6c1d7e0..8c4ebc774c 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -189,6 +189,7 @@ struct fwd_engine * fwd_engines[] = { }; struct rte_mempool *mempools[RTE_MAX_NUMA_NODES]; +uint16_t mempool_flags; struct fwd_config cur_fwd_config; struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */ @@ -867,7 +868,7 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf, rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf, mb_size, (unsigned int) mb_mempool_cache, sizeof(struct rte_pktmbuf_pool_private), - socket_id, 0); + socket_id, mempool_flags); if (rte_mp == NULL) goto err; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 84ce8ffa2f..46d26181dd 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -266,6 +266,8 @@ extern struct fwd_engine * fwd_engines[]; /**< NULL terminated array. */ extern struct rte_mempool *mempools[RTE_MAX_NUMA_NODES]; +extern uint16_t mempool_flags; + /** * Forwarding Configuration * diff --git a/doc/guides/testpmd_app_ug/run_app.rst b/doc/guides/testpmd_app_ug/run_app.rst index b717b8c7b7..7b4341647f 100644 --- a/doc/guides/testpmd_app_ug/run_app.rst +++ b/doc/guides/testpmd_app_ug/run_app.rst @@ -427,3 +427,8 @@ The commandline options are: Set the number of r/w accesses to be done in noisy neighbour simulation memory buffer to N. Only available with the noisy forwarding mode. The default value is 0. + +* ``--no-iova-contig`` + + Enable to create mempool which is not IOVA contiguous. Valid only with --mp-alloc=anon. + The default value is 0. From patchwork Mon Apr 1 10:34:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahaf Shuler X-Patchwork-Id: 51970 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8B6CB378E; Mon, 1 Apr 2019 12:34:31 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id D97D8316B for ; Mon, 1 Apr 2019 12:34:27 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from shahafs@mellanox.com) with ESMTPS (AES256-SHA encrypted); 1 Apr 2019 13:34:23 +0300 Received: from unicorn01.mtl.labs.mlnx. (unicorn01.mtl.labs.mlnx [10.7.12.62]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x31AYM8w014978; Mon, 1 Apr 2019 13:34:23 +0300 From: Shahaf Shuler To: wenzhuo.lu@intel.com, jingjing.wu@intel.com, bernard.iremonger@intel.com Cc: dev@dpdk.org, rasland@mellanox.com, thomas@monjalon.net, ferruh.yigit@intel.com Date: Mon, 1 Apr 2019 13:34:06 +0300 Message-Id: X-Mailer: git-send-email 2.12.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 3/3] app/testpmd: map anonymous memory for eth devices X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Mempools can be populated with anonymous memory when using command line parameter --mp-alloc=anon. Considering the mempools are going to be used by the net devices, it is better to DMA map this memory. This patch add such mapping now that we have the APIs in place[1]. [1] commit c33a675b6276 ("bus: introduce device level DMA memory mapping") Signed-off-by: Shahaf Shuler --- app/test-pmd/testpmd.c | 62 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 8c4ebc774c..6729469c6b 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -834,6 +834,61 @@ setup_extmem(uint32_t nb_mbufs, uint32_t mbuf_sz, bool huge) return 0; } +static void +dma_unmap_cb(struct rte_mempool *mp __rte_unused, void *opaque __rte_unused, + struct rte_mempool_memhdr *memhdr, unsigned mem_idx __rte_unused) +{ + uint16_t pid = 0; + int ret; + + ret = rte_extmem_unregister(memhdr->addr, memhdr->len); + if (ret) { + TESTPMD_LOG(DEBUG, + "unable to un-register addr 0x%p\n", memhdr->addr); + return; + } + RTE_ETH_FOREACH_DEV(pid) { + struct rte_eth_dev *dev = + &rte_eth_devices[pid]; + + ret = rte_dev_dma_unmap(dev->device, memhdr->addr, 0, + memhdr->len); + if (ret) { + TESTPMD_LOG(DEBUG, + "unable to DMA unmap addr 0x%p\n", + memhdr->addr); + } + } +} + +static void +dma_map_cb(struct rte_mempool *mp __rte_unused, void *opaque __rte_unused, + struct rte_mempool_memhdr *memhdr, unsigned mem_idx __rte_unused) +{ + uint16_t pid = 0; + size_t page_size = sysconf(_SC_PAGESIZE); + int ret; + + ret = rte_extmem_register(memhdr->addr, memhdr->len, NULL, 0, + page_size); + if (ret) { + TESTPMD_LOG(DEBUG, + "unable to register addr 0x%p\n", memhdr->addr); + return; + } + RTE_ETH_FOREACH_DEV(pid) { + struct rte_eth_dev *dev = + &rte_eth_devices[pid]; + + ret = rte_dev_dma_map(dev->device, memhdr->addr, 0, + memhdr->len); + if (ret) { + TESTPMD_LOG(DEBUG, + "unable to DMA map addr 0x%p\n", + memhdr->addr); + } + } +} /* * Configuration initialisation done once at init time. @@ -879,6 +934,7 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf, } rte_pktmbuf_pool_init(rte_mp, NULL); rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL); + rte_mempool_mem_iter(rte_mp, dma_map_cb, NULL); break; } case MP_ALLOC_XMEM: @@ -2460,8 +2516,12 @@ pmd_test_exit(void) } } for (i = 0 ; i < RTE_MAX_NUMA_NODES ; i++) - if (mempools[i]) + if (mempools[i]) { + if (mp_alloc_type == MP_ALLOC_ANON) + rte_mempool_mem_iter(mempools[i], dma_unmap_cb, + NULL); rte_mempool_free(mempools[i]); + } printf("\nBye...\n"); }