From patchwork Tue Mar 6 18:28:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnon Warshavsky X-Patchwork-Id: 35701 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3032C5F18; Tue, 6 Mar 2018 19:28:58 +0100 (CET) Received: from mta.qwilt.com (mta.qwilt.com [52.9.191.255]) by dpdk.org (Postfix) with ESMTP id 23A1A325F for ; Tue, 6 Mar 2018 19:28:56 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mta.qwilt.com (Postfix) with ESMTP id 21E6280C26A; Tue, 6 Mar 2018 18:28:56 +0000 (UTC) X-Virus-Scanned: amavisd-new at qwilt.com Received: from mta.qwilt.com ([127.0.0.1]) by localhost (mta.qwilt.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id INdQwPKTW-Om; Tue, 6 Mar 2018 18:28:55 +0000 (UTC) Received: from localhost.localdomain (unknown [46.121.100.37]) by mta.qwilt.com (Postfix) with ESMTPSA id BDD2280C268; Tue, 6 Mar 2018 18:28:53 +0000 (UTC) From: Arnon Warshavsky To: thomas@monjalon.net, bruce.richardson@intel.com Cc: dev@dpdk.org, Arnon Warshavsky Date: Tue, 6 Mar 2018 20:28:48 +0200 Message-Id: <1520360928-9375-1-git-send-email-arnon@qwilt.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] eal: register rte_panic user callback 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The use case addressed here is dpdk environment init aborting the process due to panic, preventing the calling process from running its own tear-down actions. A preferred, though ABI breaking solution would be to have the environment init always return a value rather than abort upon distress. This patch defines a couple of callback registration functions, one for panic and one for exit in case one wishes to distinguish between these events. Once a callback is set and panic takes place, it will be called prior to calling abort. Maiden voyage patch for Qwilt and myself. Signed-off-by: Arnon Warshavsky --- lib/librte_eal/bsdapp/eal/eal_debug.c | 37 ++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_debug.h | 24 +++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_debug.c | 38 +++++++++++++++++++++++++++++++ lib/librte_eal/rte_eal_version.map | 2 ++ 4 files changed, 101 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c index 5d92500..010859d 100644 --- a/lib/librte_eal/bsdapp/eal/eal_debug.c +++ b/lib/librte_eal/bsdapp/eal/eal_debug.c @@ -18,6 +18,39 @@ #define BACKTRACE_SIZE 256 +/* + * user function pointers that when assigned, gets to be called + * during ret_exit() + */ +static rte_user_abort_callback_t *exit_user_callback; + +/* + * user function pointers that when assigned, gets to be called + * during ret_panic() + */ +static rte_user_abort_callback_t *panic_user_callback; + +/** + * Register user callback function to be called during rte_panic() + * Deregisteration is by passing NULL as the parameter + */ +void __rte_experimental +rte_panic_user_callback_register(rte_user_abort_callback_t *cb) +{ + panic_user_callback = cb; +} + +/** + * Register user callback function to be called during rte_exit() + * Deregisteration is by passing NULL as the parameter + */ +void __rte_experimental +rte_exit_user_callback_register(rte_user_abort_callback_t *cb) +{ + exit_user_callback = cb; +} + + /* dump the stack of the calling core */ void rte_dump_stack(void) { @@ -59,6 +92,8 @@ void __rte_panic(const char *funcname, const char *format, ...) va_end(ap); rte_dump_stack(); rte_dump_registers(); + if (panic_user_callback) + (*panic_user_callback)(); abort(); } @@ -78,6 +113,8 @@ rte_exit(int exit_code, const char *format, ...) va_start(ap, format); rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap); va_end(ap); + if (exit_user_callback) + (*exit_user_callback)(); #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR if (rte_eal_cleanup() != 0) diff --git a/lib/librte_eal/common/include/rte_debug.h b/lib/librte_eal/common/include/rte_debug.h index 272df49..7e3d0a2 100644 --- a/lib/librte_eal/common/include/rte_debug.h +++ b/lib/librte_eal/common/include/rte_debug.h @@ -16,11 +16,35 @@ #include "rte_log.h" #include "rte_branch_prediction.h" +#include #ifdef __cplusplus extern "C" { #endif + +/* + * Definition of user function pointer type to be called during + * the execution of rte_panic + */ + +typedef void (*rte_user_abort_callback_t)(void); +/**< @internal Ethernet device configuration. */ + +/** + * Register user callback function to be called during rte_panic() + * Deregisteration is by passing NULL as the parameter + */ +void __rte_experimental +rte_panic_user_callback_register(rte_user_abort_callback_t *cb); + +/** + * Register user callback function to be called during rte_exit() + * Deregisteration is by passing NULL as the parameter + */ +void __rte_experimental +rte_exit_user_callback_register(rte_user_abort_callback_t *cb); + /** * Dump the stack of the calling core to the console. */ diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c index 5d92500..b1748b8 100644 --- a/lib/librte_eal/linuxapp/eal/eal_debug.c +++ b/lib/librte_eal/linuxapp/eal/eal_debug.c @@ -16,8 +16,42 @@ #include #include + #define BACKTRACE_SIZE 256 +/* + * user function pointers that when assigned, gets to be called + * during ret_exit() + */ +static rte_user_abort_callback_t *exit_user_callback; + +/* + * user function pointers that when assigned, gets to be called + * during ret_panic() + */ +static rte_user_abort_callback_t *panic_user_callback; + +/** + * Register user callback function to be called during rte_panic() + * Deregisteration is by passing NULL as the parameter + */ +void __rte_experimental +rte_panic_user_callback_register(rte_user_abort_callback_t *cb) +{ + panic_user_callback = cb; +} + +/** + * Register user callback function to be called during rte_exit() + * Deregisteration is by passing NULL as the parameter + */ +void __rte_experimental +rte_exit_user_callback_register(rte_user_abort_callback_t *cb) +{ + exit_user_callback = cb; +} + + /* dump the stack of the calling core */ void rte_dump_stack(void) { @@ -59,6 +93,8 @@ void __rte_panic(const char *funcname, const char *format, ...) va_end(ap); rte_dump_stack(); rte_dump_registers(); + if (panic_user_callback) + (*panic_user_callback)(); abort(); } @@ -78,6 +114,8 @@ rte_exit(int exit_code, const char *format, ...) va_start(ap, format); rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap); va_end(ap); + if (exit_user_callback) + (*exit_user_callback)(); #ifndef RTE_EAL_ALWAYS_PANIC_ON_ERROR if (rte_eal_cleanup() != 0) diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index d123602..7b8f55d 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -221,11 +221,13 @@ EXPERIMENTAL { rte_eal_hotplug_add; rte_eal_hotplug_remove; rte_eal_mbuf_user_pool_ops; + rte_exit_user_callback_register; rte_mp_action_register; rte_mp_action_unregister; rte_mp_sendmsg; rte_mp_request; rte_mp_reply; + rte_panic_user_callback_register; rte_service_attr_get; rte_service_attr_reset_all; rte_service_component_register;