Add support for remote unwind
Subsystems (2)
v8 cover Add support for remote unwind
v7 url:
http://thread.gmane.org/gmane.linux.kernel/2231229/focus=2232166
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.
v8:
- Put unwind__register_ops call into unwind__prepare_access from patch 4 to patch 3.
- Fail thread__insert_map on error.
- Remove unused macro HAVE_LIBUNWIND_LOCAL_SUPPORT.
- Return once find that thread->addr_space is valid and check this value first.
- Add comments in file 'util/libunwind/arm64.c', 'util/libunwind/x86_32.c', and explain the reason for debug-frame flag in non-arm arch.
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 | 691 ++----------------------- tools/perf/util/unwind.h | 27 +- 17 files changed, 924 insertions(+), 673 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
Signature · 1 line
1.8.5.2
PATCH v8 1/14 perf tools: 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.
--- tools/perf/config/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+)
tools/perf/config/Makefile +9 -0
@@ -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)
Signature · 1 line
1.8.5.2
PATCH v8 2/14 perf tools: Decouple thread->address_space on libunwind
In reply to He KuangCurrently, 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.
--- tools/perf/util/thread.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/thread.h +1 -4
@@ -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 };
Signature · 1 line
1.8.5.2
PATCH v8 3/14 perf tools: Introducing struct unwind_libunwind_ops for local unwind
In reply to He KuangCurrently, 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.
--- tools/perf/util/thread.h | 4 ++- tools/perf/util/unwind-libunwind.c | 57 +++++++++++++++++++++++++++++++++++--- tools/perf/util/unwind.h | 19 +++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-)
tools/perf/util/thread.h +3 -1
@@ -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 };
tools/perf/util/unwind-libunwind.c +53 -4
84 lines not on this page · raw message
tools/perf/util/unwind.h +19 -0
@@ -14,6 +14,17 @@ struct unwind_entry {typedef int (*unwind_entry_cb_t )(struct unwind_entry *entry,void *arg); +struct unwind_libunwind_ops { +int (*prepare_access)(struct thread *thread); +void (*flush_access)(struct thread *thread); +void (*finish_access)(struct thread *thread); +int (*get_entries)(unwind_entry_cb_t cb,void *arg, +struct thread *thread, +struct perf_sample *data,int max_stack); +}; + +struct unwind_libunwind_ops *local_unwind_libunwind_ops; +#ifdef HAVE_DWARF_UNWIND_SUPPORT int unwind__get_entries(unwind_entry_cb_t cb, void *arg, struct thread *thread,
@@ -24,6 +35,8 @@ int libunwind__arch_reg_id(int regnum);int unwind__prepare_access (struct thread *thread);void unwind__flush_access (struct thread *thread);void unwind__finish_access (struct thread *thread); +void unwind__register_ops (struct thread *thread, +struct unwind_libunwind_ops *ops);#else static inline int unwind__prepare_access (struct thread *thread__maybe_unused ) {
@@ -32,6 +45,9 @@ static inline int unwind__prepare_access(struct thread *thread __maybe_unused)static inline void unwind__flush_access (struct thread *thread__maybe_unused ) {}static inline void unwind__finish_access (struct thread *thread__maybe_unused ) {} +static inline void +unwind__register_ops (struct thread *thread__maybe_unused , +struct unwind_libunwind_ops *ops__maybe_unused ) {}#endif #else static inline int
@@ -51,5 +67,8 @@ static inline int unwind__prepare_access(struct thread *thread __maybe_unused)static inline void unwind__flush_access (struct thread *thread__maybe_unused ) {}static inline void unwind__finish_access (struct thread *thread__maybe_unused ) {} +static inline void +unwind__register_ops (struct thread *thread__maybe_unused , +struct unwind_libunwind_ops *ops__maybe_unused ) {}#endif /* HAVE_DWARF_UNWIND_SUPPORT */ #endif /* __UNWIND_H */
Signature · 1 line
1.8.5.2
Re: [PATCH v8 03/14] perf tools: Introducing struct unwind_libunwind_ops for local unwind
On Thu, Jun 02, 2016 at 09:55:15AM +0000, He Kuang wrote:
SNIP
Quoted 11 lines
tools/perf/util/unwind-libunwind.c +7
-0@@ -680,3 +680,52 @@ 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,
tools/perf/util/unwind-libunwind.c int unwind__get_entries(unwind_entry_cb_t cb, void *arg, · line 699
Quoted 10 lines
tools/perf/util/unwind-libunwind.c +10
-0+}; + +struct unwind_libunwind_ops * +local_unwind_libunwind_ops = &_unwind_libunwind_ops; + +void unwind__register_ops (struct thread *thread, +struct unwind_libunwind_ops *ops) +{ + thread->unwind_libunwind_ops = ops; +}
no need for unwind__register_ops to be global
please make it static
jirka
PATCH v8 4/14 perf tools: Move unwind__prepare_access from thread_new into thread__insert_map
In reply to He KuangFor 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.
--- 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(-)
tools/perf/util/machine.c +12 -2
@@ -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 *eventif (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:
tools/perf/util/thread.c +9 -4
@@ -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; +map_groups__fixup_overlappings (thread->mg, map, stderr);map_groups__insert (thread->mg, map); + + ret =unwind__prepare_access (thread); +if (ret) +map_groups__remove (thread->mg, map); + +return ret; } static int thread__clone_map_groups(struct thread *thread,
tools/perf/util/thread.h +1 -1
@@ -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);
Signature · 1 line
1.8.5.2
Re: [PATCH v8 04/14] perf tools: Move unwind__prepare_access from thread_new into thread__insert_map
On Thu, Jun 02, 2016 at 09:55:16AM +0000, He Kuang wrote:
SNIP
tools/perf/util/thread.c size_t thread__fprintf(struct thread *thread, FILE *fp) · line 210
Quoted 13 lines
}
tools/perf/util/thread.c +7
-1-void thread__insert_map (struct thread *thread,struct map *map) +int thread__insert_map (struct thread *thread,struct map *map) { +int ret; +map_groups__fixup_overlappings (thread->mg, map, stderr);map_groups__insert (thread->mg, map); + + ret =unwind__prepare_access (thread); +if (ret) +map_groups__remove (thread->mg, map);
we could move this call to the top and sve the call to map_groups__remove
jirka
PATCH v8 5/14 perf tools: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS
In reply to He KuangLIBUNWIND_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.
--- tools/perf/config/Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/config/Makefile +3 -4
@@ -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
Signature · 1 line
1.8.5.2
PATCH v8 6/14 perf tools: Separate local/remote libunwind config
In reply to He KuangCONFIG_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.
--- 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(-)
tools/perf/arch/arm/util/Build +1 -1
@@ -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
tools/perf/arch/arm64/util/Build +1 -1
@@ -1,2 +1,2 @@ libperf-$(CONFIG_DWARF) += dwarf-regs.o -libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o +libperf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
tools/perf/arch/x86/util/Build +1 -1
@@ -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
tools/perf/config/Makefile +17 -3
@@ -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
Signature · 1 line
1.8.5.2
PATCH v8 7/14 perf tools: Rename unwind-libunwind.c to unwind-libunwind-local.c
In reply to He KuangSince 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.
---
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%)tools/perf/util/Build +1 -1
@@ -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
tools/perf/util/unwind-libunwind-local.c renamed from tools/perf/util/unwind-libunwind.c +0 -0
Signature · 1 line
1.8.5.2
PATCH v8 8/14 perf tools: Extract common API out of unwind-libunwind-local.c
In reply to He KuangThis patch extracts common unwind-libunwind APIs out of unwind-libunwind-local.c, this part will be used by both local and remote libunwind.
--- tools/perf/util/Build | 1 + tools/perf/util/unwind-libunwind-local.c | 38 ----------------------------- tools/perf/util/unwind-libunwind.c | 42 ++++++++++++++++++++++++++++++++ tools/perf/util/unwind.h | 2 -- 4 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 tools/perf/util/unwind-libunwind.c
tools/perf/util/Build +1 -0
@@ -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
tools/perf/util/unwind-libunwind-local.c +0 -38
@@ -691,41 +691,3 @@ _unwind_libunwind_ops = {struct unwind_libunwind_ops * local_unwind_libunwind_ops = &_unwind_libunwind_ops; - -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 ; -}
tools/perf/util/unwind-libunwind.c new file +42 -0
42 lines not on this page · raw message
tools/perf/util/unwind.h +0 -2
@@ -23,8 +23,6 @@ struct unwind_libunwind_ops { struct perf_sample *data, int max_stack); }; -struct unwind_libunwind_ops *local_unwind_libunwind_ops; -#ifdef HAVE_DWARF_UNWIND_SUPPORT int unwind__get_entries(unwind_entry_cb_t cb, void *arg, struct thread *thread,
Signature · 1 line
1.8.5.2
Re: [PATCH v8 08/14] perf tools: Extract common API out of unwind-libunwind-local.c
On Thu, Jun 02, 2016 at 09:55:20AM +0000, He Kuang wrote:
SNIP
Quoted 5 lines
tools/perf/util/unwind-libunwind.c new file +5
-0+void unwind__finish_access (struct thread *thread) +{ +if (thread->unwind_libunwind_ops) + thread->unwind_libunwind_ops->finish_access (thread); +}
tools/perf/util/unwind-libunwind.c line 39
Quoted 10 lines
tools/perf/util/unwind-libunwind.c new file +10
-0+ +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);
please enclose both if and else paths into { }
there's a rule to do that for multiple line paths
thanks,
jirka
PATCH v8 9/14 perf tools: Export normalize_arch() function
In reply to He KuangExport normalize_arch() function, so other part of perf can get normalized form of arch string.
--- tools/perf/arch/common.c | 2 +- tools/perf/arch/common.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
tools/perf/arch/common.c +1 -1
@@ -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" ;
tools/perf/arch/common.h +1 -0
@@ -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 */
Signature · 1 line
1.8.5.2
PATCH v8 10/14 perf tools: Check the target platform before assigning unwind methods
In reply to He KuangCurrently, 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.
--- tools/perf/util/thread.c | 2 +- tools/perf/util/unwind-libunwind.c | 24 +++++++++++++++++++++++- tools/perf/util/unwind.h | 5 +++-- 3 files changed, 27 insertions(+), 4 deletions(-)
tools/perf/util/thread.c +1 -1
@@ -205,7 +205,7 @@ int thread__insert_map(struct thread *thread, struct map *map)map_groups__fixup_overlappings (thread->mg, map, stderr);map_groups__insert (thread->mg, map); - ret =unwind__prepare_access (thread); + ret =unwind__prepare_access (thread, map);if (ret)map_groups__remove (thread->mg, map);
tools/perf/util/unwind-libunwind.c +23 -1
@@ -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 @@ 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);
tools/perf/util/unwind.h +3 -2
@@ -30,13 +30,14 @@ 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);void unwind__register_ops (struct thread *thread,struct unwind_libunwind_ops *ops);#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 ; }
Signature · 1 line
1.8.5.2
PATCH v8 11/14 perf tools: Change fixed name of libunwind__arch_reg_id to macro
In reply to He KuangFor 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.
--- tools/perf/util/unwind-libunwind-local.c | 2 +- tools/perf/util/unwind.h | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/unwind-libunwind-local.c +1 -1
@@ -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 ;
tools/perf/util/unwind.h +4 -1
@@ -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);
Signature · 1 line
1.8.5.2
PATCH v8 12/14 perf tools: Introduce flag to separate local/remote unwind compilation
In reply to He KuangThis is a preparation for including unwind-libunwind-local.c in other files for remote libunwind.
--- tools/perf/util/unwind-libunwind-local.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/util/unwind-libunwind-local.c +4 -0
@@ -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
Signature · 1 line
1.8.5.2
PATCH v8 13/14 perf callchain: Support x86 target platform
In reply to He KuangSupport x86(32-bit) cross platform callchain unwind.
--- 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 | 14 +++++++++-- 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tools/perf/util/libunwind/x86_32.c
tools/perf/arch/x86/util/unwind-libunwind.c +4 -2
@@ -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;
tools/perf/config/Makefile +8 -0
@@ -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
tools/perf/util/Build +1 -0
@@ -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
tools/perf/util/libunwind/x86_32.c new file +37 -0
@@ -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;
tools/perf/util/unwind-libunwind.c +12 -2
@@ -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;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,17 @@ 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); }
Signature · 1 line
1.8.5.2
Re: [PATCH v8 13/14] perf callchain: Support x86 target platform
On Thu, Jun 02, 2016 at 09:55:25AM +0000, He Kuang wrote:
SNIP
tools/perf/util/unwind-libunwind.c int unwind__prepare_access(struct thread *thread, struct map *map) · line 39
Quoted 10 lines
tools/perf/util/unwind-libunwind.c +3
-2@@ -31,9 +33,17 @@ 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;
pleas enclose above into { }
thanks,
jirka
PATCH v8 14/14 perf callchain: Support aarch64 cross-platform
In reply to He KuangSupport aarch64 cross platform callchain unwind.
--- 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 | 7 +++++- 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tools/perf/util/libunwind/arm64.c
tools/perf/arch/arm64/util/unwind-libunwind.c +3 -1
@@ -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 :
tools/perf/config/Makefile +12 -0
@@ -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
tools/perf/util/Build +1 -0
@@ -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
tools/perf/util/libunwind/arm64.c new file +35 -0
@@ -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;
tools/perf/util/unwind-libunwind.c +6 -1
@@ -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;void unwind__register_ops (struct thread *thread,struct unwind_libunwind_ops *ops)
@@ -34,9 +35,13 @@ int unwind__prepare_access(struct thread *thread, struct map *map) arch =normalize_arch (thread->mg->machine->env->arch); -if (!strcmp (arch,"x86" )) +if (!strcmp (arch,"x86" )) {if (dso_type !=DSO__TYPE_64BIT ) 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) {pr_err ("unwind: target platform=%s is not supported\n" , arch);
Signature · 1 line
1.8.5.2
On Thu, Jun 02, 2016 at 09:55:12AM +0000, He Kuang wrote:
SNIP
Quoted 5 lines
and now we can use
LIBUNWIND_DIRto specific custom dirctories containing libunwind libs.v8:
Quoted 9 lines
- Put
unwind__register_opscall intounwind__prepare_accessfrom patch 4 to patch 3.
- Failthread__insert_mapon error.
- Remove unused macroHAVE_LIBUNWIND_LOCAL_SUPPORT.
- Return once find thatthread->addr_spaceis valid and check this value first.
- Add comments in file 'util/libunwind/arm64.c', 'util/libunwind/x86_32.c', and explain the reason for debug-frame flag in non-arm arch.
apart from few nitpicks, this looks ok to me
I tried with 32bit unwind under 64bits and it works nicely, plus 64bit unwind seems not to be broken as well ;-)
considerring those nitpicks solved:
thanks,
jirka