[dpdk-dev] [PATCH] eal: register rte_panic user callback
Arnon Warshavsky
arnon at qwilt.com
Tue Mar 6 19:28:48 CET 2018
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 <arnon at qwilt.com>
---
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 <rte_compat.h>
#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 <rte_common.h>
#include <rte_eal.h>
+
#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;
--
2.7.4
More information about the dev
mailing list