linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v9 00/14] Add support for remote unwind
@ 2016-06-03  3:33 He Kuang
  2016-06-03  3:33 ` [PATCH v9 01/14] perf tools: Use LIBUNWIND_DIR for remote libunwind feature check He Kuang
                   ` (14 more replies)
  0 siblings, 15 replies; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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

v8 url:
  http://thread.gmane.org/gmane.linux.kernel/2233232

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)

For using remote libunwind libraries, reference this:
  http://thread.gmane.org/gmane.linux.kernel/2224430

and now we can use LIBUNWIND_DIR to specific custom dirctories
containing libunwind libs.

Acked-by: Jiri Olsa <jolsa@kernel.org> for most patches except:

v9:
 - Change function unwind__register_ops() to static.
 - Move up unwind__prepare_access() in thread__insert_map() and save
   map_groups__remove() call.
 - Enclose multiple line if/else into braces.
 - Fix miss modified function declaration for unwind__prepare_access()
   in patch 10.

Thanks.

He Kuang (14):
  perf tools: Use LIBUNWIND_DIR for remote libunwind feature check
  perf tools: Decouple thread->address_space on libunwind
  perf tools: Introducing struct unwind_libunwind_ops for local unwind
  perf tools: Move unwind__prepare_access from thread_new into
    thread__insert_map
  perf tools: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS
  perf tools: Separate local/remote libunwind config
  perf tools: Rename unwind-libunwind.c to unwind-libunwind-local.c
  perf tools: Extract common API out of unwind-libunwind-local.c
  perf tools: Export normalize_arch() function
  perf tools: Check the target platform before assigning unwind methods
  perf tools: Change fixed name of libunwind__arch_reg_id to macro
  perf tools: Introduce flag to separate local/remote unwind compilation
  perf callchain: Support x86 target platform
  perf callchain: Support aarch64 cross-platform

 tools/perf/arch/arm/util/Build                |   2 +-
 tools/perf/arch/arm64/util/Build              |   2 +-
 tools/perf/arch/arm64/util/unwind-libunwind.c |   4 +-
 tools/perf/arch/common.c                      |   2 +-
 tools/perf/arch/common.h                      |   1 +
 tools/perf/arch/x86/util/Build                |   2 +-
 tools/perf/arch/x86/util/unwind-libunwind.c   |   6 +-
 tools/perf/config/Makefile                    |  52 +-
 tools/perf/util/Build                         |   3 +
 tools/perf/util/libunwind/arm64.c             |  35 ++
 tools/perf/util/libunwind/x86_32.c            |  37 ++
 tools/perf/util/machine.c                     |  14 +-
 tools/perf/util/thread.c                      |  13 +-
 tools/perf/util/thread.h                      |   9 +-
 tools/perf/util/unwind-libunwind-local.c      | 697 ++++++++++++++++++++++++++
 tools/perf/util/unwind-libunwind.c            | 692 ++-----------------------
 tools/perf/util/unwind.h                      |  22 +-
 17 files changed, 919 insertions(+), 674 deletions(-)
 create mode 100644 tools/perf/util/libunwind/arm64.c
 create mode 100644 tools/perf/util/libunwind/x86_32.c
 create mode 100644 tools/perf/util/unwind-libunwind-local.c

-- 
1.8.5.2

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

* [PATCH v9 01/14] perf tools: Use LIBUNWIND_DIR for remote libunwind feature check
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:45   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 02/14] perf tools: Decouple thread->address_space on libunwind He Kuang
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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

Pass LIBUNWIND_DIR to feature check flags for remote libunwind
tests. So perf can be able to detect remote libunwind libraries from
arbitrary directory.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/config/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 1e46277..6f9f566 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -67,9 +67,18 @@ endif
 #
 #   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
 #
+
+libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
+define libunwind_arch_set_flags_code
+  FEATURE_CHECK_CFLAGS-libunwind-$(1)  = -I$(LIBUNWIND_DIR)/include
+  FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
+endef
+
 ifdef LIBUNWIND_DIR
   LIBUNWIND_CFLAGS  = -I$(LIBUNWIND_DIR)/include
   LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
+  LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
+  $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
 endif
 LIBUNWIND_LDFLAGS += $(LIBUNWIND_LIBS)
 
-- 
1.8.5.2

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

* [PATCH v9 02/14] perf tools: Decouple thread->address_space on libunwind
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
  2016-06-03  3:33 ` [PATCH v9 01/14] perf tools: Use LIBUNWIND_DIR for remote libunwind feature check He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:46   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 03/14] perf tools: Introducing struct unwind_libunwind_ops for local unwind He Kuang
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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, the type of thread->addr_space is unw_addr_space_t, which
is a pointer defined in libunwind headers. For local libunwind, we can
simple include "libunwind.h", but for remote libunwind, the header
file is depends on the target libunwind platform. This patch uses
'void *' instead to decouple the dependence on libunwind.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/thread.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 45fba13..aa3a8ff 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -9,9 +9,6 @@
 #include "symbol.h"
 #include <strlist.h>
 #include <intlist.h>
-#ifdef HAVE_LIBUNWIND_SUPPORT
-#include <libunwind.h>
-#endif
 
 struct thread_stack;
 
@@ -36,7 +33,7 @@ struct thread {
 	void			*priv;
 	struct thread_stack	*ts;
 #ifdef HAVE_LIBUNWIND_SUPPORT
-	unw_addr_space_t	addr_space;
+	void			*addr_space;
 #endif
 };
 
-- 
1.8.5.2

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

* [PATCH v9 03/14] perf tools: Introducing struct unwind_libunwind_ops for local unwind
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
  2016-06-03  3:33 ` [PATCH v9 01/14] perf tools: Use LIBUNWIND_DIR for remote libunwind feature check He Kuang
  2016-06-03  3:33 ` [PATCH v9 02/14] perf tools: Decouple thread->address_space on libunwind He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:46   ` [tip:perf/core] perf unwind: Introduce 'struct unwind_libunwind_ops' " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 04/14] perf tools: Move unwind__prepare_access from thread_new into thread__insert_map He Kuang
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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, libunwind operations are fixed, and they are chosen
according to the host architecture. This will lead a problem that if a
thread is run as x86_32 on x86_64 machine, perf will use libunwind
methods for x86_64 to parse the callchain and get wrong result.

This patch changes the fixed methods of libunwind operations to
thread/map related, and each thread can have indivadual libunwind
operations. Local libunwind methods are registered as default value.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/thread.h           |  4 ++-
 tools/perf/util/unwind-libunwind.c | 58 +++++++++++++++++++++++++++++++++++---
 tools/perf/util/unwind.h           |  9 ++++++
 3 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index aa3a8ff..152fb9a 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -11,6 +11,7 @@
 #include <intlist.h>
 
 struct thread_stack;
+struct unwind_libunwind_ops;
 
 struct thread {
 	union {
@@ -33,7 +34,8 @@ struct thread {
 	void			*priv;
 	struct thread_stack	*ts;
 #ifdef HAVE_LIBUNWIND_SUPPORT
-	void			*addr_space;
+	void				*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..284cd09 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -579,7 +579,7 @@ static unw_accessors_t accessors = {
 	.get_proc_name		= get_proc_name,
 };
 
-int unwind__prepare_access(struct thread *thread)
+static int _unwind__prepare_access(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return 0;
@@ -594,7 +594,7 @@ int unwind__prepare_access(struct thread *thread)
 	return 0;
 }
 
-void unwind__flush_access(struct thread *thread)
+static void _unwind__flush_access(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return;
@@ -602,7 +602,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 _unwind__finish_access(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return;
@@ -662,7 +662,7 @@ 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,
+static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct thread *thread,
 			struct perf_sample *data, int max_stack)
 {
@@ -680,3 +680,53 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 
 	return get_entries(&ui, cb, arg, max_stack);
 }
+
+static struct unwind_libunwind_ops
+_unwind_libunwind_ops = {
+	.prepare_access = _unwind__prepare_access,
+	.flush_access   = _unwind__flush_access,
+	.finish_access  = _unwind__finish_access,
+	.get_entries    = _unwind__get_entries,
+};
+
+struct unwind_libunwind_ops *
+local_unwind_libunwind_ops = &_unwind_libunwind_ops;
+
+static void unwind__register_ops(struct thread *thread,
+				 struct unwind_libunwind_ops *ops)
+{
+	thread->unwind_libunwind_ops = ops;
+}
+
+int unwind__prepare_access(struct thread *thread)
+{
+	unwind__register_ops(thread, local_unwind_libunwind_ops);
+
+	return thread->unwind_libunwind_ops->prepare_access(thread);
+}
+
+void unwind__flush_access(struct thread *thread)
+{
+	if (thread->unwind_libunwind_ops)
+		thread->unwind_libunwind_ops->flush_access(thread);
+}
+
+void unwind__finish_access(struct thread *thread)
+{
+	if (thread->unwind_libunwind_ops)
+		thread->unwind_libunwind_ops->finish_access(thread);
+}
+
+int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
+			 struct thread *thread,
+			 struct perf_sample *data, int max_stack)
+{
+	if (thread->unwind_libunwind_ops) {
+		return thread->unwind_libunwind_ops->get_entries(cb, arg,
+								 thread,
+								 data,
+								 max_stack);
+	} else {
+		return 0;
+	}
+}
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 12790cf..bbd73d9 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -14,6 +14,15 @@ 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);
+};
+
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
 int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct thread *thread,
-- 
1.8.5.2

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

* [PATCH v9 04/14] perf tools: Move unwind__prepare_access from thread_new into thread__insert_map
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (2 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 03/14] perf tools: Introducing struct unwind_libunwind_ops for local unwind He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:47   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 05/14] perf tools: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS He Kuang
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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

For determine the libunwind methods to use, we should get the
32bit/64bit information from maps of a thread. When a thread is newly
created, the information is not prepared. This patch moves
unwind__prepare_access() into thread__insert_map() so we can get the
information we need from maps. Meanwhile, let thread__insert_map()
return value and show messages on error.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/machine.c | 14 ++++++++++++--
 tools/perf/util/thread.c  | 13 +++++++++----
 tools/perf/util/thread.h  |  2 +-
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index bdc33ce..ef4f785 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1353,11 +1353,16 @@ int machine__process_mmap2_event(struct machine *machine,
 	if (map == NULL)
 		goto out_problem_map;
 
-	thread__insert_map(thread, map);
+	ret = thread__insert_map(thread, map);
+	if (ret)
+		goto out_problem_insert;
+
 	thread__put(thread);
 	map__put(map);
 	return 0;
 
+out_problem_insert:
+	map__put(map);
 out_problem_map:
 	thread__put(thread);
 out_problem:
@@ -1403,11 +1408,16 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
 	if (map == NULL)
 		goto out_problem_map;
 
-	thread__insert_map(thread, map);
+	ret = thread__insert_map(thread, map);
+	if (ret)
+		goto out_problem_insert;
+
 	thread__put(thread);
 	map__put(map);
 	return 0;
 
+out_problem_insert:
+	map__put(map);
 out_problem_map:
 	thread__put(thread);
 out_problem:
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 45fcb71..d05843e 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;
@@ -201,10 +198,18 @@ size_t thread__fprintf(struct thread *thread, FILE *fp)
 	       map_groups__fprintf(thread->mg, fp);
 }
 
-void thread__insert_map(struct thread *thread, struct map *map)
+int thread__insert_map(struct thread *thread, struct map *map)
 {
+	int ret;
+
+	ret = unwind__prepare_access(thread);
+	if (ret)
+		return ret;
+
 	map_groups__fixup_overlappings(thread->mg, map, stderr);
 	map_groups__insert(thread->mg, map);
+
+	return 0;
 }
 
 static int thread__clone_map_groups(struct thread *thread,
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 152fb9a..e7a82a3 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -76,7 +76,7 @@ int thread__comm_len(struct thread *thread);
 struct comm *thread__comm(const struct thread *thread);
 struct comm *thread__exec_comm(const struct thread *thread);
 const char *thread__comm_str(const struct thread *thread);
-void thread__insert_map(struct thread *thread, struct map *map);
+int thread__insert_map(struct thread *thread, struct map *map);
 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
 size_t thread__fprintf(struct thread *thread, FILE *fp);
 
-- 
1.8.5.2

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

* [PATCH v9 05/14] perf tools: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (3 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 04/14] perf tools: Move unwind__prepare_access from thread_new into thread__insert_map He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:47   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 06/14] perf tools: Separate local/remote libunwind config He Kuang
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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

LIBUNWIND_LIBS contains libunwind libraries used for local only, don't
mix this into LIBUNWIND_LDFLAGS so we can later use LIBUNWIND_LDFLAGS
both for local and remote libunwind.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/config/Makefile | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 6f9f566..118df2d 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -80,13 +80,12 @@ ifdef LIBUNWIND_DIR
   LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
   $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
 endif
-LIBUNWIND_LDFLAGS += $(LIBUNWIND_LIBS)
 
 # Set per-feature check compilation flags
 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS)
+FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS)
+FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
 
 ifeq ($(NO_PERF_REGS),0)
   CFLAGS += -DHAVE_PERF_REGS_SUPPORT
@@ -409,7 +408,7 @@ ifndef NO_LIBUNWIND
   CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
   EXTLIBS += $(LIBUNWIND_LIBS)
   CFLAGS  += $(LIBUNWIND_CFLAGS)
-  LDFLAGS += $(LIBUNWIND_LDFLAGS)
+  LDFLAGS += $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
 endif
 
 ifndef NO_LIBAUDIT
-- 
1.8.5.2

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

* [PATCH v9 06/14] perf tools: Separate local/remote libunwind config
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (4 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 05/14] perf tools: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:47   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 07/14] perf tools: Rename unwind-libunwind.c to unwind-libunwind-local.c He Kuang
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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

CONFIG_LIBUNWIND/NO_LIBUNWIND are changed to
CONFIG_LOCAL_LIBUNWIND/NO_LOCAL_LIBUNWIND for retaining local unwind
features. The new CONFIG_LIBUNWIND stands for either local or remote
or both unwind are supported, and NO_LIBUNWIND means that neither
local nor remote unwind is supported.

LIBUNWIND_LIBS is eliminated in LDFLAGS if local libunwind is not
supported.

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

diff --git a/tools/perf/arch/arm/util/Build b/tools/perf/arch/arm/util/Build
index d22e3d0..f98da17 100644
--- a/tools/perf/arch/arm/util/Build
+++ b/tools/perf/arch/arm/util/Build
@@ -1,4 +1,4 @@
 libperf-$(CONFIG_DWARF) += dwarf-regs.o
 
-libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
+libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind.o
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build
index e58123a8..02f41db 100644
--- a/tools/perf/arch/arm64/util/Build
+++ b/tools/perf/arch/arm64/util/Build
@@ -1,2 +1,2 @@
 libperf-$(CONFIG_DWARF)     += dwarf-regs.o
-libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o
+libperf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build
index 4659703..bc24b75 100644
--- a/tools/perf/arch/x86/util/Build
+++ b/tools/perf/arch/x86/util/Build
@@ -7,7 +7,7 @@ libperf-y += perf_regs.o
 libperf-$(CONFIG_DWARF) += dwarf-regs.o
 libperf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o
 
-libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
+libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind.o
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 
 libperf-$(CONFIG_AUXTRACE) += auxtrace.o
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 118df2d..3918687 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -353,10 +353,20 @@ ifeq ($(ARCH),powerpc)
 endif
 
 ifndef NO_LIBUNWIND
+  have_libunwind :=
   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
+    $(call detected,CONFIG_LOCAL_LIBUNWIND)
+  endif
+
+  ifneq ($(have_libunwind), 1)
     NO_LIBUNWIND := 1
   endif
+else
+  NO_LOCAL_LIBUNWIND := 1
 endif
 
 ifndef NO_LIBBPF
@@ -394,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)
@@ -405,10 +415,14 @@ 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)
+  LDFLAGS += $(LIBUNWIND_LIBS)
+endif
+
+ifndef NO_LIBUNWIND
+  CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
   CFLAGS  += $(LIBUNWIND_CFLAGS)
-  LDFLAGS += $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
+  LDFLAGS += $(LIBUNWIND_LDFLAGS)
 endif
 
 ifndef NO_LIBAUDIT
-- 
1.8.5.2

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

* [PATCH v9 07/14] perf tools: Rename unwind-libunwind.c to unwind-libunwind-local.c
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (5 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 06/14] perf tools: Separate local/remote libunwind config He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:48   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 08/14] perf tools: Extract common API out of unwind-libunwind-local.c He Kuang
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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

Since unwind-libunwind.c contains code for specific arithecture, we
change it's name to unwind-libunwind-local.c, and let it only be built
if local libunwind is supported.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/Build                                            | 2 +-
 tools/perf/util/{unwind-libunwind.c => unwind-libunwind-local.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename tools/perf/util/{unwind-libunwind.c => unwind-libunwind-local.c} (100%)

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8c6c8a0..5e23d85 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-local.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind-local.c
similarity index 100%
rename from tools/perf/util/unwind-libunwind.c
rename to tools/perf/util/unwind-libunwind-local.c
-- 
1.8.5.2

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

* [PATCH v9 08/14] perf tools: Extract common API out of unwind-libunwind-local.c
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (6 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 07/14] perf tools: Rename unwind-libunwind.c to unwind-libunwind-local.c He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:48   ` [tip:perf/core] " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 09/14] perf tools: Export normalize_arch() function He Kuang
                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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 extracts common unwind-libunwind APIs out of
unwind-libunwind-local.c, this part will be used by both local and
remote libunwind.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/Build                    |  1 +
 tools/perf/util/unwind-libunwind-local.c | 39 -----------------------------
 tools/perf/util/unwind-libunwind.c       | 43 ++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 39 deletions(-)
 create mode 100644 tools/perf/util/unwind-libunwind.c

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 5e23d85..004fb1d 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_LOCAL_LIBUNWIND)    += unwind-libunwind-local.o
+libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 284cd09..9c70486 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -691,42 +691,3 @@ _unwind_libunwind_ops = {
 
 struct unwind_libunwind_ops *
 local_unwind_libunwind_ops = &_unwind_libunwind_ops;
-
-static void unwind__register_ops(struct thread *thread,
-				 struct unwind_libunwind_ops *ops)
-{
-	thread->unwind_libunwind_ops = ops;
-}
-
-int unwind__prepare_access(struct thread *thread)
-{
-	unwind__register_ops(thread, local_unwind_libunwind_ops);
-
-	return thread->unwind_libunwind_ops->prepare_access(thread);
-}
-
-void unwind__flush_access(struct thread *thread)
-{
-	if (thread->unwind_libunwind_ops)
-		thread->unwind_libunwind_ops->flush_access(thread);
-}
-
-void unwind__finish_access(struct thread *thread)
-{
-	if (thread->unwind_libunwind_ops)
-		thread->unwind_libunwind_ops->finish_access(thread);
-}
-
-int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
-			 struct thread *thread,
-			 struct perf_sample *data, int max_stack)
-{
-	if (thread->unwind_libunwind_ops) {
-		return thread->unwind_libunwind_ops->get_entries(cb, arg,
-								 thread,
-								 data,
-								 max_stack);
-	} else {
-		return 0;
-	}
-}
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
new file mode 100644
index 0000000..9365f0e
--- /dev/null
+++ b/tools/perf/util/unwind-libunwind.c
@@ -0,0 +1,43 @@
+#include "unwind.h"
+#include "thread.h"
+
+struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
+
+static void unwind__register_ops(struct thread *thread,
+			  struct unwind_libunwind_ops *ops)
+{
+	thread->unwind_libunwind_ops = ops;
+}
+
+int unwind__prepare_access(struct thread *thread)
+{
+	unwind__register_ops(thread, local_unwind_libunwind_ops);
+
+	return thread->unwind_libunwind_ops->prepare_access(thread);
+}
+
+void unwind__flush_access(struct thread *thread)
+{
+	if (thread->unwind_libunwind_ops)
+		thread->unwind_libunwind_ops->flush_access(thread);
+}
+
+void unwind__finish_access(struct thread *thread)
+{
+	if (thread->unwind_libunwind_ops)
+		thread->unwind_libunwind_ops->finish_access(thread);
+}
+
+int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
+			 struct thread *thread,
+			 struct perf_sample *data, int max_stack)
+{
+	if (thread->unwind_libunwind_ops) {
+		return thread->unwind_libunwind_ops->get_entries(cb, arg,
+								 thread,
+								 data,
+								 max_stack);
+	} else {
+		return 0;
+	}
+}
-- 
1.8.5.2

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

* [PATCH v9 09/14] perf tools: Export normalize_arch() function
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (7 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 08/14] perf tools: Extract common API out of unwind-libunwind-local.c He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:49   ` [tip:perf/core] " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 10/14] perf tools: Check the target platform before assigning unwind methods He Kuang
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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

Export normalize_arch() function, so other part of perf can get
normalized form of arch string.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/arch/common.c | 2 +-
 tools/perf/arch/common.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

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 */
-- 
1.8.5.2

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

* [PATCH v9 10/14] perf tools: Check the target platform before assigning unwind methods
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (8 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 09/14] perf tools: Export normalize_arch() function He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-04  5:36   ` [PATCH v9 10/14 UPDATE] " He Kuang
  2016-06-08  8:49   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 11/14] perf tools: Change fixed name of libunwind__arch_reg_id to macro He Kuang
                   ` (4 subsequent siblings)
  14 siblings, 2 replies; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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 without any warnings when unwinding callchains of x86(32-bit)
on x86(64-bit) machine.

This patch adds extra step that check the target platform before
assigning unwind methods. In the latter patches in this series, we can
use this info to assign the right unwind methods for supported
platforms.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/thread.c           |  2 +-
 tools/perf/util/unwind-libunwind.c | 24 +++++++++++++++++++++++-
 tools/perf/util/unwind.h           |  8 +++++---
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index d05843e..d1a12144e 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -202,7 +202,7 @@ int thread__insert_map(struct thread *thread, struct map *map)
 {
 	int ret;
 
-	ret = unwind__prepare_access(thread);
+	ret = unwind__prepare_access(thread, map);
 	if (ret)
 		return ret;
 
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 9365f0e..1d72819 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -1,5 +1,8 @@
 #include "unwind.h"
 #include "thread.h"
+#include "session.h"
+#include "debug.h"
+#include "arch/common.h"
 
 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
 
@@ -9,8 +12,27 @@ static void unwind__register_ops(struct thread *thread,
 	thread->unwind_libunwind_ops = ops;
 }
 
-int unwind__prepare_access(struct thread *thread)
+int unwind__prepare_access(struct thread *thread, struct map *map)
 {
+	const char *arch;
+	enum dso_type dso_type;
+
+	if (thread->addr_space) {
+		pr_debug("unwind: thread map already set, dso=%s\n",
+			 map->dso->name);
+		return 0;
+	}
+
+	if (!thread->mg->machine->env)
+		return 0;
+
+	dso_type = dso__type(map->dso, thread->mg->machine);
+	if (dso_type == DSO__TYPE_UNKNOWN)
+		return 0;
+
+	arch = normalize_arch(thread->mg->machine->env->arch);
+	pr_debug("unwind: target platform=%s\n", arch);
+
 	unwind__register_ops(thread, local_unwind_libunwind_ops);
 
 	return thread->unwind_libunwind_ops->prepare_access(thread);
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index bbd73d9..bf9f593 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -30,11 +30,12 @@ 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);
+int unwind__prepare_access(struct thread *thread, struct map *map);
 void unwind__flush_access(struct thread *thread);
 void unwind__finish_access(struct thread *thread);
 #else
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
+static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
+					 struct map *map __maybe_unused)
 {
 	return 0;
 }
@@ -53,7 +54,8 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
 	return 0;
 }
 
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
+static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
+					 struct map *map __maybe_unused)
 {
 	return 0;
 }
-- 
1.8.5.2

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

* [PATCH v9 11/14] perf tools: Change fixed name of libunwind__arch_reg_id to macro
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (9 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 10/14] perf tools: Check the target platform before assigning unwind methods He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:50   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 12/14] perf tools: Introduce flag to separate local/remote unwind compilation He Kuang
                   ` (3 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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

For local libunwind, it uses the fixed methods to convert register id
according to the host platform, but in remote libunwind, this convert
function should be the one for remote architecture. This patch changes
the fixed name to macro and code for each remote platform can be
compiled indivadually.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/unwind-libunwind-local.c | 2 +-
 tools/perf/util/unwind.h                 | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 9c70486..631b40d 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -508,7 +508,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 bf9f593..b074662 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -29,7 +29,10 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct perf_sample *data, int max_stack);
 /* libunwind specific */
 #ifdef HAVE_LIBUNWIND_SUPPORT
-int libunwind__arch_reg_id(int regnum);
+#ifndef LIBUNWIND__ARCH_REG_ID
+#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
+#endif
+int LIBUNWIND__ARCH_REG_ID(int regnum);
 int unwind__prepare_access(struct thread *thread, struct map *map);
 void unwind__flush_access(struct thread *thread);
 void unwind__finish_access(struct thread *thread);
-- 
1.8.5.2

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

* [PATCH v9 12/14] perf tools: Introduce flag to separate local/remote unwind compilation
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (10 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 11/14] perf tools: Change fixed name of libunwind__arch_reg_id to macro He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:50   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 13/14] perf callchain: Support x86 target platform He Kuang
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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 is a preparation for including unwind-libunwind-local.c in other
files for remote libunwind.

Signed-off-by: He Kuang <hekuang@huawei.com>
---
 tools/perf/util/unwind-libunwind-local.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 631b40d..01c2e86 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -22,8 +22,10 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <linux/list.h>
+#ifndef REMOTE_UNWIND_LIBUNWIND
 #include <libunwind.h>
 #include <libunwind-ptrace.h>
+#endif
 #include "callchain.h"
 #include "thread.h"
 #include "session.h"
@@ -689,5 +691,7 @@ _unwind_libunwind_ops = {
 	.get_entries    = _unwind__get_entries,
 };
 
+#ifndef REMOTE_UNWIND_LIBUNWIND
 struct unwind_libunwind_ops *
 local_unwind_libunwind_ops = &_unwind_libunwind_ops;
+#endif
-- 
1.8.5.2

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

* [PATCH v9 13/14] perf callchain: Support x86 target platform
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (11 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 12/14] perf tools: Introduce flag to separate local/remote unwind compilation He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:51   ` [tip:perf/core] " tip-bot for He Kuang
  2016-06-03  3:33 ` [PATCH v9 14/14] perf callchain: Support aarch64 cross-platform He Kuang
  2016-06-03  7:06 ` [PATCH v9 00/14] Add support for remote unwind Jiri Olsa
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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/util/unwind-libunwind.c |  6 +++--
 tools/perf/config/Makefile                  |  8 +++++++
 tools/perf/util/Build                       |  1 +
 tools/perf/util/libunwind/x86_32.c          | 37 +++++++++++++++++++++++++++++
 tools/perf/util/unwind-libunwind.c          | 15 ++++++++++--
 5 files changed, 63 insertions(+), 4 deletions(-)
 create mode 100644 tools/perf/util/libunwind/x86_32.c

diff --git a/tools/perf/arch/x86/util/unwind-libunwind.c b/tools/perf/arch/x86/util/unwind-libunwind.c
index db25e93..4f16661 100644
--- a/tools/perf/arch/x86/util/unwind-libunwind.c
+++ b/tools/perf/arch/x86/util/unwind-libunwind.c
@@ -1,12 +1,14 @@
 
+#ifndef REMOTE_UNWIND_LIBUNWIND
 #include <errno.h>
 #include <libunwind.h>
 #include "perf_regs.h"
 #include "../../util/unwind.h"
 #include "../../util/debug.h"
+#endif
 
 #ifdef HAVE_ARCH_X86_64_SUPPORT
-int libunwind__arch_reg_id(int regnum)
+int LIBUNWIND__ARCH_REG_ID(int regnum)
 {
 	int id;
 
@@ -70,7 +72,7 @@ int libunwind__arch_reg_id(int regnum)
 	return id;
 }
 #else
-int libunwind__arch_reg_id(int regnum)
+int LIBUNWIND__ARCH_REG_ID(int regnum)
 {
 	int id;
 
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 3918687..34999fb 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -354,6 +354,14 @@ endif
 
 ifndef NO_LIBUNWIND
   have_libunwind :=
+
+  ifeq ($(feature-libunwind-x86), 1)
+    $(call detected,CONFIG_LIBUNWIND_X86)
+    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
+    LDFLAGS += -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
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 004fb1d..7746e09 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -101,6 +101,7 @@ libperf-$(CONFIG_DWARF) += dwarf-aux.o
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind-local.o
 libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
+libperf-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/libunwind/x86_32.c b/tools/perf/util/libunwind/x86_32.c
new file mode 100644
index 0000000..d98c17e
--- /dev/null
+++ b/tools/perf/util/libunwind/x86_32.c
@@ -0,0 +1,37 @@
+/*
+ * This file setups defines to compile arch specific binary from the
+ * generic one.
+ *
+ * The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch
+ * name and the defination of this function is included directly from
+ * 'arch/x86/util/unwind-libunwind.c', to make sure that this function
+ * is defined no matter what arch the host is.
+ *
+ * Finally, the arch specific unwind methods are exported which will
+ * be assigned to each x86 thread.
+ */
+
+#define REMOTE_UNWIND_LIBUNWIND
+#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__x86_reg_id(regnum)
+
+#include "unwind.h"
+#include "debug.h"
+#include "libunwind-x86.h"
+#include <../../../../arch/x86/include/uapi/asm/perf_regs.h>
+
+/* HAVE_ARCH_X86_64_SUPPORT is used in'arch/x86/util/unwind-libunwind.c'
+ * for x86_32, we undef it to compile code for x86_32 only.
+ */
+#undef HAVE_ARCH_X86_64_SUPPORT
+#include "../../arch/x86/util/unwind-libunwind.c"
+
+/* Explicitly define NO_LIBUNWIND_DEBUG_FRAME, because non-ARM has no
+ * dwarf_find_debug_frame() function.
+ */
+#ifndef NO_LIBUNWIND_DEBUG_FRAME
+#define NO_LIBUNWIND_DEBUG_FRAME
+#endif
+#include "util/unwind-libunwind-local.c"
+
+struct unwind_libunwind_ops *
+x86_32_unwind_libunwind_ops = &_unwind_libunwind_ops;
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 1d72819..c4d6388 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -5,6 +5,7 @@
 #include "arch/common.h"
 
 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
+struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
 
 static void unwind__register_ops(struct thread *thread,
 			  struct unwind_libunwind_ops *ops)
@@ -16,6 +17,7 @@ int unwind__prepare_access(struct thread *thread, struct map *map)
 {
 	const char *arch;
 	enum dso_type dso_type;
+	struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
 
 	if (thread->addr_space) {
 		pr_debug("unwind: thread map already set, dso=%s\n",
@@ -31,9 +33,18 @@ int unwind__prepare_access(struct thread *thread, struct map *map)
 		return 0;
 
 	arch = normalize_arch(thread->mg->machine->env->arch);
-	pr_debug("unwind: target platform=%s\n", arch);
 
-	unwind__register_ops(thread, local_unwind_libunwind_ops);
+	if (!strcmp(arch, "x86")) {
+		if (dso_type != DSO__TYPE_64BIT)
+			ops = x86_32_unwind_libunwind_ops;
+	}
+
+	if (!ops) {
+		pr_err("unwind: target platform=%s is not supported\n", arch);
+		return -1;
+	}
+
+	unwind__register_ops(thread, ops);
 
 	return thread->unwind_libunwind_ops->prepare_access(thread);
 }
-- 
1.8.5.2

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

* [PATCH v9 14/14] perf callchain: Support aarch64 cross-platform
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (12 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 13/14] perf callchain: Support x86 target platform He Kuang
@ 2016-06-03  3:33 ` He Kuang
  2016-06-08  8:51   ` [tip:perf/core] " tip-bot for He Kuang
  2016-06-03  7:06 ` [PATCH v9 00/14] Add support for remote unwind Jiri Olsa
  14 siblings, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-03  3:33 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>
---
 tools/perf/arch/arm64/util/unwind-libunwind.c |  4 ++-
 tools/perf/config/Makefile                    | 12 +++++++++
 tools/perf/util/Build                         |  1 +
 tools/perf/util/libunwind/arm64.c             | 35 +++++++++++++++++++++++++++
 tools/perf/util/unwind-libunwind.c            |  4 +++
 5 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/util/libunwind/arm64.c

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/config/Makefile b/tools/perf/config/Makefile
index 34999fb..47e8f58 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -362,6 +362,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/Build b/tools/perf/util/Build
index 7746e09..fced833 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -102,6 +102,7 @@ libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind-local.o
 libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
 libperf-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
+libperf-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/libunwind/arm64.c b/tools/perf/util/libunwind/arm64.c
new file mode 100644
index 0000000..4fb5395
--- /dev/null
+++ b/tools/perf/util/libunwind/arm64.c
@@ -0,0 +1,35 @@
+/*
+ * This file setups defines to compile arch specific binary from the
+ * generic one.
+ *
+ * The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch
+ * name and the defination of this function is included directly from
+ * 'arch/arm64/util/unwind-libunwind.c', to make sure that this function
+ * is defined no matter what arch the host is.
+ *
+ * Finally, the arch specific unwind methods are exported which will
+ * be assigned to each arm64 thread.
+ */
+
+#define REMOTE_UNWIND_LIBUNWIND
+
+#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arm64_reg_id(regnum)
+
+#include "unwind.h"
+#include "debug.h"
+#include "libunwind-aarch64.h"
+#include <../../../../arch/arm64/include/uapi/asm/perf_regs.h>
+#include "../../arch/arm64/util/unwind-libunwind.c"
+
+/* NO_LIBUNWIND_DEBUG_FRAME is a feature flag for local libunwind,
+ * assign NO_LIBUNWIND_DEBUG_FRAME_AARCH64 to it for compiling arm64
+ * unwind methods.
+ */
+#undef NO_LIBUNWIND_DEBUG_FRAME
+#ifdef NO_LIBUNWIND_DEBUG_FRAME_AARCH64
+#define NO_LIBUNWIND_DEBUG_FRAME
+#endif
+#include "util/unwind-libunwind-local.c"
+
+struct unwind_libunwind_ops *
+arm64_unwind_libunwind_ops = &_unwind_libunwind_ops;
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index c4d6388..2c3ec8c 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -6,6 +6,7 @@
 
 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
 struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
+struct unwind_libunwind_ops __weak *arm64_unwind_libunwind_ops;
 
 static void unwind__register_ops(struct thread *thread,
 			  struct unwind_libunwind_ops *ops)
@@ -37,6 +38,9 @@ int unwind__prepare_access(struct thread *thread, struct map *map)
 	if (!strcmp(arch, "x86")) {
 		if (dso_type != DSO__TYPE_64BIT)
 			ops = x86_32_unwind_libunwind_ops;
+	} else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
+		if (dso_type == DSO__TYPE_64BIT)
+			ops = arm64_unwind_libunwind_ops;
 	}
 
 	if (!ops) {
-- 
1.8.5.2

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
                   ` (13 preceding siblings ...)
  2016-06-03  3:33 ` [PATCH v9 14/14] perf callchain: Support aarch64 cross-platform He Kuang
@ 2016-06-03  7:06 ` Jiri Olsa
  2016-06-03 19:42   ` Arnaldo Carvalho de Melo
  2016-06-07 19:44   ` Arnaldo Carvalho de Melo
  14 siblings, 2 replies; 40+ messages in thread
From: Jiri Olsa @ 2016-06-03  7:06 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 Fri, Jun 03, 2016 at 03:33:09AM +0000, He Kuang wrote:

SNIP

> For using remote libunwind libraries, reference this:
>   http://thread.gmane.org/gmane.linux.kernel/2224430
> 
> and now we can use LIBUNWIND_DIR to specific custom dirctories
> containing libunwind libs.
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org> for most patches except:
> 
> v9:
>  - Change function unwind__register_ops() to static.
>  - Move up unwind__prepare_access() in thread__insert_map() and save
>    map_groups__remove() call.
>  - Enclose multiple line if/else into braces.
>  - Fix miss modified function declaration for unwind__prepare_access()
>    in patch 10.

for patchset:

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

thanks,
jirka

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-03  7:06 ` [PATCH v9 00/14] Add support for remote unwind Jiri Olsa
@ 2016-06-03 19:42   ` Arnaldo Carvalho de Melo
  2016-06-03 21:06     ` Arnaldo Carvalho de Melo
  2016-06-07 19:44   ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-03 19:42 UTC (permalink / raw)
  To: Jiri Olsa
  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

Em Fri, Jun 03, 2016 at 09:06:29AM +0200, Jiri Olsa escreveu:
> On Fri, Jun 03, 2016 at 03:33:09AM +0000, He Kuang wrote:
> > v9:
> >  - Change function unwind__register_ops() to static.
> >  - Move up unwind__prepare_access() in thread__insert_map() and save
> >    map_groups__remove() call.
> >  - Enclose multiple line if/else into braces.
> >  - Fix miss modified function declaration for unwind__prepare_access()
> >    in patch 10.
 
> for patchset:
 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks, applied, build testing.

- Arnaldo

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-03 19:42   ` Arnaldo Carvalho de Melo
@ 2016-06-03 21:06     ` Arnaldo Carvalho de Melo
  2016-06-03 21:09       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-03 21:06 UTC (permalink / raw)
  To: He Kuang
  Cc: Jiri Olsa, peterz, mingo, alexander.shishkin, wangnan0, jpoimboe,
	ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern,
	linux-kernel

Em Fri, Jun 03, 2016 at 04:42:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Jun 03, 2016 at 09:06:29AM +0200, Jiri Olsa escreveu:
> > On Fri, Jun 03, 2016 at 03:33:09AM +0000, He Kuang wrote:
> > > v9:
> > >  - Change function unwind__register_ops() to static.
> > >  - Move up unwind__prepare_access() in thread__insert_map() and save
> > >    map_groups__remove() call.
> > >  - Enclose multiple line if/else into braces.
> > >  - Fix miss modified function declaration for unwind__prepare_access()
> > >    in patch 10.
>  
> > for patchset:
>  
> > Acked-by: Jiri Olsa <jolsa@kernel.org>
> 
> Thanks, applied, build testing.

Build tested went ok, but then 'perf top' crashes:

[root@jouet ~]# perf top
perf: Segmentation fault
-------- backtrace --------
perf[0x55591b]
/lib64/libc.so.6(+0x34ab0)[0x7f38ad9c1ab0]
perf(normalize_arch+0x27)[0x534797]
perf(unwind__prepare_access+0xbb)[0x52b15b]
perf(thread__insert_map+0x27)[0x4d4837]
perf(machine__process_mmap2_event+0xd7)[0x4ca187]
perf(perf_event__synthesize_mmap_events+0x3e2)[0x491b32]
perf(perf_event__synthesize_threads+0x445)[0x492635]
perf(cmd_top+0xee0)[0x442f50]
perf[0x486a91]
perf(main+0x6ee)[0x42485e]
/lib64/libc.so.6(__libc_start_main+0xf0)[0x7f38ad9ad580]
perf(_start+0x29)[0x424949]
[0x0]
[root@jouet ~]#

And I bet that 'perf trace' will too, lemme see, well, it crashes even
more spetacularly, but that is the topic of another bug report, will
send soon.

Anyway, please try your patchkit with 'perf top' and 'perf trace', as
both don't use perf.data files, i.e. they work 'live', so probably
things that you touch in normalize_arch() are not initialized and need
to be setup.

- Arnaldo

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-03 21:06     ` Arnaldo Carvalho de Melo
@ 2016-06-03 21:09       ` Arnaldo Carvalho de Melo
  2016-06-04  5:39         ` Hekuang
  0 siblings, 1 reply; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-03 21:09 UTC (permalink / raw)
  To: He Kuang
  Cc: Jiri Olsa, peterz, mingo, alexander.shishkin, wangnan0, jpoimboe,
	ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern,
	linux-kernel

Em Fri, Jun 03, 2016 at 06:06:02PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Jun 03, 2016 at 04:42:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, Jun 03, 2016 at 09:06:29AM +0200, Jiri Olsa escreveu:
> > > On Fri, Jun 03, 2016 at 03:33:09AM +0000, He Kuang wrote:
> > > > v9:
> > > >  - Change function unwind__register_ops() to static.
> > > >  - Move up unwind__prepare_access() in thread__insert_map() and save
> > > >    map_groups__remove() call.
> > > >  - Enclose multiple line if/else into braces.
> > > >  - Fix miss modified function declaration for unwind__prepare_access()
> > > >    in patch 10.
> >  
> > > for patchset:
> >  
> > > Acked-by: Jiri Olsa <jolsa@kernel.org>
> > 
> > Thanks, applied, build testing.
> 
> Build tested went ok, but then 'perf top' crashes:
> 
> [root@jouet ~]# perf top
> perf: Segmentation fault
> -------- backtrace --------
> perf[0x55591b]
> /lib64/libc.so.6(+0x34ab0)[0x7f38ad9c1ab0]
> perf(normalize_arch+0x27)[0x534797]
> perf(unwind__prepare_access+0xbb)[0x52b15b]
> perf(thread__insert_map+0x27)[0x4d4837]
> perf(machine__process_mmap2_event+0xd7)[0x4ca187]
> perf(perf_event__synthesize_mmap_events+0x3e2)[0x491b32]
> perf(perf_event__synthesize_threads+0x445)[0x492635]
> perf(cmd_top+0xee0)[0x442f50]
> perf[0x486a91]
> perf(main+0x6ee)[0x42485e]
> /lib64/libc.so.6(__libc_start_main+0xf0)[0x7f38ad9ad580]
> perf(_start+0x29)[0x424949]
> [0x0]
> [root@jouet ~]#
> 
> And I bet that 'perf trace' will too, lemme see, well, it crashes even
> more spetacularly, but that is the topic of another bug report, will
> send soon.
> 
> Anyway, please try your patchkit with 'perf top' and 'perf trace', as
> both don't use perf.data files, i.e. they work 'live', so probably
> things that you touch in normalize_arch() are not initialized and need
> to be setup.

Ah, no need to resend the whole patchkit, just find out what is the bug
and send me a patch and I'll insert it at the right point to avoid
introducing a bisect breaking point.

Your patchkit is in my perf/unwind branch at my tree, I already added
Jiri's Acked-by in all the patches.

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git

Thanks,

- Arnaldo
-

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

* [PATCH v9 10/14 UPDATE] perf tools: Check the target platform before assigning unwind methods
  2016-06-03  3:33 ` [PATCH v9 10/14] perf tools: Check the target platform before assigning unwind methods He Kuang
@ 2016-06-04  5:36   ` He Kuang
  2016-06-07 18:06     ` Arnaldo Carvalho de Melo
  2016-06-08  8:49   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
  1 sibling, 1 reply; 40+ messages in thread
From: He Kuang @ 2016-06-04  5:36 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 without any warnings when unwinding callchains of x86(32-bit)
on x86(64-bit) machine.

This patch adds extra step that check the target platform before
assigning unwind methods. In the latter patches in this series, we can
use this info to assign the right unwind methods for supported
platforms.

Signed-off-by: He Kuang <hekuang@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/thread.c           |  2 +-
 tools/perf/util/unwind-libunwind.c | 25 ++++++++++++++++++++++++-
 tools/perf/util/unwind.h           |  8 +++++---
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index d05843e..d1a12144e 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -202,7 +202,7 @@ int thread__insert_map(struct thread *thread, struct map *map)
 {
 	int ret;
 
-	ret = unwind__prepare_access(thread);
+	ret = unwind__prepare_access(thread, map);
 	if (ret)
 		return ret;
 
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 9365f0e..452b4e1 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -1,5 +1,8 @@
 #include "unwind.h"
 #include "thread.h"
+#include "session.h"
+#include "debug.h"
+#include "arch/common.h"
 
 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
 
@@ -9,8 +12,28 @@ static void unwind__register_ops(struct thread *thread,
 	thread->unwind_libunwind_ops = ops;
 }
 
-int unwind__prepare_access(struct thread *thread)
+int unwind__prepare_access(struct thread *thread, struct map *map)
 {
+	const char *arch;
+	enum dso_type dso_type;
+
+	if (thread->addr_space) {
+		pr_debug("unwind: thread map already set, dso=%s\n",
+			 map->dso->name);
+		return 0;
+	}
+
+	/* env->arch is NULL for live-mode (i.e. perf top) */
+	if (!thread->mg->machine->env || !thread->mg->machine->env->arch)
+		return 0;
+
+	dso_type = dso__type(map->dso, thread->mg->machine);
+	if (dso_type == DSO__TYPE_UNKNOWN)
+		return 0;
+
+	arch = normalize_arch(thread->mg->machine->env->arch);
+	pr_debug("unwind: target platform=%s\n", arch);
+
 	unwind__register_ops(thread, local_unwind_libunwind_ops);
 
 	return thread->unwind_libunwind_ops->prepare_access(thread);
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index bbd73d9..bf9f593 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -30,11 +30,12 @@ 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);
+int unwind__prepare_access(struct thread *thread, struct map *map);
 void unwind__flush_access(struct thread *thread);
 void unwind__finish_access(struct thread *thread);
 #else
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
+static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
+					 struct map *map __maybe_unused)
 {
 	return 0;
 }
@@ -53,7 +54,8 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
 	return 0;
 }
 
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
+static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
+					 struct map *map __maybe_unused)
 {
 	return 0;
 }
-- 
1.8.5.2

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-03 21:09       ` Arnaldo Carvalho de Melo
@ 2016-06-04  5:39         ` Hekuang
  2016-06-07 15:12           ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 40+ messages in thread
From: Hekuang @ 2016-06-04  5:39 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, peterz, mingo, alexander.shishkin, wangnan0, jpoimboe,
	ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern,
	linux-kernel



在 2016/6/4 5:09, Arnaldo Carvalho de Melo 写道:
> Em Fri, Jun 03, 2016 at 06:06:02PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Fri, Jun 03, 2016 at 04:42:05PM -0300, Arnaldo Carvalho de Melo escreveu:
>>> Em Fri, Jun 03, 2016 at 09:06:29AM +0200, Jiri Olsa escreveu:
>>>> On Fri, Jun 03, 2016 at 03:33:09AM +0000, He Kuang wrote:
>>>>> v9:
>>>>>   - Change function unwind__register_ops() to static.
>>>>>   - Move up unwind__prepare_access() in thread__insert_map() and save
>>>>>     map_groups__remove() call.
>>>>>   - Enclose multiple line if/else into braces.
>>>>>   - Fix miss modified function declaration for unwind__prepare_access()
>>>>>     in patch 10.
>>>   
>>>> for patchset:
>>>   
>>>> Acked-by: Jiri Olsa <jolsa@kernel.org>
>>> Thanks, applied, build testing.
>> Build tested went ok, but then 'perf top' crashes:
>>
>> [root@jouet ~]# perf top
>> perf: Segmentation fault
>> -------- backtrace --------
>> perf[0x55591b]
>> /lib64/libc.so.6(+0x34ab0)[0x7f38ad9c1ab0]
>> perf(normalize_arch+0x27)[0x534797]
>> perf(unwind__prepare_access+0xbb)[0x52b15b]
>> perf(thread__insert_map+0x27)[0x4d4837]
>> perf(machine__process_mmap2_event+0xd7)[0x4ca187]
>> perf(perf_event__synthesize_mmap_events+0x3e2)[0x491b32]
>> perf(perf_event__synthesize_threads+0x445)[0x492635]
>> perf(cmd_top+0xee0)[0x442f50]
>> perf[0x486a91]
>> perf(main+0x6ee)[0x42485e]
>> /lib64/libc.so.6(__libc_start_main+0xf0)[0x7f38ad9ad580]
>> perf(_start+0x29)[0x424949]
>> [0x0]
>> [root@jouet ~]#
>>
>> And I bet that 'perf trace' will too, lemme see, well, it crashes even
>> more spetacularly, but that is the topic of another bug report, will
>> send soon.
>>
>> Anyway, please try your patchkit with 'perf top' and 'perf trace', as
>> both don't use perf.data files, i.e. they work 'live', so probably
>> things that you touch in normalize_arch() are not initialized and need
>> to be setup.
> Ah, no need to resend the whole patchkit, just find out what is the bug
> and send me a patch and I'll insert it at the right point to avoid
> introducing a bisect breaking point.
>
> Your patchkit is in my perf/unwind branch at my tree, I already added
> Jiri's Acked-by in all the patches.
>
> git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
>
> Thanks,
>
> - Arnaldo
> -

I send the updated one after PATCH 10/14,  env->arch is null in live mode,
comments are added and "perf top/trace" works now.

Thanks.

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-04  5:39         ` Hekuang
@ 2016-06-07 15:12           ` Arnaldo Carvalho de Melo
  2016-06-07 15:14             ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-07 15:12 UTC (permalink / raw)
  To: Hekuang
  Cc: Jiri Olsa, peterz, mingo, alexander.shishkin, wangnan0, jpoimboe,
	ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern,
	linux-kernel

Em Sat, Jun 04, 2016 at 01:39:04PM +0800, Hekuang escreveu:
> 在 2016/6/4 5:09, Arnaldo Carvalho de Melo 写道:
> > Em Fri, Jun 03, 2016 at 06:06:02PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Anyway, please try your patchkit with 'perf top' and 'perf trace', as
> > > both don't use perf.data files, i.e. they work 'live', so probably
> > > things that you touch in normalize_arch() are not initialized and need
> > > to be setup.
> > Ah, no need to resend the whole patchkit, just find out what is the bug
> > and send me a patch and I'll insert it at the right point to avoid
> > introducing a bisect breaking point.

> > Your patchkit is in my perf/unwind branch at my tree, I already added
> > Jiri's Acked-by in all the patches.

> > git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git

> I send the updated one after PATCH 10/14,  env->arch is null in live mode,
> comments are added and "perf top/trace" works now.

Ok, now it fails 'perf test unwind' and I bisected it to:


[acme@jouet linux]$ git bisect good
e2b6ce1ca32cedeb2cef08f49aa812f0eadcc3c5 is the first bad commit
commit e2b6ce1ca32cedeb2cef08f49aa812f0eadcc3c5
Author: He Kuang <hekuang@huawei.com>
Date:   Fri Jun 3 03:33:19 2016 +0000

    perf unwind: Check the target platform before assigning unwind methods
    
    Currently, 'perf script' uses host unwind methods to parse perf.data
    callchain info without taking the target architecture into account, i.e.
    assuming the perf.data file was generated on the same machine where the
    analysis is being performed. So we get wrong result without any warnings
    when unwinding callchains of x86(32-bit) on x86(64-bit) machine.
    
    This patch adds an extra step that checks the target platform before
    assigning unwind methods. In later patches in this series, we can use
    this info to assign the right unwind methods for supported platforms.

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-07 15:12           ` Arnaldo Carvalho de Melo
@ 2016-06-07 15:14             ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-07 15:14 UTC (permalink / raw)
  To: Hekuang
  Cc: Jiri Olsa, peterz, mingo, alexander.shishkin, wangnan0, jpoimboe,
	ak, eranian, namhyung, adrian.hunter, sukadev,
	masami.hiramatsu.pt, tumanova, kan.liang, penberg, dsahern,
	linux-kernel

Em Tue, Jun 07, 2016 at 12:12:15PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Sat, Jun 04, 2016 at 01:39:04PM +0800, Hekuang escreveu:
> > 在 2016/6/4 5:09, Arnaldo Carvalho de Melo 写道:
> > > Em Fri, Jun 03, 2016 at 06:06:02PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > Anyway, please try your patchkit with 'perf top' and 'perf trace', as
> > > > both don't use perf.data files, i.e. they work 'live', so probably
> > > > things that you touch in normalize_arch() are not initialized and need
> > > > to be setup.
> > > Ah, no need to resend the whole patchkit, just find out what is the bug
> > > and send me a patch and I'll insert it at the right point to avoid
> > > introducing a bisect breaking point.
> 
> > > Your patchkit is in my perf/unwind branch at my tree, I already added
> > > Jiri's Acked-by in all the patches.
> 
> > > git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
> 
> > I send the updated one after PATCH 10/14,  env->arch is null in live mode,
> > comments are added and "perf top/trace" works now.
> 
> Ok, now it fails 'perf test unwind' and I bisected it to:

Further info:

[root@jouet ~]# perf test -v unwind
48: Test dwarf unwind                                        :
--- start ---
test child forked, pid 25078
got wrong number of stack entries 0 != 8
test child finished with -1
---- end ----
Test dwarf unwind: FAILED!
[root@jouet ~]#
 
> [acme@jouet linux]$ git bisect good
> e2b6ce1ca32cedeb2cef08f49aa812f0eadcc3c5 is the first bad commit
> commit e2b6ce1ca32cedeb2cef08f49aa812f0eadcc3c5
> Author: He Kuang <hekuang@huawei.com>
> Date:   Fri Jun 3 03:33:19 2016 +0000
> 
>     perf unwind: Check the target platform before assigning unwind methods
>     
>     Currently, 'perf script' uses host unwind methods to parse perf.data
>     callchain info without taking the target architecture into account, i.e.
>     assuming the perf.data file was generated on the same machine where the
>     analysis is being performed. So we get wrong result without any warnings
>     when unwinding callchains of x86(32-bit) on x86(64-bit) machine.
>     
>     This patch adds an extra step that checks the target platform before
>     assigning unwind methods. In later patches in this series, we can use
>     this info to assign the right unwind methods for supported platforms.
> 

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

* Re: [PATCH v9 10/14 UPDATE] perf tools: Check the target platform before assigning unwind methods
  2016-06-04  5:36   ` [PATCH v9 10/14 UPDATE] " He Kuang
@ 2016-06-07 18:06     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-07 18:06 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 Sat, Jun 04, 2016 at 05:36:29AM +0000, He Kuang escreveu:
> -int unwind__prepare_access(struct thread *thread)
> +int unwind__prepare_access(struct thread *thread, struct map *map)
>  {
> +	const char *arch;
> +	enum dso_type dso_type;
> +
> +	if (thread->addr_space) {
> +		pr_debug("unwind: thread map already set, dso=%s\n",
> +			 map->dso->name);
> +		return 0;
> +	}
> +
> +	/* env->arch is NULL for live-mode (i.e. perf top) */
> +	if (!thread->mg->machine->env || !thread->mg->machine->env->arch)
> +		return 0;

You can not simply return here, you need to jump to...

> +
> +	dso_type = dso__type(map->dso, thread->mg->machine);
> +	if (dso_type == DSO__TYPE_UNKNOWN)
> +		return 0;
> +
> +	arch = normalize_arch(thread->mg->machine->env->arch);
> +	pr_debug("unwind: target platform=%s\n", arch);
> +

Here:

>  	unwind__register_ops(thread, local_unwind_libunwind_ops);

This way things continue work on, say:

  perf top --call-graph dwarf

or:

  perf trace --call-graph dwarf usleep 1

And also:

  perf test unwind

Will pass, fixing it.
  
>  	return thread->unwind_libunwind_ops->prepare_access(thread);
> diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
> index bbd73d9..bf9f593 100644
> --- a/tools/perf/util/unwind.h
> +++ b/tools/perf/util/unwind.h
> @@ -30,11 +30,12 @@ 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);
> +int unwind__prepare_access(struct thread *thread, struct map *map);
>  void unwind__flush_access(struct thread *thread);
>  void unwind__finish_access(struct thread *thread);
>  #else
> -static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
> +static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
> +					 struct map *map __maybe_unused)
>  {
>  	return 0;
>  }
> @@ -53,7 +54,8 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
>  	return 0;
>  }
>  
> -static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
> +static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
> +					 struct map *map __maybe_unused)
>  {
>  	return 0;
>  }
> -- 
> 1.8.5.2

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-03  7:06 ` [PATCH v9 00/14] Add support for remote unwind Jiri Olsa
  2016-06-03 19:42   ` Arnaldo Carvalho de Melo
@ 2016-06-07 19:44   ` Arnaldo Carvalho de Melo
  2016-06-08  7:33     ` Hekuang
  1 sibling, 1 reply; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-06-07 19:44 UTC (permalink / raw)
  To: Jiri Olsa
  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

Em Fri, Jun 03, 2016 at 09:06:29AM +0200, Jiri Olsa escreveu:
> On Fri, Jun 03, 2016 at 03:33:09AM +0000, He Kuang wrote:
> 
> SNIP
> 
> > For using remote libunwind libraries, reference this:
> >   http://thread.gmane.org/gmane.linux.kernel/2224430
> > 
> > and now we can use LIBUNWIND_DIR to specific custom dirctories
> > containing libunwind libs.
> > 
> > Acked-by: Jiri Olsa <jolsa@kernel.org> for most patches except:
> > 
> > v9:
> >  - Change function unwind__register_ops() to static.
> >  - Move up unwind__prepare_access() in thread__insert_map() and save
> >    map_groups__remove() call.
> >  - Enclose multiple line if/else into braces.
> >  - Fix miss modified function declaration for unwind__prepare_access()
> >    in patch 10.
> 
> for patchset:
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Ok, I'm applying it, after fixing 'perf test unwind', 'perf top --call-graph dwarf'
and 'perf trace --call-graph dwarf', but I have one question, is the
scenario where we collect on a x86_64 machine and want to do analysis on
a ARM64 or x86-32 machine supported? This should be the odd case now,
but from a quick look I couldn't see this as being supported, is that
true or I was just lazy not to have tried this?

- Arnaldo

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

* Re: [PATCH v9 00/14] Add support for remote unwind
  2016-06-07 19:44   ` Arnaldo Carvalho de Melo
@ 2016-06-08  7:33     ` Hekuang
  0 siblings, 0 replies; 40+ messages in thread
From: Hekuang @ 2016-06-08  7:33 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: peterz, mingo, alexander.shishkin, wangnan0, jpoimboe, ak,
	eranian, namhyung, adrian.hunter, sukadev, masami.hiramatsu.pt,
	tumanova, kan.liang, penberg, dsahern, linux-kernel

hi

在 2016/6/8 3:44, Arnaldo Carvalho de Melo 写道:
> Em Fri, Jun 03, 2016 at 09:06:29AM +0200, Jiri Olsa escreveu:
>> On Fri, Jun 03, 2016 at 03:33:09AM +0000, He Kuang wrote:
>>
>> SNIP
>>
>>> For using remote libunwind libraries, reference this:
>>>    http://thread.gmane.org/gmane.linux.kernel/2224430
>>>
>>> and now we can use LIBUNWIND_DIR to specific custom dirctories
>>> containing libunwind libs.
>>>
>>> Acked-by: Jiri Olsa <jolsa@kernel.org> for most patches except:
>>>
>>> v9:
>>>   - Change function unwind__register_ops() to static.
>>>   - Move up unwind__prepare_access() in thread__insert_map() and save
>>>     map_groups__remove() call.
>>>   - Enclose multiple line if/else into braces.
>>>   - Fix miss modified function declaration for unwind__prepare_access()
>>>     in patch 10.
>> for patchset:
>>
>> Acked-by: Jiri Olsa <jolsa@kernel.org>
> Ok, I'm applying it, after fixing 'perf test unwind', 'perf top --call-graph dwarf'
> and 'perf trace --call-graph dwarf', but I have one question, is the
> scenario where we collect on a x86_64 machine and want to do analysis on
> a ARM64 or x86-32 machine supported? This should be the odd case now,
Yes, it's supported.

But I never tested this before, so I just compiled libunwind for
aarch64, and tested unwinding i686 perf.data on aarch64. Then I
found another issue I've considered but missed at some version of
this patch series.

In util/unwind-libunwind-local.c, PERF_REG_SP/IP is used, but
those macros are assigned to the host platform, we should
redefine them in the wrapper file, for example in
"util/libunwind/x86_32.c".

After fixing this problem, i686 perf.data can be parsed on
aarch64 machine.  Since you've already applied the v9 patches,
should I send patches based on the lastest tree as bug fixes or
just update v9 patches?

Thank you.

Here is the modified part:

diff --git a/tools/perf/util/libunwind/arm64.c 
b/tools/perf/util/libunwind/arm64.c
index 4fb5395..8a5c2fc 100644
--- a/tools/perf/util/libunwind/arm64.c
+++ b/tools/perf/util/libunwind/arm64.c
@@ -29,6 +29,11 @@
  #ifdef NO_LIBUNWIND_DEBUG_FRAME_AARCH64
  #define NO_LIBUNWIND_DEBUG_FRAME
  #endif
+
+#undef PERF_REG_IP
+#undef PERF_REG_SP
+#define PERF_REG_IP PERF_REG_ARM64_PC
+#define PERF_REG_SP PERF_REG_ARM64_SP
  #include "util/unwind-libunwind-local.c"

  struct unwind_libunwind_ops *
diff --git a/tools/perf/util/libunwind/x86_32.c 
b/tools/perf/util/libunwind/x86_32.c
index d98c17e..de21a39 100644
--- a/tools/perf/util/libunwind/x86_32.c
+++ b/tools/perf/util/libunwind/x86_32.c
@@ -31,6 +31,11 @@
  #ifndef NO_LIBUNWIND_DEBUG_FRAME
  #define NO_LIBUNWIND_DEBUG_FRAME
  #endif
+
+#undef PERF_REG_IP
+#undef PERF_REG_SP
+#define PERF_REG_IP PERF_REG_X86_IP
+#define PERF_REG_SP PERF_REG_X86_SP
  #include "util/unwind-libunwind-local.c"

  struct unwind_libunwind_ops *


> but from a quick look I couldn't see this as being supported, is that
> true or I was just lazy not to have tried this?
>
> - Arnaldo

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

* [tip:perf/core] perf unwind: Use LIBUNWIND_DIR for remote libunwind feature check
  2016-06-03  3:33 ` [PATCH v9 01/14] perf tools: Use LIBUNWIND_DIR for remote libunwind feature check He Kuang
@ 2016-06-08  8:45   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: namhyung, eranian, ak, jpoimboe, hekuang, hpa,
	alexander.shishkin, dsahern, sukadev, kan.liang, acme, tglx,
	adrian.hunter, mhiramat, linux-kernel, tumanova, peterz, jolsa,
	wangnan0, penberg, mingo

Commit-ID:  195106b9ff87da6da600b2c33d6a8b38281e1af3
Gitweb:     http://git.kernel.org/tip/195106b9ff87da6da600b2c33d6a8b38281e1af3
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:10 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:51 -0300

perf unwind: Use LIBUNWIND_DIR for remote libunwind feature check

Pass LIBUNWIND_DIR to feature check flags for remote libunwind
tests. So perf can be able to detect remote libunwind libraries from
arbitrary directory.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-2-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/config/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 1e46277..6f9f566 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -67,9 +67,18 @@ endif
 #
 #   make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
 #
+
+libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
+define libunwind_arch_set_flags_code
+  FEATURE_CHECK_CFLAGS-libunwind-$(1)  = -I$(LIBUNWIND_DIR)/include
+  FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
+endef
+
 ifdef LIBUNWIND_DIR
   LIBUNWIND_CFLAGS  = -I$(LIBUNWIND_DIR)/include
   LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
+  LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
+  $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
 endif
 LIBUNWIND_LDFLAGS += $(LIBUNWIND_LIBS)
 

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

* [tip:perf/core] perf unwind: Decouple thread->address_space on libunwind
  2016-06-03  3:33 ` [PATCH v9 02/14] perf tools: Decouple thread->address_space on libunwind He Kuang
@ 2016-06-08  8:46   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ak, tumanova, linux-kernel, peterz, jpoimboe, adrian.hunter,
	mhiramat, tglx, jolsa, alexander.shishkin, acme, hekuang,
	dsahern, mingo, namhyung, kan.liang, wangnan0, sukadev, eranian,
	penberg, hpa

Commit-ID:  c1d1d0d9b302cb5f0365f4de78dd7fcbf7983c05
Gitweb:     http://git.kernel.org/tip/c1d1d0d9b302cb5f0365f4de78dd7fcbf7983c05
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:11 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:51 -0300

perf unwind: Decouple thread->address_space on libunwind

Currently, the type of thread->addr_space is unw_addr_space_t, which is
a pointer defined in libunwind headers. For local libunwind, we can
simple include "libunwind.h", but for remote libunwind, the header file
is depends on the target libunwind platform. This patch uses 'void *'
instead to decouple the dependence on libunwind.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-3-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/thread.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 08fcb14..4c9f0aa 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -9,9 +9,6 @@
 #include "symbol.h"
 #include <strlist.h>
 #include <intlist.h>
-#ifdef HAVE_LIBUNWIND_SUPPORT
-#include <libunwind.h>
-#endif
 
 struct thread_stack;
 
@@ -36,7 +33,7 @@ struct thread {
 	void			*priv;
 	struct thread_stack	*ts;
 #ifdef HAVE_LIBUNWIND_SUPPORT
-	unw_addr_space_t	addr_space;
+	void			*addr_space;
 #endif
 };
 

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

* [tip:perf/core] perf unwind: Introduce 'struct unwind_libunwind_ops' for local unwind
  2016-06-03  3:33 ` [PATCH v9 03/14] perf tools: Introducing struct unwind_libunwind_ops for local unwind He Kuang
@ 2016-06-08  8:46   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, acme, wangnan0, hpa, tglx, sukadev, eranian,
	linux-kernel, dsahern, hekuang, namhyung, penberg, mingo,
	jpoimboe, kan.liang, tumanova, adrian.hunter, mhiramat, jolsa,
	ak, peterz

Commit-ID:  f83c04156c1483f16ac548516f41212cf244e441
Gitweb:     http://git.kernel.org/tip/f83c04156c1483f16ac548516f41212cf244e441
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:12 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:52 -0300

perf unwind: Introduce 'struct unwind_libunwind_ops' for local unwind

Currently, libunwind operations are fixed, and they are chosen according
to the host architecture. This will lead to a problem that if a thread
is run as x86_32 on a x86_64 machine, perf will use libunwind methods
for x86_64 to parse the callchain and get wrong results.

This patch changes the fixed methods of libunwind operations to be
thread/map related, and each thread can have individual libunwind
operations. Local libunwind methods are registered as default value.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-4-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/thread.h           |  4 ++-
 tools/perf/util/unwind-libunwind.c | 53 +++++++++++++++++++++++++++++++++++---
 tools/perf/util/unwind.h           |  9 +++++++
 3 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 4c9f0aa..07ffb18 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -11,6 +11,7 @@
 #include <intlist.h>
 
 struct thread_stack;
+struct unwind_libunwind_ops;
 
 struct thread {
 	union {
@@ -33,7 +34,8 @@ struct thread {
 	void			*priv;
 	struct thread_stack	*ts;
 #ifdef HAVE_LIBUNWIND_SUPPORT
-	void			*addr_space;
+	void				*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..b0c5db1 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -579,7 +579,7 @@ static unw_accessors_t accessors = {
 	.get_proc_name		= get_proc_name,
 };
 
-int unwind__prepare_access(struct thread *thread)
+static int _unwind__prepare_access(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return 0;
@@ -594,7 +594,7 @@ int unwind__prepare_access(struct thread *thread)
 	return 0;
 }
 
-void unwind__flush_access(struct thread *thread)
+static void _unwind__flush_access(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return;
@@ -602,7 +602,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 _unwind__finish_access(struct thread *thread)
 {
 	if (callchain_param.record_mode != CALLCHAIN_DWARF)
 		return;
@@ -662,7 +662,7 @@ 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,
+static int _unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct thread *thread,
 			struct perf_sample *data, int max_stack)
 {
@@ -680,3 +680,48 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 
 	return get_entries(&ui, cb, arg, max_stack);
 }
+
+static struct unwind_libunwind_ops
+_unwind_libunwind_ops = {
+	.prepare_access = _unwind__prepare_access,
+	.flush_access   = _unwind__flush_access,
+	.finish_access  = _unwind__finish_access,
+	.get_entries    = _unwind__get_entries,
+};
+
+struct unwind_libunwind_ops *
+local_unwind_libunwind_ops = &_unwind_libunwind_ops;
+
+static void unwind__register_ops(struct thread *thread,
+				 struct unwind_libunwind_ops *ops)
+{
+	thread->unwind_libunwind_ops = ops;
+}
+
+int unwind__prepare_access(struct thread *thread)
+{
+	unwind__register_ops(thread, local_unwind_libunwind_ops);
+
+	return thread->unwind_libunwind_ops->prepare_access(thread);
+}
+
+void unwind__flush_access(struct thread *thread)
+{
+	if (thread->unwind_libunwind_ops)
+		thread->unwind_libunwind_ops->flush_access(thread);
+}
+
+void unwind__finish_access(struct thread *thread)
+{
+	if (thread->unwind_libunwind_ops)
+		thread->unwind_libunwind_ops->finish_access(thread);
+}
+
+int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
+			 struct thread *thread,
+			 struct perf_sample *data, int max_stack)
+{
+	if (thread->unwind_libunwind_ops)
+		return thread->unwind_libunwind_ops->get_entries(cb, arg, thread, data, max_stack);
+	return 0;
+}
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index 12790cf..bbd73d9 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -14,6 +14,15 @@ 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);
+};
+
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
 int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct thread *thread,

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

* [tip:perf/core] perf unwind: Move unwind__prepare_access from thread_new into thread__insert_map
  2016-06-03  3:33 ` [PATCH v9 04/14] perf tools: Move unwind__prepare_access from thread_new into thread__insert_map He Kuang
@ 2016-06-08  8:47   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:47 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, alexander.shishkin, ak, adrian.hunter, wangnan0, kan.liang,
	mingo, jpoimboe, penberg, sukadev, tumanova, mhiramat, tglx,
	jolsa, peterz, eranian, hekuang, dsahern, acme, namhyung,
	linux-kernel

Commit-ID:  8132a2a84147d3c98cf580d5759387325fbabf73
Gitweb:     http://git.kernel.org/tip/8132a2a84147d3c98cf580d5759387325fbabf73
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:13 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:52 -0300

perf unwind: Move unwind__prepare_access from thread_new into thread__insert_map

To determine the libunwind methods to use, we should get the
32bit/64bit information from maps of a thread. When a thread is newly
created, the information is not prepared. This patch moves
unwind__prepare_access() into thread__insert_map() so we can get the
information we need from maps. Meanwhile, let thread__insert_map()
return value and show messages on error.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-5-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 14 ++++++++++++--
 tools/perf/util/thread.c  | 13 +++++++++----
 tools/perf/util/thread.h  |  2 +-
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 205d270..9d931f5 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1353,11 +1353,16 @@ int machine__process_mmap2_event(struct machine *machine,
 	if (map == NULL)
 		goto out_problem_map;
 
-	thread__insert_map(thread, map);
+	ret = thread__insert_map(thread, map);
+	if (ret)
+		goto out_problem_insert;
+
 	thread__put(thread);
 	map__put(map);
 	return 0;
 
+out_problem_insert:
+	map__put(map);
 out_problem_map:
 	thread__put(thread);
 out_problem:
@@ -1403,11 +1408,16 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
 	if (map == NULL)
 		goto out_problem_map;
 
-	thread__insert_map(thread, map);
+	ret = thread__insert_map(thread, map);
+	if (ret)
+		goto out_problem_insert;
+
 	thread__put(thread);
 	map__put(map);
 	return 0;
 
+out_problem_insert:
+	map__put(map);
 out_problem_map:
 	thread__put(thread);
 out_problem:
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index ada58e6..0bf55256 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;
@@ -201,10 +198,18 @@ size_t thread__fprintf(struct thread *thread, FILE *fp)
 	       map_groups__fprintf(thread->mg, fp);
 }
 
-void thread__insert_map(struct thread *thread, struct map *map)
+int thread__insert_map(struct thread *thread, struct map *map)
 {
+	int ret;
+
+	ret = unwind__prepare_access(thread);
+	if (ret)
+		return ret;
+
 	map_groups__fixup_overlappings(thread->mg, map, stderr);
 	map_groups__insert(thread->mg, map);
+
+	return 0;
 }
 
 static int thread__clone_map_groups(struct thread *thread,
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 07ffb18..99263cb 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -76,7 +76,7 @@ int thread__comm_len(struct thread *thread);
 struct comm *thread__comm(const struct thread *thread);
 struct comm *thread__exec_comm(const struct thread *thread);
 const char *thread__comm_str(const struct thread *thread);
-void thread__insert_map(struct thread *thread, struct map *map);
+int thread__insert_map(struct thread *thread, struct map *map);
 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
 size_t thread__fprintf(struct thread *thread, FILE *fp);
 

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

* [tip:perf/core] perf unwind: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS
  2016-06-03  3:33 ` [PATCH v9 05/14] perf tools: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS He Kuang
@ 2016-06-08  8:47   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:47 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, tglx, peterz, sukadev, linux-kernel, eranian, wangnan0,
	alexander.shishkin, mhiramat, jpoimboe, adrian.hunter, ak,
	penberg, kan.liang, tumanova, acme, hpa, mingo, namhyung,
	hekuang, dsahern

Commit-ID:  403cacb8a25eb86d564750fce2293978814d2d15
Gitweb:     http://git.kernel.org/tip/403cacb8a25eb86d564750fce2293978814d2d15
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:14 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:52 -0300

perf unwind: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS

LIBUNWIND_LIBS contains libunwind libraries used for local only, don't
mix this into LIBUNWIND_LDFLAGS so we can later use LIBUNWIND_LDFLAGS
both for local and remote libunwind.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-6-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/config/Makefile | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 6f9f566..118df2d 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -80,13 +80,12 @@ ifdef LIBUNWIND_DIR
   LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64
   $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
 endif
-LIBUNWIND_LDFLAGS += $(LIBUNWIND_LIBS)
 
 # Set per-feature check compilation flags
 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS)
+FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
-FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS)
+FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
 
 ifeq ($(NO_PERF_REGS),0)
   CFLAGS += -DHAVE_PERF_REGS_SUPPORT
@@ -409,7 +408,7 @@ ifndef NO_LIBUNWIND
   CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
   EXTLIBS += $(LIBUNWIND_LIBS)
   CFLAGS  += $(LIBUNWIND_CFLAGS)
-  LDFLAGS += $(LIBUNWIND_LDFLAGS)
+  LDFLAGS += $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
 endif
 
 ifndef NO_LIBAUDIT

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

* [tip:perf/core] perf unwind: Separate local/remote libunwind config
  2016-06-03  3:33 ` [PATCH v9 06/14] perf tools: Separate local/remote libunwind config He Kuang
@ 2016-06-08  8:47   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:47 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tumanova, wangnan0, hekuang, acme, hpa, kan.liang, dsahern,
	jolsa, linux-kernel, sukadev, peterz, alexander.shishkin,
	adrian.hunter, tglx, mingo, jpoimboe, namhyung, ak, mhiramat,
	eranian, penberg

Commit-ID:  9d8e14d306ef2f5daf2fd099ef07c39dd83e2c0d
Gitweb:     http://git.kernel.org/tip/9d8e14d306ef2f5daf2fd099ef07c39dd83e2c0d
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:15 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:52 -0300

perf unwind: Separate local/remote libunwind config

CONFIG_LIBUNWIND/NO_LIBUNWIND are changed to CONFIG_LOCAL_LIBUNWIND/
NO_LOCAL_LIBUNWIND for retaining local unwind features. The new
CONFIG_LIBUNWIND stands for either local or remote or both unwind are
supported, and NO_LIBUNWIND means that neither local nor remote unwind
is supported.

LIBUNWIND_LIBS is eliminated in LDFLAGS if local libunwind is not
supported.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-7-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/arm/util/Build   |  2 +-
 tools/perf/arch/arm64/util/Build |  2 +-
 tools/perf/arch/x86/util/Build   |  2 +-
 tools/perf/config/Makefile       | 20 +++++++++++++++++---
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/tools/perf/arch/arm/util/Build b/tools/perf/arch/arm/util/Build
index d22e3d0..f98da17 100644
--- a/tools/perf/arch/arm/util/Build
+++ b/tools/perf/arch/arm/util/Build
@@ -1,4 +1,4 @@
 libperf-$(CONFIG_DWARF) += dwarf-regs.o
 
-libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
+libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind.o
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build
index e58123a8..02f41db 100644
--- a/tools/perf/arch/arm64/util/Build
+++ b/tools/perf/arch/arm64/util/Build
@@ -1,2 +1,2 @@
 libperf-$(CONFIG_DWARF)     += dwarf-regs.o
-libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o
+libperf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build
index 4cd8a16..f95e6f4 100644
--- a/tools/perf/arch/x86/util/Build
+++ b/tools/perf/arch/x86/util/Build
@@ -8,7 +8,7 @@ libperf-y += group.o
 libperf-$(CONFIG_DWARF) += dwarf-regs.o
 libperf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o
 
-libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
+libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind.o
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 
 libperf-$(CONFIG_AUXTRACE) += auxtrace.o
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 118df2d..3918687 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -353,10 +353,20 @@ ifeq ($(ARCH),powerpc)
 endif
 
 ifndef NO_LIBUNWIND
+  have_libunwind :=
   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
+    $(call detected,CONFIG_LOCAL_LIBUNWIND)
+  endif
+
+  ifneq ($(have_libunwind), 1)
     NO_LIBUNWIND := 1
   endif
+else
+  NO_LOCAL_LIBUNWIND := 1
 endif
 
 ifndef NO_LIBBPF
@@ -394,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)
@@ -405,10 +415,14 @@ 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)
+  LDFLAGS += $(LIBUNWIND_LIBS)
+endif
+
+ifndef NO_LIBUNWIND
+  CFLAGS  += -DHAVE_LIBUNWIND_SUPPORT
   CFLAGS  += $(LIBUNWIND_CFLAGS)
-  LDFLAGS += $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
+  LDFLAGS += $(LIBUNWIND_LDFLAGS)
 endif
 
 ifndef NO_LIBAUDIT

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

* [tip:perf/core] perf unwind: Rename unwind-libunwind.c to unwind-libunwind-local.c
  2016-06-03  3:33 ` [PATCH v9 07/14] perf tools: Rename unwind-libunwind.c to unwind-libunwind-local.c He Kuang
@ 2016-06-08  8:48   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, dsahern, tglx, kan.liang, hekuang, penberg,
	eranian, hpa, linux-kernel, tumanova, adrian.hunter, jolsa,
	mhiramat, namhyung, sukadev, acme, wangnan0, mingo, jpoimboe,
	peterz, ak

Commit-ID:  a597b547d6a599b088e3789a9095bd9bf2b28aaa
Gitweb:     http://git.kernel.org/tip/a597b547d6a599b088e3789a9095bd9bf2b28aaa
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:16 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:53 -0300

perf unwind: Rename unwind-libunwind.c to unwind-libunwind-local.c

Since unwind-libunwind.c contains code for specific arithecture, we
change it's name to unwind-libunwind-local.c, and let it only be built
if local libunwind is supported.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-8-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/Build                                            | 2 +-
 tools/perf/util/{unwind-libunwind.c => unwind-libunwind-local.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8c6c8a0..5e23d85 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-local.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind-local.c
similarity index 100%
rename from tools/perf/util/unwind-libunwind.c
rename to tools/perf/util/unwind-libunwind-local.c

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

* [tip:perf/core] perf tools: Extract common API out of unwind-libunwind-local.c
  2016-06-03  3:33 ` [PATCH v9 08/14] perf tools: Extract common API out of unwind-libunwind-local.c He Kuang
@ 2016-06-08  8:48   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:48 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dsahern, wangnan0, linux-kernel, jpoimboe, hpa, kan.liang, tglx,
	mhiramat, tumanova, hekuang, mingo, eranian, alexander.shishkin,
	adrian.hunter, peterz, sukadev, acme, namhyung, ak, penberg,
	jolsa

Commit-ID:  f6d725324ab281880a0b736df5812e3a1e807779
Gitweb:     http://git.kernel.org/tip/f6d725324ab281880a0b736df5812e3a1e807779
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:17 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:53 -0300

perf tools: Extract common API out of unwind-libunwind-local.c

This patch extracts common unwind-libunwind APIs out of
unwind-libunwind-local.c, this part will be used by both local and
remote libunwind.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-9-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/Build                    |  1 +
 tools/perf/util/unwind-libunwind-local.c | 34 ----------------------------
 tools/perf/util/unwind-libunwind.c       | 38 ++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 5e23d85..004fb1d 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_LOCAL_LIBUNWIND)    += unwind-libunwind-local.o
+libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index b0c5db1..9c70486 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -691,37 +691,3 @@ _unwind_libunwind_ops = {
 
 struct unwind_libunwind_ops *
 local_unwind_libunwind_ops = &_unwind_libunwind_ops;
-
-static void unwind__register_ops(struct thread *thread,
-				 struct unwind_libunwind_ops *ops)
-{
-	thread->unwind_libunwind_ops = ops;
-}
-
-int unwind__prepare_access(struct thread *thread)
-{
-	unwind__register_ops(thread, local_unwind_libunwind_ops);
-
-	return thread->unwind_libunwind_ops->prepare_access(thread);
-}
-
-void unwind__flush_access(struct thread *thread)
-{
-	if (thread->unwind_libunwind_ops)
-		thread->unwind_libunwind_ops->flush_access(thread);
-}
-
-void unwind__finish_access(struct thread *thread)
-{
-	if (thread->unwind_libunwind_ops)
-		thread->unwind_libunwind_ops->finish_access(thread);
-}
-
-int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
-			 struct thread *thread,
-			 struct perf_sample *data, int max_stack)
-{
-	if (thread->unwind_libunwind_ops)
-		return thread->unwind_libunwind_ops->get_entries(cb, arg, thread, data, max_stack);
-	return 0;
-}
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
new file mode 100644
index 0000000..f86f903
--- /dev/null
+++ b/tools/perf/util/unwind-libunwind.c
@@ -0,0 +1,38 @@
+#include "unwind.h"
+#include "thread.h"
+
+struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
+
+static void unwind__register_ops(struct thread *thread,
+			  struct unwind_libunwind_ops *ops)
+{
+	thread->unwind_libunwind_ops = ops;
+}
+
+int unwind__prepare_access(struct thread *thread)
+{
+	unwind__register_ops(thread, local_unwind_libunwind_ops);
+
+	return thread->unwind_libunwind_ops->prepare_access(thread);
+}
+
+void unwind__flush_access(struct thread *thread)
+{
+	if (thread->unwind_libunwind_ops)
+		thread->unwind_libunwind_ops->flush_access(thread);
+}
+
+void unwind__finish_access(struct thread *thread)
+{
+	if (thread->unwind_libunwind_ops)
+		thread->unwind_libunwind_ops->finish_access(thread);
+}
+
+int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
+			 struct thread *thread,
+			 struct perf_sample *data, int max_stack)
+{
+	if (thread->unwind_libunwind_ops)
+		return thread->unwind_libunwind_ops->get_entries(cb, arg, thread, data, max_stack);
+	return 0;
+}

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

* [tip:perf/core] perf tools: Export normalize_arch() function
  2016-06-03  3:33 ` [PATCH v9 09/14] perf tools: Export normalize_arch() function He Kuang
@ 2016-06-08  8:49   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, hekuang, sukadev, dsahern, adrian.hunter, jpoimboe,
	peterz, tumanova, jolsa, alexander.shishkin, acme, namhyung, hpa,
	linux-kernel, penberg, wangnan0, kan.liang, eranian, mhiramat,
	ak, tglx

Commit-ID:  940e6987fcfb6092cda8f2f87f2937c55fa038c4
Gitweb:     http://git.kernel.org/tip/940e6987fcfb6092cda8f2f87f2937c55fa038c4
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:18 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 12:08:53 -0300

perf tools: Export normalize_arch() function

Export normalize_arch() function, so other part of perf can get
normalized form of arch string.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-10-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/common.c | 2 +-
 tools/perf/arch/common.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

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 */

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

* [tip:perf/core] perf unwind: Check the target platform before assigning unwind methods
  2016-06-03  3:33 ` [PATCH v9 10/14] perf tools: Check the target platform before assigning unwind methods He Kuang
  2016-06-04  5:36   ` [PATCH v9 10/14 UPDATE] " He Kuang
@ 2016-06-08  8:49   ` tip-bot for He Kuang
  1 sibling, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: sukadev, eranian, hekuang, linux-kernel, kan.liang, mingo,
	peterz, namhyung, dsahern, mhiramat, penberg, wangnan0, tglx,
	acme, ak, tumanova, adrian.hunter, jolsa, alexander.shishkin,
	hpa, jpoimboe

Commit-ID:  d64ec10ec8b43a519f132e7c33c1815a4e86949e
Gitweb:     http://git.kernel.org/tip/d64ec10ec8b43a519f132e7c33c1815a4e86949e
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:19 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 15:09:36 -0300

perf unwind: Check the target platform before assigning unwind methods

Currently, 'perf script' uses host unwind methods to parse perf.data
callchain info without taking the target architecture into account, i.e.
assuming the perf.data file was generated on the same machine where the
analysis is being performed. So we get wrong result without any warnings
when unwinding callchains of x86(32-bit) on x86(64-bit) machine.

This patch adds an extra step that checks the target platform before
assigning unwind methods. In later patches in this series, we can use
this info to assign the right unwind methods for supported platforms.

Committer note:

After fixing it to register the local unwinder for live mode tools
('perf trace', 'perf top'), i.e. tools that don't use a perf.data file,
it works as intended and passes the 'perf test unwind' test:

  # perf trace -e nanosleep --call dwarf usleep 1
     0.328 ( 0.058 ms): usleep/11115 nanosleep(rqtp: 0x7fff083fa480) = 0
                                       __nanosleep_nocancel+0x7 (/usr/lib64/libc-2.22.so)
                                       usleep+0x34 (/usr/lib64/libc-2.22.so)
                                       main+0x1eb (/usr/bin/usleep)
                                       __libc_start_main+0xf0 (/usr/lib64/libc-2.22.so)
                                       _start+0x29 (/usr/bin/usleep)
  # perf test 48
  48: Test dwarf unwind         : Ok
  #

Signed-off-by: He Kuang <hekuang@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-11-git-send-email-hekuang@huawei.com
[ Fixed exit path for 'live' mode tools, where we need to default to local unwinding ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/thread.c           |  2 +-
 tools/perf/util/unwind-libunwind.c | 25 ++++++++++++++++++++++++-
 tools/perf/util/unwind.h           |  8 +++++---
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 0bf55256..f30f956 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -202,7 +202,7 @@ int thread__insert_map(struct thread *thread, struct map *map)
 {
 	int ret;
 
-	ret = unwind__prepare_access(thread);
+	ret = unwind__prepare_access(thread, map);
 	if (ret)
 		return ret;
 
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index f86f903..0086726 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -1,5 +1,8 @@
 #include "unwind.h"
 #include "thread.h"
+#include "session.h"
+#include "debug.h"
+#include "arch/common.h"
 
 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
 
@@ -9,8 +12,28 @@ static void unwind__register_ops(struct thread *thread,
 	thread->unwind_libunwind_ops = ops;
 }
 
-int unwind__prepare_access(struct thread *thread)
+int unwind__prepare_access(struct thread *thread, struct map *map)
 {
+	const char *arch;
+	enum dso_type dso_type;
+
+	if (thread->addr_space) {
+		pr_debug("unwind: thread map already set, dso=%s\n",
+			 map->dso->name);
+		return 0;
+	}
+
+	/* env->arch is NULL for live-mode (i.e. perf top) */
+	if (!thread->mg->machine->env || !thread->mg->machine->env->arch)
+		goto out_register;
+
+	dso_type = dso__type(map->dso, thread->mg->machine);
+	if (dso_type == DSO__TYPE_UNKNOWN)
+		return 0;
+
+	arch = normalize_arch(thread->mg->machine->env->arch);
+	pr_debug("unwind: target platform=%s\n", arch);
+out_register:
 	unwind__register_ops(thread, local_unwind_libunwind_ops);
 
 	return thread->unwind_libunwind_ops->prepare_access(thread);
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index bbd73d9..bf9f593 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -30,11 +30,12 @@ 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);
+int unwind__prepare_access(struct thread *thread, struct map *map);
 void unwind__flush_access(struct thread *thread);
 void unwind__finish_access(struct thread *thread);
 #else
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
+static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
+					 struct map *map __maybe_unused)
 {
 	return 0;
 }
@@ -53,7 +54,8 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
 	return 0;
 }
 
-static inline int unwind__prepare_access(struct thread *thread __maybe_unused)
+static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
+					 struct map *map __maybe_unused)
 {
 	return 0;
 }

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

* [tip:perf/core] perf unwind: Change fixed name of libunwind__arch_reg_id to macro
  2016-06-03  3:33 ` [PATCH v9 11/14] perf tools: Change fixed name of libunwind__arch_reg_id to macro He Kuang
@ 2016-06-08  8:50   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: adrian.hunter, sukadev, linux-kernel, ak, tumanova, wangnan0,
	jolsa, mingo, hpa, tglx, eranian, mhiramat, dsahern,
	alexander.shishkin, jpoimboe, peterz, hekuang, kan.liang, acme,
	penberg, namhyung

Commit-ID:  eeb118c5d77878948e09308afe4fd9d0efe68ef7
Gitweb:     http://git.kernel.org/tip/eeb118c5d77878948e09308afe4fd9d0efe68ef7
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:20 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 15:11:46 -0300

perf unwind: Change fixed name of libunwind__arch_reg_id to macro

For local libunwind, it uses the fixed methods to convert register id
according to the host platform, but in remote libunwind, this convert
function should be the one for remote architecture. This patch changes
the fixed name to macro and code for each remote platform can be
compiled indivadually.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-12-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/unwind-libunwind-local.c | 2 +-
 tools/perf/util/unwind.h                 | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 9c70486..631b40d 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -508,7 +508,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 bf9f593..b074662 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -29,7 +29,10 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct perf_sample *data, int max_stack);
 /* libunwind specific */
 #ifdef HAVE_LIBUNWIND_SUPPORT
-int libunwind__arch_reg_id(int regnum);
+#ifndef LIBUNWIND__ARCH_REG_ID
+#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
+#endif
+int LIBUNWIND__ARCH_REG_ID(int regnum);
 int unwind__prepare_access(struct thread *thread, struct map *map);
 void unwind__flush_access(struct thread *thread);
 void unwind__finish_access(struct thread *thread);

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

* [tip:perf/core] perf unwind: Introduce flag to separate local/remote unwind compilation
  2016-06-03  3:33 ` [PATCH v9 12/14] perf tools: Introduce flag to separate local/remote unwind compilation He Kuang
@ 2016-06-08  8:50   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, acme, namhyung, eranian, ak, jpoimboe,
	adrian.hunter, tumanova, alexander.shishkin, mingo, mhiramat,
	dsahern, kan.liang, wangnan0, peterz, jolsa, hpa, tglx, sukadev,
	penberg, hekuang

Commit-ID:  19473e7ba8f8f443f09d4187791de9d6f95fdc1d
Gitweb:     http://git.kernel.org/tip/19473e7ba8f8f443f09d4187791de9d6f95fdc1d
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:21 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 15:11:46 -0300

perf unwind: Introduce flag to separate local/remote unwind compilation

This is a preparation for including unwind-libunwind-local.c in other
files for remote libunwind.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-13-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/unwind-libunwind-local.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c
index 631b40d..01c2e86 100644
--- a/tools/perf/util/unwind-libunwind-local.c
+++ b/tools/perf/util/unwind-libunwind-local.c
@@ -22,8 +22,10 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <linux/list.h>
+#ifndef REMOTE_UNWIND_LIBUNWIND
 #include <libunwind.h>
 #include <libunwind-ptrace.h>
+#endif
 #include "callchain.h"
 #include "thread.h"
 #include "session.h"
@@ -689,5 +691,7 @@ _unwind_libunwind_ops = {
 	.get_entries    = _unwind__get_entries,
 };
 
+#ifndef REMOTE_UNWIND_LIBUNWIND
 struct unwind_libunwind_ops *
 local_unwind_libunwind_ops = &_unwind_libunwind_ops;
+#endif

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

* [tip:perf/core] perf callchain: Support x86 target platform
  2016-06-03  3:33 ` [PATCH v9 13/14] perf callchain: Support x86 target platform He Kuang
@ 2016-06-08  8:51   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:51 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: penberg, alexander.shishkin, mhiramat, wangnan0, ak, jolsa,
	tumanova, eranian, jpoimboe, namhyung, kan.liang, hekuang, acme,
	peterz, tglx, linux-kernel, sukadev, mingo, adrian.hunter,
	dsahern, hpa

Commit-ID:  52ffe0ff02fc053a025c381d5808e9ecd3206dfe
Gitweb:     http://git.kernel.org/tip/52ffe0ff02fc053a025c381d5808e9ecd3206dfe
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:22 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 15:13:27 -0300

perf callchain: Support x86 target platform

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

Signed-off-by: He Kuang <hekuang@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-14-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/x86/util/unwind-libunwind.c |  6 +++--
 tools/perf/config/Makefile                  |  8 +++++++
 tools/perf/util/Build                       |  1 +
 tools/perf/util/libunwind/x86_32.c          | 37 +++++++++++++++++++++++++++++
 tools/perf/util/unwind-libunwind.c          | 15 ++++++++++--
 5 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/tools/perf/arch/x86/util/unwind-libunwind.c b/tools/perf/arch/x86/util/unwind-libunwind.c
index db25e93..4f16661 100644
--- a/tools/perf/arch/x86/util/unwind-libunwind.c
+++ b/tools/perf/arch/x86/util/unwind-libunwind.c
@@ -1,12 +1,14 @@
 
+#ifndef REMOTE_UNWIND_LIBUNWIND
 #include <errno.h>
 #include <libunwind.h>
 #include "perf_regs.h"
 #include "../../util/unwind.h"
 #include "../../util/debug.h"
+#endif
 
 #ifdef HAVE_ARCH_X86_64_SUPPORT
-int libunwind__arch_reg_id(int regnum)
+int LIBUNWIND__ARCH_REG_ID(int regnum)
 {
 	int id;
 
@@ -70,7 +72,7 @@ int libunwind__arch_reg_id(int regnum)
 	return id;
 }
 #else
-int libunwind__arch_reg_id(int regnum)
+int LIBUNWIND__ARCH_REG_ID(int regnum)
 {
 	int id;
 
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 3918687..34999fb 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -354,6 +354,14 @@ endif
 
 ifndef NO_LIBUNWIND
   have_libunwind :=
+
+  ifeq ($(feature-libunwind-x86), 1)
+    $(call detected,CONFIG_LIBUNWIND_X86)
+    CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
+    LDFLAGS += -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
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 004fb1d..7746e09 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -101,6 +101,7 @@ libperf-$(CONFIG_DWARF) += dwarf-aux.o
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind-local.o
 libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
+libperf-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/libunwind/x86_32.c b/tools/perf/util/libunwind/x86_32.c
new file mode 100644
index 0000000..d98c17e
--- /dev/null
+++ b/tools/perf/util/libunwind/x86_32.c
@@ -0,0 +1,37 @@
+/*
+ * This file setups defines to compile arch specific binary from the
+ * generic one.
+ *
+ * The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch
+ * name and the defination of this function is included directly from
+ * 'arch/x86/util/unwind-libunwind.c', to make sure that this function
+ * is defined no matter what arch the host is.
+ *
+ * Finally, the arch specific unwind methods are exported which will
+ * be assigned to each x86 thread.
+ */
+
+#define REMOTE_UNWIND_LIBUNWIND
+#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__x86_reg_id(regnum)
+
+#include "unwind.h"
+#include "debug.h"
+#include "libunwind-x86.h"
+#include <../../../../arch/x86/include/uapi/asm/perf_regs.h>
+
+/* HAVE_ARCH_X86_64_SUPPORT is used in'arch/x86/util/unwind-libunwind.c'
+ * for x86_32, we undef it to compile code for x86_32 only.
+ */
+#undef HAVE_ARCH_X86_64_SUPPORT
+#include "../../arch/x86/util/unwind-libunwind.c"
+
+/* Explicitly define NO_LIBUNWIND_DEBUG_FRAME, because non-ARM has no
+ * dwarf_find_debug_frame() function.
+ */
+#ifndef NO_LIBUNWIND_DEBUG_FRAME
+#define NO_LIBUNWIND_DEBUG_FRAME
+#endif
+#include "util/unwind-libunwind-local.c"
+
+struct unwind_libunwind_ops *
+x86_32_unwind_libunwind_ops = &_unwind_libunwind_ops;
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index 0086726..e65515a 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -5,6 +5,7 @@
 #include "arch/common.h"
 
 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
+struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
 
 static void unwind__register_ops(struct thread *thread,
 			  struct unwind_libunwind_ops *ops)
@@ -16,6 +17,7 @@ int unwind__prepare_access(struct thread *thread, struct map *map)
 {
 	const char *arch;
 	enum dso_type dso_type;
+	struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
 
 	if (thread->addr_space) {
 		pr_debug("unwind: thread map already set, dso=%s\n",
@@ -32,9 +34,18 @@ int unwind__prepare_access(struct thread *thread, struct map *map)
 		return 0;
 
 	arch = normalize_arch(thread->mg->machine->env->arch);
-	pr_debug("unwind: target platform=%s\n", arch);
+
+	if (!strcmp(arch, "x86")) {
+		if (dso_type != DSO__TYPE_64BIT)
+			ops = x86_32_unwind_libunwind_ops;
+	}
+
+	if (!ops) {
+		pr_err("unwind: target platform=%s is not supported\n", arch);
+		return -1;
+	}
 out_register:
-	unwind__register_ops(thread, local_unwind_libunwind_ops);
+	unwind__register_ops(thread, ops);
 
 	return thread->unwind_libunwind_ops->prepare_access(thread);
 }

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

* [tip:perf/core] perf callchain: Support aarch64 cross-platform
  2016-06-03  3:33 ` [PATCH v9 14/14] perf callchain: Support aarch64 cross-platform He Kuang
@ 2016-06-08  8:51   ` tip-bot for He Kuang
  0 siblings, 0 replies; 40+ messages in thread
From: tip-bot for He Kuang @ 2016-06-08  8:51 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, alexander.shishkin, eranian, tumanova, jpoimboe,
	kan.liang, acme, hpa, adrian.hunter, penberg, jolsa, mhiramat,
	namhyung, sukadev, ak, wangnan0, peterz, tglx, hekuang, dsahern,
	mingo

Commit-ID:  057fbfb25cde4a368418f3f720cdc31d48800c4d
Gitweb:     http://git.kernel.org/tip/057fbfb25cde4a368418f3f720cdc31d48800c4d
Author:     He Kuang <hekuang@huawei.com>
AuthorDate: Fri, 3 Jun 2016 03:33:23 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 15:13:35 -0300

perf callchain: Support aarch64 cross-platform

Support aarch64 cross platform callchain unwind.

Signed-off-by: He Kuang <hekuang@huawei.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: David Ahern <dsahern@gmail.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 <mhiramat@kernel.org>
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/1464924803-22214-15-git-send-email-hekuang@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/arch/arm64/util/unwind-libunwind.c |  4 ++-
 tools/perf/config/Makefile                    | 12 +++++++++
 tools/perf/util/Build                         |  1 +
 tools/perf/util/libunwind/arm64.c             | 35 +++++++++++++++++++++++++++
 tools/perf/util/unwind-libunwind.c            |  4 +++
 5 files changed, 55 insertions(+), 1 deletion(-)

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/config/Makefile b/tools/perf/config/Makefile
index 34999fb..47e8f58 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -362,6 +362,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/Build b/tools/perf/util/Build
index 7746e09..fced833 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -102,6 +102,7 @@ libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
 libperf-$(CONFIG_LOCAL_LIBUNWIND)    += unwind-libunwind-local.o
 libperf-$(CONFIG_LIBUNWIND)          += unwind-libunwind.o
 libperf-$(CONFIG_LIBUNWIND_X86)      += libunwind/x86_32.o
+libperf-$(CONFIG_LIBUNWIND_AARCH64)  += libunwind/arm64.o
 
 libperf-$(CONFIG_LIBBABELTRACE) += data-convert-bt.o
 
diff --git a/tools/perf/util/libunwind/arm64.c b/tools/perf/util/libunwind/arm64.c
new file mode 100644
index 0000000..4fb5395
--- /dev/null
+++ b/tools/perf/util/libunwind/arm64.c
@@ -0,0 +1,35 @@
+/*
+ * This file setups defines to compile arch specific binary from the
+ * generic one.
+ *
+ * The function 'LIBUNWIND__ARCH_REG_ID' name is set according to arch
+ * name and the defination of this function is included directly from
+ * 'arch/arm64/util/unwind-libunwind.c', to make sure that this function
+ * is defined no matter what arch the host is.
+ *
+ * Finally, the arch specific unwind methods are exported which will
+ * be assigned to each arm64 thread.
+ */
+
+#define REMOTE_UNWIND_LIBUNWIND
+
+#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arm64_reg_id(regnum)
+
+#include "unwind.h"
+#include "debug.h"
+#include "libunwind-aarch64.h"
+#include <../../../../arch/arm64/include/uapi/asm/perf_regs.h>
+#include "../../arch/arm64/util/unwind-libunwind.c"
+
+/* NO_LIBUNWIND_DEBUG_FRAME is a feature flag for local libunwind,
+ * assign NO_LIBUNWIND_DEBUG_FRAME_AARCH64 to it for compiling arm64
+ * unwind methods.
+ */
+#undef NO_LIBUNWIND_DEBUG_FRAME
+#ifdef NO_LIBUNWIND_DEBUG_FRAME_AARCH64
+#define NO_LIBUNWIND_DEBUG_FRAME
+#endif
+#include "util/unwind-libunwind-local.c"
+
+struct unwind_libunwind_ops *
+arm64_unwind_libunwind_ops = &_unwind_libunwind_ops;
diff --git a/tools/perf/util/unwind-libunwind.c b/tools/perf/util/unwind-libunwind.c
index e65515a..8547119 100644
--- a/tools/perf/util/unwind-libunwind.c
+++ b/tools/perf/util/unwind-libunwind.c
@@ -6,6 +6,7 @@
 
 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
 struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
+struct unwind_libunwind_ops __weak *arm64_unwind_libunwind_ops;
 
 static void unwind__register_ops(struct thread *thread,
 			  struct unwind_libunwind_ops *ops)
@@ -38,6 +39,9 @@ int unwind__prepare_access(struct thread *thread, struct map *map)
 	if (!strcmp(arch, "x86")) {
 		if (dso_type != DSO__TYPE_64BIT)
 			ops = x86_32_unwind_libunwind_ops;
+	} else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
+		if (dso_type == DSO__TYPE_64BIT)
+			ops = arm64_unwind_libunwind_ops;
 	}
 
 	if (!ops) {

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

end of thread, other threads:[~2016-06-08  8:52 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03  3:33 [PATCH v9 00/14] Add support for remote unwind He Kuang
2016-06-03  3:33 ` [PATCH v9 01/14] perf tools: Use LIBUNWIND_DIR for remote libunwind feature check He Kuang
2016-06-08  8:45   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 02/14] perf tools: Decouple thread->address_space on libunwind He Kuang
2016-06-08  8:46   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 03/14] perf tools: Introducing struct unwind_libunwind_ops for local unwind He Kuang
2016-06-08  8:46   ` [tip:perf/core] perf unwind: Introduce 'struct unwind_libunwind_ops' " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 04/14] perf tools: Move unwind__prepare_access from thread_new into thread__insert_map He Kuang
2016-06-08  8:47   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 05/14] perf tools: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS He Kuang
2016-06-08  8:47   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 06/14] perf tools: Separate local/remote libunwind config He Kuang
2016-06-08  8:47   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 07/14] perf tools: Rename unwind-libunwind.c to unwind-libunwind-local.c He Kuang
2016-06-08  8:48   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 08/14] perf tools: Extract common API out of unwind-libunwind-local.c He Kuang
2016-06-08  8:48   ` [tip:perf/core] " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 09/14] perf tools: Export normalize_arch() function He Kuang
2016-06-08  8:49   ` [tip:perf/core] " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 10/14] perf tools: Check the target platform before assigning unwind methods He Kuang
2016-06-04  5:36   ` [PATCH v9 10/14 UPDATE] " He Kuang
2016-06-07 18:06     ` Arnaldo Carvalho de Melo
2016-06-08  8:49   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 11/14] perf tools: Change fixed name of libunwind__arch_reg_id to macro He Kuang
2016-06-08  8:50   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 12/14] perf tools: Introduce flag to separate local/remote unwind compilation He Kuang
2016-06-08  8:50   ` [tip:perf/core] perf unwind: " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 13/14] perf callchain: Support x86 target platform He Kuang
2016-06-08  8:51   ` [tip:perf/core] " tip-bot for He Kuang
2016-06-03  3:33 ` [PATCH v9 14/14] perf callchain: Support aarch64 cross-platform He Kuang
2016-06-08  8:51   ` [tip:perf/core] " tip-bot for He Kuang
2016-06-03  7:06 ` [PATCH v9 00/14] Add support for remote unwind Jiri Olsa
2016-06-03 19:42   ` Arnaldo Carvalho de Melo
2016-06-03 21:06     ` Arnaldo Carvalho de Melo
2016-06-03 21:09       ` Arnaldo Carvalho de Melo
2016-06-04  5:39         ` Hekuang
2016-06-07 15:12           ` Arnaldo Carvalho de Melo
2016-06-07 15:14             ` Arnaldo Carvalho de Melo
2016-06-07 19:44   ` Arnaldo Carvalho de Melo
2016-06-08  7:33     ` Hekuang

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