From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id DCB0EA0547;
	Tue, 19 Oct 2021 20:36:03 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id C455D410EB;
	Tue, 19 Oct 2021 20:36:03 +0200 (CEST)
Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com
 [67.231.148.174])
 by mails.dpdk.org (Postfix) with ESMTP id 3BC8E410EA
 for <dev@dpdk.org>; Tue, 19 Oct 2021 20:36:02 +0200 (CEST)
Received: from pps.filterd (m0045849.ppops.net [127.0.0.1])
 by mx0a-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19JGSaIu025397; 
 Tue, 19 Oct 2021 11:35:59 -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-type; s=pfpt0220; bh=PWPRS5zf11SJAi/s7d3WRGfQ+sIr5kE10pkYlCJMwFM=;
 b=V9MNQ/zDpU/KR2x2oYZ2UxYdUN2h6YineVYM2SDPqv4CN6IYQAqsic0E5NZ1iYyq5JOY
 R8jNiqakm923xW8Tt9z01OQ9qJd/qAnHaqlQKYUxy1MJLTGQs85m6gRYCfEXgoP4o10i
 iCNJZrpmasG8TVGTVAF3Tv4/OH2Ywd6FmJ8BxoaiDNETGgE7jBRX6Wd15ctIrHRxFmAm
 DhQjWAtmZKaDgahn1hIrXKiQAl+2YH/b81cw3JsjMYZkedp1deJX9fD+ovbRcH2BhOXX
 cTxONXcYv20O3INF9IuRGvc1sgzOY4YFhjztqKQe0By0w5Vgr/FjpR3HNI5zd7IfEfhv dQ== 
Received: from dc5-exch02.marvell.com ([199.233.59.182])
 by mx0a-0016f401.pphosted.com with ESMTP id 3bt1jtrk9j-1
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT);
 Tue, 19 Oct 2021 11:35:59 -0700
Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com
 (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18;
 Tue, 19 Oct 2021 11:35:58 -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.18 via Frontend
 Transport; Tue, 19 Oct 2021 11:35:58 -0700
Received: from localhost.localdomain (unknown [10.29.52.211])
 by maili.marvell.com (Postfix) with ESMTP id A9AD63F7043;
 Tue, 19 Oct 2021 11:35:53 -0700 (PDT)
From: Harman Kalra <hkalra@marvell.com>
To: <dev@dpdk.org>, Anatoly Burakov <anatoly.burakov@intel.com>
CC: <david.marchand@redhat.com>, <dmitry.kozliuk@gmail.com>, <mdr@ashroe.eu>, 
 <thomas@monjalon.net>, Harman Kalra <hkalra@marvell.com>
Date: Wed, 20 Oct 2021 00:05:36 +0530
Message-ID: <20211019183543.132084-2-hkalra@marvell.com>
X-Mailer: git-send-email 2.18.0
In-Reply-To: <20211019183543.132084-1-hkalra@marvell.com>
References: <20210826145726.102081-1-hkalra@marvell.com>
 <20211019183543.132084-1-hkalra@marvell.com>
MIME-Version: 1.0
Content-Type: text/plain
X-Proofpoint-GUID: o-pMUlXaBKMz3RjLe2UVR02PEnX3xuwa
X-Proofpoint-ORIG-GUID: o-pMUlXaBKMz3RjLe2UVR02PEnX3xuwa
X-Proofpoint-Virus-Version: vendor=baseguard
 engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475
 definitions=2021-10-19_02,2021-10-19_01,2020-04-07_01
Subject: [dpdk-dev] [PATCH v4 1/7] malloc: introduce malloc is ready API
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

Implementing a new API get the state if DPDK memory management
APIs are initialized.
One of the use case of this API is while allocating an interrupt
instance, if malloc APIs are ready memory for interrupt handles
should be allocated via rte_malloc_* APIs else glibc malloc APIs
are used. Eg. Alarm subsystem is initialised before DPDK memory
infra setup and it allocates an interrupt handle.

Signed-off-by: Harman Kalra <hkalra@marvell.com>
---
 lib/eal/common/malloc_heap.c | 16 +++++++++++++++-
 lib/eal/common/malloc_heap.h |  6 ++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index ee400f38ec..35affecf91 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -36,6 +36,8 @@
 #define CONST_MAX(a, b) (a > b ? a : b) /* RTE_MAX is not a constant */
 #define EXTERNAL_HEAP_MIN_SOCKET_ID (CONST_MAX((1 << 8), RTE_MAX_NUMA_NODES))
 
+static bool malloc_ready;
+
 static unsigned
 check_hugepage_sz(unsigned flags, uint64_t hugepage_sz)
 {
@@ -1328,6 +1330,7 @@ rte_eal_malloc_heap_init(void)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	unsigned int i;
+	int ret;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
@@ -1369,5 +1372,16 @@ rte_eal_malloc_heap_init(void)
 		return 0;
 
 	/* add all IOVA-contiguous areas to the heap */
-	return rte_memseg_contig_walk(malloc_add_seg, NULL);
+	ret = rte_memseg_contig_walk(malloc_add_seg, NULL);
+
+	if (ret == 0)
+		malloc_ready = true;
+
+	return ret;
+}
+
+bool
+rte_malloc_is_ready(void)
+{
+	return malloc_ready == true;
 }
diff --git a/lib/eal/common/malloc_heap.h b/lib/eal/common/malloc_heap.h
index 3a6ec6ecf0..bc23944958 100644
--- a/lib/eal/common/malloc_heap.h
+++ b/lib/eal/common/malloc_heap.h
@@ -96,4 +96,10 @@ malloc_socket_to_heap_id(unsigned int socket_id);
 int
 rte_eal_malloc_heap_init(void);
 
+/* This API is used to know if DPDK memory subsystem is setup and its
+ * corresponding APIs are ready to be used.
+ */
+bool
+rte_malloc_is_ready(void);
+
 #endif /* MALLOC_HEAP_H_ */
-- 
2.18.0