Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1395729

[PATCH 7/8] perf callchain: Support x86 target platform

From He Kuang <hekuang@huawei.com>
Newsgroups linux.kernel
Subject [PATCH 7/8] perf callchain: Support x86 target platform
Date 2016-05-06 11:10 +0200
Message-ID <rvJVN-2eU-39@gated-at.bofh.it> (permalink)
References <rvJVM-2eU-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Support x86(32bit) cross platform callchain unwind.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 .../arch/x86/include/libunwind/libunwind-arch.h    | 18 ++++++++++
 tools/perf/arch/x86/util/unwind-libunwind.c        | 42 ++++++++++++++++++++++
 tools/perf/util/Build                              |  6 ++++
 tools/perf/util/thread.c                           | 10 +++---
 tools/perf/util/unwind-libunwind.c                 |  2 +-
 tools/perf/util/unwind.h                           |  5 +++
 6 files changed, 77 insertions(+), 6 deletions(-)
 create mode 100644 tools/perf/arch/x86/include/libunwind/libunwind-arch.h

diff --git a/tools/perf/arch/x86/include/libunwind/libunwind-arch.h b/tools/perf/arch/x86/include/libunwind/libunwind-arch.h
new file mode 100644
index 0000000..265f14d
--- /dev/null
+++ b/tools/perf/arch/x86/include/libunwind/libunwind-arch.h
@@ -0,0 +1,18 @@
+#ifndef _LIBUNWIND_ARCH_H
+#define _LIBUNWIND_ARCH_H
+
+#include <libunwind-x86.h>
+#include <../perf_regs.h>
+#include <../../../../../../arch/x86/include/uapi/asm/perf_regs.h>
+
+#define LIBUNWIND_X86_32
+int libunwind__x86_reg_id(int regnum);
+
+#include <../../../x86/util/unwind-libunwind.c>
+
+#define LIBUNWIND__ARCH_REG_ID libunwind__x86_reg_id
+
+#define UNWT_PREFIX	UNW_PASTE(UNW_PASTE(_U, x86), _)
+#define UNWT_OBJ(fn)	UNW_PASTE(UNWT_PREFIX, fn)
+
+#endif /* _LIBUNWIND_ARCH_H */
diff --git a/tools/perf/arch/x86/util/unwind-libunwind.c b/tools/perf/arch/x86/util/unwind-libunwind.c
index db25e93..d422fbf 100644
--- a/tools/perf/arch/x86/util/unwind-libunwind.c
+++ b/tools/perf/arch/x86/util/unwind-libunwind.c
@@ -5,6 +5,7 @@
 #include "../../util/unwind.h"
 #include "../../util/debug.h"
 
+#ifndef LIBUNWIND_X86_32
 #ifdef HAVE_ARCH_X86_64_SUPPORT
 int libunwind__arch_reg_id(int regnum)
 {
@@ -110,3 +111,44 @@ int libunwind__arch_reg_id(int regnum)
 	return id;
 }
 #endif /* HAVE_ARCH_X86_64_SUPPORT */
+#else
+int libunwind__x86_reg_id(int regnum)
+{
+	int id;
+
+	switch (regnum) {
+	case UNW_X86_EAX:
+		id = PERF_REG_X86_AX;
+		break;
+	case UNW_X86_EDX:
+		id = PERF_REG_X86_DX;
+		break;
+	case UNW_X86_ECX:
+		id = PERF_REG_X86_CX;
+		break;
+	case UNW_X86_EBX:
+		id = PERF_REG_X86_BX;
+		break;
+	case UNW_X86_ESI:
+		id = PERF_REG_X86_SI;
+		break;
+	case UNW_X86_EDI:
+		id = PERF_REG_X86_DI;
+		break;
+	case UNW_X86_EBP:
+		id = PERF_REG_X86_BP;
+		break;
+	case UNW_X86_ESP:
+		id = PERF_REG_X86_SP;
+		break;
+	case UNW_X86_EIP:
+		id = PERF_REG_X86_IP;
+		break;
+	default:
+		pr_err("unwind: invalid reg id %d\n", regnum);
+		return -EINVAL;
+	}
+
+	return id;
+}
+#endif /* LIBUNWIND_X86_32 */
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 2e21529..2dd3939 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -1,3 +1,5 @@
+include ../scripts/Makefile.include
+
 libperf-y += alias.o
 libperf-y += annotate.o
 libperf-y += build-id.o
@@ -99,6 +101,10 @@ libperf-$(CONFIG_DWARF) += dwarf-aux.o
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind.o
 libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind_common.o
+libperf-$(CONFIG_LIBUNWIND_X86)      += unwind-libunwind_x86_32.o
+
+$(OUTPUT)util/unwind-libunwind_x86_32.o: util/unwind-libunwind.c arch/x86/util/unwind-libunwind.c
+	$(QUIET_CC)$(CC) $(CFLAGS) -DARCH_UNWIND_LIBUNWIND -Iarch/x86/include/libunwind -c -o $@ util/unwind-libunwind.c
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index cf60db1..2b93856 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -214,12 +214,12 @@ void thread__insert_map(struct thread *thread, struct map *map)
 		pr_debug("Thread map is X86, 64bit is %d\n", is_64_bit);
 		if (!is_64_bit) {
 #ifdef HAVE_LIBUNWIND_X86_SUPPORT
-			pr_err("target platform=%s is not implemented!\n",
-			       arch);
+			register_unwind_libunwind_ops(
+				&_Ux86_unwind_libunwind_ops, thread);
 #else
-			pr_err("target platform=%s is not supported!\n", arch);
-#endif
+			register_null_unwind_libunwind_ops(thread);
 			goto err;
+#endif
 		}
 	} else {
 		register_local_unwind_libunwind_ops(thread);
@@ -231,7 +231,7 @@ void thread__insert_map(struct thread *thread, struct map *map)
 	return;
 
 err: __maybe_unused
-	register_null_unwind_libunwind_ops(thread);
+	pr_err("target platform=%s not support!\n", arch);
 	return;
 #endif
 }
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 2558bf3..a195b56 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -527,7 +527,7 @@ static int access_reg(unw_addr_space_t __maybe_unused as,
 		return 0;
 	}
 
-	id = libunwind__arch_reg_id(regnum);
+	id = LIBUNWIND__ARCH_REG_ID(regnum);
 	if (id < 0)
 		return -EINVAL;
 
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 61b44a6..98d40bd 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -55,6 +55,11 @@ static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
 static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
 static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
 #endif
+
+#ifdef HAVE_LIBUNWIND_X86_SUPPORT
+extern struct unwind_libunwind_ops _Ux86_unwind_libunwind_ops;
+#endif
+
 #else
 static inline int
 unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
-- 
1.8.5.2

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/8] Add support for remote unwind He Kuang <hekuang@huawei.com> - 2016-05-06 11:10 +0200
  [PATCH 7/8] perf callchain: Support x86 target platform He Kuang <hekuang@huawei.com> - 2016-05-06 11:10 +0200
  [PATCH 2/8] perf script: Add options for custom vdso name He Kuang <hekuang@huawei.com> - 2016-05-06 11:10 +0200
    Re: [PATCH 2/8] perf script: Add options for custom vdso name Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-06 13:50 +0200
    Re: [PATCH 2/8] perf script: Add options for custom vdso name Jiri Olsa <jolsa@redhat.com> - 2016-05-07 20:20 +0200
  Re: [PATCH 0/8] Add support for remote unwind Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-05-06 14:00 +0200

csiph-web