linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/6] Add support for remote unwind
@ 2016-05-19 11:47 He Kuang
  2016-05-19 11:47 ` [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided He Kuang
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: He Kuang @ 2016-05-19 11:47 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, wangnan0,
	hekuang, jpoimboe, ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern
  Cc: linux-kernel

v3 url:
  http://thread.gmane.org/gmane.linux.kernel/2220387

Currently, perf script uses host unwind methods(local unwind) to parse
perf.data callchain info regardless of the target architecture. So we
get wrong result and no promotion when do remote unwind on other
platforms/machines.

This patchset checks whether a dso is 32-bit or 64-bit according to
elf class info for each thread to let perf use the correct remote
unwind methods instead.

Only x86 and aarch64 is added in this patchset to show the work flow,
other platforms can be added easily.

We can see the right result for unwind info on different machines, for
example: perf.data recorded on i686 qemu with '-g' option and parsed
on x86_64 machine.

before this patchset:

  hello  1219 [001] 72190.667975: probe:sys_close: (c1169d60)
                  c1169d61 sys_close ([kernel.kallsyms])
                  c189c0d7 sysenter_past_esp ([kernel.kallsyms])
                  b777aba9 [unknown] ([vdso32])

after:
(Add vdso into buildid-cache first by 'perf buildid-cache -a' and
libraries are provided in symfs dir)

  hello  1219 [001] 72190.667975: probe:sys_close: (c1169d60)
                  c1169d61 sys_close ([kernel.kallsyms])
                  c189c0d7 sysenter_past_esp ([kernel.kallsyms])
                  b777aba9 __kernel_vsyscall ([vdso32])
                  b76971cc close (/lib/libc-2.22.so)
                   804842e fib (/tmp/hello)
                   804849d main (/tmp/hello)
                  b75d746e __libc_start_main (/lib/libc-2.22.so)
                   8048341 _start (/tmp/hello)

v4:

 - Move reference of buildid dir to 'symfs/.debug' if --symfs is
   given.
 - Split makefile changes out of patch 'Add support for
   cross-platform unwind'.
 - Use existing code normalize_arch() for testing the arch of
   perf.data.

v3:

 - Remove --vdso option, store vdso buildid in perf.data and let perf
   fetch it automatically.
 - Use existing dso__type() function to test if dso is 32-bit or
   64-bit.

v2:

 - Explain the reason why we can omit dwarf judgement when recording
   in commit message.
 - Elaborate on why we need to add a custom vdso path option, and
   change the type name to DSO_BINARY_TYPE__VDSO.
 - Hide the build tests status for cross platform unwind.
 - Keep generic version of libunwind-debug-frame test.
 - Put 32/64-bit test functions into separate patch.
 - Extract unwind related functions to unwind-libunwind.c and add new
   file for common parts used by both local and remote unwind.
 - Eliminate most of the ifdefs in .c file.

Thanks.

He Kuang (6):
  perf tools: Set buildid dir under symfs when --symfs is provided
  perf tools: Promote proper messages for cross-platform unwind
  perf tools: Separate local and remote unwind support detection
  perf callchain: Add support for cross-platform unwind
  perf callchain: Support x86 target platform
  perf callchain: Support aarch64 cross-platform

 .../arch/arm64/include/libunwind/libunwind-arch.h  |  18 ++++
 tools/perf/arch/arm64/util/unwind-libunwind.c      |   5 +-
 tools/perf/arch/common.c                           |   2 +-
 tools/perf/arch/common.h                           |   1 +
 .../arch/x86/include/libunwind/libunwind-arch.h    |  18 ++++
 tools/perf/arch/x86/util/unwind-libunwind.c        |  12 ++-
 tools/perf/builtin-annotate.c                      |   5 +-
 tools/perf/builtin-diff.c                          |   5 +-
 tools/perf/builtin-report.c                        |   5 +-
 tools/perf/builtin-script.c                        |   5 +-
 tools/perf/builtin-timechart.c                     |   5 +-
 tools/perf/config/Makefile                         |  37 ++++++-
 tools/perf/util/Build                              |  13 ++-
 tools/perf/util/dso.c                              |   4 +-
 tools/perf/util/symbol.c                           |  23 +++++
 tools/perf/util/symbol.h                           |   2 +
 tools/perf/util/thread.c                           |   7 +-
 tools/perf/util/thread.h                           |  14 ++-
 tools/perf/util/unwind-libunwind.c                 |  48 +++++++--
 tools/perf/util/unwind-libunwind_common.c          | 109 +++++++++++++++++++++
 tools/perf/util/unwind.h                           |  45 +++++++--
 21 files changed, 341 insertions(+), 42 deletions(-)
 create mode 100644 tools/perf/arch/arm64/include/libunwind/libunwind-arch.h
 create mode 100644 tools/perf/arch/x86/include/libunwind/libunwind-arch.h
 create mode 100644 tools/perf/util/unwind-libunwind_common.c

-- 
1.8.5.2

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided
  2016-05-19 11:47 [PATCH v4 0/6] Add support for remote unwind He Kuang
@ 2016-05-19 11:47 ` He Kuang
  2016-05-19 14:23   ` David Ahern
                     ` (2 more replies)
  2016-05-19 11:47 ` [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind He Kuang
                   ` (4 subsequent siblings)
  5 siblings, 3 replies; 17+ messages in thread
From: He Kuang @ 2016-05-19 11:47 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, wangnan0,
	hekuang, jpoimboe, ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern
  Cc: linux-kernel

This patch moves the reference of buildid dir to 'symfs/.debug' and
skips the local buildid dir when '--symfs' is given, so that every
single file opened by perf is relateive to symfs directory now.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/builtin-annotate.c  |  5 +++--
 tools/perf/builtin-diff.c      |  5 +++--
 tools/perf/builtin-report.c    |  5 +++--
 tools/perf/builtin-script.c    |  5 +++--
 tools/perf/builtin-timechart.c |  5 +++--
 tools/perf/util/dso.c          |  4 +---
 tools/perf/util/symbol.c       | 23 +++++++++++++++++++++++
 tools/perf/util/symbol.h       |  2 ++
 8 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 8141583..25c8173 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -324,8 +324,9 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
 		    "Skip symbols that cannot be annotated"),
 	OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		   "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
 		    "Interleave source code with assembly code (default)"),
 	OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 9ce354f..f7645a4 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -812,8 +812,9 @@ static const struct option options[] = {
 	OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
 		   "separator for columns, no spaces will be added between "
 		   "columns '.' is reserved."),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		    "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_UINTEGER('o', "order", &sort_compute, "Specify compute sorting."),
 	OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
 		     "How to display percentage of filtered entries", parse_filter_percentage),
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 87d40e3..84b4f730 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -770,8 +770,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "columns '.' is reserved."),
 	OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
 		    "Only display entries resolved to a symbol"),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		    "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
 		   "list of cpus to profile"),
 	OPT_BOOLEAN('I', "show-info", &report.show_full_info,
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index efca816..a8bf0e2 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2010,8 +2010,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "file", "kallsyms pathname"),
 	OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
 		    "When printing symbols do not display call chain"),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		    "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_CALLBACK('F', "fields", NULL, "str",
 		     "comma separated output fields prepend with 'type:'. "
 		     "Valid types: hw,sw,trace,raw. "
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 40cc9bb..733a554 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1945,8 +1945,9 @@ int cmd_timechart(int argc, const char **argv,
 	OPT_CALLBACK('p', "process", NULL, "process",
 		      "process selector. Pass a pid or process name.",
 		       parse_process),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		    "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_INTEGER('n', "proc-num", &tchart.proc_num,
 		    "min. number of tasks to print"),
 	OPT_BOOLEAN('t', "topology", &tchart.topology,
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 75b7561..5d286f5 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -63,9 +63,7 @@ int dso__read_binary_type_filename(const struct dso *dso,
 		}
 		break;
 	case DSO_BINARY_TYPE__BUILD_ID_CACHE:
-		/* skip the locally configured cache if a symfs is given */
-		if (symbol_conf.symfs[0] ||
-		    (dso__build_id_filename(dso, filename, size) == NULL))
+		if (dso__build_id_filename(dso, filename, size) == NULL)
 			ret = -1;
 		break;
 
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 2252b54..20f9cb3 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2033,3 +2033,26 @@ void symbol__exit(void)
 	symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
 	symbol_conf.initialized = false;
 }
+
+int symbol__config_symfs(const struct option *opt __maybe_unused,
+			 const char *dir, int unset __maybe_unused)
+{
+	char *bf = NULL;
+	int ret;
+
+	symbol_conf.symfs = strdup(dir);
+	if (symbol_conf.symfs == NULL)
+		return -ENOMEM;
+
+	/* skip the locally configured cache if a symfs is given, and
+	 * config buildid dir to symfs/.debug
+	 */
+	ret = asprintf(&bf, "%s/%s", dir, ".debug");
+	if (ret < 0)
+		return -ENOMEM;
+
+	set_buildid_dir(bf);
+
+	free(bf);
+	return 0;
+}
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 25f2fd67..fa41534 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -290,6 +290,8 @@ bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 bool symbol__restricted_filename(const char *filename,
 				 const char *restricted_filename);
 bool symbol__is_idle(struct symbol *sym);
+int symbol__config_symfs(const struct option *opt __maybe_unused,
+			 const char *dir, int unset __maybe_unused);
 
 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 		  struct symsrc *runtime_ss, symbol_filter_t filter,
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind
  2016-05-19 11:47 [PATCH v4 0/6] Add support for remote unwind He Kuang
  2016-05-19 11:47 ` [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided He Kuang
@ 2016-05-19 11:47 ` He Kuang
  2016-05-19 14:50   ` Arnaldo Carvalho de Melo
  2016-05-19 16:46   ` Jiri Olsa
  2016-05-19 11:47 ` [PATCH v4 3/6] perf tools: Separate local and remote unwind support detection He Kuang
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 17+ messages in thread
From: He Kuang @ 2016-05-19 11:47 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, wangnan0,
	hekuang, jpoimboe, ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern
  Cc: linux-kernel

Currently, perf script uses host unwind methods to parse perf.data
callchain info regardless of the target architecture. So we get wrong
result and no promotion when unwinding callchains of x86(32-bit) on
x86(64-bit) machine.

This patch shows proper error messages when we do remote unwind
x86(32-bit) on other machines. Same thing for other platforms will be
added in next patches.

Common functions which will be used by both local unwind and remote
unwind are separated into new file 'unwind-libunwind_common.c'.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/arch/common.c                  |  2 +-
 tools/perf/arch/common.h                  |  1 +
 tools/perf/config/Makefile                |  6 ++++++
 tools/perf/util/Build                     |  1 +
 tools/perf/util/thread.c                  |  2 ++
 tools/perf/util/unwind-libunwind_common.c | 34 +++++++++++++++++++++++++++++++
 tools/perf/util/unwind.h                  |  5 +++++
 7 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/util/unwind-libunwind_common.c

diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
index e83c8ce..fa090a9 100644
--- a/tools/perf/arch/common.c
+++ b/tools/perf/arch/common.c
@@ -102,7 +102,7 @@ static int lookup_triplets(const char *const *triplets, const char *name)
  * Return architecture name in a normalized form.
  * The conversion logic comes from the Makefile.
  */
-static const char *normalize_arch(char *arch)
+const char *normalize_arch(char *arch)
 {
 	if (!strcmp(arch, "x86_64"))
 		return "x86";
diff --git a/tools/perf/arch/common.h b/tools/perf/arch/common.h
index 7529cfb..6b01c73 100644
--- a/tools/perf/arch/common.h
+++ b/tools/perf/arch/common.h
@@ -6,5 +6,6 @@
 extern const char *objdump_path;
 
 int perf_env__lookup_objdump(struct perf_env *env);
+const char *normalize_arch(char *arch);
 
 #endif /* ARCH_PERF_COMMON_H */
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 1e46277..a86b864 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -345,6 +345,12 @@ ifeq ($(ARCH),powerpc)
 endif
 
 ifndef NO_LIBUNWIND
+  ifeq ($(feature-libunwind-x86), 1)
+    LIBUNWIND_LIBS += -lunwind-x86
+    $(call detected,CONFIG_LIBUNWIND_X86)
+    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
+  endif
+
   ifneq ($(feature-libunwind), 1)
     msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
     NO_LIBUNWIND := 1
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8c6c8a0..25c31fb 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -100,6 +100,7 @@ libperf-$(CONFIG_DWARF) += dwarf-aux.o
 
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
+libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind_common.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 45fcb71..3043113 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -205,6 +205,8 @@ void thread__insert_map(struct thread *thread, struct map *map)
 {
 	map_groups__fixup_overlappings(thread->mg, map, stderr);
 	map_groups__insert(thread->mg, map);
+
+	unwind__get_arch(thread, map);
 }
 
 static int thread__clone_map_groups(struct thread *thread,
diff --git a/tools/perf/util/unwind-libunwind_common.c b/tools/perf/util/unwind-libunwind_common.c
new file mode 100644
index 0000000..3946c99
--- /dev/null
+++ b/tools/perf/util/unwind-libunwind_common.c
@@ -0,0 +1,34 @@
+#include "thread.h"
+#include "session.h"
+#include "unwind.h"
+#include "symbol.h"
+#include "debug.h"
+#include "arch/common.h"
+
+void unwind__get_arch(struct thread *thread, struct map *map)
+{
+	const char *arch;
+	enum dso_type dso_type;
+
+	if (!thread->mg->machine->env)
+		return;
+
+	dso_type = dso__type(map->dso, thread->mg->machine);
+	if (dso_type == DSO__TYPE_UNKNOWN)
+		return;
+
+	if (thread->addr_space)
+		pr_debug("unwind: thread map already set, 64bit is %d, dso=%s\n",
+			 dso_type == DSO__TYPE_64BIT, map->dso->name);
+
+	arch = normalize_arch(thread->mg->machine->env->arch);
+
+	if (!strcmp(arch, "x86")) {
+		if (dso_type != DSO__TYPE_64BIT)
+#ifdef HAVE_LIBUNWIND_X86_SUPPORT
+			pr_err("unwind: target platform=%s is not implemented\n", arch);
+#else
+			pr_err("unwind: target platform=%s is not supported\n", arch);
+#endif
+	}
+}
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 12790cf..889d630 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -24,6 +24,7 @@ int libunwind__arch_reg_id(int regnum);
 int unwind__prepare_access(struct thread *thread);
 void unwind__flush_access(struct thread *thread);
 void unwind__finish_access(struct thread *thread);
+void unwind__get_arch(struct thread *thread, struct map *map);
 #else
 static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
 {
@@ -32,6 +33,8 @@ 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) {}
+static inline void unwind__get_arch(struct thread *thread __maybe_unused,
+				    struct map *map __maybe_unused) {}
 #endif
 #else
 static inline int
@@ -51,5 +54,7 @@ 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) {}
+static inline void unwind__get_arch(struct thread *thread __maybe_unused,
+				    struct map *map __maybe_unused) {}
 #endif /* HAVE_DWARF_UNWIND_SUPPORT */
 #endif /* __UNWIND_H */
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v4 3/6] perf tools: Separate local and remote unwind support detection
  2016-05-19 11:47 [PATCH v4 0/6] Add support for remote unwind He Kuang
  2016-05-19 11:47 ` [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided He Kuang
  2016-05-19 11:47 ` [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind He Kuang
@ 2016-05-19 11:47 ` He Kuang
  2016-05-19 11:47 ` [PATCH v4 4/6] perf callchain: Add support for cross-platform unwind He Kuang
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 17+ messages in thread
From: He Kuang @ 2016-05-19 11:47 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, wangnan0,
	hekuang, jpoimboe, ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern
  Cc: linux-kernel

This patch changes original CONFIG_LIBUNWIND/NO_LIBUNWIND to
CONFIG_LOCAL_LIBUNWIND/NO_LOCAL_LIBUNWIND for retaining local unwind
features. CONFIG_LIBUNWIND stands for either local or remote or both
unwind are supported and NO_LIBUNWIND means neither local nor remote
libunwind are supported.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/config/Makefile | 21 ++++++++++++++++++---
 tools/perf/util/Build      |  2 +-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index a86b864..3035dbf 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -345,16 +345,28 @@ ifeq ($(ARCH),powerpc)
 endif
 
 ifndef NO_LIBUNWIND
+  have_libunwind =
   ifeq ($(feature-libunwind-x86), 1)
-    LIBUNWIND_LIBS += -lunwind-x86
     $(call detected,CONFIG_LIBUNWIND_X86)
     CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
+    LDFLAGS += -lunwind -lunwind-x86
+    have_libunwind = 1
   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
+  else
+    have_libunwind = 1
+    CFLAGS += -DHAVE_LIBUNWIND_LOCAL_SUPPORT
+    $(call detected,CONFIG_LOCAL_LIBUNWIND)
+  endif
+
+  ifneq ($(have_libunwind), 1)
     NO_LIBUNWIND := 1
   endif
+else
+  NO_LOCAL_LIBUNWIND := 1
 endif
 
 ifndef NO_LIBBPF
@@ -392,7 +404,7 @@ else
   NO_DWARF_UNWIND := 1
 endif
 
-ifndef NO_LIBUNWIND
+ifndef NO_LOCAL_LIBUNWIND
   ifeq ($(ARCH),$(filter $(ARCH),arm arm64))
     $(call feature_check,libunwind-debug-frame)
     ifneq ($(feature-libunwind-debug-frame), 1)
@@ -403,12 +415,15 @@ ifndef NO_LIBUNWIND
     # non-ARM has no dwarf_find_debug_frame() function:
     CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
   endif
-  CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
   EXTLIBS += $(LIBUNWIND_LIBS)
   CFLAGS  += $(LIBUNWIND_CFLAGS)
   LDFLAGS += $(LIBUNWIND_LDFLAGS)
 endif
 
+ifndef NO_LIBUNWIND
+  CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
+endif
+
 ifndef NO_LIBAUDIT
   ifneq ($(feature-libaudit), 1)
     msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 25c31fb..ce69721 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -99,7 +99,7 @@ libperf-$(CONFIG_DWARF) += probe-finder.o
 libperf-$(CONFIG_DWARF) += dwarf-aux.o
 
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
-libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
+libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind.o
 libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind_common.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v4 4/6] perf callchain: Add support for cross-platform unwind
  2016-05-19 11:47 [PATCH v4 0/6] Add support for remote unwind He Kuang
                   ` (2 preceding siblings ...)
  2016-05-19 11:47 ` [PATCH v4 3/6] perf tools: Separate local and remote unwind support detection He Kuang
@ 2016-05-19 11:47 ` He Kuang
  2016-05-19 11:47 ` [PATCH v4 5/6] perf callchain: Support x86 target platform He Kuang
  2016-05-19 11:47 ` [PATCH v4 6/6] perf callchain: Support aarch64 cross-platform He Kuang
  5 siblings, 0 replies; 17+ messages in thread
From: He Kuang @ 2016-05-19 11:47 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, wangnan0,
	hekuang, jpoimboe, ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern
  Cc: linux-kernel

Use thread specific unwind ops to unwind cross-platform callchains.

Before this patch, unwind methods is suitable for local unwind, this
patch changes the fixed methods to thread/map related. Each time a map
is inserted, we find the target arch and see if this platform can be
remote unwind. In this patch, we test for x86 platform and only show
proper messages. The real unwind methods are not implemented, will be
introduced in next patch.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/thread.c                  |  5 +--
 tools/perf/util/thread.h                  | 14 +++++-
 tools/perf/util/unwind-libunwind.c        | 48 ++++++++++++++++++---
 tools/perf/util/unwind-libunwind_common.c | 71 +++++++++++++++++++++++++++++--
 tools/perf/util/unwind.h                  | 32 +++++++++-----
 5 files changed, 145 insertions(+), 25 deletions(-)

diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 3043113..4e1aaf5 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -43,9 +43,6 @@ struct thread *thread__new(pid_t pid, pid_t tid)
 		thread->cpu = -1;
 		INIT_LIST_HEAD(&thread->comm_list);
 
-		if (unwind__prepare_access(thread) < 0)
-			goto err_thread;
-
 		comm_str = malloc(32);
 		if (!comm_str)
 			goto err_thread;
@@ -59,6 +56,8 @@ struct thread *thread__new(pid_t pid, pid_t tid)
 		list_add(&comm->list, &thread->comm_list);
 		atomic_set(&thread->refcnt, 1);
 		RB_CLEAR_NODE(&thread->rb_node);
+
+		register_null_unwind_libunwind_ops(thread);
 	}
 
 	return thread;
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 45fba13..de8e42e 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -15,6 +15,17 @@
 
 struct thread_stack;
 
+struct unwind_entry;
+typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
+struct unwind_libunwind_ops {
+	int (*prepare_access)(struct thread *thread);
+	void (*flush_access)(struct thread *thread);
+	void (*finish_access)(struct thread *thread);
+	int (*get_entries)(unwind_entry_cb_t cb, void *arg,
+			   struct thread *thread,
+			   struct perf_sample *data, int max_stack);
+};
+
 struct thread {
 	union {
 		struct rb_node	 rb_node;
@@ -36,7 +47,8 @@ struct thread {
 	void			*priv;
 	struct thread_stack	*ts;
 #ifdef HAVE_LIBUNWIND_SUPPORT
-	unw_addr_space_t	addr_space;
+	unw_addr_space_t		addr_space;
+	struct unwind_libunwind_ops	*unwind_libunwind_ops;
 #endif
 };
 
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 63687d3..d3a2ec44 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -22,6 +22,9 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <linux/list.h>
+#ifdef REMOTE_UNWIND_LIBUNWIND
+#include "libunwind-arch.h"
+#endif
 #include <libunwind.h>
 #include <libunwind-ptrace.h>
 #include "callchain.h"
@@ -34,6 +37,21 @@
 #include "debug.h"
 #include "asm/bug.h"
 
+#ifndef REMOTE_UNWIND_LIBUNWIND
+  #define LIBUNWIND__ARCH_REG_ID libunwind__arch_reg_id
+  #define LOCAL_UNWIND_LIBUNWIND
+  #undef UNWT_OBJ
+  #define UNWT_OBJ(x) _##x
+#else
+  #undef NO_LIBUNWIND_DEBUG_FRAME
+  #if defined(LIBUNWIND_ARM) && !defined(NO_LIBUNWIND_DEBUG_FRAME_ARM)
+  #elif defined(LIBUNWIND_AARCH64) &&                    \
+	  defined(NO_LIBUNWIND_DEBUG_FRAME_ARM_AARCH64)
+  #else
+    #define NO_LIBUNWIND_DEBUG_FRAME
+  #endif
+#endif
+
 extern int
 UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as,
 				    unw_word_t ip,
@@ -508,7 +526,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;
 
@@ -579,7 +597,7 @@ static unw_accessors_t accessors = {
 	.get_proc_name		= get_proc_name,
 };
 
-int unwind__prepare_access(struct thread *thread)
+static int UNWT_OBJ(_unwind__prepare_access)(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return 0;
@@ -594,7 +612,7 @@ int unwind__prepare_access(struct thread *thread)
 	return 0;
 }
 
-void unwind__flush_access(struct thread *thread)
+static void UNWT_OBJ(_unwind__flush_access)(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return;
@@ -602,7 +620,7 @@ void unwind__flush_access(struct thread *thread)
 	unw_flush_cache(thread->addr_space, 0, 0);
 }
 
-void unwind__finish_access(struct thread *thread)
+static void UNWT_OBJ(_unwind__finish_access)(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return;
@@ -662,9 +680,10 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
 	return ret;
 }
 
-int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
-			struct thread *thread,
-			struct perf_sample *data, int max_stack)
+static int UNWT_OBJ(_unwind__get_entries)(unwind_entry_cb_t cb, void *arg,
+					 struct thread *thread,
+					 struct perf_sample *data,
+					 int max_stack)
 {
 	struct unwind_info ui = {
 		.sample       = data,
@@ -680,3 +699,18 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 
 	return get_entries(&ui, cb, arg, max_stack);
 }
+
+struct unwind_libunwind_ops
+UNWT_OBJ(unwind_libunwind_ops) = {
+	.prepare_access = UNWT_OBJ(_unwind__prepare_access),
+	.flush_access   = UNWT_OBJ(_unwind__flush_access),
+	.finish_access  = UNWT_OBJ(_unwind__finish_access),
+	.get_entries    = UNWT_OBJ(_unwind__get_entries),
+};
+
+#ifdef LOCAL_UNWIND_LIBUNWIND
+void register_local_unwind_libunwind_ops(struct thread *thread)
+{
+	thread->unwind_libunwind_ops = &UNWT_OBJ(unwind_libunwind_ops);
+}
+#endif
diff --git a/tools/perf/util/unwind-libunwind_common.c b/tools/perf/util/unwind-libunwind_common.c
index 3946c99..f44833b 100644
--- a/tools/perf/util/unwind-libunwind_common.c
+++ b/tools/perf/util/unwind-libunwind_common.c
@@ -5,10 +5,64 @@
 #include "debug.h"
 #include "arch/common.h"
 
+static int __null__prepare_access(struct thread *thread __maybe_unused)
+{
+	return 0;
+}
+
+static void __null__flush_access(struct thread *thread __maybe_unused)
+{
+}
+
+static void __null__finish_access(struct thread *thread __maybe_unused)
+{
+}
+
+static int __null__get_entries(unwind_entry_cb_t cb __maybe_unused,
+			       void *arg __maybe_unused,
+			       struct thread *thread __maybe_unused,
+			       struct perf_sample *data __maybe_unused,
+			       int max_stack __maybe_unused)
+{
+	return 0;
+}
+
+static struct unwind_libunwind_ops null_unwind_libunwind_ops = {
+	.prepare_access = __null__prepare_access,
+	.flush_access   = __null__flush_access,
+	.finish_access  = __null__finish_access,
+	.get_entries    = __null__get_entries,
+};
+
+void register_null_unwind_libunwind_ops(struct thread *thread)
+{
+	thread->unwind_libunwind_ops = &null_unwind_libunwind_ops;
+	if (thread->mg)
+		pr_err("unwind: target platform=%s unwind unsupported\n",
+		       thread->mg->machine->env->arch);
+}
+
+void register_unwind_libunwind_ops(struct unwind_libunwind_ops *ops,
+				   struct thread *thread)
+{
+	thread->unwind_libunwind_ops = ops;
+}
+
+void unwind__flush_access(struct thread *thread)
+{
+	thread->unwind_libunwind_ops->flush_access(thread);
+}
+
+void unwind__finish_access(struct thread *thread)
+{
+	thread->unwind_libunwind_ops->finish_access(thread);
+}
+
 void unwind__get_arch(struct thread *thread, struct map *map)
 {
 	const char *arch;
 	enum dso_type dso_type;
+	int use_local_unwind = 1;
 
 	if (!thread->mg->machine->env)
 		return;
@@ -17,18 +71,27 @@ void unwind__get_arch(struct thread *thread, struct map *map)
 	if (dso_type == DSO__TYPE_UNKNOWN)
 		return;
 
-	if (thread->addr_space)
+	if (thread->addr_space) {
 		pr_debug("unwind: thread map already set, 64bit is %d, dso=%s\n",
 			 dso_type == DSO__TYPE_64BIT, map->dso->name);
+		return;
+	}
 
 	arch = normalize_arch(thread->mg->machine->env->arch);
 
 	if (!strcmp(arch, "x86")) {
-		if (dso_type != DSO__TYPE_64BIT)
+		if (dso_type != DSO__TYPE_64BIT) {
 #ifdef HAVE_LIBUNWIND_X86_SUPPORT
 			pr_err("unwind: target platform=%s is not implemented\n", arch);
-#else
-			pr_err("unwind: target platform=%s is not supported\n", arch);
 #endif
+			register_null_unwind_libunwind_ops(thread);
+			use_local_unwind = 0;
+		}
 	}
+
+	if (use_local_unwind)
+		register_local_unwind_libunwind_ops(thread);
+
+	if (thread->unwind_libunwind_ops->prepare_access(thread) < 0)
+		return;
 }
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 889d630..1187950 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -21,20 +21,35 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 /* libunwind specific */
 #ifdef HAVE_LIBUNWIND_SUPPORT
 int libunwind__arch_reg_id(int regnum);
-int unwind__prepare_access(struct thread *thread);
 void unwind__flush_access(struct thread *thread);
 void unwind__finish_access(struct thread *thread);
 void unwind__get_arch(struct thread *thread, struct map *map);
-#else
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
-{
-	return 0;
+void register_unwind_libunwind_ops(struct unwind_libunwind_ops *ops,
+				   struct thread *thread);
+void register_null_unwind_libunwind_ops(struct thread *thread);
+
+#ifndef HAVE_LIBUNWIND_LOCAL_SUPPORT
+static inline void
+register_local_unwind_libunwind_ops(struct thread *thread) {
+	register_null_unwind_libunwind_ops(thread);
 }
+#else
+void register_local_unwind_libunwind_ops(struct thread *thread);
+#endif
 
+#define unwind__get_entries(cb, arg,					\
+			    thread,					\
+			    data, max_stack)				\
+	thread->unwind_libunwind_ops->get_entries(cb, arg, thread,	\
+						  data, max_stack)
+
+#else
 static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
 static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
 static inline void unwind__get_arch(struct thread *thread __maybe_unused,
 				    struct map *map __maybe_unused) {}
+static inline void
+register_null_unwind_libunwind_ops(struct thread *thread __maybe_unused) {}
 #endif
 #else
 static inline int
@@ -47,14 +62,11 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
 	return 0;
 }
 
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
-{
-	return 0;
-}
-
 static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
 static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
 static inline void unwind__get_arch(struct thread *thread __maybe_unused,
 				    struct map *map __maybe_unused) {}
+static inline void
+register_null_unwind_libunwind_ops(struct thread *thread __maybe_unused) {}
 #endif /* HAVE_DWARF_UNWIND_SUPPORT */
 #endif /* __UNWIND_H */
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v4 5/6] perf callchain: Support x86 target platform
  2016-05-19 11:47 [PATCH v4 0/6] Add support for remote unwind He Kuang
                   ` (3 preceding siblings ...)
  2016-05-19 11:47 ` [PATCH v4 4/6] perf callchain: Add support for cross-platform unwind He Kuang
@ 2016-05-19 11:47 ` He Kuang
  2016-05-19 11:47 ` [PATCH v4 6/6] perf callchain: Support aarch64 cross-platform He Kuang
  5 siblings, 0 replies; 17+ messages in thread
From: He Kuang @ 2016-05-19 11:47 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, wangnan0,
	hekuang, jpoimboe, ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern
  Cc: linux-kernel

Support x86(32-bit) cross platform callchain unwind.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/arch/x86/include/libunwind/libunwind-arch.h | 18 ++++++++++++++++++
 tools/perf/arch/x86/util/unwind-libunwind.c            | 12 +++++++++---
 tools/perf/util/Build                                  |  6 ++++++
 tools/perf/util/unwind-libunwind_common.c              |  6 ++++--
 tools/perf/util/unwind.h                               |  5 +++++
 5 files changed, 42 insertions(+), 5 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..a4f5449 100644
--- a/tools/perf/arch/x86/util/unwind-libunwind.c
+++ b/tools/perf/arch/x86/util/unwind-libunwind.c
@@ -5,7 +5,7 @@
 #include "../../util/unwind.h"
 #include "../../util/debug.h"
 
-#ifdef HAVE_ARCH_X86_64_SUPPORT
+#if !defined(LIBUNWIND_X86_32) && defined(HAVE_ARCH_X86_64_SUPPORT)
 int libunwind__arch_reg_id(int regnum)
 {
 	int id;
@@ -69,8 +69,14 @@ int libunwind__arch_reg_id(int regnum)
 
 	return id;
 }
-#else
+#endif
+
+#if defined(LIBUNWIND_X86_32) || !defined(HAVE_ARCH_X86_64_SUPPORT)
+#ifndef LIBUNWIND_X86_32
 int libunwind__arch_reg_id(int regnum)
+#else
+int libunwind__x86_reg_id(int regnum)
+#endif
 {
 	int id;
 
@@ -109,4 +115,4 @@ int libunwind__arch_reg_id(int regnum)
 
 	return id;
 }
-#endif /* HAVE_ARCH_X86_64_SUPPORT */
+#endif
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index ce69721..2373130 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
@@ -101,6 +103,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) -DREMOTE_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/unwind-libunwind_common.c b/tools/perf/util/unwind-libunwind_common.c
index f44833b..619c6c0 100644
--- a/tools/perf/util/unwind-libunwind_common.c
+++ b/tools/perf/util/unwind-libunwind_common.c
@@ -82,9 +82,11 @@ void unwind__get_arch(struct thread *thread, struct map *map)
 	if (!strcmp(arch, "x86")) {
 		if (dso_type != DSO__TYPE_64BIT) {
 #ifdef HAVE_LIBUNWIND_X86_SUPPORT
-			pr_err("unwind: target platform=%s is not implemented\n", arch);
-#endif
+			register_unwind_libunwind_ops(
+				&_Ux86_unwind_libunwind_ops, thread);
+#else
 			register_null_unwind_libunwind_ops(thread);
+#endif
 			use_local_unwind = 0;
 		}
 	}
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 1187950..73f4bd9 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -51,6 +51,11 @@ static inline void unwind__get_arch(struct thread *thread __maybe_unused,
 static inline void
 register_null_unwind_libunwind_ops(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

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v4 6/6] perf callchain: Support aarch64 cross-platform
  2016-05-19 11:47 [PATCH v4 0/6] Add support for remote unwind He Kuang
                   ` (4 preceding siblings ...)
  2016-05-19 11:47 ` [PATCH v4 5/6] perf callchain: Support x86 target platform He Kuang
@ 2016-05-19 11:47 ` He Kuang
  5 siblings, 0 replies; 17+ messages in thread
From: He Kuang @ 2016-05-19 11:47 UTC (permalink / raw)
  To: peterz, mingo, acme, alexander.shishkin, jolsa, wangnan0,
	hekuang, jpoimboe, ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern
  Cc: linux-kernel

Support aarch64 cross platform callchain unwind.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 .../perf/arch/arm64/include/libunwind/libunwind-arch.h | 18 ++++++++++++++++++
 tools/perf/arch/arm64/util/unwind-libunwind.c          |  5 ++++-
 tools/perf/config/Makefile                             | 12 ++++++++++++
 tools/perf/util/Build                                  |  4 ++++
 tools/perf/util/unwind-libunwind_common.c              | 10 ++++++++++
 tools/perf/util/unwind.h                               |  3 +++
 6 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/arch/arm64/include/libunwind/libunwind-arch.h

diff --git a/tools/perf/arch/arm64/include/libunwind/libunwind-arch.h b/tools/perf/arch/arm64/include/libunwind/libunwind-arch.h
new file mode 100644
index 0000000..7bc8a00
--- /dev/null
+++ b/tools/perf/arch/arm64/include/libunwind/libunwind-arch.h
@@ -0,0 +1,18 @@
+#ifndef _LIBUNWIND_ARCH_H
+#define _LIBUNWIND_ARCH_H
+
+#include <libunwind-aarch64.h>
+#include <../perf_regs.h>
+#include <../../../../../../arch/arm64/include/uapi/asm/perf_regs.h>
+
+#define LIBUNWIND_AARCH64
+int libunwind__aarch64_reg_id(int regnum);
+
+#include <../../../arm64/util/unwind-libunwind.c>
+
+#define LIBUNWIND__ARCH_REG_ID libunwind__aarch64_reg_id
+
+#define UNWT_PREFIX	UNW_PASTE(UNW_PASTE(_U, aarch64), _)
+#define UNWT_OBJ(fn)	UNW_PASTE(UNWT_PREFIX, fn)
+
+#endif /* _LIBUNWIND_ARCH_H */
diff --git a/tools/perf/arch/arm64/util/unwind-libunwind.c b/tools/perf/arch/arm64/util/unwind-libunwind.c
index a87afa9..5b557a5 100644
--- a/tools/perf/arch/arm64/util/unwind-libunwind.c
+++ b/tools/perf/arch/arm64/util/unwind-libunwind.c
@@ -1,11 +1,14 @@
 
 #include <errno.h>
-#include <libunwind.h>
 #include "perf_regs.h"
 #include "../../util/unwind.h"
 #include "../../util/debug.h"
 
+#ifndef LIBUNWIND_AARCH64
 int libunwind__arch_reg_id(int regnum)
+#else
+int libunwind__aarch64_reg_id(int regnum)
+#endif
 {
 	switch (regnum) {
 	case UNW_AARCH64_X0:
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 3035dbf..d3b77d8 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -353,6 +353,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 -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/Build b/tools/perf/util/Build
index 2373130..f1b51a2 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -104,10 +104,14 @@ 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
+libperf-$(CONFIG_LIBUNWIND_AARCH64)  += unwind-libunwind_arm64.o
 
 $(OUTPUT)util/unwind-libunwind_x86_32.o: util/unwind-libunwind.c arch/x86/util/unwind-libunwind.c
 	$(QUIET_CC)$(CC) $(CFLAGS) -DREMOTE_UNWIND_LIBUNWIND -Iarch/x86/include/libunwind -c -o $@ util/unwind-libunwind.c
 
+$(OUTPUT)util/unwind-libunwind_arm64.o: util/unwind-libunwind.c arch/arm64/util/unwind-libunwind.c
+	$(QUIET_CC)$(CC) $(CFLAGS) -DREMOTE_UNWIND_LIBUNWIND -Iarch/arm64/include/libunwind -c -o $@ util/unwind-libunwind.c
+
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
 libperf-y += scripting-engines/
diff --git a/tools/perf/util/unwind-libunwind_common.c b/tools/perf/util/unwind-libunwind_common.c
index 619c6c0..d19b062 100644
--- a/tools/perf/util/unwind-libunwind_common.c
+++ b/tools/perf/util/unwind-libunwind_common.c
@@ -89,6 +89,16 @@ void unwind__get_arch(struct thread *thread, struct map *map)
 #endif
 			use_local_unwind = 0;
 		}
+	} else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
+		if (dso_type == DSO__TYPE_64BIT) {
+#ifdef HAVE_LIBUNWIND_AARCH64_SUPPORT
+			register_unwind_libunwind_ops(
+				&_Uaarch64_unwind_libunwind_ops, thread);
+#else
+			register_null_unwind_libunwind_ops(thread);
+#endif
+			use_local_unwind = 0;
+		}
 	}
 
 	if (use_local_unwind)
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 73f4bd9..9748c36 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -55,6 +55,9 @@ register_null_unwind_libunwind_ops(struct thread *thread __maybe_unused) {}
 #ifdef HAVE_LIBUNWIND_X86_SUPPORT
 extern struct unwind_libunwind_ops _Ux86_unwind_libunwind_ops;
 #endif
+#ifdef HAVE_LIBUNWIND_AARCH64_SUPPORT
+extern struct unwind_libunwind_ops _Uaarch64_unwind_libunwind_ops;
+#endif
 
 #else
 static inline int
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided
  2016-05-19 11:47 ` [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided He Kuang
@ 2016-05-19 14:23   ` David Ahern
  2016-05-19 16:07   ` Jiri Olsa
  2016-05-20 17:46   ` [tip:perf/urgent] " tip-bot for He Kuang
  2 siblings, 0 replies; 17+ messages in thread
From: David Ahern @ 2016-05-19 14:23 UTC (permalink / raw)
  To: He Kuang, peterz, mingo, acme, alexander.shishkin, jolsa,
	wangnan0, jpoimboe, ak, eranian, namhyung, adrian.hunter,
	sukadev, masami.hiramatsu.pt, tumanova, kan.liang, penberg
  Cc: linux-kernel

On 5/19/16 5:47 AM, He Kuang wrote:
> This patch moves the reference of buildid dir to 'symfs/.debug' and
> skips the local buildid dir when '--symfs' is given, so that every
> single file opened by perf is relateive to symfs directory now.
>
> Signed-off-by: He Kuang <hekuang@huawei.com>
> ---
>  tools/perf/builtin-annotate.c  |  5 +++--
>  tools/perf/builtin-diff.c      |  5 +++--
>  tools/perf/builtin-report.c    |  5 +++--
>  tools/perf/builtin-script.c    |  5 +++--
>  tools/perf/builtin-timechart.c |  5 +++--
>  tools/perf/util/dso.c          |  4 +---
>  tools/perf/util/symbol.c       | 23 +++++++++++++++++++++++
>  tools/perf/util/symbol.h       |  2 ++
>  8 files changed, 41 insertions(+), 13 deletions(-)

Acked-by: David Ahern <dsahern@gmail.com>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind
  2016-05-19 11:47 ` [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind He Kuang
@ 2016-05-19 14:50   ` Arnaldo Carvalho de Melo
  2016-05-19 16:19     ` Jiri Olsa
  2016-05-19 16:46   ` Jiri Olsa
  1 sibling, 1 reply; 17+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-05-19 14:50 UTC (permalink / raw)
  To: He Kuang
  Cc: peterz, mingo, alexander.shishkin, jolsa, wangnan0, jpoimboe, ak,
	eranian, namhyung, adrian.hunter, sukadev, masami.hiramatsu.pt,
	tumanova, kan.liang, penberg, dsahern, linux-kernel

Em Thu, May 19, 2016 at 11:47:38AM +0000, He Kuang escreveu:
> Currently, perf script uses host unwind methods to parse perf.data
> callchain info regardless of the target architecture. So we get wrong
> result and no promotion when unwinding callchains of x86(32-bit) on

What you mean by "promotion" here? Can you use some other synonym so
that I can make sense of this description?

> x86(64-bit) machine.
> 
> This patch shows proper error messages when we do remote unwind
> x86(32-bit) on other machines. Same thing for other platforms will be
> added in next patches.
> 
> Common functions which will be used by both local unwind and remote
> unwind are separated into new file 'unwind-libunwind_common.c'.
> 
> Signed-off-by: He Kuang <hekuang@huawei.com>
> ---
>  tools/perf/arch/common.c                  |  2 +-
>  tools/perf/arch/common.h                  |  1 +
>  tools/perf/config/Makefile                |  6 ++++++
>  tools/perf/util/Build                     |  1 +
>  tools/perf/util/thread.c                  |  2 ++
>  tools/perf/util/unwind-libunwind_common.c | 34 +++++++++++++++++++++++++++++++
>  tools/perf/util/unwind.h                  |  5 +++++
>  7 files changed, 50 insertions(+), 1 deletion(-)
>  create mode 100644 tools/perf/util/unwind-libunwind_common.c
> 
> diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
> index e83c8ce..fa090a9 100644
> --- a/tools/perf/arch/common.c
> +++ b/tools/perf/arch/common.c
> @@ -102,7 +102,7 @@ static int lookup_triplets(const char *const *triplets, const char *name)
>   * Return architecture name in a normalized form.
>   * The conversion logic comes from the Makefile.
>   */
> -static const char *normalize_arch(char *arch)
> +const char *normalize_arch(char *arch)
>  {
>  	if (!strcmp(arch, "x86_64"))
>  		return "x86";
> diff --git a/tools/perf/arch/common.h b/tools/perf/arch/common.h
> index 7529cfb..6b01c73 100644
> --- a/tools/perf/arch/common.h
> +++ b/tools/perf/arch/common.h
> @@ -6,5 +6,6 @@
>  extern const char *objdump_path;
>  
>  int perf_env__lookup_objdump(struct perf_env *env);
> +const char *normalize_arch(char *arch);
>  
>  #endif /* ARCH_PERF_COMMON_H */
> diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
> index 1e46277..a86b864 100644
> --- a/tools/perf/config/Makefile
> +++ b/tools/perf/config/Makefile
> @@ -345,6 +345,12 @@ ifeq ($(ARCH),powerpc)
>  endif
>  
>  ifndef NO_LIBUNWIND
> +  ifeq ($(feature-libunwind-x86), 1)
> +    LIBUNWIND_LIBS += -lunwind-x86
> +    $(call detected,CONFIG_LIBUNWIND_X86)
> +    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
> +  endif
> +
>    ifneq ($(feature-libunwind), 1)
>      msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
>      NO_LIBUNWIND := 1
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index 8c6c8a0..25c31fb 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -100,6 +100,7 @@ libperf-$(CONFIG_DWARF) += dwarf-aux.o
>  
>  libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
>  libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
> +libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind_common.o
>  
>  libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
>  
> diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> index 45fcb71..3043113 100644
> --- a/tools/perf/util/thread.c
> +++ b/tools/perf/util/thread.c
> @@ -205,6 +205,8 @@ void thread__insert_map(struct thread *thread, struct map *map)
>  {
>  	map_groups__fixup_overlappings(thread->mg, map, stderr);
>  	map_groups__insert(thread->mg, map);
> +
> +	unwind__get_arch(thread, map);
>  }
>  
>  static int thread__clone_map_groups(struct thread *thread,
> diff --git a/tools/perf/util/unwind-libunwind_common.c b/tools/perf/util/unwind-libunwind_common.c
> new file mode 100644
> index 0000000..3946c99
> --- /dev/null
> +++ b/tools/perf/util/unwind-libunwind_common.c
> @@ -0,0 +1,34 @@
> +#include "thread.h"
> +#include "session.h"
> +#include "unwind.h"
> +#include "symbol.h"
> +#include "debug.h"
> +#include "arch/common.h"
> +
> +void unwind__get_arch(struct thread *thread, struct map *map)
> +{
> +	const char *arch;
> +	enum dso_type dso_type;
> +
> +	if (!thread->mg->machine->env)
> +		return;
> +
> +	dso_type = dso__type(map->dso, thread->mg->machine);
> +	if (dso_type == DSO__TYPE_UNKNOWN)
> +		return;
> +
> +	if (thread->addr_space)
> +		pr_debug("unwind: thread map already set, 64bit is %d, dso=%s\n",
> +			 dso_type == DSO__TYPE_64BIT, map->dso->name);
> +
> +	arch = normalize_arch(thread->mg->machine->env->arch);
> +
> +	if (!strcmp(arch, "x86")) {
> +		if (dso_type != DSO__TYPE_64BIT)
> +#ifdef HAVE_LIBUNWIND_X86_SUPPORT
> +			pr_err("unwind: target platform=%s is not implemented\n", arch);
> +#else
> +			pr_err("unwind: target platform=%s is not supported\n", arch);
> +#endif
> +	}
> +}
> diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
> index 12790cf..889d630 100644
> --- a/tools/perf/util/unwind.h
> +++ b/tools/perf/util/unwind.h
> @@ -24,6 +24,7 @@ int libunwind__arch_reg_id(int regnum);
>  int unwind__prepare_access(struct thread *thread);
>  void unwind__flush_access(struct thread *thread);
>  void unwind__finish_access(struct thread *thread);
> +void unwind__get_arch(struct thread *thread, struct map *map);
>  #else
>  static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
>  {
> @@ -32,6 +33,8 @@ 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) {}
> +static inline void unwind__get_arch(struct thread *thread __maybe_unused,
> +				    struct map *map __maybe_unused) {}
>  #endif
>  #else
>  static inline int
> @@ -51,5 +54,7 @@ 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) {}
> +static inline void unwind__get_arch(struct thread *thread __maybe_unused,
> +				    struct map *map __maybe_unused) {}
>  #endif /* HAVE_DWARF_UNWIND_SUPPORT */
>  #endif /* __UNWIND_H */
> -- 
> 1.8.5.2

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided
  2016-05-19 11:47 ` [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided He Kuang
  2016-05-19 14:23   ` David Ahern
@ 2016-05-19 16:07   ` Jiri Olsa
  2016-05-20 17:46   ` [tip:perf/urgent] " tip-bot for He Kuang
  2 siblings, 0 replies; 17+ messages in thread
From: Jiri Olsa @ 2016-05-19 16:07 UTC (permalink / raw)
  To: He Kuang
  Cc: peterz, mingo, acme, alexander.shishkin, wangnan0, jpoimboe, ak,
	eranian, namhyung, adrian.hunter, sukadev, masami.hiramatsu.pt,
	tumanova, kan.liang, penberg, dsahern, linux-kernel

On Thu, May 19, 2016 at 11:47:37AM +0000, He Kuang wrote:
> This patch moves the reference of buildid dir to 'symfs/.debug' and
> skips the local buildid dir when '--symfs' is given, so that every
> single file opened by perf is relateive to symfs directory now.
> 
> Signed-off-by: He Kuang <hekuang@huawei.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind
  2016-05-19 14:50   ` Arnaldo Carvalho de Melo
@ 2016-05-19 16:19     ` Jiri Olsa
  2016-05-20  3:00       ` Hekuang
  0 siblings, 1 reply; 17+ messages in thread
From: Jiri Olsa @ 2016-05-19 16:19 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: He Kuang, peterz, mingo, alexander.shishkin, wangnan0, jpoimboe,
	ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern,
	linux-kernel

On Thu, May 19, 2016 at 11:50:10AM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, May 19, 2016 at 11:47:38AM +0000, He Kuang escreveu:
> > Currently, perf script uses host unwind methods to parse perf.data
> > callchain info regardless of the target architecture. So we get wrong
> > result and no promotion when unwinding callchains of x86(32-bit) on
> 
> What you mean by "promotion" here? Can you use some other synonym so
> that I can make sense of this description?

I'd say something like: s/and no promotion/without any warning/

jirka

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind
  2016-05-19 11:47 ` [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind He Kuang
  2016-05-19 14:50   ` Arnaldo Carvalho de Melo
@ 2016-05-19 16:46   ` Jiri Olsa
  2016-05-19 17:15     ` Jiri Olsa
  2016-05-20  2:59     ` Hekuang
  1 sibling, 2 replies; 17+ messages in thread
From: Jiri Olsa @ 2016-05-19 16:46 UTC (permalink / raw)
  To: He Kuang
  Cc: peterz, mingo, acme, alexander.shishkin, wangnan0, jpoimboe, ak,
	eranian, namhyung, adrian.hunter, sukadev, masami.hiramatsu.pt,
	tumanova, kan.liang, penberg, dsahern, linux-kernel

On Thu, May 19, 2016 at 11:47:38AM +0000, He Kuang wrote:

SNIP

>  #endif /* ARCH_PERF_COMMON_H */
> diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
> index 1e46277..a86b864 100644
> --- a/tools/perf/config/Makefile
> +++ b/tools/perf/config/Makefile
> @@ -345,6 +345,12 @@ ifeq ($(ARCH),powerpc)
>  endif
>  
>  ifndef NO_LIBUNWIND
> +  ifeq ($(feature-libunwind-x86), 1)
> +    LIBUNWIND_LIBS += -lunwind-x86
> +    $(call detected,CONFIG_LIBUNWIND_X86)
> +    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
> +  endif
> +

how does one install that lirary?

thanks,
jirka

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind
  2016-05-19 16:46   ` Jiri Olsa
@ 2016-05-19 17:15     ` Jiri Olsa
  2016-05-20  2:59     ` Hekuang
  1 sibling, 0 replies; 17+ messages in thread
From: Jiri Olsa @ 2016-05-19 17:15 UTC (permalink / raw)
  To: He Kuang
  Cc: peterz, mingo, acme, alexander.shishkin, wangnan0, jpoimboe, ak,
	eranian, namhyung, adrian.hunter, sukadev, masami.hiramatsu.pt,
	tumanova, kan.liang, penberg, dsahern, linux-kernel

On Thu, May 19, 2016 at 06:46:09PM +0200, Jiri Olsa wrote:
> On Thu, May 19, 2016 at 11:47:38AM +0000, He Kuang wrote:
> 
> SNIP
> 
> >  #endif /* ARCH_PERF_COMMON_H */
> > diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
> > index 1e46277..a86b864 100644
> > --- a/tools/perf/config/Makefile
> > +++ b/tools/perf/config/Makefile
> > @@ -345,6 +345,12 @@ ifeq ($(ARCH),powerpc)
> >  endif
> >  
> >  ifndef NO_LIBUNWIND
> > +  ifeq ($(feature-libunwind-x86), 1)
> > +    LIBUNWIND_LIBS += -lunwind-x86
> > +    $(call detected,CONFIG_LIBUNWIND_X86)
> > +    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
> > +  endif
> > +
> 
> how does one install that lirary?

had to uninstall x86_64..

[jolsa@krava perf]$ rpm -qa | grep libunw
libunwind-devel-1.1-10.fc22.i686
libunwind-1.1-10.fc22.i686
libunwind-1.1-10.fc22.x86_64


however it's still off:

[jolsa@krava perf]$ make VF=1
  BUILD:   Doing 'make -j4' parallel build

Auto-detecting system features:

SNIP

...                     libunwind: [ OFF ]

SNIP

...                 libunwind-x86: [ OFF ]
...              libunwind-x86_64: [ OFF ]
...                 libunwind-arm: [ OFF ]
...             libunwind-aarch64: [ OFF ]
...   pthread-attr-setaffinity-np: [ on  ]
...            stackprotector-all: [ on  ]
...                       timerfd: [ on  ]


thanks,
jirka

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind
  2016-05-19 16:46   ` Jiri Olsa
  2016-05-19 17:15     ` Jiri Olsa
@ 2016-05-20  2:59     ` Hekuang
  2016-05-20  9:53       ` Jiri Olsa
  1 sibling, 1 reply; 17+ messages in thread
From: Hekuang @ 2016-05-20  2:59 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: peterz, mingo, acme, alexander.shishkin, wangnan0, jpoimboe, ak,
	eranian, namhyung, adrian.hunter, sukadev, masami.hiramatsu.pt,
	tumanova, kan.liang, penberg, dsahern, linux-kernel

hi

在 2016/5/20 0:46, Jiri Olsa 写道:
> On Thu, May 19, 2016 at 11:47:38AM +0000, He Kuang wrote:
>
> SNIP
>
>>   #endif /* ARCH_PERF_COMMON_H */
>> diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
>> index 1e46277..a86b864 100644
>> --- a/tools/perf/config/Makefile
>> +++ b/tools/perf/config/Makefile
>> @@ -345,6 +345,12 @@ ifeq ($(ARCH),powerpc)
>>   endif
>>   
>>   ifndef NO_LIBUNWIND
>> +  ifeq ($(feature-libunwind-x86), 1)
>> +    LIBUNWIND_LIBS += -lunwind-x86
>> +    $(call detected,CONFIG_LIBUNWIND_X86)
>> +    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
>> +  endif
>> +
> how does one install that lirary?
>
> thanks,
> jirka

My work environment is on an old suse distribution, so it's
difficult to find libunwind-$arch rpm packages, so I build them
from source.

The git repository url is here:
http://git.savannah.gnu.org/r/libunwind.git(master)

Then flow the build step in README, first for i686:

   $ ./autogen.sh
   $ ./configure prefix=/xx/dst_i686 --target=i686-oe-linux 
CC=x86_64-oe-linux-gcc
   $ make && make install

Similar for aarch64:

   $ make clean
   $ ./configure prefix=/xx/dst_aarch64 --target=i686-oe-linux 
CC=x86_64-oe-linux-gcc
   $ make && make install

NOTICE: the contents in '--target' should be like
'i686-oe-linux', only give 'i686' cause strange build errors.

It looks like that libunwind don't support building for multiple
platforms at the same time, so I build them separately into
different directories.

Finally, copy the outputs into /usr/include and /usr/lib64, now
perf can detect them:

   $ make VF=1 ARCH=x86_64 CROSS_COMPILE=x86_64-oe-linux- 
EXTRA_CFLAGS="-m64"
   ...

   ...                 libunwind-x86: [ on  ]
   ...              libunwind-x86_64: [ OFF ]
   ...                 libunwind-arm: [ OFF ]
   ...             libunwind-aarch64: [ on  ]

Thanks.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind
  2016-05-19 16:19     ` Jiri Olsa
@ 2016-05-20  3:00       ` Hekuang
  0 siblings, 0 replies; 17+ messages in thread
From: Hekuang @ 2016-05-20  3:00 UTC (permalink / raw)
  To: Jiri Olsa, Arnaldo Carvalho de Melo
  Cc: peterz, mingo, alexander.shishkin, wangnan0, jpoimboe, ak,
	eranian, namhyung, adrian.hunter, sukadev, masami.hiramatsu.pt,
	tumanova, kan.liang, penberg, dsahern, linux-kernel



在 2016/5/20 0:19, Jiri Olsa 写道:
> On Thu, May 19, 2016 at 11:50:10AM -0300, Arnaldo Carvalho de Melo wrote:
>> Em Thu, May 19, 2016 at 11:47:38AM +0000, He Kuang escreveu:
>>> Currently, perf script uses host unwind methods to parse perf.data
>>> callchain info regardless of the target architecture. So we get wrong
>>> result and no promotion when unwinding callchains of x86(32-bit) on
>> What you mean by "promotion" here? Can you use some other synonym so
>> that I can make sense of this description?
> I'd say something like: s/and no promotion/without any warning/
>
> jirka

Yes, that's what I want to express.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind
  2016-05-20  2:59     ` Hekuang
@ 2016-05-20  9:53       ` Jiri Olsa
  0 siblings, 0 replies; 17+ messages in thread
From: Jiri Olsa @ 2016-05-20  9:53 UTC (permalink / raw)
  To: Hekuang
  Cc: peterz, mingo, acme, alexander.shishkin, wangnan0, jpoimboe, ak,
	eranian, namhyung, adrian.hunter, sukadev, masami.hiramatsu.pt,
	tumanova, kan.liang, penberg, dsahern, linux-kernel

On Fri, May 20, 2016 at 10:59:05AM +0800, Hekuang wrote:
> hi
> 
> 在 2016/5/20 0:46, Jiri Olsa 写道:
> > On Thu, May 19, 2016 at 11:47:38AM +0000, He Kuang wrote:
> > 
> > SNIP
> > 
> > >   #endif /* ARCH_PERF_COMMON_H */
> > > diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
> > > index 1e46277..a86b864 100644
> > > --- a/tools/perf/config/Makefile
> > > +++ b/tools/perf/config/Makefile
> > > @@ -345,6 +345,12 @@ ifeq ($(ARCH),powerpc)
> > >   endif
> > >   ifndef NO_LIBUNWIND
> > > +  ifeq ($(feature-libunwind-x86), 1)
> > > +    LIBUNWIND_LIBS += -lunwind-x86
> > > +    $(call detected,CONFIG_LIBUNWIND_X86)
> > > +    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
> > > +  endif
> > > +
> > how does one install that lirary?
> > 
> > thanks,
> > jirka
> 
> My work environment is on an old suse distribution, so it's
> difficult to find libunwind-$arch rpm packages, so I build them
> from source.
> 
> The git repository url is here:
> http://git.savannah.gnu.org/r/libunwind.git(master)
> 
> Then flow the build step in README, first for i686:
> 
>   $ ./autogen.sh
>   $ ./configure prefix=/xx/dst_i686 --target=i686-oe-linux
> CC=x86_64-oe-linux-gcc
>   $ make && make install
> 
> Similar for aarch64:
> 
>   $ make clean
>   $ ./configure prefix=/xx/dst_aarch64 --target=i686-oe-linux
> CC=x86_64-oe-linux-gcc
>   $ make && make install
> 
> NOTICE: the contents in '--target' should be like
> 'i686-oe-linux', only give 'i686' cause strange build errors.
> 
> It looks like that libunwind don't support building for multiple
> platforms at the same time, so I build them separately into
> different directories.
> 
> Finally, copy the outputs into /usr/include and /usr/lib64, now
> perf can detect them:

we will need to extend LIBUNWIND_DIR or add variable,
to be able to detect this from arbitrary directory

jirka

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [tip:perf/urgent] perf tools: Set buildid dir under symfs when --symfs is provided
  2016-05-19 11:47 ` [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided He Kuang
  2016-05-19 14:23   ` David Ahern
  2016-05-19 16:07   ` Jiri Olsa
@ 2016-05-20 17:46   ` tip-bot for He Kuang
  2 siblings, 0 replies; 17+ messages in thread
From: tip-bot for He Kuang @ 2016-05-20 17:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dsahern, sukadev, acme, tumanova, linux-kernel, tglx, hpa,
	namhyung, penberg, hekuang, wangnan0, kan.liang, jolsa,
	masami.hiramatsu.pt, jpoimboe, eranian, alexander.shishkin,
	adrian.hunter, ak, peterz, mingo

Commit-ID:  a706670900073d236938d539d1109338d64b47bb
Gitweb:     http://git.kernel.org/tip/a706670900073d236938d539d1109338d64b47bb
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Thu, 19 May 2016 11:47:37 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 20 May 2016 11:43:58 -0300

perf tools: Set buildid dir under symfs when --symfs is provided

This patch moves the reference of buildid dir to 'symfs/.debug' and
skips the local buildid dir when '--symfs' is given, so that every
single file opened by perf is relative to symfs directory now.

Signed-off-by: He Kuang <hekuang@huawei.com>
Acked-by: David Ahern <dsahern@gmail.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1463658462-85131-2-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-annotate.c  |  5 +++--
 tools/perf/builtin-diff.c      |  5 +++--
 tools/perf/builtin-report.c    |  5 +++--
 tools/perf/builtin-script.c    |  5 +++--
 tools/perf/builtin-timechart.c |  5 +++--
 tools/perf/util/dso.c          |  4 +---
 tools/perf/util/symbol.c       | 23 +++++++++++++++++++++++
 tools/perf/util/symbol.h       |  2 ++
 8 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 8141583..25c8173 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -324,8 +324,9 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
 		    "Skip symbols that cannot be annotated"),
 	OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		   "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
 		    "Interleave source code with assembly code (default)"),
 	OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 9ce354f..f7645a4 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -812,8 +812,9 @@ static const struct option options[] = {
 	OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
 		   "separator for columns, no spaces will be added between "
 		   "columns '.' is reserved."),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		    "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_UINTEGER('o', "order", &sort_compute, "Specify compute sorting."),
 	OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
 		     "How to display percentage of filtered entries", parse_filter_percentage),
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 9bc71c6..a87cb33 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -770,8 +770,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "columns '.' is reserved."),
 	OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
 		    "Only display entries resolved to a symbol"),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		    "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_STRING('C', "cpu", &report.cpu_list, "cpu",
 		   "list of cpus to profile"),
 	OPT_BOOLEAN('I', "show-info", &report.show_full_info,
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 0a83f4b..e3ce2f3 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2010,8 +2010,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "file", "kallsyms pathname"),
 	OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
 		    "When printing symbols do not display call chain"),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		    "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_CALLBACK('F', "fields", NULL, "str",
 		     "comma separated output fields prepend with 'type:'. "
 		     "Valid types: hw,sw,trace,raw. "
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 40cc9bb..733a554 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1945,8 +1945,9 @@ int cmd_timechart(int argc, const char **argv,
 	OPT_CALLBACK('p', "process", NULL, "process",
 		      "process selector. Pass a pid or process name.",
 		       parse_process),
-	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-		    "Look for files with symbols relative to this directory"),
+	OPT_CALLBACK(0, "symfs", NULL, "directory",
+		     "Look for files with symbols relative to this directory",
+		     symbol__config_symfs),
 	OPT_INTEGER('n', "proc-num", &tchart.proc_num,
 		    "min. number of tasks to print"),
 	OPT_BOOLEAN('t', "topology", &tchart.topology,
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 75b7561..5d286f5 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -63,9 +63,7 @@ int dso__read_binary_type_filename(const struct dso *dso,
 		}
 		break;
 	case DSO_BINARY_TYPE__BUILD_ID_CACHE:
-		/* skip the locally configured cache if a symfs is given */
-		if (symbol_conf.symfs[0] ||
-		    (dso__build_id_filename(dso, filename, size) == NULL))
+		if (dso__build_id_filename(dso, filename, size) == NULL)
 			ret = -1;
 		break;
 
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 2252b54..20f9cb3 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2033,3 +2033,26 @@ void symbol__exit(void)
 	symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
 	symbol_conf.initialized = false;
 }
+
+int symbol__config_symfs(const struct option *opt __maybe_unused,
+			 const char *dir, int unset __maybe_unused)
+{
+	char *bf = NULL;
+	int ret;
+
+	symbol_conf.symfs = strdup(dir);
+	if (symbol_conf.symfs == NULL)
+		return -ENOMEM;
+
+	/* skip the locally configured cache if a symfs is given, and
+	 * config buildid dir to symfs/.debug
+	 */
+	ret = asprintf(&bf, "%s/%s", dir, ".debug");
+	if (ret < 0)
+		return -ENOMEM;
+
+	set_buildid_dir(bf);
+
+	free(bf);
+	return 0;
+}
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 25f2fd67..fa41534 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -290,6 +290,8 @@ bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 bool symbol__restricted_filename(const char *filename,
 				 const char *restricted_filename);
 bool symbol__is_idle(struct symbol *sym);
+int symbol__config_symfs(const struct option *opt __maybe_unused,
+			 const char *dir, int unset __maybe_unused);
 
 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 		  struct symsrc *runtime_ss, symbol_filter_t filter,

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-05-20 17:47 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-19 11:47 [PATCH v4 0/6] Add support for remote unwind He Kuang
2016-05-19 11:47 ` [PATCH v4 1/6] perf tools: Set buildid dir under symfs when --symfs is provided He Kuang
2016-05-19 14:23   ` David Ahern
2016-05-19 16:07   ` Jiri Olsa
2016-05-20 17:46   ` [tip:perf/urgent] " tip-bot for He Kuang
2016-05-19 11:47 ` [PATCH v4 2/6] perf tools: Promote proper messages for cross-platform unwind He Kuang
2016-05-19 14:50   ` Arnaldo Carvalho de Melo
2016-05-19 16:19     ` Jiri Olsa
2016-05-20  3:00       ` Hekuang
2016-05-19 16:46   ` Jiri Olsa
2016-05-19 17:15     ` Jiri Olsa
2016-05-20  2:59     ` Hekuang
2016-05-20  9:53       ` Jiri Olsa
2016-05-19 11:47 ` [PATCH v4 3/6] perf tools: Separate local and remote unwind support detection He Kuang
2016-05-19 11:47 ` [PATCH v4 4/6] perf callchain: Add support for cross-platform unwind He Kuang
2016-05-19 11:47 ` [PATCH v4 5/6] perf callchain: Support x86 target platform He Kuang
2016-05-19 11:47 ` [PATCH v4 6/6] perf callchain: Support aarch64 cross-platform He Kuang

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).