DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/4] service: move finalize to internal
@ 2018-01-27 18:31 Harry van Haaren
  2018-01-27 18:31 ` [dpdk-dev] [PATCH 2/4] eal: add function to release internal resources Harry van Haaren
                   ` (3 more replies)
  0 siblings, 4 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-27 18:31 UTC (permalink / raw)
  To: dev; +Cc: thomas, Harry van Haaren, vipin.varghese

This commit moves the rte_service_finalize() function
to be in the component header, and marks it as @internal.
The function is only called internally by rte_eal_finalize().

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 lib/librte_eal/common/include/rte_service.h           | 11 -----------
 lib/librte_eal/common/include/rte_service_component.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h
index 5e3e3a6..02b1512 100644
--- a/lib/librte_eal/common/include/rte_service.h
+++ b/lib/librte_eal/common/include/rte_service.h
@@ -429,17 +429,6 @@ int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id,
  */
 int32_t rte_service_attr_reset_all(uint32_t id);
 
-/**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
- * Free up the memory that has been initialized. This routine
- * is to be invoked prior to process termination.
- *
- * @retval None
- */
-void rte_service_finalize(void);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/include/rte_service_component.h b/lib/librte_eal/common/include/rte_service_component.h
index 849c71d..f881ac0 100644
--- a/lib/librte_eal/common/include/rte_service_component.h
+++ b/lib/librte_eal/common/include/rte_service_component.h
@@ -139,4 +139,15 @@ int32_t rte_service_component_runstate_set(uint32_t id, uint32_t runstate);
  */
 int32_t rte_service_init(void);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @internal Free up the memory that has been initialized.
+ * This routine is to be invoked prior to process termination.
+ *
+ * @retval None
+ */
+void rte_service_finalize(void);
+
 #endif /* _RTE_SERVICE_PRIVATE_H_ */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH 2/4] eal: add function to release internal resources
  2018-01-27 18:31 [dpdk-dev] [PATCH 1/4] service: move finalize to internal Harry van Haaren
@ 2018-01-27 18:31 ` Harry van Haaren
  2018-01-27 18:31 ` [dpdk-dev] [PATCH 3/4] app/pdump: call eal finalize before exit Harry van Haaren
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-27 18:31 UTC (permalink / raw)
  To: dev; +Cc: thomas, Harry van Haaren, vipin.varghese

This commit adds a new function rte_eal_finalize().
The function serves as a hook to allow DPDK to release
internal resources (e.g.: hugepage allocations).

This function allows DPDK to become more like an ordinary
library, where the library context itself can be initialized
and finalized by the application.

The rte_exit() and rte_panic() functions must be considered,
particularly if they should call finalize() to cleanup any
resources or not. This patch adds the cleanup to rte_exit(),
but does not clean up on rte_panic(). The reason to not clean
up on panicing is that the developer may wish to inspect the
exact internal state of EAL.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 doc/guides/prog_guide/env_abstraction_layer.rst |  8 ++++++++
 doc/guides/rel_notes/release_18_02.rst          |  9 +++++++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/eal_debug.c           |  5 +++++
 lib/librte_eal/common/include/rte_eal.h         | 15 +++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile            |  1 +
 lib/librte_eal/linuxapp/eal/eal_debug.c         |  5 +++++
 lib/librte_eal/rte_eal_version.map              |  1 +
 8 files changed, 45 insertions(+)

diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
index 34d871c..f020041 100644
--- a/doc/guides/prog_guide/env_abstraction_layer.rst
+++ b/doc/guides/prog_guide/env_abstraction_layer.rst
@@ -99,6 +99,14 @@ It consist of calls to the pthread library (more specifically, pthread_self(), p
     The creation and initialization functions for these objects are not multi-thread safe.
     However, once initialized, the objects themselves can safely be used in multiple threads simultaneously.
 
+Finalizing and Cleanup
+~~~~~~~~~~~~~~~~~~~~~~
+
+During the initialization of EAL resources such as hugepage backed memory can be
+allocated by core components.  The memory allocated during ``rte_eal_init()``
+can be released by calling the ``rte_eal_finalize()`` function. Refer to the
+API documentation for details.
+
 Multi-process Support
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 00b3224..5c7410e 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -41,6 +41,15 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Add function to allow releasing internal EAL resources on exit**
+
+  During ``rte_eal_init()`` EAL allocates memory from hugepages to enable its
+  core libraries to perform their tasks. The ``rte_eal_finalize()`` function
+  releases these resources, ensuring that no hugepage memory is leaked. It is
+  expected that all DPDK applications call ``rte_eal_finalize()`` before
+  exiting. Not calling this function could result in leaking hugepages, leading
+  to failure during initialization of secondary processes.
+
 * **Added the ixgbe ethernet driver to support RSS with flow API.**
 
   Rte_flow actually defined to include RSS, but till now, RSS is out of
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index c694076..7480f98 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -34,6 +34,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c
index b0ae2b7..1a17ce3 100644
--- a/lib/librte_eal/bsdapp/eal/eal_debug.c
+++ b/lib/librte_eal/bsdapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_finalize();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 2aba2c8..b2f5869 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -170,6 +170,21 @@ int rte_eal_iopl_init(void);
 int rte_eal_init(int argc, char **argv);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ * Finalize the Environment Abstraction Layer (EAL)
+ *
+ * This function must be called to release any internal resources that EAL has
+ * allocated during rte_eal_init(). After this call, no DPDK function calls may
+ * be made. It is expected that common usage of this function is to call it
+ * just before terminating the process.
+ *
+ * @return 0 Successfully released all internal EAL resources
+ * @return -EFAULT There was an error in releasing all resources.
+ */
+int rte_eal_finalize(void);
+
+/**
  * Check if a primary process is currently alive
  *
  * This function returns true when a primary process is currently
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 7bf278f..ad20f2f 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c
index b0ae2b7..1a17ce3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_debug.c
+++ b/lib/librte_eal/linuxapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_finalize();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index 1a8b1b5..c906305 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -215,6 +215,7 @@ EXPERIMENTAL {
 	rte_eal_devargs_insert;
 	rte_eal_devargs_parse;
 	rte_eal_devargs_remove;
+	rte_eal_finalize;
 	rte_eal_hotplug_add;
 	rte_eal_hotplug_remove;
 	rte_service_attr_get;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH 3/4] app/pdump: call eal finalize before exit
  2018-01-27 18:31 [dpdk-dev] [PATCH 1/4] service: move finalize to internal Harry van Haaren
  2018-01-27 18:31 ` [dpdk-dev] [PATCH 2/4] eal: add function to release internal resources Harry van Haaren
@ 2018-01-27 18:31 ` Harry van Haaren
  2018-01-27 18:31 ` [dpdk-dev] [PATCH 4/4] app/proc_info: " Harry van Haaren
  2018-01-29 10:45 ` [dpdk-dev] [PATCH v2 1/4] service: move finalize to internal Harry van Haaren
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-27 18:31 UTC (permalink / raw)
  To: dev; +Cc: thomas, Harry van Haaren, vipin.varghese

This patch adds a call to the newly introduced finalize()
function just before quitting the pdump app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/pdump/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 0f70c75..6c58cda 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -882,5 +882,10 @@ main(int argc, char **argv)
 	/* dump debug stats */
 	print_pdump_stats();
 
+	ret = rte_eal_finalize();
+	if (ret)
+		printf("Error from rte_eal_finalize(), %d\n", ret);
+
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH 4/4] app/proc_info: call eal finalize before exit
  2018-01-27 18:31 [dpdk-dev] [PATCH 1/4] service: move finalize to internal Harry van Haaren
  2018-01-27 18:31 ` [dpdk-dev] [PATCH 2/4] eal: add function to release internal resources Harry van Haaren
  2018-01-27 18:31 ` [dpdk-dev] [PATCH 3/4] app/pdump: call eal finalize before exit Harry van Haaren
@ 2018-01-27 18:31 ` Harry van Haaren
  2018-01-29 10:45 ` [dpdk-dev] [PATCH v2 1/4] service: move finalize to internal Harry van Haaren
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-27 18:31 UTC (permalink / raw)
  To: dev; +Cc: thomas, Harry van Haaren, vipin.varghese

This patch adds a call to the newly introduced finalize()
function just before quitting the app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/proc_info/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 94d53f5..44efbc4 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -660,5 +660,9 @@ main(int argc, char **argv)
 	if (enable_metrics)
 		metrics_display(RTE_METRICS_GLOBAL);
 
+	ret = rte_eal_finalize();
+	if (ret)
+		printf("Error from rte_eal_finalize(), %d\n", ret);
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v2 1/4] service: move finalize to internal
  2018-01-27 18:31 [dpdk-dev] [PATCH 1/4] service: move finalize to internal Harry van Haaren
                   ` (2 preceding siblings ...)
  2018-01-27 18:31 ` [dpdk-dev] [PATCH 4/4] app/proc_info: " Harry van Haaren
@ 2018-01-29 10:45 ` Harry van Haaren
  2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources Harry van Haaren
                     ` (3 more replies)
  3 siblings, 4 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 10:45 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This commit moves the rte_service_finalize() function
to be in the component header, and marks it as @internal.
The function is only called internally by rte_eal_finalize().

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 lib/librte_eal/common/include/rte_service.h           | 11 -----------
 lib/librte_eal/common/include/rte_service_component.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h
index 5e3e3a6..02b1512 100644
--- a/lib/librte_eal/common/include/rte_service.h
+++ b/lib/librte_eal/common/include/rte_service.h
@@ -429,17 +429,6 @@ int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id,
  */
 int32_t rte_service_attr_reset_all(uint32_t id);
 
-/**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
- * Free up the memory that has been initialized. This routine
- * is to be invoked prior to process termination.
- *
- * @retval None
- */
-void rte_service_finalize(void);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/include/rte_service_component.h b/lib/librte_eal/common/include/rte_service_component.h
index 849c71d..f881ac0 100644
--- a/lib/librte_eal/common/include/rte_service_component.h
+++ b/lib/librte_eal/common/include/rte_service_component.h
@@ -139,4 +139,15 @@ int32_t rte_service_component_runstate_set(uint32_t id, uint32_t runstate);
  */
 int32_t rte_service_init(void);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @internal Free up the memory that has been initialized.
+ * This routine is to be invoked prior to process termination.
+ *
+ * @retval None
+ */
+void rte_service_finalize(void);
+
 #endif /* _RTE_SERVICE_PRIVATE_H_ */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources
  2018-01-29 10:45 ` [dpdk-dev] [PATCH v2 1/4] service: move finalize to internal Harry van Haaren
@ 2018-01-29 10:45   ` Harry van Haaren
  2018-01-29 10:55     ` Thomas Monjalon
  2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 3/4] app/pdump: call eal finalize before exit Harry van Haaren
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 10:45 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This commit adds a new function rte_eal_finalize().
The function serves as a hook to allow DPDK to release
internal resources (e.g.: hugepage allocations).

This function allows DPDK to become more like an ordinary
library, where the library context itself can be initialized
and finalized by the application.

The rte_exit() and rte_panic() functions must be considered,
particularly if they should call finalize() to cleanup any
resources or not. This patch adds the cleanup to rte_exit(),
but does not clean up on rte_panic(). The reason to not clean
up on panicing is that the developer may wish to inspect the
exact internal state of EAL.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

v2:
- Add eal_common.c file to commit, fixing build (Vipin)
  [OT] Meson/ninja has a nice feature to avoid this error: ninja dist

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 doc/guides/prog_guide/env_abstraction_layer.rst |  8 ++++++++
 doc/guides/rel_notes/release_18_02.rst          |  9 +++++++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/eal_debug.c           |  5 +++++
 lib/librte_eal/common/eal_common.c              | 11 +++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 15 +++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile            |  1 +
 lib/librte_eal/linuxapp/eal/eal_debug.c         |  5 +++++
 lib/librte_eal/rte_eal_version.map              |  1 +
 9 files changed, 56 insertions(+)
 create mode 100644 lib/librte_eal/common/eal_common.c

diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
index 34d871c..f020041 100644
--- a/doc/guides/prog_guide/env_abstraction_layer.rst
+++ b/doc/guides/prog_guide/env_abstraction_layer.rst
@@ -99,6 +99,14 @@ It consist of calls to the pthread library (more specifically, pthread_self(), p
     The creation and initialization functions for these objects are not multi-thread safe.
     However, once initialized, the objects themselves can safely be used in multiple threads simultaneously.
 
+Finalizing and Cleanup
+~~~~~~~~~~~~~~~~~~~~~~
+
+During the initialization of EAL resources such as hugepage backed memory can be
+allocated by core components.  The memory allocated during ``rte_eal_init()``
+can be released by calling the ``rte_eal_finalize()`` function. Refer to the
+API documentation for details.
+
 Multi-process Support
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 00b3224..5c7410e 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -41,6 +41,15 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Add function to allow releasing internal EAL resources on exit**
+
+  During ``rte_eal_init()`` EAL allocates memory from hugepages to enable its
+  core libraries to perform their tasks. The ``rte_eal_finalize()`` function
+  releases these resources, ensuring that no hugepage memory is leaked. It is
+  expected that all DPDK applications call ``rte_eal_finalize()`` before
+  exiting. Not calling this function could result in leaking hugepages, leading
+  to failure during initialization of secondary processes.
+
 * **Added the ixgbe ethernet driver to support RSS with flow API.**
 
   Rte_flow actually defined to include RSS, but till now, RSS is out of
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index c694076..7480f98 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -34,6 +34,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c
index b0ae2b7..1a17ce3 100644
--- a/lib/librte_eal/bsdapp/eal/eal_debug.c
+++ b/lib/librte_eal/bsdapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_finalize();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/common/eal_common.c b/lib/librte_eal/common/eal_common.c
new file mode 100644
index 0000000..46e8c62
--- /dev/null
+++ b/lib/librte_eal/common/eal_common.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <rte_service_component.h>
+
+int rte_eal_finalize(void)
+{
+	rte_service_finalize();
+	return 0;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 2aba2c8..b2f5869 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -170,6 +170,21 @@ int rte_eal_iopl_init(void);
 int rte_eal_init(int argc, char **argv);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ * Finalize the Environment Abstraction Layer (EAL)
+ *
+ * This function must be called to release any internal resources that EAL has
+ * allocated during rte_eal_init(). After this call, no DPDK function calls may
+ * be made. It is expected that common usage of this function is to call it
+ * just before terminating the process.
+ *
+ * @return 0 Successfully released all internal EAL resources
+ * @return -EFAULT There was an error in releasing all resources.
+ */
+int rte_eal_finalize(void);
+
+/**
  * Check if a primary process is currently alive
  *
  * This function returns true when a primary process is currently
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 7bf278f..ad20f2f 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c
index b0ae2b7..1a17ce3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_debug.c
+++ b/lib/librte_eal/linuxapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_finalize();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index 1a8b1b5..c906305 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -215,6 +215,7 @@ EXPERIMENTAL {
 	rte_eal_devargs_insert;
 	rte_eal_devargs_parse;
 	rte_eal_devargs_remove;
+	rte_eal_finalize;
 	rte_eal_hotplug_add;
 	rte_eal_hotplug_remove;
 	rte_service_attr_get;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v2 3/4] app/pdump: call eal finalize before exit
  2018-01-29 10:45 ` [dpdk-dev] [PATCH v2 1/4] service: move finalize to internal Harry van Haaren
  2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources Harry van Haaren
@ 2018-01-29 10:45   ` Harry van Haaren
  2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 4/4] app/proc_info: " Harry van Haaren
  2018-01-29 12:08   ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 10:45 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This patch adds a call to the newly introduced finalize()
function just before quitting the pdump app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/pdump/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 0f70c75..6c58cda 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -882,5 +882,10 @@ main(int argc, char **argv)
 	/* dump debug stats */
 	print_pdump_stats();
 
+	ret = rte_eal_finalize();
+	if (ret)
+		printf("Error from rte_eal_finalize(), %d\n", ret);
+
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v2 4/4] app/proc_info: call eal finalize before exit
  2018-01-29 10:45 ` [dpdk-dev] [PATCH v2 1/4] service: move finalize to internal Harry van Haaren
  2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources Harry van Haaren
  2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 3/4] app/pdump: call eal finalize before exit Harry van Haaren
@ 2018-01-29 10:45   ` Harry van Haaren
  2018-01-29 12:08   ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 10:45 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This patch adds a call to the newly introduced finalize()
function just before quitting the app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/proc_info/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 94d53f5..44efbc4 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -660,5 +660,9 @@ main(int argc, char **argv)
 	if (enable_metrics)
 		metrics_display(RTE_METRICS_GLOBAL);
 
+	ret = rte_eal_finalize();
+	if (ret)
+		printf("Error from rte_eal_finalize(), %d\n", ret);
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources
  2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources Harry van Haaren
@ 2018-01-29 10:55     ` Thomas Monjalon
  2018-01-29 11:10       ` Van Haaren, Harry
  0 siblings, 1 reply; 31+ messages in thread
From: Thomas Monjalon @ 2018-01-29 10:55 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev, vipin.varghese

29/01/2018 11:45, Harry van Haaren:
> --- a/doc/guides/prog_guide/env_abstraction_layer.rst
> +++ b/doc/guides/prog_guide/env_abstraction_layer.rst
> +Finalizing and Cleanup
> +~~~~~~~~~~~~~~~~~~~~~~
> +
> +During the initialization of EAL resources such as hugepage backed memory can be
> +allocated by core components.  The memory allocated during ``rte_eal_init()``
> +can be released by calling the ``rte_eal_finalize()`` function. Refer to the
> +API documentation for details.

About naming, what is better between
	rte_eal_finalize() and
	rte_eal_cleanup() ?
I tend to think that "cleanup" is more descriptive.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources
  2018-01-29 10:55     ` Thomas Monjalon
@ 2018-01-29 11:10       ` Van Haaren, Harry
  2018-01-29 11:55         ` Thomas Monjalon
  0 siblings, 1 reply; 31+ messages in thread
From: Van Haaren, Harry @ 2018-01-29 11:10 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Varghese, Vipin

> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Monday, January 29, 2018 10:56 AM
> To: Van Haaren, Harry <harry.van.haaren@intel.com>
> Cc: dev@dpdk.org; Varghese, Vipin <vipin.varghese@intel.com>
> Subject: Re: [PATCH v2 2/4] eal: add function to release internal resources
> 
> 29/01/2018 11:45, Harry van Haaren:
> > --- a/doc/guides/prog_guide/env_abstraction_layer.rst
> > +++ b/doc/guides/prog_guide/env_abstraction_layer.rst
> > +Finalizing and Cleanup
> > +~~~~~~~~~~~~~~~~~~~~~~
> > +
> > +During the initialization of EAL resources such as hugepage backed memory
> can be
> > +allocated by core components.  The memory allocated during
> ``rte_eal_init()``
> > +can be released by calling the ``rte_eal_finalize()`` function. Refer to
> the
> > +API documentation for details.
> 
> About naming, what is better between
> 	rte_eal_finalize() and
> 	rte_eal_cleanup() ?
> I tend to think that "cleanup" is more descriptive.

Sure cleanup() is fine for me, I'll spin a v3 with the function name change.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources
  2018-01-29 11:10       ` Van Haaren, Harry
@ 2018-01-29 11:55         ` Thomas Monjalon
  2018-01-29 12:04           ` Bruce Richardson
  2018-01-29 12:12           ` Van Haaren, Harry
  0 siblings, 2 replies; 31+ messages in thread
From: Thomas Monjalon @ 2018-01-29 11:55 UTC (permalink / raw)
  To: Van Haaren, Harry; +Cc: dev, Varghese, Vipin

29/01/2018 12:10, Van Haaren, Harry:
> > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > Sent: Monday, January 29, 2018 10:56 AM
> > To: Van Haaren, Harry <harry.van.haaren@intel.com>
> > Cc: dev@dpdk.org; Varghese, Vipin <vipin.varghese@intel.com>
> > Subject: Re: [PATCH v2 2/4] eal: add function to release internal resources
> > 
> > 29/01/2018 11:45, Harry van Haaren:
> > > --- a/doc/guides/prog_guide/env_abstraction_layer.rst
> > > +++ b/doc/guides/prog_guide/env_abstraction_layer.rst
> > > +Finalizing and Cleanup
> > > +~~~~~~~~~~~~~~~~~~~~~~
> > > +
> > > +During the initialization of EAL resources such as hugepage backed memory
> > can be
> > > +allocated by core components.  The memory allocated during
> > ``rte_eal_init()``
> > > +can be released by calling the ``rte_eal_finalize()`` function. Refer to
> > the
> > > +API documentation for details.
> > 
> > About naming, what is better between
> > 	rte_eal_finalize() and
> > 	rte_eal_cleanup() ?
> > I tend to think that "cleanup" is more descriptive.
> 
> Sure cleanup() is fine for me, I'll spin a v3 with the function name change.

Harry, it is a real question!
If someone thinks "finalize" is better, I would like to hear it
because we may use the same wording in more DPDK functions.

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources
  2018-01-29 11:55         ` Thomas Monjalon
@ 2018-01-29 12:04           ` Bruce Richardson
  2018-01-29 12:12           ` Van Haaren, Harry
  1 sibling, 0 replies; 31+ messages in thread
From: Bruce Richardson @ 2018-01-29 12:04 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: Van Haaren, Harry, dev, Varghese, Vipin

On Mon, Jan 29, 2018 at 12:55:35PM +0100, Thomas Monjalon wrote:
> 29/01/2018 12:10, Van Haaren, Harry:
> > > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > Sent: Monday, January 29, 2018 10:56 AM
> > > To: Van Haaren, Harry <harry.van.haaren@intel.com>
> > > Cc: dev@dpdk.org; Varghese, Vipin <vipin.varghese@intel.com>
> > > Subject: Re: [PATCH v2 2/4] eal: add function to release internal resources
> > > 
> > > 29/01/2018 11:45, Harry van Haaren:
> > > > --- a/doc/guides/prog_guide/env_abstraction_layer.rst
> > > > +++ b/doc/guides/prog_guide/env_abstraction_layer.rst
> > > > +Finalizing and Cleanup
> > > > +~~~~~~~~~~~~~~~~~~~~~~
> > > > +
> > > > +During the initialization of EAL resources such as hugepage backed memory
> > > can be
> > > > +allocated by core components.  The memory allocated during
> > > ``rte_eal_init()``
> > > > +can be released by calling the ``rte_eal_finalize()`` function. Refer to
> > > the
> > > > +API documentation for details.
> > > 
> > > About naming, what is better between
> > > 	rte_eal_finalize() and
> > > 	rte_eal_cleanup() ?
> > > I tend to think that "cleanup" is more descriptive.
> > 
> > Sure cleanup() is fine for me, I'll spin a v3 with the function name change.
> 
> Harry, it is a real question!
> If someone thinks "finalize" is better, I would like to hear it
> because we may use the same wording in more DPDK functions.
> 

I like finalize better.

1) Both initialize and finalize sound similar as both end in "ize" so
sound like they are a pair
2) The use of .init and .fini elf sessions are precedent for the naming

/Bruce

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal
  2018-01-29 10:45 ` [dpdk-dev] [PATCH v2 1/4] service: move finalize to internal Harry van Haaren
                     ` (2 preceding siblings ...)
  2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 4/4] app/proc_info: " Harry van Haaren
@ 2018-01-29 12:08   ` Harry van Haaren
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 2/4] eal: add function to release internal resources Harry van Haaren
                       ` (4 more replies)
  3 siblings, 5 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 12:08 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This commit moves the rte_service_finalize() function
to be in the component header, and marks it as @internal.
The function is only called internally by rte_eal_finalize().

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 lib/librte_eal/common/include/rte_service.h           | 11 -----------
 lib/librte_eal/common/include/rte_service_component.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h
index 5e3e3a6..02b1512 100644
--- a/lib/librte_eal/common/include/rte_service.h
+++ b/lib/librte_eal/common/include/rte_service.h
@@ -429,17 +429,6 @@ int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id,
  */
 int32_t rte_service_attr_reset_all(uint32_t id);
 
-/**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
- * Free up the memory that has been initialized. This routine
- * is to be invoked prior to process termination.
- *
- * @retval None
- */
-void rte_service_finalize(void);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/include/rte_service_component.h b/lib/librte_eal/common/include/rte_service_component.h
index 849c71d..f881ac0 100644
--- a/lib/librte_eal/common/include/rte_service_component.h
+++ b/lib/librte_eal/common/include/rte_service_component.h
@@ -139,4 +139,15 @@ int32_t rte_service_component_runstate_set(uint32_t id, uint32_t runstate);
  */
 int32_t rte_service_init(void);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @internal Free up the memory that has been initialized.
+ * This routine is to be invoked prior to process termination.
+ *
+ * @retval None
+ */
+void rte_service_finalize(void);
+
 #endif /* _RTE_SERVICE_PRIVATE_H_ */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v3 2/4] eal: add function to release internal resources
  2018-01-29 12:08   ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
@ 2018-01-29 12:08     ` Harry van Haaren
  2018-01-29 15:07       ` Varghese, Vipin
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
                       ` (3 subsequent siblings)
  4 siblings, 1 reply; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 12:08 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This commit adds a new function rte_eal_cleanup().
The function serves as a hook to allow DPDK to release
internal resources (e.g.: hugepage allocations).

This function allows DPDK to become more like an ordinary
library, where the library context itself can be initialized
and cleaned up by the application.

The rte_exit() and rte_panic() functions must be considered,
particularly if they should call rte_eal_cleanup() to release any
resources or not. This patch adds the cleanup to rte_exit(),
but does not clean up on rte_panic(). The reason to not clean
up on panicing is that the developer may wish to inspect the
exact internal state of EAL and hugepages.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

v3:
- Rename function to cleanup (Thomas)

v2:
- Add eal_common.c file commit (Vipin)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 doc/guides/prog_guide/env_abstraction_layer.rst |  8 ++++++++
 doc/guides/rel_notes/release_18_02.rst          |  9 +++++++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/eal_debug.c           |  5 +++++
 lib/librte_eal/common/eal_common.c              | 11 +++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 16 ++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile            |  1 +
 lib/librte_eal/linuxapp/eal/eal_debug.c         |  5 +++++
 lib/librte_eal/rte_eal_version.map              |  1 +
 9 files changed, 57 insertions(+)
 create mode 100644 lib/librte_eal/common/eal_common.c

diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
index 34d871c..04bd776 100644
--- a/doc/guides/prog_guide/env_abstraction_layer.rst
+++ b/doc/guides/prog_guide/env_abstraction_layer.rst
@@ -99,6 +99,14 @@ It consist of calls to the pthread library (more specifically, pthread_self(), p
     The creation and initialization functions for these objects are not multi-thread safe.
     However, once initialized, the objects themselves can safely be used in multiple threads simultaneously.
 
+Shutdown and Cleanup
+~~~~~~~~~~~~~~~~~~~~
+
+During the initialization of EAL resources such as hugepage backed memory can be
+allocated by core components.  The memory allocated during ``rte_eal_init()``
+can be released by calling the ``rte_eal_cleanup()`` function. Refer to the
+API documentation for details.
+
 Multi-process Support
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 00b3224..8c3968e 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -41,6 +41,15 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Add function to allow releasing internal EAL resources on exit**
+
+  During ``rte_eal_init()`` EAL allocates memory from hugepages to enable its
+  core libraries to perform their tasks. The ``rte_eal_cleanup()`` function
+  releases these resources, ensuring that no hugepage memory is leaked. It is
+  expected that all DPDK applications call ``rte_eal_cleanup()`` before
+  exiting. Not calling this function could result in leaking hugepages, leading
+  to failure during initialization of secondary processes.
+
 * **Added the ixgbe ethernet driver to support RSS with flow API.**
 
   Rte_flow actually defined to include RSS, but till now, RSS is out of
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index c694076..7480f98 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -34,6 +34,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c
index b0ae2b7..f66e504 100644
--- a/lib/librte_eal/bsdapp/eal/eal_debug.c
+++ b/lib/librte_eal/bsdapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_cleanup();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/common/eal_common.c b/lib/librte_eal/common/eal_common.c
new file mode 100644
index 0000000..52771e7
--- /dev/null
+++ b/lib/librte_eal/common/eal_common.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <rte_service_component.h>
+
+int rte_eal_cleanup(void)
+{
+	rte_service_finalize();
+	return 0;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 2aba2c8..8b36fea 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -170,6 +170,22 @@ int rte_eal_iopl_init(void);
 int rte_eal_init(int argc, char **argv);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Clean up the Environment Abstraction Layer (EAL)
+ *
+ * This function must be called to release any internal resources that EAL has
+ * allocated during rte_eal_init(). After this call, no DPDK function calls may
+ * be made. It is expected that common usage of this function is to call it
+ * just before terminating the process.
+ *
+ * @return 0 Successfully released all internal EAL resources
+ * @return -EFAULT There was an error in releasing all resources.
+ */
+int rte_eal_cleanup(void);
+
+/**
  * Check if a primary process is currently alive
  *
  * This function returns true when a primary process is currently
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 7bf278f..ad20f2f 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c
index b0ae2b7..f66e504 100644
--- a/lib/librte_eal/linuxapp/eal/eal_debug.c
+++ b/lib/librte_eal/linuxapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_cleanup();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index 1a8b1b5..8dd4abf 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -215,6 +215,7 @@ EXPERIMENTAL {
 	rte_eal_devargs_insert;
 	rte_eal_devargs_parse;
 	rte_eal_devargs_remove;
+	rte_eal_cleanup;
 	rte_eal_hotplug_add;
 	rte_eal_hotplug_remove;
 	rte_service_attr_get;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v3 3/4] app/pdump: call eal cleanup before exit
  2018-01-29 12:08   ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 2/4] eal: add function to release internal resources Harry van Haaren
@ 2018-01-29 12:08     ` Harry van Haaren
  2018-01-29 15:09       ` Varghese, Vipin
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 4/4] app/proc_info: " Harry van Haaren
                       ` (2 subsequent siblings)
  4 siblings, 1 reply; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 12:08 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This patch adds a call to the newly introduced cleanup()
function just before quitting the pdump app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

v3:
- Rework to new cleanup() function name (Thomas)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/pdump/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 0f70c75..50772cb 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -882,5 +882,10 @@ main(int argc, char **argv)
 	/* dump debug stats */
 	print_pdump_stats();
 
+	ret = rte_eal_cleanup();
+	if (ret)
+		printf("Error from rte_eal_cleanup(), %d\n", ret);
+
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v3 4/4] app/proc_info: call eal cleanup before exit
  2018-01-29 12:08   ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 2/4] eal: add function to release internal resources Harry van Haaren
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
@ 2018-01-29 12:08     ` Harry van Haaren
  2018-01-29 15:09       ` Varghese, Vipin
  2018-01-29 15:05     ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Varghese, Vipin
  2018-01-29 16:00     ` [dpdk-dev] [PATCH v4 " Harry van Haaren
  4 siblings, 1 reply; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 12:08 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This patch adds a call to the newly introduced cleanup()
function just before quitting the app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

---

v3:
- Rework to use cleanup() function name (Thomas)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/proc_info/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 94d53f5..2f53e3c 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -660,5 +660,9 @@ main(int argc, char **argv)
 	if (enable_metrics)
 		metrics_display(RTE_METRICS_GLOBAL);
 
+	ret = rte_eal_cleanup();
+	if (ret)
+		printf("Error from rte_eal_cleanup(), %d\n", ret);
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources
  2018-01-29 11:55         ` Thomas Monjalon
  2018-01-29 12:04           ` Bruce Richardson
@ 2018-01-29 12:12           ` Van Haaren, Harry
  1 sibling, 0 replies; 31+ messages in thread
From: Van Haaren, Harry @ 2018-01-29 12:12 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Varghese, Vipin

> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Monday, January 29, 2018 11:56 AM
> To: Van Haaren, Harry <harry.van.haaren@intel.com>
> Cc: dev@dpdk.org; Varghese, Vipin <vipin.varghese@intel.com>
> Subject: Re: [PATCH v2 2/4] eal: add function to release internal resources
> 
> 29/01/2018 12:10, Van Haaren, Harry:
> > > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > Sent: Monday, January 29, 2018 10:56 AM
> > > To: Van Haaren, Harry <harry.van.haaren@intel.com>
> > > Cc: dev@dpdk.org; Varghese, Vipin <vipin.varghese@intel.com>
> > > Subject: Re: [PATCH v2 2/4] eal: add function to release internal
> resources
> > >
> > > 29/01/2018 11:45, Harry van Haaren:
> > > > --- a/doc/guides/prog_guide/env_abstraction_layer.rst
> > > > +++ b/doc/guides/prog_guide/env_abstraction_layer.rst
> > > > +Finalizing and Cleanup
> > > > +~~~~~~~~~~~~~~~~~~~~~~
> > > > +
> > > > +During the initialization of EAL resources such as hugepage backed
> memory
> > > can be
> > > > +allocated by core components.  The memory allocated during
> > > ``rte_eal_init()``
> > > > +can be released by calling the ``rte_eal_finalize()`` function. Refer
> to
> > > the
> > > > +API documentation for details.
> > >
> > > About naming, what is better between
> > > 	rte_eal_finalize() and
> > > 	rte_eal_cleanup() ?
> > > I tend to think that "cleanup" is more descriptive.
> >
> > Sure cleanup() is fine for me, I'll spin a v3 with the function name
> change.
> 
> Harry, it is a real question!

Yup,

> If someone thinks "finalize" is better, I would like to hear it
> because we may use the same wording in more DPDK functions.


To me, finalize() and cleanup() mean the same thing.
I think cleanup() is a simpler term (and I like simple :)

Hence, v3 sent with cleanup()

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal
  2018-01-29 12:08   ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
                       ` (2 preceding siblings ...)
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 4/4] app/proc_info: " Harry van Haaren
@ 2018-01-29 15:05     ` Varghese, Vipin
  2018-01-29 16:00     ` [dpdk-dev] [PATCH v4 " Harry van Haaren
  4 siblings, 0 replies; 31+ messages in thread
From: Varghese, Vipin @ 2018-01-29 15:05 UTC (permalink / raw)
  To: Van Haaren, Harry, dev; +Cc: thomas

Moving the function as internal is ok with me.

Acked-by: Vipin Varghese <vipin.varghese@intel.com>

> -----Original Message-----
> From: Van Haaren, Harry
> Sent: Monday, January 29, 2018 5:38 PM
> To: dev@dpdk.org
> Cc: Van Haaren, Harry <harry.van.haaren@intel.com>; thomas@monjalon.net;
> Varghese, Vipin <vipin.varghese@intel.com>
> Subject: [PATCH v3 1/4] service: move finalize to internal
> 
> This commit moves the rte_service_finalize() function to be in the component
> header, and marks it as @internal.
> The function is only called internally by rte_eal_finalize().
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> 
> ---
> 
> Cc: thomas@monjalon.net
> Cc: vipin.varghese@intel.com
> ---
>  lib/librte_eal/common/include/rte_service.h           | 11 -----------
>  lib/librte_eal/common/include/rte_service_component.h | 11 +++++++++++
>  2 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_service.h
> b/lib/librte_eal/common/include/rte_service.h
> index 5e3e3a6..02b1512 100644
> --- a/lib/librte_eal/common/include/rte_service.h
> +++ b/lib/librte_eal/common/include/rte_service.h
> @@ -429,17 +429,6 @@ int32_t rte_service_attr_get(uint32_t id, uint32_t
> attr_id,
>   */
>  int32_t rte_service_attr_reset_all(uint32_t id);
> 
> -/**
> - * @warning
> - * @b EXPERIMENTAL: this API may change without prior notice
> - *
> - * Free up the memory that has been initialized. This routine
> - * is to be invoked prior to process termination.
> - *
> - * @retval None
> - */
> -void rte_service_finalize(void);
> -
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/lib/librte_eal/common/include/rte_service_component.h
> b/lib/librte_eal/common/include/rte_service_component.h
> index 849c71d..f881ac0 100644
> --- a/lib/librte_eal/common/include/rte_service_component.h
> +++ b/lib/librte_eal/common/include/rte_service_component.h
> @@ -139,4 +139,15 @@ int32_t rte_service_component_runstate_set(uint32_t
> id, uint32_t runstate);
>   */
>  int32_t rte_service_init(void);
> 
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this API may change without prior notice
> + *
> + * @internal Free up the memory that has been initialized.
> + * This routine is to be invoked prior to process termination.
> + *
> + * @retval None
> + */
> +void rte_service_finalize(void);
> +
>  #endif /* _RTE_SERVICE_PRIVATE_H_ */
> --
> 2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v3 2/4] eal: add function to release internal resources
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 2/4] eal: add function to release internal resources Harry van Haaren
@ 2018-01-29 15:07       ` Varghese, Vipin
  0 siblings, 0 replies; 31+ messages in thread
From: Varghese, Vipin @ 2018-01-29 15:07 UTC (permalink / raw)
  To: Van Haaren, Harry, dev; +Cc: thomas



> -----Original Message-----
> From: Van Haaren, Harry
> Sent: Monday, January 29, 2018 5:38 PM
> To: dev@dpdk.org
> Cc: Van Haaren, Harry <harry.van.haaren@intel.com>; thomas@monjalon.net;
> Varghese, Vipin <vipin.varghese@intel.com>
> Subject: [PATCH v3 2/4] eal: add function to release internal resources
> 
> This commit adds a new function rte_eal_cleanup().
> The function serves as a hook to allow DPDK to release internal resources (e.g.:
> hugepage allocations).
> 
> This function allows DPDK to become more like an ordinary library, where the
> library context itself can be initialized and cleaned up by the application.
> 
> The rte_exit() and rte_panic() functions must be considered, particularly if they
> should call rte_eal_cleanup() to release any resources or not. This patch adds
> the cleanup to rte_exit(), but does not clean up on rte_panic(). The reason to not
> clean up on panicing is that the developer may wish to inspect the exact internal
> state of EAL and hugepages.
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> 
> ---
> 
> v3:
> - Rename function to cleanup (Thomas)
> 
> v2:
> - Add eal_common.c file commit (Vipin)
> 
> Cc: thomas@monjalon.net
> Cc: vipin.varghese@intel.com
> ---
>  doc/guides/prog_guide/env_abstraction_layer.rst |  8 ++++++++
>  doc/guides/rel_notes/release_18_02.rst          |  9 +++++++++
>  lib/librte_eal/bsdapp/eal/Makefile              |  1 +
>  lib/librte_eal/bsdapp/eal/eal_debug.c           |  5 +++++
>  lib/librte_eal/common/eal_common.c              | 11 +++++++++++
>  lib/librte_eal/common/include/rte_eal.h         | 16 ++++++++++++++++
>  lib/librte_eal/linuxapp/eal/Makefile            |  1 +
>  lib/librte_eal/linuxapp/eal/eal_debug.c         |  5 +++++
>  lib/librte_eal/rte_eal_version.map              |  1 +
>  9 files changed, 57 insertions(+)
>  create mode 100644 lib/librte_eal/common/eal_common.c
> 
> diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst
> b/doc/guides/prog_guide/env_abstraction_layer.rst
> index 34d871c..04bd776 100644
> --- a/doc/guides/prog_guide/env_abstraction_layer.rst
> +++ b/doc/guides/prog_guide/env_abstraction_layer.rst
> @@ -99,6 +99,14 @@ It consist of calls to the pthread library (more specifically,
> pthread_self(), p
>      The creation and initialization functions for these objects are not multi-thread
> safe.
>      However, once initialized, the objects themselves can safely be used in
> multiple threads simultaneously.
> 
> +Shutdown and Cleanup
> +~~~~~~~~~~~~~~~~~~~~
> +
> +During the initialization of EAL resources such as hugepage backed
> +memory can be allocated by core components.  The memory allocated
> +during ``rte_eal_init()`` can be released by calling the
> +``rte_eal_cleanup()`` function. Refer to the API documentation for details.
> +
>  Multi-process Support
>  ~~~~~~~~~~~~~~~~~~~~~
> 
> diff --git a/doc/guides/rel_notes/release_18_02.rst
> b/doc/guides/rel_notes/release_18_02.rst
> index 00b3224..8c3968e 100644
> --- a/doc/guides/rel_notes/release_18_02.rst
> +++ b/doc/guides/rel_notes/release_18_02.rst
> @@ -41,6 +41,15 @@ New Features
>       Also, make sure to start the actual text at the margin.
>       =========================================================
> 
> +* **Add function to allow releasing internal EAL resources on exit**
> +
> +  During ``rte_eal_init()`` EAL allocates memory from hugepages to
> + enable its  core libraries to perform their tasks. The
> + ``rte_eal_cleanup()`` function  releases these resources, ensuring
> + that no hugepage memory is leaked. It is  expected that all DPDK
> + applications call ``rte_eal_cleanup()`` before  exiting. Not calling
> + this function could result in leaking hugepages, leading  to failure during
> initialization of secondary processes.
> +
>  * **Added the ixgbe ethernet driver to support RSS with flow API.**
> 
>    Rte_flow actually defined to include RSS, but till now, RSS is out of diff --git
> a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
> index c694076..7480f98 100644
> --- a/lib/librte_eal/bsdapp/eal/Makefile
> +++ b/lib/librte_eal/bsdapp/eal/Makefile
> @@ -34,6 +34,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) +=
> eal_interrupts.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c
> 
>  # from common dir
> +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c diff --
> git a/lib/librte_eal/bsdapp/eal/eal_debug.c
> b/lib/librte_eal/bsdapp/eal/eal_debug.c
> index b0ae2b7..f66e504 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_debug.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_debug.c
> @@ -14,6 +14,7 @@
>  #include <rte_log.h>
>  #include <rte_debug.h>
>  #include <rte_common.h>
> +#include <rte_eal.h>
> 
>  #define BACKTRACE_SIZE 256
> 
> @@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
>  	va_end(ap);
> 
>  #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
> +	int ret = rte_eal_cleanup();
> +	if (ret)
> +		RTE_LOG(CRIT, EAL,
> +			"EAL could not release all resources, code %d\n", ret);
>  	exit(exit_code);
>  #else
>  	rte_dump_stack();
> diff --git a/lib/librte_eal/common/eal_common.c
> b/lib/librte_eal/common/eal_common.c
> new file mode 100644
> index 0000000..52771e7
> --- /dev/null
> +++ b/lib/librte_eal/common/eal_common.c
> @@ -0,0 +1,11 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018 Intel Corporation
> + */
> +
> +#include <rte_service_component.h>
> +
> +int rte_eal_cleanup(void)
> +{
> +	rte_service_finalize();
> +	return 0;
> +}
> diff --git a/lib/librte_eal/common/include/rte_eal.h
> b/lib/librte_eal/common/include/rte_eal.h
> index 2aba2c8..8b36fea 100644
> --- a/lib/librte_eal/common/include/rte_eal.h
> +++ b/lib/librte_eal/common/include/rte_eal.h
> @@ -170,6 +170,22 @@ int rte_eal_iopl_init(void);  int rte_eal_init(int argc,
> char **argv);
> 
>  /**
> + * @warning
> + * @b EXPERIMENTAL: this API may change without prior notice
> + *
> + * Clean up the Environment Abstraction Layer (EAL)
> + *
> + * This function must be called to release any internal resources that
> +EAL has
> + * allocated during rte_eal_init(). After this call, no DPDK function
> +calls may
> + * be made. It is expected that common usage of this function is to
> +call it
> + * just before terminating the process.
> + *
> + * @return 0 Successfully released all internal EAL resources
> + * @return -EFAULT There was an error in releasing all resources.
> + */
> +int rte_eal_cleanup(void);
> +
> +/**
>   * Check if a primary process is currently alive
>   *
>   * This function returns true when a primary process is currently diff --git
> a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
> index 7bf278f..ad20f2f 100644
> --- a/lib/librte_eal/linuxapp/eal/Makefile
> +++ b/lib/librte_eal/linuxapp/eal/Makefile
> @@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) +=
> eal_interrupts.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c
> 
>  # from common dir
> +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
>  SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c diff -
> -git a/lib/librte_eal/linuxapp/eal/eal_debug.c
> b/lib/librte_eal/linuxapp/eal/eal_debug.c
> index b0ae2b7..f66e504 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_debug.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_debug.c
> @@ -14,6 +14,7 @@
>  #include <rte_log.h>
>  #include <rte_debug.h>
>  #include <rte_common.h>
> +#include <rte_eal.h>
> 
>  #define BACKTRACE_SIZE 256
> 
> @@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
>  	va_end(ap);
> 
>  #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
> +	int ret = rte_eal_cleanup();
> +	if (ret)
> +		RTE_LOG(CRIT, EAL,
> +			"EAL could not release all resources, code %d\n", ret);
>  	exit(exit_code);
>  #else
>  	rte_dump_stack();
> diff --git a/lib/librte_eal/rte_eal_version.map
> b/lib/librte_eal/rte_eal_version.map
> index 1a8b1b5..8dd4abf 100644
> --- a/lib/librte_eal/rte_eal_version.map
> +++ b/lib/librte_eal/rte_eal_version.map
> @@ -215,6 +215,7 @@ EXPERIMENTAL {
>  	rte_eal_devargs_insert;
>  	rte_eal_devargs_parse;
>  	rte_eal_devargs_remove;
> +	rte_eal_cleanup;
>  	rte_eal_hotplug_add;
>  	rte_eal_hotplug_remove;
>  	rte_service_attr_get;
> --
> 2.7.4

Thanks, Checked for Linux application.

Acked-by: Vipin Varghese <vipin.varghese@intel.com>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v3 3/4] app/pdump: call eal cleanup before exit
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
@ 2018-01-29 15:09       ` Varghese, Vipin
  0 siblings, 0 replies; 31+ messages in thread
From: Varghese, Vipin @ 2018-01-29 15:09 UTC (permalink / raw)
  To: Van Haaren, Harry, dev; +Cc: thomas



> -----Original Message-----
> From: Van Haaren, Harry
> Sent: Monday, January 29, 2018 5:38 PM
> To: dev@dpdk.org
> Cc: Van Haaren, Harry <harry.van.haaren@intel.com>; thomas@monjalon.net;
> Varghese, Vipin <vipin.varghese@intel.com>
> Subject: [PATCH v3 3/4] app/pdump: call eal cleanup before exit
> 
> This patch adds a call to the newly introduced cleanup() function just before
> quitting the pdump app.
> 
> Adding this function call before quitting from a secondary processes is
> important, as otherwise it will leak hugepage memory. For a secondary process
> that is run multiple times, this could cause hugepage memory to become
> depleted and stop a secondary process from starting.
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> 
> ---
> 
> v3:
> - Rework to new cleanup() function name (Thomas)
> 
> Cc: thomas@monjalon.net
> Cc: vipin.varghese@intel.com
> ---
>  app/pdump/main.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/app/pdump/main.c b/app/pdump/main.c index 0f70c75..50772cb
> 100644
> --- a/app/pdump/main.c
> +++ b/app/pdump/main.c
> @@ -882,5 +882,10 @@ main(int argc, char **argv)
>  	/* dump debug stats */
>  	print_pdump_stats();
> 
> +	ret = rte_eal_cleanup();
> +	if (ret)
> +		printf("Error from rte_eal_cleanup(), %d\n", ret);
> +
> +
>  	return 0;
>  }
> --
> 2.7.4

Tested with static and dynamic library on Linux

Acked-by: Vipin Varghese <vipin.varghese@intel.com>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v3 4/4] app/proc_info: call eal cleanup before exit
  2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 4/4] app/proc_info: " Harry van Haaren
@ 2018-01-29 15:09       ` Varghese, Vipin
  0 siblings, 0 replies; 31+ messages in thread
From: Varghese, Vipin @ 2018-01-29 15:09 UTC (permalink / raw)
  To: Van Haaren, Harry, dev; +Cc: thomas



> -----Original Message-----
> From: Van Haaren, Harry
> Sent: Monday, January 29, 2018 5:38 PM
> To: dev@dpdk.org
> Cc: Van Haaren, Harry <harry.van.haaren@intel.com>; thomas@monjalon.net;
> Varghese, Vipin <vipin.varghese@intel.com>
> Subject: [PATCH v3 4/4] app/proc_info: call eal cleanup before exit
> 
> This patch adds a call to the newly introduced cleanup() function just before
> quitting the app.
> 
> Adding this function call before quitting from a secondary processes is
> important, as otherwise it will leak hugepage memory. For a secondary process
> that is run multiple times, this could cause hugepage memory to become
> depleted and stop a secondary process from starting.
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> 
> ---
> 
> v3:
> - Rework to use cleanup() function name (Thomas)
> 
> Cc: thomas@monjalon.net
> Cc: vipin.varghese@intel.com
> ---
>  app/proc_info/main.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/app/proc_info/main.c b/app/proc_info/main.c index
> 94d53f5..2f53e3c 100644
> --- a/app/proc_info/main.c
> +++ b/app/proc_info/main.c
> @@ -660,5 +660,9 @@ main(int argc, char **argv)
>  	if (enable_metrics)
>  		metrics_display(RTE_METRICS_GLOBAL);
> 
> +	ret = rte_eal_cleanup();
> +	if (ret)
> +		printf("Error from rte_eal_cleanup(), %d\n", ret);
> +
>  	return 0;
>  }
> --
> 2.7.4

Acked-by: Vipin Varghese <vipin.varghese@intel.com>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v4 1/4] service: move finalize to internal
  2018-01-29 12:08   ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
                       ` (3 preceding siblings ...)
  2018-01-29 15:05     ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Varghese, Vipin
@ 2018-01-29 16:00     ` Harry van Haaren
  2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 2/4] eal: add function to release internal resources Harry van Haaren
                         ` (3 more replies)
  4 siblings, 4 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 16:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This commit moves the rte_service_finalize() function
to be in the component header, and marks it as @internal.
The function is only called internally by rte_eal_finalize().

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Vipin Varghese <vipin.varghese@intel.com>

---

v4:
- Include Ack

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 lib/librte_eal/common/include/rte_service.h           | 11 -----------
 lib/librte_eal/common/include/rte_service_component.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h
index 5e3e3a6..02b1512 100644
--- a/lib/librte_eal/common/include/rte_service.h
+++ b/lib/librte_eal/common/include/rte_service.h
@@ -429,17 +429,6 @@ int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id,
  */
 int32_t rte_service_attr_reset_all(uint32_t id);
 
-/**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
- * Free up the memory that has been initialized. This routine
- * is to be invoked prior to process termination.
- *
- * @retval None
- */
-void rte_service_finalize(void);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/include/rte_service_component.h b/lib/librte_eal/common/include/rte_service_component.h
index 849c71d..f881ac0 100644
--- a/lib/librte_eal/common/include/rte_service_component.h
+++ b/lib/librte_eal/common/include/rte_service_component.h
@@ -139,4 +139,15 @@ int32_t rte_service_component_runstate_set(uint32_t id, uint32_t runstate);
  */
 int32_t rte_service_init(void);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @internal Free up the memory that has been initialized.
+ * This routine is to be invoked prior to process termination.
+ *
+ * @retval None
+ */
+void rte_service_finalize(void);
+
 #endif /* _RTE_SERVICE_PRIVATE_H_ */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v4 2/4] eal: add function to release internal resources
  2018-01-29 16:00     ` [dpdk-dev] [PATCH v4 " Harry van Haaren
@ 2018-01-29 16:00       ` Harry van Haaren
  2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 16:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This commit adds a new function rte_eal_cleanup().
The function serves as a hook to allow DPDK to release
internal resources (e.g.: hugepage allocations).

This function allows DPDK to become more like an ordinary
library, where the library context itself can be initialized
and cleaned up by the application.

The rte_exit() and rte_panic() functions must be considered,
particularly if they should call rte_eal_cleanup() to release any
resources or not. This patch adds the cleanup to rte_exit(),
but does not clean up on rte_panic(). The reason to not clean
up on panicing is that the developer may wish to inspect the
exact internal state of EAL and hugepages.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Vipin Varghese <vipin.varghese@intel.com>

---

v4:
- Include Ack
- Fix map file order introduced in v3 rename

v3:
- Rename function to cleanup (Thomas)

v2:
- Add eal_common.c file commit (Vipin)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 doc/guides/prog_guide/env_abstraction_layer.rst |  8 ++++++++
 doc/guides/rel_notes/release_18_02.rst          |  9 +++++++++
 lib/librte_eal/bsdapp/eal/Makefile              |  1 +
 lib/librte_eal/bsdapp/eal/eal_debug.c           |  5 +++++
 lib/librte_eal/common/eal_common.c              | 11 +++++++++++
 lib/librte_eal/common/include/rte_eal.h         | 16 ++++++++++++++++
 lib/librte_eal/linuxapp/eal/Makefile            |  1 +
 lib/librte_eal/linuxapp/eal/eal_debug.c         |  5 +++++
 lib/librte_eal/rte_eal_version.map              |  1 +
 9 files changed, 57 insertions(+)
 create mode 100644 lib/librte_eal/common/eal_common.c

diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
index 34d871c..04bd776 100644
--- a/doc/guides/prog_guide/env_abstraction_layer.rst
+++ b/doc/guides/prog_guide/env_abstraction_layer.rst
@@ -99,6 +99,14 @@ It consist of calls to the pthread library (more specifically, pthread_self(), p
     The creation and initialization functions for these objects are not multi-thread safe.
     However, once initialized, the objects themselves can safely be used in multiple threads simultaneously.
 
+Shutdown and Cleanup
+~~~~~~~~~~~~~~~~~~~~
+
+During the initialization of EAL resources such as hugepage backed memory can be
+allocated by core components.  The memory allocated during ``rte_eal_init()``
+can be released by calling the ``rte_eal_cleanup()`` function. Refer to the
+API documentation for details.
+
 Multi-process Support
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 00b3224..8c3968e 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -41,6 +41,15 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Add function to allow releasing internal EAL resources on exit**
+
+  During ``rte_eal_init()`` EAL allocates memory from hugepages to enable its
+  core libraries to perform their tasks. The ``rte_eal_cleanup()`` function
+  releases these resources, ensuring that no hugepage memory is leaked. It is
+  expected that all DPDK applications call ``rte_eal_cleanup()`` before
+  exiting. Not calling this function could result in leaking hugepages, leading
+  to failure during initialization of secondary processes.
+
 * **Added the ixgbe ethernet driver to support RSS with flow API.**
 
   Rte_flow actually defined to include RSS, but till now, RSS is out of
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index c694076..7480f98 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -34,6 +34,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c
index b0ae2b7..f66e504 100644
--- a/lib/librte_eal/bsdapp/eal/eal_debug.c
+++ b/lib/librte_eal/bsdapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_cleanup();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/common/eal_common.c b/lib/librte_eal/common/eal_common.c
new file mode 100644
index 0000000..52771e7
--- /dev/null
+++ b/lib/librte_eal/common/eal_common.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018 Intel Corporation
+ */
+
+#include <rte_service_component.h>
+
+int rte_eal_cleanup(void)
+{
+	rte_service_finalize();
+	return 0;
+}
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 2aba2c8..8b36fea 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -170,6 +170,22 @@ int rte_eal_iopl_init(void);
 int rte_eal_init(int argc, char **argv);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Clean up the Environment Abstraction Layer (EAL)
+ *
+ * This function must be called to release any internal resources that EAL has
+ * allocated during rte_eal_init(). After this call, no DPDK function calls may
+ * be made. It is expected that common usage of this function is to call it
+ * just before terminating the process.
+ *
+ * @return 0 Successfully released all internal EAL resources
+ * @return -EFAULT There was an error in releasing all resources.
+ */
+int rte_eal_cleanup(void);
+
+/**
  * Check if a primary process is currently alive
  *
  * This function returns true when a primary process is currently
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 7bf278f..ad20f2f 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -41,6 +41,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_interrupts.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_alarm.c
 
 # from common dir
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_lcore.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c
index b0ae2b7..f66e504 100644
--- a/lib/librte_eal/linuxapp/eal/eal_debug.c
+++ b/lib/librte_eal/linuxapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_cleanup();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index 1a8b1b5..b7c0317 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -212,6 +212,7 @@ DPDK_18.02 {
 EXPERIMENTAL {
 	global:
 
+	rte_eal_cleanup;
 	rte_eal_devargs_insert;
 	rte_eal_devargs_parse;
 	rte_eal_devargs_remove;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v4 3/4] app/pdump: call eal cleanup before exit
  2018-01-29 16:00     ` [dpdk-dev] [PATCH v4 " Harry van Haaren
  2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 2/4] eal: add function to release internal resources Harry van Haaren
@ 2018-01-29 16:00       ` Harry van Haaren
  2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 4/4] app/proc_info: " Harry van Haaren
  2018-01-29 16:37       ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Harry van Haaren
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 16:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This patch adds a call to the newly introduced cleanup()
function just before quitting the pdump app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Vipin Varghese <vipin.varghese@intel.com>

---

v4:
- Include Ack

v3:
- Rework to new cleanup() function name (Thomas)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/pdump/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 0f70c75..50772cb 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -882,5 +882,10 @@ main(int argc, char **argv)
 	/* dump debug stats */
 	print_pdump_stats();
 
+	ret = rte_eal_cleanup();
+	if (ret)
+		printf("Error from rte_eal_cleanup(), %d\n", ret);
+
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v4 4/4] app/proc_info: call eal cleanup before exit
  2018-01-29 16:00     ` [dpdk-dev] [PATCH v4 " Harry van Haaren
  2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 2/4] eal: add function to release internal resources Harry van Haaren
  2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
@ 2018-01-29 16:00       ` Harry van Haaren
  2018-01-29 16:37       ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Harry van Haaren
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 16:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This patch adds a call to the newly introduced cleanup()
function just before quitting the app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Vipin Varghese <vipin.varghese@intel.com>

---

v4:
- Include Acks

v3:
- Rework to use cleanup() function name (Thomas)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/proc_info/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 94d53f5..2f53e3c 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -660,5 +660,9 @@ main(int argc, char **argv)
 	if (enable_metrics)
 		metrics_display(RTE_METRICS_GLOBAL);
 
+	ret = rte_eal_cleanup();
+	if (ret)
+		printf("Error from rte_eal_cleanup(), %d\n", ret);
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal
  2018-01-29 16:00     ` [dpdk-dev] [PATCH v4 " Harry van Haaren
                         ` (2 preceding siblings ...)
  2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 4/4] app/proc_info: " Harry van Haaren
@ 2018-01-29 16:37       ` Harry van Haaren
  2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 2/4] eal: add function to release internal resources Harry van Haaren
                           ` (3 more replies)
  3 siblings, 4 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 16:37 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This commit moves the rte_service_finalize() function
to be in the component header, and marks it as @internal.
The function is only called internally by rte_eal_finalize().

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Vipin Varghese <vipin.varghese@intel.com>

---

v4:
- Include Ack

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 lib/librte_eal/common/include/rte_service.h           | 11 -----------
 lib/librte_eal/common/include/rte_service_component.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h
index 5e3e3a6..02b1512 100644
--- a/lib/librte_eal/common/include/rte_service.h
+++ b/lib/librte_eal/common/include/rte_service.h
@@ -429,17 +429,6 @@ int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id,
  */
 int32_t rte_service_attr_reset_all(uint32_t id);
 
-/**
- * @warning
- * @b EXPERIMENTAL: this API may change without prior notice
- *
- * Free up the memory that has been initialized. This routine
- * is to be invoked prior to process termination.
- *
- * @retval None
- */
-void rte_service_finalize(void);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/include/rte_service_component.h b/lib/librte_eal/common/include/rte_service_component.h
index 849c71d..f881ac0 100644
--- a/lib/librte_eal/common/include/rte_service_component.h
+++ b/lib/librte_eal/common/include/rte_service_component.h
@@ -139,4 +139,15 @@ int32_t rte_service_component_runstate_set(uint32_t id, uint32_t runstate);
  */
 int32_t rte_service_init(void);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * @internal Free up the memory that has been initialized.
+ * This routine is to be invoked prior to process termination.
+ *
+ * @retval None
+ */
+void rte_service_finalize(void);
+
 #endif /* _RTE_SERVICE_PRIVATE_H_ */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v5 2/4] eal: add function to release internal resources
  2018-01-29 16:37       ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Harry van Haaren
@ 2018-01-29 16:37         ` Harry van Haaren
  2018-01-29 18:20           ` Thomas Monjalon
  2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
                           ` (2 subsequent siblings)
  3 siblings, 1 reply; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 16:37 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This commit adds a new function rte_eal_cleanup().
The function serves as a hook to allow DPDK to release
internal resources (e.g.: hugepage allocations).

This function allows DPDK to become more like an ordinary
library, where the library context itself can be initialized
and cleaned up by the application.

The rte_exit() and rte_panic() functions must be considered,
particularly if they should call rte_eal_cleanup() to release any
resources or not. This patch adds the cleanup to rte_exit(),
but does not clean up on rte_panic(). The reason to not clean
up on panicing is that the developer may wish to inspect the
exact internal state of EAL and hugepages.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Vipin Varghese <vipin.varghese@intel.com>

---

v5:
- Split cleanup() implementation to linux/bsd (Bruce)
  This removes the new file - which is nice :)

v4:
- Include Ack
- Fix map file order introduced in v3 rename

v3:
- Rename function to cleanup (Thomas)

v2:
- Add eal_common.c file commit (Vipin)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 doc/guides/prog_guide/env_abstraction_layer.rst |  8 ++++++++
 doc/guides/rel_notes/release_18_02.rst          |  9 +++++++++
 lib/librte_eal/bsdapp/eal/eal.c                 |  6 ++++++
 lib/librte_eal/bsdapp/eal/eal_debug.c           |  5 +++++
 lib/librte_eal/common/include/rte_eal.h         | 16 ++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal.c               |  6 ++++++
 lib/librte_eal/linuxapp/eal/eal_debug.c         |  5 +++++
 lib/librte_eal/rte_eal_version.map              |  1 +
 8 files changed, 56 insertions(+)

diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst
index 34d871c..04bd776 100644
--- a/doc/guides/prog_guide/env_abstraction_layer.rst
+++ b/doc/guides/prog_guide/env_abstraction_layer.rst
@@ -99,6 +99,14 @@ It consist of calls to the pthread library (more specifically, pthread_self(), p
     The creation and initialization functions for these objects are not multi-thread safe.
     However, once initialized, the objects themselves can safely be used in multiple threads simultaneously.
 
+Shutdown and Cleanup
+~~~~~~~~~~~~~~~~~~~~
+
+During the initialization of EAL resources such as hugepage backed memory can be
+allocated by core components.  The memory allocated during ``rte_eal_init()``
+can be released by calling the ``rte_eal_cleanup()`` function. Refer to the
+API documentation for details.
+
 Multi-process Support
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_18_02.rst b/doc/guides/rel_notes/release_18_02.rst
index 00b3224..8c3968e 100644
--- a/doc/guides/rel_notes/release_18_02.rst
+++ b/doc/guides/rel_notes/release_18_02.rst
@@ -41,6 +41,15 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Add function to allow releasing internal EAL resources on exit**
+
+  During ``rte_eal_init()`` EAL allocates memory from hugepages to enable its
+  core libraries to perform their tasks. The ``rte_eal_cleanup()`` function
+  releases these resources, ensuring that no hugepage memory is leaked. It is
+  expected that all DPDK applications call ``rte_eal_cleanup()`` before
+  exiting. Not calling this function could result in leaking hugepages, leading
+  to failure during initialization of secondary processes.
+
 * **Added the ixgbe ethernet driver to support RSS with flow API.**
 
   Rte_flow actually defined to include RSS, but till now, RSS is out of
diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 04cbd81..d02233a 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -709,6 +709,12 @@ rte_eal_init(int argc, char **argv)
 	return fctret;
 }
 
+int rte_eal_cleanup(void)
+{
+	rte_service_finalize();
+	return 0;
+}
+
 /* get core role */
 enum rte_lcore_role_t
 rte_eal_lcore_role(unsigned lcore_id)
diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c
index b0ae2b7..f66e504 100644
--- a/lib/librte_eal/bsdapp/eal/eal_debug.c
+++ b/lib/librte_eal/bsdapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_cleanup();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 2aba2c8..8b36fea 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -170,6 +170,22 @@ int rte_eal_iopl_init(void);
 int rte_eal_init(int argc, char **argv);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Clean up the Environment Abstraction Layer (EAL)
+ *
+ * This function must be called to release any internal resources that EAL has
+ * allocated during rte_eal_init(). After this call, no DPDK function calls may
+ * be made. It is expected that common usage of this function is to call it
+ * just before terminating the process.
+ *
+ * @return 0 Successfully released all internal EAL resources
+ * @return -EFAULT There was an error in releasing all resources.
+ */
+int rte_eal_cleanup(void);
+
+/**
  * Check if a primary process is currently alive
  *
  * This function returns true when a primary process is currently
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 229eec9..4d5e96d 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -974,6 +974,12 @@ rte_eal_init(int argc, char **argv)
 	return fctret;
 }
 
+int rte_eal_cleanup(void)
+{
+	rte_service_finalize();
+	return 0;
+}
+
 /* get core role */
 enum rte_lcore_role_t
 rte_eal_lcore_role(unsigned lcore_id)
diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c
index b0ae2b7..f66e504 100644
--- a/lib/librte_eal/linuxapp/eal/eal_debug.c
+++ b/lib/librte_eal/linuxapp/eal/eal_debug.c
@@ -14,6 +14,7 @@
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_common.h>
+#include <rte_eal.h>
 
 #define BACKTRACE_SIZE 256
 
@@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
 #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
+	int ret = rte_eal_cleanup();
+	if (ret)
+		RTE_LOG(CRIT, EAL,
+			"EAL could not release all resources, code %d\n", ret);
 	exit(exit_code);
 #else
 	rte_dump_stack();
diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map
index ce299d3..93f6c13 100644
--- a/lib/librte_eal/rte_eal_version.map
+++ b/lib/librte_eal/rte_eal_version.map
@@ -214,6 +214,7 @@ DPDK_18.02 {
 EXPERIMENTAL {
 	global:
 
+	rte_eal_cleanup;
 	rte_eal_devargs_insert;
 	rte_eal_devargs_parse;
 	rte_eal_devargs_remove;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v5 3/4] app/pdump: call eal cleanup before exit
  2018-01-29 16:37       ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Harry van Haaren
  2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 2/4] eal: add function to release internal resources Harry van Haaren
@ 2018-01-29 16:37         ` Harry van Haaren
  2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 4/4] app/proc_info: " Harry van Haaren
  2018-01-29 18:28         ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Thomas Monjalon
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 16:37 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This patch adds a call to the newly introduced cleanup()
function just before quitting the pdump app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Vipin Varghese <vipin.varghese@intel.com>

---

v4:
- Include Ack

v3:
- Rework to new cleanup() function name (Thomas)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/pdump/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 0f70c75..50772cb 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -882,5 +882,10 @@ main(int argc, char **argv)
 	/* dump debug stats */
 	print_pdump_stats();
 
+	ret = rte_eal_cleanup();
+	if (ret)
+		printf("Error from rte_eal_cleanup(), %d\n", ret);
+
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [dpdk-dev] [PATCH v5 4/4] app/proc_info: call eal cleanup before exit
  2018-01-29 16:37       ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Harry van Haaren
  2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 2/4] eal: add function to release internal resources Harry van Haaren
  2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
@ 2018-01-29 16:37         ` Harry van Haaren
  2018-01-29 18:28         ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Thomas Monjalon
  3 siblings, 0 replies; 31+ messages in thread
From: Harry van Haaren @ 2018-01-29 16:37 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, thomas, vipin.varghese

This patch adds a call to the newly introduced cleanup()
function just before quitting the app.

Adding this function call before quitting from a secondary processes
is important, as otherwise it will leak hugepage memory. For a secondary
process that is run multiple times, this could cause hugepage memory
to become depleted and stop a secondary process from starting.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
Acked-by: Vipin Varghese <vipin.varghese@intel.com>

---

v4:
- Include Acks

v3:
- Rework to use cleanup() function name (Thomas)

Cc: thomas@monjalon.net
Cc: vipin.varghese@intel.com
---
 app/proc_info/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 94d53f5..2f53e3c 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -660,5 +660,9 @@ main(int argc, char **argv)
 	if (enable_metrics)
 		metrics_display(RTE_METRICS_GLOBAL);
 
+	ret = rte_eal_cleanup();
+	if (ret)
+		printf("Error from rte_eal_cleanup(), %d\n", ret);
+
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v5 2/4] eal: add function to release internal resources
  2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 2/4] eal: add function to release internal resources Harry van Haaren
@ 2018-01-29 18:20           ` Thomas Monjalon
  0 siblings, 0 replies; 31+ messages in thread
From: Thomas Monjalon @ 2018-01-29 18:20 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev, vipin.varghese

29/01/2018 17:37, Harry van Haaren:
> @@ -79,6 +80,10 @@ rte_exit(int exit_code, const char *format, ...)
>  	va_end(ap);
>  
>  #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR
> +	int ret = rte_eal_cleanup();

You should not declare a variable in the middle of the function.
Will fix on apply.

> +	if (ret)
> +		RTE_LOG(CRIT, EAL,
> +			"EAL could not release all resources, code %d\n", ret);
>  	exit(exit_code);
>  #else
>  	rte_dump_stack();

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal
  2018-01-29 16:37       ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Harry van Haaren
                           ` (2 preceding siblings ...)
  2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 4/4] app/proc_info: " Harry van Haaren
@ 2018-01-29 18:28         ` Thomas Monjalon
  3 siblings, 0 replies; 31+ messages in thread
From: Thomas Monjalon @ 2018-01-29 18:28 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev, vipin.varghese

29/01/2018 17:37, Harry van Haaren:
> This commit moves the rte_service_finalize() function
> to be in the component header, and marks it as @internal.
> The function is only called internally by rte_eal_finalize().
> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> Acked-by: Vipin Varghese <vipin.varghese@intel.com>

Series applied with a minor change, thanks

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2018-01-29 18:28 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-27 18:31 [dpdk-dev] [PATCH 1/4] service: move finalize to internal Harry van Haaren
2018-01-27 18:31 ` [dpdk-dev] [PATCH 2/4] eal: add function to release internal resources Harry van Haaren
2018-01-27 18:31 ` [dpdk-dev] [PATCH 3/4] app/pdump: call eal finalize before exit Harry van Haaren
2018-01-27 18:31 ` [dpdk-dev] [PATCH 4/4] app/proc_info: " Harry van Haaren
2018-01-29 10:45 ` [dpdk-dev] [PATCH v2 1/4] service: move finalize to internal Harry van Haaren
2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 2/4] eal: add function to release internal resources Harry van Haaren
2018-01-29 10:55     ` Thomas Monjalon
2018-01-29 11:10       ` Van Haaren, Harry
2018-01-29 11:55         ` Thomas Monjalon
2018-01-29 12:04           ` Bruce Richardson
2018-01-29 12:12           ` Van Haaren, Harry
2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 3/4] app/pdump: call eal finalize before exit Harry van Haaren
2018-01-29 10:45   ` [dpdk-dev] [PATCH v2 4/4] app/proc_info: " Harry van Haaren
2018-01-29 12:08   ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 2/4] eal: add function to release internal resources Harry van Haaren
2018-01-29 15:07       ` Varghese, Vipin
2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
2018-01-29 15:09       ` Varghese, Vipin
2018-01-29 12:08     ` [dpdk-dev] [PATCH v3 4/4] app/proc_info: " Harry van Haaren
2018-01-29 15:09       ` Varghese, Vipin
2018-01-29 15:05     ` [dpdk-dev] [PATCH v3 1/4] service: move finalize to internal Varghese, Vipin
2018-01-29 16:00     ` [dpdk-dev] [PATCH v4 " Harry van Haaren
2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 2/4] eal: add function to release internal resources Harry van Haaren
2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
2018-01-29 16:00       ` [dpdk-dev] [PATCH v4 4/4] app/proc_info: " Harry van Haaren
2018-01-29 16:37       ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Harry van Haaren
2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 2/4] eal: add function to release internal resources Harry van Haaren
2018-01-29 18:20           ` Thomas Monjalon
2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
2018-01-29 16:37         ` [dpdk-dev] [PATCH v5 4/4] app/proc_info: " Harry van Haaren
2018-01-29 18:28         ` [dpdk-dev] [PATCH v5 1/4] service: move finalize to internal Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).