From: Arnon Warshavsky <arnon@qwilt.com>
To: thomas@monjalon.net, bruce.richardson@intel.com
Cc: dev@dpdk.org, Arnon Warshavsky <arnon@qwilt.com>
Subject: [dpdk-dev] [PATCH] eal: register rte_panic user callback
Date: Tue, 6 Mar 2018 20:28:48 +0200 [thread overview]
Message-ID: <1520360928-9375-1-git-send-email-arnon@qwilt.com> (raw)
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@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
next reply other threads:[~2018-03-06 18:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 18:28 Arnon Warshavsky [this message]
2018-03-07 8:32 ` Thomas Monjalon
2018-03-07 8:57 ` Arnon Warshavsky
2018-03-07 9:05 ` Burakov, Anatoly
2018-03-07 9:59 ` Thomas Monjalon
2018-03-07 11:02 ` Arnon Warshavsky
2018-03-07 15:04 ` Thomas Monjalon
2018-03-07 16:26 ` Arnon Warshavsky
2018-03-07 11:29 ` Burakov, Anatoly
2018-03-07 13:23 ` Arnon Warshavsky
2018-03-07 15:06 ` Thomas Monjalon
2018-03-07 16:31 ` Arnon Warshavsky
2018-03-07 17:17 ` 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=1520360928-9375-1-git-send-email-arnon@qwilt.com \
--to=arnon@qwilt.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=thomas@monjalon.net \
/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 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).