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 7A7B642BEF; Wed, 31 May 2023 10:42:01 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 01C8440ED7; Wed, 31 May 2023 10:42:01 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2084.outbound.protection.outlook.com [40.107.220.84]) by mails.dpdk.org (Postfix) with ESMTP id DE59A40A82 for ; Wed, 31 May 2023 10:41:58 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B30zzMA5ULT+rYGKul0Elys0S0hSa2LDqX1NUC68+FpX7QKRI+Ibmbr0HUzhfy6W2wR1VDv7TaSdMM4bNucCqYkhnDR5RwE4yzDMEMMVMnlqGLIsstsOeH1r1+Og4/4KYXnhfBsDCF1Je0MaeqbkP9Y6TLjTdDQ07iABwvYNyw5c7jGi+f+tOiKyzQ1YDqLEAw/5H/qFzvw8YwyclJcn+c5NjOvX+tI8YXB0ESgggFir1usBx5HlHKj4TMmG6/il/Asj6GQtwydaGo2zS4bM/00AcolFmGQwyuaoTzAZLYizKDJ1AXaTgqHfI0eRqOuReNsCrDMx7mKf6oLjn/ZUSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qYr6FNHj9C2/Bhlbl7U0twGx8Knx4NGnO3LlDg8/YmA=; b=B304wJowrGkMTFI9DuwH5C37OJ9/Od5cp71dB7Bt167xeH7y4oEXMDjdwP+IAU9n2pgn2L9d3z6iCL+6HDpY9aopzvRWxFB7EhHDwfPTqJhmzlLBJVv0KrdhVVoPKw6B7QaopKKr1uAcVV7mq8nYY/oF/FDOnGoU4NeWtWUnr9ie6By4/sVZjem1orwaaT/3Moy6SRCVuy7XUN2OUaiqCx69juvHL71QztkC8HR5tUK4U4rVrG1iLgltthaAnON9DVsDc5KSsj1RRKdD7eIuG8PhYF0y3mKLQcUTV3zJ9Rx0SvoWkf+b1G3CrUdUZ5VVz168qeR0Fs0qTCxXtVR5fg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qYr6FNHj9C2/Bhlbl7U0twGx8Knx4NGnO3LlDg8/YmA=; b=e9MlF33VUmOBKTt+QjDOuTsoJ/kYe1oqQTzA9sjPgYeZfM1xssRrh3sapLuBxrlbJou6BaJRu/bvjwme6m5jocGf6ZDw/mW5weLFuxHQdXrSxJ0i71yCRvzgsS+2VYhk0cu7IQn/Rx4MyP0vEN/orHrELWG/XCzTv7MkE3MaF9VoCGMkmrmBQ4mf2WZ6YZwyscMr/hPuRbFHQ0WFBIKHINd8iSvUHnsqDKhURnyWhFjy6SOwRY7/UiMIbJjyYjdmRqooD5IzrDpUTZM8TgBJmMpJnMzVv1pkx7fLMe3NY5szS9NaO7mOmzT/pp9bCdo2x74JGpjEp3vMEosafjcfXg== Received: from DS0PR17CA0001.namprd17.prod.outlook.com (2603:10b6:8:191::19) by SN7PR12MB8791.namprd12.prod.outlook.com (2603:10b6:806:32a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.24; Wed, 31 May 2023 08:41:56 +0000 Received: from DM6NAM11FT102.eop-nam11.prod.protection.outlook.com (2603:10b6:8:191:cafe::f3) by DS0PR17CA0001.outlook.office365.com (2603:10b6:8:191::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.22 via Frontend Transport; Wed, 31 May 2023 08:41:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DM6NAM11FT102.mail.protection.outlook.com (10.13.173.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Wed, 31 May 2023 08:41:55 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Wed, 31 May 2023 01:41:48 -0700 Received: from nvidia.com (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Wed, 31 May 2023 01:41:45 -0700 From: Ophir Munk To: , Bruce Richardson , "Devendra Singh Rawat" , Alok Prasad CC: Ophir Munk , Matan Azrad , "Thomas Monjalon" , Lior Margalit , "David Marchand" , Anatoly Burakov Subject: [PATCH V6] lib: set/get max memzone segments Date: Wed, 31 May 2023 11:41:31 +0300 Message-ID: <20230531084131.3853333-1-ophirmu@nvidia.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20230531075222.3851505-1-ophirmu@nvidia.com> References: <20230531075222.3851505-1-ophirmu@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT102:EE_|SN7PR12MB8791:EE_ X-MS-Office365-Filtering-Correlation-Id: a0d9d512-b55f-4f13-e1e7-08db61b2e3ef X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /lfTbdCBxvAujG7Hw+Bpop00nKYxBSUA5+jEQD0pT5K+neH0U8bskUEGtrLbgEUS4XFHReN+/1GO0VF520UXERGNnW18ySnvz1rJR+G+PvpWln2t7RtQeIMIfqi8d5mrKeA4kB9+isAx6FyrBGohySDm7pKv2aj2FPBv4sHdW23l8arTxWhRU2U5CIGV6kDBxwdn1a+vHb3vmrcLevifs4Kh6tMI523QCKPY/AIIPOIEDMwDGj8Jz4G9HGKUC3ZF30vl77892duEyve8rt6xeKTJkyfn02VSSqgwVDPx2gs45Un7CIo6jHUmKLH/88wNV4xgDkyTfVQoJbwwPYPvlJRJLDoWQJmxPhbLRQPSeCiAW3PEbnZMZ40AFUX7k1c+5jF/cMKsqdxXhocoDs3Fw82Ab3ADeepK8f2rX93IWhsMEClxSPyoTGyaI+4Ie/L4oc9WsflQweHMsLcT93kO4gzZgyLlV5eVOG18wsmhHCHc/sex986rwWK8Y+dfeM/COJysyoyXm8QGG00tuk/veHPHdKJf8UtpqDqW5c8gBqTVMgW3DKoNgwhcLs1MzPrOzkBkOGOKwEB2f78aZ5qqWlhAgBBe2yE0X/q09BKFqnFaRbv5cF+/LaQ9WnubiTUrE1FGAhkKt+hsg3x2Zd/WvsUZuhrxWgaYgnw51GMUPGgXDcXiP8ISbI0lnviwlZXEHzzonrVyWLayb3KV3XiVxXy+lP46jKQ/uBOhRrJ67hokLKPJIBM7GMVLHlXcv1AU X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230028)(4636009)(396003)(346002)(376002)(136003)(39860400002)(451199021)(40470700004)(36840700001)(46966006)(110136005)(54906003)(8936002)(8676002)(30864003)(70206006)(2906002)(70586007)(4326008)(41300700001)(5660300002)(316002)(478600001)(36860700001)(40460700003)(7696005)(6666004)(1076003)(82740400003)(7636003)(356005)(40480700001)(16526019)(186003)(55016003)(6286002)(26005)(83380400001)(336012)(426003)(66574015)(36756003)(47076005)(82310400005)(86362001)(2616005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2023 08:41:55.7716 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0d9d512-b55f-4f13-e1e7-08db61b2e3ef X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT102.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8791 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 Currently, the max memzones count constat (RTE_MAX_MEMZONE) is used to decide how many memzones a DPDK application can have. This value could technically be changed by manually editing `rte_config.h` before compilation, but if DPDK is already compiled, that option is not useful. There are certain use cases that would benefit from making this value configurable. This commit addresses the issue by adding a new API to set the max number of memzones before EAL initialization (while using the old constant as default value), as well as an API to get current maximum number of memzones. Signed-off-by: Ophir Munk Reviewed-by: Thomas Monjalon Reviewed-by: David Marchand Reviewed-by: Anatoly Burakov Acked-by: Morten Brørup Acked-by: Alok Prasad --- app/test/test_func_reentrancy.c | 2 +- app/test/test_malloc_perf.c | 2 +- app/test/test_memzone.c | 42 ++++++++++++++++++++++------------- config/rte_config.h | 1 - drivers/net/qede/base/bcm_osal.c | 38 ++++++++++++++++++++++++++------ drivers/net/qede/base/bcm_osal.h | 3 +++ drivers/net/qede/qede_main.c | 7 ++++++ lib/eal/common/eal_common_memzone.c | 44 ++++++++++++++++++++++++++++++++++--- lib/eal/common/eal_memcfg.h | 2 ++ lib/eal/include/rte_memzone.h | 30 +++++++++++++++++++++++++ lib/eal/version.map | 4 ++++ 11 files changed, 147 insertions(+), 28 deletions(-) diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c index d1ed5d4..ae9de6f 100644 v6: Style error fix --- a/app/test/test_func_reentrancy.c +++ b/app/test/test_func_reentrancy.c @@ -51,7 +51,7 @@ typedef void (*case_clean_t)(unsigned lcore_id); #define MEMPOOL_ELT_SIZE (sizeof(uint32_t)) #define MEMPOOL_SIZE (4) -#define MAX_LCORES (RTE_MAX_MEMZONE / (MAX_ITER_MULTI * 4U)) +#define MAX_LCORES (rte_memzone_max_get() / (MAX_ITER_MULTI * 4U)) static uint32_t obj_count; static uint32_t synchro; diff --git a/app/test/test_malloc_perf.c b/app/test/test_malloc_perf.c index ccec43a..9bd1662 100644 --- a/app/test/test_malloc_perf.c +++ b/app/test/test_malloc_perf.c @@ -165,7 +165,7 @@ test_malloc_perf(void) return -1; if (test_alloc_perf("rte_memzone_reserve", memzone_alloc, memzone_free, - NULL, memset_us_gb, RTE_MAX_MEMZONE - 1) < 0) + NULL, memset_us_gb, rte_memzone_max_get() - 1) < 0) return -1; return 0; diff --git a/app/test/test_memzone.c b/app/test/test_memzone.c index c9255e5..f10f4fd 100644 --- a/app/test/test_memzone.c +++ b/app/test/test_memzone.c @@ -871,9 +871,17 @@ test_memzone_bounded(void) static int test_memzone_free(void) { - const struct rte_memzone *mz[RTE_MAX_MEMZONE + 1]; + const struct rte_memzone **mz; int i; char name[20]; + int rc = -1; + + mz = rte_calloc("memzone_test", rte_memzone_max_get() + 1, + sizeof(struct rte_memzone *), 0); + if (!mz) { + printf("Fail allocating memzone test array\n"); + return rc; + } mz[0] = rte_memzone_reserve(TEST_MEMZONE_NAME("tempzone0"), 2000, SOCKET_ID_ANY, 0); @@ -881,42 +889,42 @@ test_memzone_free(void) SOCKET_ID_ANY, 0); if (mz[0] > mz[1]) - return -1; + goto exit_test; if (!rte_memzone_lookup(TEST_MEMZONE_NAME("tempzone0"))) - return -1; + goto exit_test; if (!rte_memzone_lookup(TEST_MEMZONE_NAME("tempzone1"))) - return -1; + goto exit_test; if (rte_memzone_free(mz[0])) { printf("Fail memzone free - tempzone0\n"); - return -1; + goto exit_test; } if (rte_memzone_lookup(TEST_MEMZONE_NAME("tempzone0"))) { printf("Found previously free memzone - tempzone0\n"); - return -1; + goto exit_test; } mz[2] = rte_memzone_reserve(TEST_MEMZONE_NAME("tempzone2"), 2000, SOCKET_ID_ANY, 0); if (mz[2] > mz[1]) { printf("tempzone2 should have gotten the free entry from tempzone0\n"); - return -1; + goto exit_test; } if (rte_memzone_free(mz[2])) { printf("Fail memzone free - tempzone2\n"); - return -1; + goto exit_test; } if (rte_memzone_lookup(TEST_MEMZONE_NAME("tempzone2"))) { printf("Found previously free memzone - tempzone2\n"); - return -1; + goto exit_test; } if (rte_memzone_free(mz[1])) { printf("Fail memzone free - tempzone1\n"); - return -1; + goto exit_test; } if (rte_memzone_lookup(TEST_MEMZONE_NAME("tempzone1"))) { printf("Found previously free memzone - tempzone1\n"); - return -1; + goto exit_test; } i = 0; @@ -928,7 +936,7 @@ test_memzone_free(void) if (rte_memzone_free(mz[0])) { printf("Fail memzone free - tempzone0\n"); - return -1; + goto exit_test; } mz[0] = rte_memzone_reserve(TEST_MEMZONE_NAME("tempzone0new"), 0, SOCKET_ID_ANY, 0); @@ -936,17 +944,21 @@ test_memzone_free(void) if (mz[0] == NULL) { printf("Fail to create memzone - tempzone0new - when MAX memzones were " "created and one was free\n"); - return -1; + goto exit_test; } for (i = i - 2; i >= 0; i--) { if (rte_memzone_free(mz[i])) { printf("Fail memzone free - tempzone%d\n", i); - return -1; + goto exit_test; } } - return 0; + rc = 0; + +exit_test: + rte_free(mz); + return rc; } static int test_memzones_left; diff --git a/config/rte_config.h b/config/rte_config.h index 7b8c85e..400e44e 100644 --- a/config/rte_config.h +++ b/config/rte_config.h @@ -34,7 +34,6 @@ #define RTE_MAX_MEM_MB_PER_LIST 32768 #define RTE_MAX_MEMSEG_PER_TYPE 32768 #define RTE_MAX_MEM_MB_PER_TYPE 65536 -#define RTE_MAX_MEMZONE 2560 #define RTE_MAX_TAILQ 32 #define RTE_LOG_DP_LEVEL RTE_LOG_INFO #define RTE_MAX_VFIO_CONTAINERS 64 diff --git a/drivers/net/qede/base/bcm_osal.c b/drivers/net/qede/base/bcm_osal.c index 2c59397..638d006 100644 --- a/drivers/net/qede/base/bcm_osal.c +++ b/drivers/net/qede/base/bcm_osal.c @@ -47,10 +47,34 @@ void osal_poll_mode_dpc(osal_int_ptr_t hwfn_cookie) } /* Array of memzone pointers */ -static const struct rte_memzone *ecore_mz_mapping[RTE_MAX_MEMZONE]; +static const struct rte_memzone **ecore_mz_mapping; /* Counter to track current memzone allocated */ static uint16_t ecore_mz_count; +static uint32_t ref_cnt; + +int ecore_mz_mapping_alloc(void) +{ + if (__atomic_fetch_add(&ref_cnt, 1, __ATOMIC_RELAXED) == 0) { + ecore_mz_mapping = rte_calloc("ecore_mz_map", + rte_memzone_max_get(), sizeof(struct rte_memzone *), 0); + } + + if (!ecore_mz_mapping) + return -ENOMEM; + + return 0; +} + +void ecore_mz_mapping_free(void) +{ + if (__atomic_fetch_sub(&ref_cnt, 1, __ATOMIC_RELAXED) - 1 == 0) { + if (ecore_mz_mapping) + rte_free(ecore_mz_mapping); + ecore_mz_mapping = NULL; + } +} + unsigned long qede_log2_align(unsigned long n) { unsigned long ret = n ? 1 : 0; @@ -132,9 +156,9 @@ void *osal_dma_alloc_coherent(struct ecore_dev *p_dev, uint32_t core_id = rte_lcore_id(); unsigned int socket_id; - if (ecore_mz_count >= RTE_MAX_MEMZONE) { - DP_ERR(p_dev, "Memzone allocation count exceeds %u\n", - RTE_MAX_MEMZONE); + if (ecore_mz_count >= rte_memzone_max_get()) { + DP_ERR(p_dev, "Memzone allocation count exceeds %zu\n", + rte_memzone_max_get()); *phys = 0; return OSAL_NULL; } @@ -171,9 +195,9 @@ void *osal_dma_alloc_coherent_aligned(struct ecore_dev *p_dev, uint32_t core_id = rte_lcore_id(); unsigned int socket_id; - if (ecore_mz_count >= RTE_MAX_MEMZONE) { - DP_ERR(p_dev, "Memzone allocation count exceeds %u\n", - RTE_MAX_MEMZONE); + if (ecore_mz_count >= rte_memzone_max_get()) { + DP_ERR(p_dev, "Memzone allocation count exceeds %zu\n", + rte_memzone_max_get()); *phys = 0; return OSAL_NULL; } diff --git a/drivers/net/qede/base/bcm_osal.h b/drivers/net/qede/base/bcm_osal.h index 67e7f75..97e261d 100644 --- a/drivers/net/qede/base/bcm_osal.h +++ b/drivers/net/qede/base/bcm_osal.h @@ -477,4 +477,7 @@ enum dbg_status qed_dbg_alloc_user_data(struct ecore_hwfn *p_hwfn, qed_dbg_alloc_user_data(p_hwfn, user_data_ptr) #define OSAL_DB_REC_OCCURRED(p_hwfn) nothing +int ecore_mz_mapping_alloc(void); +void ecore_mz_mapping_free(void); + #endif /* __BCM_OSAL_H */ diff --git a/drivers/net/qede/qede_main.c b/drivers/net/qede/qede_main.c index 0303903..fd63262 100644 --- a/drivers/net/qede/qede_main.c +++ b/drivers/net/qede/qede_main.c @@ -72,6 +72,12 @@ qed_probe(struct ecore_dev *edev, struct rte_pci_device *pci_dev, hw_prepare_params.allow_mdump = false; hw_prepare_params.b_en_pacing = false; hw_prepare_params.epoch = OSAL_GET_EPOCH(ECORE_LEADING_HWFN(edev)); + rc = ecore_mz_mapping_alloc(); + if (rc) { + DP_ERR(edev, "mem zones array allocation failed\n"); + return rc; + } + rc = ecore_hw_prepare(edev, &hw_prepare_params); if (rc) { DP_ERR(edev, "hw prepare failed\n"); @@ -722,6 +728,7 @@ static void qed_remove(struct ecore_dev *edev) return; ecore_hw_remove(edev); + ecore_mz_mapping_free(); } static int qed_send_drv_state(struct ecore_dev *edev, bool active) diff --git a/lib/eal/common/eal_common_memzone.c b/lib/eal/common/eal_common_memzone.c index a9cd91f..d024410 100644 --- a/lib/eal/common/eal_common_memzone.c +++ b/lib/eal/common/eal_common_memzone.c @@ -22,6 +22,9 @@ #include "eal_private.h" #include "eal_memcfg.h" +/* Default count used until rte_memzone_max_set() is called */ +#define DEFAULT_MAX_MEMZONE_COUNT 2560 + static inline const struct rte_memzone * memzone_lookup_thread_unsafe(const char *name) { @@ -81,8 +84,9 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, /* no more room in config */ if (arr->count >= arr->len) { RTE_LOG(ERR, EAL, - "%s(): Number of requested memzone segments exceeds RTE_MAX_MEMZONE\n", - __func__); + "%s(): Number of requested memzone segments exceeds maximum " + "%u\n", __func__, arr->len); + rte_errno = ENOSPC; return NULL; } @@ -396,7 +400,7 @@ rte_eal_memzone_init(void) if (rte_eal_process_type() == RTE_PROC_PRIMARY && rte_fbarray_init(&mcfg->memzones, "memzone", - RTE_MAX_MEMZONE, sizeof(struct rte_memzone))) { + rte_memzone_max_get(), sizeof(struct rte_memzone))) { RTE_LOG(ERR, EAL, "Cannot allocate memzone list\n"); ret = -1; } else if (rte_eal_process_type() == RTE_PROC_SECONDARY && @@ -430,3 +434,37 @@ void rte_memzone_walk(void (*func)(const struct rte_memzone *, void *), } rte_rwlock_read_unlock(&mcfg->mlock); } + +int +rte_memzone_max_set(size_t max) +{ + struct rte_mem_config *mcfg; + + if (eal_get_internal_configuration()->init_complete > 0) { + RTE_LOG(ERR, EAL, "Max memzone cannot be set after calling " + "eal init\n"); + return -1; + } + + mcfg = rte_eal_get_configuration()->mem_config; + if (mcfg == NULL) { + RTE_LOG(ERR, EAL, "Failed to set max memzone\n"); + return -1; + } + + mcfg->max_memzone = max; + + return 0; +} + +size_t +rte_memzone_max_get(void) +{ + struct rte_mem_config *mcfg; + + mcfg = rte_eal_get_configuration()->mem_config; + if (mcfg == NULL || mcfg->max_memzone == 0) + return DEFAULT_MAX_MEMZONE_COUNT; + + return mcfg->max_memzone; +} diff --git a/lib/eal/common/eal_memcfg.h b/lib/eal/common/eal_memcfg.h index ea013a9..8889ba0 100644 --- a/lib/eal/common/eal_memcfg.h +++ b/lib/eal/common/eal_memcfg.h @@ -75,6 +75,8 @@ struct rte_mem_config { /**< TSC rate */ uint8_t dma_maskbits; /**< Keeps the more restricted dma mask. */ + + size_t max_memzone; /**< Maximum number of allocated memzones. */ }; /* update internal config from shared mem config */ diff --git a/lib/eal/include/rte_memzone.h b/lib/eal/include/rte_memzone.h index 5302caa..44dcd22 100644 --- a/lib/eal/include/rte_memzone.h +++ b/lib/eal/include/rte_memzone.h @@ -305,6 +305,36 @@ void rte_memzone_dump(FILE *f); void rte_memzone_walk(void (*func)(const struct rte_memzone *, void *arg), void *arg); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Set max memzone count. + * + * This function can only be called prior to rte_eal_init(). + * + * @param max + * Maximum number of memzones + * @return + * 0 on success, -1 otherwise + */ +__rte_experimental +int rte_memzone_max_set(size_t max); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Get the maximum number of memzones. + * + * @note: The maximum value will not change after calling rte_eal_init(). + * + * @return + * Maximum number of memzones + */ +__rte_experimental +size_t rte_memzone_max_get(void); + #ifdef __cplusplus } #endif diff --git a/lib/eal/version.map b/lib/eal/version.map index 51a820d..b52a83c 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -430,6 +430,10 @@ EXPERIMENTAL { rte_thread_create_control; rte_thread_set_name; __rte_eal_trace_generic_blob; + + # added in 23.07 + rte_memzone_max_set; + rte_memzone_max_get; }; INTERNAL { -- 2.8.4