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 <hka...@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