From patchwork Tue Aug 22 17:01:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Sekhar T K X-Patchwork-Id: 130648 X-Patchwork-Delegate: jerinj@marvell.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 7014C430D2; Tue, 22 Aug 2023 19:02:10 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 50F4040697; Tue, 22 Aug 2023 19:02:10 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 78C384021D for ; Tue, 22 Aug 2023 19:02:08 +0200 (CEST) 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 37M8Zaik015708 for ; Tue, 22 Aug 2023 10:02:07 -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=5Fny+BzIT1ycF5Yty/etjMYr+kTMMfQ4gOxmSqoEmZg=; b=KsHdwK12XWpvSYeKWxMIdGHmJYFpO3sFHG584wVqxVL7GxfYl7nqXO25KcF/Vaz6HDFu rMS2mn+7C1pJpCDRopiLFIg5/VQZVYtjiCfI9oUvaHkenIhTb2ieg7olzyPhJVsJJnj+ 5FENiVW8rBgsrUhedMuZ91o+hnyxPDp+37zU4fX9nFxZXA7wL0atrxFKdADRdXbYkcoH AgFdGpCC94yDlS8ag1FJIT659jTAspzzhHllCax4vUFcYj9t8dTWCvQTUEJO2sxhKWC+ d5loZjcYD0ERNy/rU27VL9wVTw0cS3Uv9wxKZ1n7MvJ1azINID9B+u9UPOR/mNfcEiwv jw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3smdthbr6j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 22 Aug 2023 10:02:07 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Tue, 22 Aug 2023 10:02:05 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Tue, 22 Aug 2023 10:02:05 -0700 Received: from localhost.localdomain (unknown [10.28.36.142]) by maili.marvell.com (Postfix) with ESMTP id BAAF73F70B4; Tue, 22 Aug 2023 10:02:01 -0700 (PDT) From: Ashwin Sekhar T K To: , Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao , Ashwin Sekhar T K , "Pavan Nikhilesh" CC: , , , , Subject: [PATCH 1/3] mempool/cnxk: limit usage of async allocs Date: Tue, 22 Aug 2023 22:31:55 +0530 Message-ID: <20230822170157.2637286-1-asekhar@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230731055514.1708500-1-asekhar@marvell.com> References: <20230731055514.1708500-1-asekhar@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: ZbJggr1-1Mtdlb6OcrntNIjWxDUGkIJk X-Proofpoint-ORIG-GUID: ZbJggr1-1Mtdlb6OcrntNIjWxDUGkIJk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-22_14,2023-08-22_01,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 Currently mempool_cnxk driver uses asynchronous allocation for all pools. This asynchronous allocation can result in local caching of additional 512 objects on a single core even when cache is disabled. This will eventually lead to starvation on pools where the number of objects is very less. This commit changes this logic to use asynchronous allocation on only those pools which have local cache enabled. Also the async buffer size will be RTE_ALIGN_CEIL(rte_mempool->cache_size, 16). This means that when cache is disabled, async alloc will be completely disabled and when cache is enabled, the additional caching due to asynchronous allocation will be limited. A limitation has been added to cnxk documentation warning the users to adjust the local cache sizes accordingly. Signed-off-by: Ashwin Sekhar T K --- doc/guides/nics/cnxk.rst | 18 ++++ drivers/mempool/cnxk/cn10k_mempool_ops.c | 103 ++++++++++++++++++++--- 2 files changed, 110 insertions(+), 11 deletions(-) diff --git a/doc/guides/nics/cnxk.rst b/doc/guides/nics/cnxk.rst index 9229056f6f..5d90d22e2b 100644 --- a/doc/guides/nics/cnxk.rst +++ b/doc/guides/nics/cnxk.rst @@ -433,6 +433,24 @@ The OCTEON CN9K/CN10K SoC family NIC has inbuilt HW assisted external mempool ma as it is performance wise most effective way for packet allocation and Tx buffer recycling on OCTEON 9 SoC platform. +``mempool_cnxk`` rte_mempool cache sizes for CN10K +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The OCTEON CN10K SoC Family supports asynchronous batch allocation of +objects from an NPA pool. In the CNXK mempool driver, asynchronous batch +allocation is enabled when local caches are enabled. This asynchronous +batch allocation will be using an additional local async buffer whose size +will be equal to ``RTE_ALIGN_CEIL(rte_mempool->cache_size, 16)``. This can +result in additional objects being cached locally. While creating an +rte_mempool using ``mempool_cnxk`` driver for OCTEON CN10K, this must be +taken into consideration and the local cache sizes should be adjusted +accordingly so that starvation does not happen. + +For Eg: If the ``cache_size`` passed into ``rte_mempool_create`` is ``8``, +then the max objects than can get cached locally on a core would be the +sum of max objects in the local cache + max objects in the async buffer +i.e ``8 + RTE_ALIGN_CEIL(8, 16) = 24``. + CRC stripping ~~~~~~~~~~~~~ diff --git a/drivers/mempool/cnxk/cn10k_mempool_ops.c b/drivers/mempool/cnxk/cn10k_mempool_ops.c index ff0015d8de..41b755b52b 100644 --- a/drivers/mempool/cnxk/cn10k_mempool_ops.c +++ b/drivers/mempool/cnxk/cn10k_mempool_ops.c @@ -10,6 +10,7 @@ #define BATCH_ALLOC_SZ ROC_CN10K_NPA_BATCH_ALLOC_MAX_PTRS #define BATCH_OP_DATA_TABLE_MZ_NAME "batch_op_data_table_mz" #define BATCH_ALLOC_WAIT_US 5 +#define BATCH_ALLOC_RETRIES 4 enum batch_op_status { BATCH_ALLOC_OP_NOT_ISSUED = 0, @@ -25,6 +26,7 @@ struct batch_op_mem { struct batch_op_data { uint64_t lmt_addr; + uint32_t max_async_batch; struct batch_op_mem mem[RTE_MAX_LCORE] __rte_aligned(ROC_ALIGN); }; @@ -97,6 +99,10 @@ batch_op_init(struct rte_mempool *mp) } op_data->lmt_addr = roc_idev_lmt_base_addr_get(); + op_data->max_async_batch = + RTE_MIN((unsigned int)BATCH_ALLOC_SZ, + RTE_ALIGN_CEIL(mp->cache_size, ROC_ALIGN / 8)); + batch_op_data_set(mp->pool_id, op_data); rte_wmb(); @@ -117,13 +123,17 @@ batch_op_fini(struct rte_mempool *mp) return; } + /* If max_async_batch == 0, then batch mem will be empty */ + if (op_data->max_async_batch == 0) + goto free_op_data; + rte_wmb(); for (i = 0; i < RTE_MAX_LCORE; i++) { struct batch_op_mem *mem = &op_data->mem[i]; if (mem->status == BATCH_ALLOC_OP_ISSUED) { mem->sz = roc_npa_aura_batch_alloc_extract( - mem->objs, mem->objs, BATCH_ALLOC_SZ); + mem->objs, mem->objs, op_data->max_async_batch); mem->status = BATCH_ALLOC_OP_DONE; } if (mem->status == BATCH_ALLOC_OP_DONE) { @@ -133,6 +143,7 @@ batch_op_fini(struct rte_mempool *mp) } } +free_op_data: rte_free(op_data); batch_op_data_set(mp->pool_id, NULL); rte_wmb(); @@ -172,6 +183,9 @@ cn10k_mempool_get_count(const struct rte_mempool *mp) int i; op_data = batch_op_data_get(mp->pool_id); + /* If max_async_batch == 0, then batch alloc mem will be empty */ + if (op_data->max_async_batch == 0) + goto npa_pool_count; rte_wmb(); for (i = 0; i < RTE_MAX_LCORE; i++) { @@ -179,19 +193,27 @@ cn10k_mempool_get_count(const struct rte_mempool *mp) if (mem->status == BATCH_ALLOC_OP_ISSUED) count += roc_npa_aura_batch_alloc_count( - mem->objs, BATCH_ALLOC_SZ, BATCH_ALLOC_WAIT_US); + mem->objs, op_data->max_async_batch, + BATCH_ALLOC_WAIT_US); if (mem->status == BATCH_ALLOC_OP_DONE) count += mem->sz; } +npa_pool_count: count += cnxk_mempool_get_count(mp); return count; } -static int __rte_hot -cn10k_mempool_deq(struct rte_mempool *mp, void **obj_table, unsigned int n) +static inline unsigned int __rte_hot +mempool_deq(struct rte_mempool *mp, void **obj_table, unsigned int n) +{ + return cnxk_mempool_deq(mp, obj_table, n) ? 0 : n; +} + +static inline unsigned int __rte_hot +mempool_deq_batch_async(struct rte_mempool *mp, void **obj_table, unsigned int n) { struct batch_op_data *op_data; struct batch_op_mem *mem; @@ -205,24 +227,24 @@ cn10k_mempool_deq(struct rte_mempool *mp, void **obj_table, unsigned int n) /* Issue batch alloc */ if (mem->status == BATCH_ALLOC_OP_NOT_ISSUED) { - rc = roc_npa_aura_batch_alloc_issue(mp->pool_id, mem->objs, - BATCH_ALLOC_SZ, 0, 1); + rc = roc_npa_aura_batch_alloc_issue( + mp->pool_id, mem->objs, op_data->max_async_batch, 0, 1); /* If issue fails, try falling back to default alloc */ if (unlikely(rc)) - return cnxk_mempool_deq(mp, obj_table, n); + return mempool_deq(mp, obj_table, n); mem->status = BATCH_ALLOC_OP_ISSUED; } - retry = 4; + retry = BATCH_ALLOC_RETRIES; while (loop) { unsigned int cur_sz; if (mem->status == BATCH_ALLOC_OP_ISSUED) { mem->sz = roc_npa_aura_batch_alloc_extract( - mem->objs, mem->objs, BATCH_ALLOC_SZ); + mem->objs, mem->objs, op_data->max_async_batch); /* If partial alloc reduce the retry count */ - retry -= (mem->sz != BATCH_ALLOC_SZ); + retry -= (mem->sz != op_data->max_async_batch); /* Break the loop if retry count exhausted */ loop = !!retry; mem->status = BATCH_ALLOC_OP_DONE; @@ -244,13 +266,72 @@ cn10k_mempool_deq(struct rte_mempool *mp, void **obj_table, unsigned int n) /* Issue next batch alloc if pointers are exhausted */ if (mem->sz == 0) { rc = roc_npa_aura_batch_alloc_issue( - mp->pool_id, mem->objs, BATCH_ALLOC_SZ, 0, 1); + mp->pool_id, mem->objs, + op_data->max_async_batch, 0, 1); /* Break loop if issue failed and set status */ loop &= !rc; mem->status = !rc; } } + return count; +} + +static inline unsigned int __rte_hot +mempool_deq_batch_sync(struct rte_mempool *mp, void **obj_table, unsigned int n) +{ + struct batch_op_data *op_data; + struct batch_op_mem *mem; + unsigned int count = 0; + int tid, retry, rc; + + op_data = batch_op_data_get(mp->pool_id); + tid = rte_lcore_id(); + mem = &op_data->mem[tid]; + + retry = BATCH_ALLOC_RETRIES; + while (count != n && retry) { + unsigned int cur_sz, batch_sz; + + cur_sz = n - count; + batch_sz = RTE_MIN(BATCH_ALLOC_SZ, (int)cur_sz); + + /* Issue batch alloc */ + rc = roc_npa_aura_batch_alloc_issue(mp->pool_id, mem->objs, + batch_sz, 0, 1); + + /* If issue fails, try falling back to default alloc */ + if (unlikely(rc)) + return count + + mempool_deq(mp, obj_table + count, n - count); + + cur_sz = roc_npa_aura_batch_alloc_extract(mem->objs, mem->objs, + batch_sz); + + /* Dequeue the pointers */ + memcpy(&obj_table[count], mem->objs, + cur_sz * sizeof(uintptr_t)); + count += cur_sz; + + /* If partial alloc reduce the retry count */ + retry -= (batch_sz != cur_sz); + } + + return count; +} + +static int __rte_hot +cn10k_mempool_deq(struct rte_mempool *mp, void **obj_table, unsigned int n) +{ + struct batch_op_data *op_data; + unsigned int count = 0; + + op_data = batch_op_data_get(mp->pool_id); + if (op_data->max_async_batch) + count = mempool_deq_batch_async(mp, obj_table, n); + else + count = mempool_deq_batch_sync(mp, obj_table, n); + if (unlikely(count != n)) { /* No partial alloc allowed. Free up allocated pointers */ cn10k_mempool_enq(mp, obj_table, count);