diff mbox series

[v3,1/7] malloc: introduce malloc is ready API

Message ID 20211018193707.123559-2-hkalra@marvell.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers show
Series make rte_intr_handle internal | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Harman Kalra Oct. 18, 2021, 7:37 p.m. UTC
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 |  3 +++
 2 files changed, 18 insertions(+), 1 deletion(-)

Comments

Thomas Monjalon Oct. 19, 2021, 3:53 p.m. UTC | #1
18/10/2021 21:37, Harman Kalra:
> @@ -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)

Style: It should be "if (ret == 0)" because ret is not a bool.

> +		malloc_ready = true;
> +
> +	return ret;
> +}
> +
> +bool
> +rte_malloc_is_ready(void)
> +{
> +	return malloc_ready == true;
>  }
> --- a/lib/eal/common/malloc_heap.h
> +++ b/lib/eal/common/malloc_heap.h
> @@ -96,4 +96,7 @@ malloc_socket_to_heap_id(unsigned int socket_id);
>  int
>  rte_eal_malloc_heap_init(void);
>  

Please insert a comment here to document what we can expect.

> +bool
> +rte_malloc_is_ready(void);
diff mbox series

Patch

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index ee400f38ec..4d649e3e5c 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)
+		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..f55d408492 100644
--- a/lib/eal/common/malloc_heap.h
+++ b/lib/eal/common/malloc_heap.h
@@ -96,4 +96,7 @@  malloc_socket_to_heap_id(unsigned int socket_id);
 int
 rte_eal_malloc_heap_init(void);
 
+bool
+rte_malloc_is_ready(void);
+
 #endif /* MALLOC_HEAP_H_ */