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 7583142F9D; Mon, 31 Jul 2023 07:55:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 04CA240A89; Mon, 31 Jul 2023 07:55:29 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 46C5140150 for ; Mon, 31 Jul 2023 07:55:27 +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 36UNSUZ3022028 for ; Sun, 30 Jul 2023 22:55:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=5Fny+BzIT1ycF5Yty/etjMYr+kTMMfQ4gOxmSqoEmZg=; b=FkHvmkKB30F2NxCkt1Wv+OTjy1Ek4O85icjhAH5VT/4xxt/UUh+9eeqlyyGR1dltCz8J IMH0OXnMHy23CbDfnHwJaikxXX9tQOqctTRRIcnKx3yCGRsfZxfMy2O9fnahsqzMV/f5 mgx1yER/ayLOjcfYDUPNp9heJTvIhwoj+Hl5qh3FeAZ3Qx+9fDVoNAq0DmRKxjHMWQ8z S1tB3aVwci/QB9YOnBNunB6k8/i8ncK1SxyJd5bPTlnRTEZDZb/yHdGWCugcbKmgcTIt pbadZCKd9H+gcCdc3nCzUhMij+smEdRIsjcyvKK7omVv78Y2QT9ocd4P5ySFXU0zEpkj ow== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3s504nmejg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 30 Jul 2023 22:55:26 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 30 Jul 2023 22:55:23 -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; Sun, 30 Jul 2023 22:55:24 -0700 Received: from localhost.localdomain (unknown [10.28.36.142]) by maili.marvell.com (Postfix) with ESMTP id 52FE53F7040; Sun, 30 Jul 2023 22:55:20 -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/2] mempool/cnxk: limit usage of async allocs Date: Mon, 31 Jul 2023 11:25:13 +0530 Message-ID: <20230731055514.1708500-1-asekhar@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: T71E_6k3V6r4gj7HZulEUMNgunqjo9O_ X-Proofpoint-GUID: T71E_6k3V6r4gj7HZulEUMNgunqjo9O_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-27_10,2023-07-26_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); -- 2.25.1