[v5,06/10] eal_memory: skip initialization

Message ID 20230817042820.137957-7-okaya@kernel.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series support reinit flow |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Sinan Kaya Aug. 17, 2023, 4:28 a.m. UTC
  From: Sinan Kaya <okaya@kernel.org>

Initialize heap area just once.

Signed-off-by: Sinan Kaya <okaya@kernel.org>
---
 lib/eal/common/eal_common_memory.c | 6 ++++++
 lib/eal/common/malloc_heap.c       | 7 +++++++
 2 files changed, 13 insertions(+)
  

Patch

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index d9433db623..1ba2007f76 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -1083,6 +1083,10 @@  rte_eal_memory_init(void)
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	int retval;
+	static bool run_once;
+
+	if (run_once)
+		return 0;
 
 	RTE_LOG(DEBUG, EAL, "Setting up physically contiguous memory...\n");
 
@@ -1101,6 +1105,8 @@  rte_eal_memory_init(void)
 	if (internal_conf->no_shconf == 0 && rte_eal_memdevice_init() < 0)
 		goto fail;
 
+	run_once = true;
+
 	return 0;
 fail:
 	return -1;
diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index 6b6cf9174c..5f01735520 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -31,6 +31,7 @@ 
 #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 unsigned
 check_hugepage_sz(unsigned flags, uint64_t hugepage_sz)
 {
@@ -1409,6 +1410,10 @@  rte_eal_malloc_heap_init(void)
 	unsigned int i;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	static bool run_once;
+
+	if (run_once)
+		return 0;
 
 	if (internal_conf->match_allocations)
 		RTE_LOG(DEBUG, EAL, "Hugepages will be freed exactly as allocated.\n");
@@ -1435,6 +1440,8 @@  rte_eal_malloc_heap_init(void)
 		return -1;
 	}
 
+	run_once = true;
+
 	return 0;
 }