[v3,3/6] eal: support libunwind based backtrace

Message ID 20210906041732.1019743-4-jerinj@marvell.com (mailing list archive)
State Rejected, archived
Delegated to: David Marchand
Headers
Series support oops handling |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jerin Jacob Kollanukkaran Sept. 6, 2021, 4:17 a.m. UTC
  From: Jerin Jacob <jerinj@marvell.com>

adding optional libwind library dependency to DPDK for
enhanced backtrace based on ucontext.

Signed-off-by: Jerin Jacob <jerinj@marvell.com>
---
 .github/workflows/build.yml |  2 +-
 .travis.yml                 |  2 +-
 config/meson.build          |  8 +++++++
 lib/eal/unix/eal_oops.c     | 45 +++++++++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger Jan. 27, 2022, 8:47 p.m. UTC | #1
On Mon, 6 Sep 2021 09:47:29 +0530
<jerinj@marvell.com> wrote:

> From: Jerin Jacob <jerinj@marvell.com>
> 
> adding optional libwind library dependency to DPDK for
> enhanced backtrace based on ucontext.
> 
> Signed-off-by: Jerin Jacob <jerinj@marvell.com>


Was looking for better backtrace and noticed that there is libbacktrace
on github (BSD licensed). It provides more information like file and line number.
Maybe DPDK should integrate it?


PS: existing rte_dump_stack() is not safe from signal handlers.
https://bugs.dpdk.org/show_bug.cgi?id=929
  
Jerin Jacob Jan. 28, 2022, 4:33 a.m. UTC | #2
On Fri, Jan 28, 2022 at 2:18 AM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On Mon, 6 Sep 2021 09:47:29 +0530
> <jerinj@marvell.com> wrote:
>
> > From: Jerin Jacob <jerinj@marvell.com>
> >
> > adding optional libwind library dependency to DPDK for
> > enhanced backtrace based on ucontext.
> >
> > Signed-off-by: Jerin Jacob <jerinj@marvell.com>
>
>
> Was looking for better backtrace and noticed that there is libbacktrace
> on github (BSD licensed). It provides more information like file and line number.
> Maybe DPDK should integrate it?

TB already decided to NOT pursue that path.


>
>
> PS: existing rte_dump_stack() is not safe from signal handlers.
> https://bugs.dpdk.org/show_bug.cgi?id=929
  
Thomas Monjalon Jan. 28, 2022, 8:41 a.m. UTC | #3
28/01/2022 05:33, Jerin Jacob:
> On Fri, Jan 28, 2022 at 2:18 AM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > On Mon, 6 Sep 2021 09:47:29 +0530
> > <jerinj@marvell.com> wrote:
> >
> > > From: Jerin Jacob <jerinj@marvell.com>
> > >
> > > adding optional libwind library dependency to DPDK for
> > > enhanced backtrace based on ucontext.
> > >
> > > Signed-off-by: Jerin Jacob <jerinj@marvell.com>
> >
> >
> > Was looking for better backtrace and noticed that there is libbacktrace
> > on github (BSD licensed). It provides more information like file and line number.
> > Maybe DPDK should integrate it?
> 
> TB already decided to NOT pursue that path.

I don't remember why.
Was it because of adding a dependency in makefile build system?
Adding optional dependencies is easier now with Meson.
  
Jerin Jacob Jan. 28, 2022, 2:27 p.m. UTC | #4
On Fri, Jan 28, 2022 at 2:11 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 28/01/2022 05:33, Jerin Jacob:
> > On Fri, Jan 28, 2022 at 2:18 AM Stephen Hemminger
> > <stephen@networkplumber.org> wrote:
> > >
> > > On Mon, 6 Sep 2021 09:47:29 +0530
> > > <jerinj@marvell.com> wrote:
> > >
> > > > From: Jerin Jacob <jerinj@marvell.com>
> > > >
> > > > adding optional libwind library dependency to DPDK for
> > > > enhanced backtrace based on ucontext.
> > > >
> > > > Signed-off-by: Jerin Jacob <jerinj@marvell.com>
> > >
> > >
> > > Was looking for better backtrace and noticed that there is libbacktrace
> > > on github (BSD licensed). It provides more information like file and line number.
> > > Maybe DPDK should integrate it?
> >
> > TB already decided to NOT pursue that path.
>
> I don't remember why.

Feature overlap with systemd features.

> Was it because of adding a dependency in makefile build system?
> Adding optional dependencies is easier now with Meson.



>
>
  
Stephen Hemminger Jan. 28, 2022, 5:05 p.m. UTC | #5
On Fri, 28 Jan 2022 19:57:40 +0530
Jerin Jacob <jerinjacobk@gmail.com> wrote:

> On Fri, Jan 28, 2022 at 2:11 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> >
> > 28/01/2022 05:33, Jerin Jacob:  
> > > On Fri, Jan 28, 2022 at 2:18 AM Stephen Hemminger
> > > <stephen@networkplumber.org> wrote:  
> > > >
> > > > On Mon, 6 Sep 2021 09:47:29 +0530
> > > > <jerinj@marvell.com> wrote:
> > > >  
> > > > > From: Jerin Jacob <jerinj@marvell.com>
> > > > >
> > > > > adding optional libwind library dependency to DPDK for
> > > > > enhanced backtrace based on ucontext.
> > > > >
> > > > > Signed-off-by: Jerin Jacob <jerinj@marvell.com>  
> > > >
> > > >
> > > > Was looking for better backtrace and noticed that there is libbacktrace
> > > > on github (BSD licensed). It provides more information like file and line number.
> > > > Maybe DPDK should integrate it?  
> > >
> > > TB already decided to NOT pursue that path.  
> >
> > I don't remember why.  
> 
> Feature overlap with systemd features.
> 
> > Was it because of adding a dependency in makefile build system?
> > Adding optional dependencies is easier now with Meson.  
> 
> 
> 
> >
> >  

Okay, thanks. I may look at the current signal unsafety bug of
the current code.
  

Patch

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 151641e6fa..de985776ed 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -93,7 +93,7 @@  jobs:
       run: sudo apt install -y ccache libnuma-dev python3-setuptools
         python3-wheel python3-pip python3-pyelftools ninja-build libbsd-dev
         libpcap-dev libibverbs-dev libcrypto++-dev libfdt-dev libjansson-dev
-        libarchive-dev
+        libarchive-dev libunwind-dev
     - name: Install libabigail build dependencies if no cache is available
       if: env.ABI_CHECKS == 'true' && steps.libabigail-cache.outputs.cache-hit != 'true'
       run: sudo apt install -y autoconf automake libtool pkg-config libxml2-dev
diff --git a/.travis.yml b/.travis.yml
index 4bb5bf629e..cfb8931d3b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,7 +16,7 @@  addons:
     packages: &required_packages
       - [libnuma-dev, python3-setuptools, python3-wheel, python3-pip, python3-pyelftools, ninja-build]
       - [libbsd-dev, libpcap-dev, libibverbs-dev, libcrypto++-dev, libfdt-dev, libjansson-dev]
-      - [libarchive-dev]
+      - [libarchive-dev, libunwind-dev]
 
 _aarch64_packages: &aarch64_packages
   - *required_packages
diff --git a/config/meson.build b/config/meson.build
index 3b5966ec2f..7f4dd52bc5 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -237,6 +237,14 @@  if cc.get_id() == 'clang' and dpdk_conf.get('RTE_ARCH_64') == false
     dpdk_extra_ldflags += '-latomic'
 endif
 
+# check for libunwind
+unwind_dep = dependency('libunwind', required: false, method: 'pkg-config')
+if unwind_dep.found() and cc.has_header('libunwind.h', dependencies: unwind_dep)
+    dpdk_conf.set('RTE_USE_LIBUNWIND', 1)
+    add_project_link_arguments('-lunwind', language: 'c')
+    dpdk_extra_ldflags += '-lunwind'
+endif
+
 # add -include rte_config to cflags
 add_project_arguments('-include', 'rte_config.h', language: 'c')
 
diff --git a/lib/eal/unix/eal_oops.c b/lib/eal/unix/eal_oops.c
index a480437f23..9c2d9d99d9 100644
--- a/lib/eal/unix/eal_oops.c
+++ b/lib/eal/unix/eal_oops.c
@@ -28,11 +28,56 @@  struct oops_signal {
 
 static struct oops_signal signals_db[RTE_DIM(oops_signals)];
 
+#if defined(RTE_USE_LIBUNWIND)
+
+#define BACKTRACE_DEPTH 256
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+
+static void
+back_trace_dump(ucontext_t *context)
+{
+	unw_cursor_t cursor;
+	unw_word_t ip, off;
+	int rc, level = 0;
+	char name[256];
+
+	if (context == NULL)
+		return;
+
+	rc = unw_init_local(&cursor, (unw_context_t *)context);
+	if (rc < 0)
+		goto fail;
+
+	for (;;) {
+		rc = unw_get_reg(&cursor, UNW_REG_IP, &ip);
+		if (rc < 0)
+			goto fail;
+		rc = unw_get_proc_name(&cursor, name, sizeof(name), &off);
+		if (rc == 0)
+			oops_print("[%16p]: %s()+0x%" PRIx64 "\n", (void *)ip,
+				   name, (uint64_t)off);
+		else
+			oops_print("[%16p]: <unknown>\n", (void *)ip);
+		rc = unw_step(&cursor);
+		if (rc <= 0 || ++level >= BACKTRACE_DEPTH)
+			break;
+	}
+	return;
+fail:
+	oops_print("libunwind call failed %s\n", unw_strerror(rc));
+}
+
+#else
+
 static void
 back_trace_dump(ucontext_t *context)
 {
 	RTE_SET_USED(context);
 }
+
+#endif
+
 static void
 siginfo_dump(int sig, siginfo_t *info)
 {