[PATCH v6 11/11] perf callchain: Support aarch64 cross-platform

From: He Kuang
Date: Sat May 28 2016 - 08:01:09 EST


Support aarch64 cross platform callchain unwind.

Signed-off-by: He Kuang <hekuang@xxxxxxxxxx>
---
tools/perf/arch/Build | 1 +
tools/perf/arch/arm64/util/unwind-libunwind.c | 4 +++-
.../perf/arch/arm64/util/unwind-libunwind_arm64.c | 22 ++++++++++++++++++++++
tools/perf/config/Makefile | 12 ++++++++++++
tools/perf/util/unwind-libunwind.c | 6 +++++-
tools/perf/util/unwind.h | 10 ++++++++++
6 files changed, 53 insertions(+), 2 deletions(-)
create mode 100644 tools/perf/arch/arm64/util/unwind-libunwind_arm64.c

diff --git a/tools/perf/arch/Build b/tools/perf/arch/Build
index 3fc4af1..bc49295 100644
--- a/tools/perf/arch/Build
+++ b/tools/perf/arch/Build
@@ -1,3 +1,4 @@
libperf-y += common.o
libperf-y += $(ARCH)/
libperf-$(CONFIG_LIBUNWIND_X86) += x86/util/unwind-libunwind_x86_32.o
+libperf-$(CONFIG_LIBUNWIND_AARCH64) += arm64/util/unwind-libunwind_arm64.o
diff --git a/tools/perf/arch/arm64/util/unwind-libunwind.c b/tools/perf/arch/arm64/util/unwind-libunwind.c
index a87afa9..c116b71 100644
--- a/tools/perf/arch/arm64/util/unwind-libunwind.c
+++ b/tools/perf/arch/arm64/util/unwind-libunwind.c
@@ -1,11 +1,13 @@

+#ifndef REMOTE_UNWIND_LIBUNWIND
#include <errno.h>
#include <libunwind.h>
#include "perf_regs.h"
#include "../../util/unwind.h"
#include "../../util/debug.h"
+#endif

-int libunwind__arch_reg_id(int regnum)
+int LIBUNWIND__ARCH_REG_ID(int regnum)
{
switch (regnum) {
case UNW_AARCH64_X0:
diff --git a/tools/perf/arch/arm64/util/unwind-libunwind_arm64.c b/tools/perf/arch/arm64/util/unwind-libunwind_arm64.c
new file mode 100644
index 0000000..ea9e7d1
--- /dev/null
+++ b/tools/perf/arch/arm64/util/unwind-libunwind_arm64.c
@@ -0,0 +1,22 @@
+#define REMOTE_UNWIND_LIBUNWIND
+
+#define LIBUNWIND__ARCH_REG_ID libunwind__arm64_reg_id
+
+#include "unwind.h"
+#include "debug.h"
+#include "libunwind-aarch64.h"
+#include <../../../../../arch/arm64/include/uapi/asm/perf_regs.h>
+#include "unwind-libunwind.c"
+
+#undef NO_LIBUNWIND_DEBUG_FRAME
+#ifdef NO_LIBUNWIND_DEBUG_FRAME_AARCH64
+#define NO_LIBUNWIND_DEBUG_FRAME
+#endif
+
+#include "util/unwind-libunwind-local.c"
+
+int register_arm64_unwind_libunwind_ops(struct thread *thread)
+{
+ thread->unwind_libunwind_ops = &_unwind_libunwind_ops;
+ return 0;
+}
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index e156f76..bb5aea8 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -363,6 +363,18 @@ ifndef NO_LIBUNWIND
have_libunwind = 1
endif

+ ifeq ($(feature-libunwind-aarch64), 1)
+ $(call detected,CONFIG_LIBUNWIND_AARCH64)
+ CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
+ LDFLAGS += -lunwind-aarch64
+ have_libunwind = 1
+ $(call feature_check,libunwind-debug-frame-aarch64)
+ ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
+ msg := $(warning No debug_frame support found in libunwind-aarch64);
+ CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
+ endif
+ endif
+
ifneq ($(feature-libunwind), 1)
msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
NO_LOCAL_LIBUNWIND := 1
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index c1d9d36..5930865 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -25,9 +25,13 @@ int unwind__prepare_access(struct thread *thread, struct map *map)

arch = normalize_arch(thread->mg->machine->env->arch);

- if (!strcmp(arch, "x86"))
+ if (!strcmp(arch, "x86")) {
if (dso_type != DSO__TYPE_64BIT)
register_func = register_x86_32_unwind_libunwind_ops;
+ } else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
+ if (dso_type == DSO__TYPE_64BIT)
+ register_func = register_arm64_unwind_libunwind_ops;
+ }

if (register_func) {
ret = register_func(thread);
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 43f9f66..e203aa9 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -56,6 +56,16 @@ register_x86_32_unwind_libunwind_ops(struct thread *thread __maybe_unused)
}
#endif

+#ifdef HAVE_LIBUNWIND_AARCH64_SUPPORT
+int register_arm64_unwind_libunwind_ops(struct thread *thread);
+#else
+static inline int
+register_arm64_unwind_libunwind_ops(struct thread *thread __maybe_unused)
+{
+ return -1;
+}
+#endif
+
#else
static inline int
unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
--
1.8.5.2