[v3,1/7] malloc: introduce malloc is ready API
Checks
Commit Message
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
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);
@@ -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;
}
@@ -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_ */