From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 2A9361B6A0 for ; Mon, 29 Jan 2018 17:37:37 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jan 2018 08:37:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,431,1511856000"; d="scan'208";a="15245388" Received: from silpixa00398672.ir.intel.com ([10.237.223.111]) by fmsmga002.fm.intel.com with ESMTP; 29 Jan 2018 08:37:36 -0800 From: Harry van Haaren To: dev@dpdk.org Cc: Harry van Haaren , thomas@monjalon.net, vipin.varghese@intel.com Date: Mon, 29 Jan 2018 16:37:30 +0000 Message-Id: <1517243852-34142-2-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517243852-34142-1-git-send-email-harry.van.haaren@intel.com> References: <1517241642-161397-1-git-send-email-harry.van.haaren@intel.com> <1517243852-34142-1-git-send-email-harry.van.haaren@intel.com> Subject: [dpdk-dev] [PATCH v5 2/4] eal: add function to release internal resources X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jan 2018 16:37:38 -0000 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 Acked-by: Vipin Varghese --- 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 #include #include +#include #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 #include #include +#include #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