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

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

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Harman Kalra Oct. 19, 2021, 6:35 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 |  6 ++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
  

Comments

Dmitry Kozlyuk Oct. 19, 2021, 10:01 p.m. UTC | #1
2021-10-20 00:05 (UTC+0530), Harman Kalra:
[...]
>  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;

A secondary process exits here...

>  	/* 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;

...and never knows that malloc is ready.
But malloc is always ready for a secondary process.
  
Dmitry Kozlyuk Oct. 19, 2021, 10:04 p.m. UTC | #2
2021-10-20 01:01 (UTC+0300), Dmitry Kozlyuk:
> 2021-10-20 00:05 (UTC+0530), Harman Kalra:
> [...]
> >  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;  
> 
> A secondary process exits here...
> 
> >  	/* 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;  
> 
> ...and never knows that malloc is ready.
> But malloc is always ready for a secondary process.

That is, before returning 0 above for a secondary process
malloc_ready should be set unconditionally.
  
Harman Kalra Oct. 20, 2021, 9:01 a.m. UTC | #3
> -----Original Message-----
> From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> Sent: Wednesday, October 20, 2021 3:34 AM
> To: Harman Kalra <hkalra@marvell.com>
> Cc: dev@dpdk.org; Anatoly Burakov <anatoly.burakov@intel.com>;
> david.marchand@redhat.com; mdr@ashroe.eu; thomas@monjalon.net
> Subject: [EXT] Re: [PATCH v4 1/7] malloc: introduce malloc is ready API
> 
> External Email
> 
> ----------------------------------------------------------------------
> 2021-10-20 01:01 (UTC+0300), Dmitry Kozlyuk:
> > 2021-10-20 00:05 (UTC+0530), Harman Kalra:
> > [...]
> > >  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;
> >
> > A secondary process exits here...
> >
> > >  	/* 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;
> >
> > ...and never knows that malloc is ready.
> > But malloc is always ready for a secondary process.
> 
> That is, before returning 0 above for a secondary process malloc_ready
> should be set unconditionally.

Yes, thanks for catching this, I will fix it V5.
  

Patch

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_ */