All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harry van Haaren <harry.van.haaren@intel.com>
To: dev@dpdk.org
Cc: Harry van Haaren <harry.van.haaren@intel.com>,
	thomas@monjalon.net, vipin.varghese@intel.com
Subject: [PATCH v4 2/4] eal: add function to release internal resources
Date: Mon, 29 Jan 2018 16:00:40 +0000	[thread overview]
Message-ID: <1517241642-161397-2-git-send-email-harry.van.haaren@intel.com> (raw)
In-Reply-To: <1517241642-161397-1-git-send-email-harry.van.haaren@intel.com>

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

  reply	other threads:[~2018-01-29 16:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-27 18:31 [PATCH 1/4] service: move finalize to internal Harry van Haaren
2018-01-27 18:31 ` [PATCH 2/4] eal: add function to release internal resources Harry van Haaren
2018-01-27 18:31 ` [PATCH 3/4] app/pdump: call eal finalize before exit Harry van Haaren
2018-01-27 18:31 ` [PATCH 4/4] app/proc_info: " Harry van Haaren
2018-01-29 10:45 ` [PATCH v2 1/4] service: move finalize to internal Harry van Haaren
2018-01-29 10:45   ` [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   ` [PATCH v2 3/4] app/pdump: call eal finalize before exit Harry van Haaren
2018-01-29 10:45   ` [PATCH v2 4/4] app/proc_info: " Harry van Haaren
2018-01-29 12:08   ` [PATCH v3 1/4] service: move finalize to internal Harry van Haaren
2018-01-29 12:08     ` [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     ` [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     ` [PATCH v3 4/4] app/proc_info: " Harry van Haaren
2018-01-29 15:09       ` Varghese, Vipin
2018-01-29 15:05     ` [PATCH v3 1/4] service: move finalize to internal Varghese, Vipin
2018-01-29 16:00     ` [PATCH v4 " Harry van Haaren
2018-01-29 16:00       ` Harry van Haaren [this message]
2018-01-29 16:00       ` [PATCH v4 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
2018-01-29 16:00       ` [PATCH v4 4/4] app/proc_info: " Harry van Haaren
2018-01-29 16:37       ` [PATCH v5 1/4] service: move finalize to internal Harry van Haaren
2018-01-29 16:37         ` [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         ` [PATCH v5 3/4] app/pdump: call eal cleanup before exit Harry van Haaren
2018-01-29 16:37         ` [PATCH v5 4/4] app/proc_info: " Harry van Haaren
2018-01-29 18:28         ` [PATCH v5 1/4] service: move finalize to internal Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1517241642-161397-2-git-send-email-harry.van.haaren@intel.com \
    --to=harry.van.haaren@intel.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=vipin.varghese@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.