New attempt at adding an disassembler to perf v2
A native disassembler in perf is very useful, in particular with perf script to trace instruction streams, but also for other analysis. Previously I attempted to do this using the udis86 library, but that was rejected because:
- udis86 was not maintained anymore and lacking recent instructions
- udis86 is dynamically linked and gives a runtime dependency.
Doing this needs a full disassembler, not just a decoder, so the existing instruction decoder cannot be used without major changes.
This patchkit addresses these issues. Intel recently released an open source version of the XED disassembler library, which is used in many other Intel software. It is very well maintained, uptodate, and supports static linking, so there is no runtime dependency. This version adds XED support to perf, and uses it to implement assembler output in perf script. It also fixes a range of issues in the previous version, see the individual change logs.
Available ingit://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc.git perf/xed-4
v1: First post of XED version
v2: Change probing to not be default and support XED_DIR. Other cleanups based on review.
-Andi
PATCH 1/5 perf, tools: Add probing for xed
From: Andi Kleen <[email protected]>
Add autoprobing for the xed disassembler library.
Can be downloaded from https://github.com/intelxed/xed
v2: Hide. Require XED=1 to enable. Add XED_DIR
--- tools/build/Makefile.feature | 8 +++++--- tools/build/feature/Makefile | 8 ++++++-- tools/build/feature/test-all.c | 5 +++++ tools/build/feature/test-xed.c | 9 +++++++++ tools/perf/Makefile.config | 16 ++++++++++++++++ tools/perf/Makefile.perf | 3 +++ 6 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 tools/build/feature/test-xed.c
tools/build/Makefile.feature +5 -3
@@ -63,7 +63,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \ # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests
@@ -74,11 +74,12 @@ FEATURE_TESTS_EXTRA := \ cplus-demangle \ hello \ libbabeltrace \ + xed \ liberty \ liberty-z \ libunwind-debug-frame \ libunwind-debug-frame-arm \ - libunwind-debug-frame-aarch64 + libunwind-debug-frame-aarch64 FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
@@ -105,7 +106,7 @@ FEATURE_DISPLAY ?= \ zlib \ lzma \ get_cpuid \ - bpf + bpf # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. # If in the future we need per-feature checks/flags for features not
@@ -140,6 +141,7 @@ ifeq ($(feature-all), 1) $(call feature_check,compile-x32) $(call feature_check,bionic) $(call feature_check,libbabeltrace) + $(call feature_check,xed) else $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat))) endif
tools/build/feature/Makefile +6 -2
@@ -48,7 +48,8 @@ FILES= \ test-get_cpuid.bin \ test-sdt.bin \ test-cxx.bin \ - test-jvmti.bin + test-jvmti.bin \ + test-xed.bin FILES := $(addprefix $(OUTPUT),$(FILES))
@@ -68,7 +69,7 @@ __BUILDXX = $(CXX) $(CXXFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) ############################### $(OUTPUT)test-all.bin: - $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma + $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma -lxed $(OUTPUT)test-hello.bin: $(BUILD)
@@ -123,6 +124,9 @@ $(OUTPUT)test-numa_num_possible_cpus.bin: $(OUTPUT)test-libunwind.bin: $(BUILD) -lelf +$(OUTPUT)test-xed.bin: + $(BUILD) -lxed + $(OUTPUT)test-libunwind-debug-frame.bin: $(BUILD) -lelf $(OUTPUT)test-libunwind-x86.bin:
tools/build/feature/test-all.c +5 -0
@@ -149,6 +149,10 @@# include "test-sdt.c" #undef main +#define main main_test_xed +# include "test-xed.c" +#endif +int main (int argc,char *argv[]) {main_test_libpython ();
@@ -183,6 +187,7 @@ int main(int argc, char *argv[])main_test_bpf ();main_test_libcrypto ();main_test_sdt (); +main_test_xed ();return 0 ; }
tools/build/feature/test-xed.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <xed/xed-interface.h> +#include <xed/xed-decode.h> +#include <xed/xed-decoded-inst-api.h> + +int main (void ) +{ +xed_tables_init (); +return 0 ; +}
tools/perf/Makefile.config +16 -0
@@ -682,6 +682,22 @@ ifndef NO_ZLIB endif endif +ifdef XED + ifdef XED_DIR + FEATURE_CHECK_CFLAGS-xed := -I $(XED_DIR)/include + # override for lib64? + FEATURE_CHECK_LDFLAGS-xed := -L $(XED_DIR)/lib -lxed + else + FEATURE_CHECK_CFLAGS-xed := + FEATURE_CHECK_LDFLAGS-xed := -lxed + endif + $(call feature_check,xed) + ifeq ($(feature-xed), 1) + EXTLIBS += -lxed + $(call detected,CONFIG_XED) + endif +endif + ifndef NO_LZMA ifeq ($(feature-lzma), 1) CFLAGS += -DHAVE_LZMA_SUPPORT
tools/perf/Makefile.perf +3 -0
@@ -84,6 +84,9 @@ include ../scripts/utilities.mak # Define NO_SDT if you do not want to define SDT event in perf tools, # note that it doesn't disable SDT scanning support. # +# Define XED=1 to build WITH the XED disassembler for perf script +# Can also set XED_DIR=/path to set XED directory. +# # Define FEATURES_DUMP to provide features detection dump file # and bypass the feature detection #
Signature · 1 line
2.9.3
Re: [PATCH 1/5] perf, tools: Add probing for xed
Hi Andi,
just a very minor cosmetic detail, but your editor seems to use tabs while there were 8 spaces around, causing visual alignment defects below :
tools/build/Makefile.feature FEATURE_TESTS_BASIC := \ · line 66
Quoted 10 lines · Andi Kleen
tools/build/Makefile.feature +1
-1@@ -63,7 +63,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \
here
tools/build/Makefile.feature FEATURE_TESTS_EXTRA := \ · line 77
Quoted 7 lines
tools/build/Makefile.feature +1
-0# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests@@ -74,11 +74,12 @@ FEATURE_TESTS_EXTRA := \ cplus-demangle \ hello \ libbabeltrace \ + xed \
here
tools/build/Makefile.feature FEATURE_TESTS_EXTRA := \ · line 82
Quoted 6 lines
tools/build/Makefile.feature +1
-1liberty \ liberty-z \ libunwind-debug-frame \ libunwind-debug-frame-arm \ - libunwind-debug-frame-aarch64 + libunwind-debug-frame-aarch64
here
tools/build/Makefile.feature FEATURE_DISPLAY ?= \ · line 109
Quoted 9 lines
tools/build/Makefile.feature +1
-1FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)@@ -105,7 +106,7 @@ FEATURE_DISPLAY ?= \ zlib \ lzma \ get_cpuid \ - bpf + bpf
and here.
I think it would be nice to fix them before merging.
Did I say it was very minor ? :-)
Regards,
Willy
Re: [PATCH 1/5] perf, tools: Add probing for xed
Quoted 50 lines · Willy Tarreau
Hi Andi,
just a very minor cosmetic detail, but your editor seems to use tabs while there were 8 spaces around, causing visual alignment defects below :
tools/build/Makefile.feature FEATURE_TESTS_BASIC := \ · line 66
Quoted 10 lines · Andi Kleen
tools/build/Makefile.feature +1
-1@@ -63,7 +63,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \here
tools/build/Makefile.feature FEATURE_TESTS_EXTRA := \ · line 77
Quoted 7 lines
tools/build/Makefile.feature +1
-0# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests@@ -74,11 +74,12 @@ FEATURE_TESTS_EXTRA := \ cplus-demangle \ hello \ libbabeltrace \ + xed \here
tools/build/Makefile.feature FEATURE_TESTS_EXTRA := \ · line 82
Quoted 6 lines
tools/build/Makefile.feature +1
-1liberty \ liberty-z \ libunwind-debug-frame \ libunwind-debug-frame-arm \ - libunwind-debug-frame-aarch64 + libunwind-debug-frame-aarch64here
tools/build/Makefile.feature FEATURE_DISPLAY ?= \ · line 109
Quoted 9 lines
tools/build/Makefile.feature +1
-1FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)@@ -105,7 +106,7 @@ FEATURE_DISPLAY ?= \ zlib \ lzma \ get_cpuid \ - bpf + bpfand here.
Quoted 3 lines
I think it would be nice to fix them before merging.
Did I say it was very minor ? :-)
yea, but still.. ;-)
jirka
PATCH 1/1 perf, tools: Add probing for xed
From: Andi Kleen <[email protected]>
Add autoprobing for the xed disassembler library.
Can be downloaded from https://github.com/intelxed/xed
v2: Hide. Require XED=1 to enable. Add XED_DIR
v3: Remove -lxed from probe all. Don't touch FEATURE_DISPLAY.
--- tools/build/Makefile.feature | 5 ++++- tools/build/feature/Makefile | 6 +++++- tools/build/feature/test-all.c | 5 +++++ tools/build/feature/test-xed.c | 9 +++++++++ tools/perf/Makefile.config | 16 ++++++++++++++++ tools/perf/Makefile.perf | 3 +++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tools/build/feature/test-xed.c
tools/build/Makefile.feature +4 -1
@@ -63,7 +63,8 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \ + xed # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests
@@ -74,6 +75,7 @@ FEATURE_TESTS_EXTRA := \ cplus-demangle \ hello \ libbabeltrace \ + xed \ liberty \ liberty-z \ libunwind-debug-frame \
@@ -140,6 +142,7 @@ ifeq ($(feature-all), 1) $(call feature_check,compile-x32) $(call feature_check,bionic) $(call feature_check,libbabeltrace) + $(call feature_check,xed) else $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat))) endif
tools/build/feature/Makefile +5 -1
@@ -48,7 +48,8 @@ FILES= \ test-get_cpuid.bin \ test-sdt.bin \ test-cxx.bin \ - test-jvmti.bin + test-jvmti.bin \ + test-xed.bin FILES := $(addprefix $(OUTPUT),$(FILES))
@@ -123,6 +124,9 @@ $(OUTPUT)test-numa_num_possible_cpus.bin: $(OUTPUT)test-libunwind.bin: $(BUILD) -lelf +$(OUTPUT)test-xed.bin: + $(BUILD) -lxed + $(OUTPUT)test-libunwind-debug-frame.bin: $(BUILD) -lelf $(OUTPUT)test-libunwind-x86.bin:
tools/build/feature/test-all.c +5 -0
@@ -149,6 +149,10 @@# include "test-sdt.c" #undef main +#define main main_test_xed +# include "test-xed.c" +#endif +int main (int argc,char *argv[]) {main_test_libpython ();
@@ -183,6 +187,7 @@ int main(int argc, char *argv[])main_test_bpf ();main_test_libcrypto ();main_test_sdt (); +main_test_xed ();return 0 ; }
tools/build/feature/test-xed.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <xed/xed-interface.h> +#include <xed/xed-decode.h> +#include <xed/xed-decoded-inst-api.h> + +int main (void ) +{ +xed_tables_init (); +return 0 ; +}
tools/perf/Makefile.config +16 -0
@@ -682,6 +682,22 @@ ifndef NO_ZLIB endif endif +ifdef XED + ifdef XED_DIR + FEATURE_CHECK_CFLAGS-xed := -I $(XED_DIR)/include + # override for lib64? + FEATURE_CHECK_LDFLAGS-xed := -L $(XED_DIR)/lib -lxed + else + FEATURE_CHECK_CFLAGS-xed := + FEATURE_CHECK_LDFLAGS-xed := -lxed + endif + $(call feature_check,xed) + ifeq ($(feature-xed), 1) + EXTLIBS += -lxed + $(call detected,CONFIG_XED) + endif +endif + ifndef NO_LZMA ifeq ($(feature-lzma), 1) CFLAGS += -DHAVE_LZMA_SUPPORT
tools/perf/Makefile.perf +3 -0
@@ -84,6 +84,9 @@ include ../scripts/utilities.mak # Define NO_SDT if you do not want to define SDT event in perf tools, # note that it doesn't disable SDT scanning support. # +# Define XED=1 to build WITH the XED disassembler for perf script +# Can also set XED_DIR=/path to set XED directory. +# # Define FEATURES_DUMP to provide features detection dump file # and bypass the feature detection #
Signature · 1 line
2.9.3
Re: [PATCH 1/5] perf, tools: Add probing for xed
In reply to Andi KleenOn Mon, Jan 09, 2017 at 05:02:21PM -0800, Andi Kleen wrote:
SNIP
tools/build/feature/Makefile __BUILDXX = $(CXX) $(CXXFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) · line 72
Quoted 3 lines
$(OUTPUT)test-all.bin:
tools/build/feature/Makefile +1
-1- $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma + $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma -lxed
I commented on this earlier:
http://marc.info/?l=linux-kernel&m=148388524322441&w=2
jirka
Re: [PATCH 1/5] perf, tools: Add probing for xed
In reply to Andi KleenQuoted 23 lines · Andi Kleen
From: Andi Kleen <[email protected]>
Add autoprobing for the xed disassembler library.
Can be downloaded from https://github.com/intelxed/xed
v2: Hide. Require XED=1 to enable. Add
XED_DIRSigned-off-by Andi Kleen <[email protected]>--- tools/build/Makefile.feature | 8 +++++--- tools/build/feature/Makefile | 8 ++++++-- tools/build/feature/test-all.c | 5 +++++ tools/build/feature/test-xed.c | 9 +++++++++ tools/perf/Makefile.config | 16 ++++++++++++++++ tools/perf/Makefile.perf | 3 +++ 6 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 tools/build/feature/test-xed.ctools/build/Makefile.feature +0
-0
tools/build/Makefile.feature FEATURE_TESTS_BASIC := \ · line 66
Quoted 5 lines
tools/build/Makefile.feature +1
-1@@ -63,7 +63,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \
looks like you forgot to add xed in here? why the '\' ?
anyway, please add it in here so it's visible under make VF=1
jirka
Re: [PATCH 1/5] perf, tools: Add probing for xed
Quoted 4 lines
Quoted 4 lines
tools/build/Makefile.feature +0
-0
Quoted 8 lines
tools/build/Makefile.feature FEATURE_TESTS_BASIC := \ · line 66
Quoted 6 lines
tools/build/Makefile.feature +1
-1@@ -63,7 +63,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \looks like you forgot to add xed in here? why the '\' ?
I removed it, but incompletely.
Quoted 1 line
anyway, please add it in here so it's visible under make VF=1
If I add it here then it is shown by default (even without VF=1). Arnaldo requested earlier that it shouldn't be shown.
-Andi
Re: [PATCH 1/5] perf, tools: Add probing for xed
Quoted 13 lines · Andi Kleen
Quoted 4 lines
Quoted 4 lines
tools/build/Makefile.feature +0
-0Quoted 8 lines
tools/build/Makefile.feature FEATURE_TESTS_BASIC := \ · line 66
Quoted 6 lines
tools/build/Makefile.feature +1
-1@@ -63,7 +63,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \looks like you forgot to add xed in here? why the '\' ?
Quoted 6 lines
I removed it, but incompletely.
Quoted 1 line
anyway, please add it in here so it's visible under make VF=1
If I add it here then it is shown by default (even without VF=1). Arnaldo requested earlier that it shouldn't be shown.
if you put it to FEATURE_TESTS_BASIC then it's displayed only for VF=1
FEATURE_DISPLAY is the one that's displayed by default
jirka
Re: [PATCH 1/5] perf, tools: Add probing for xed
Quoted 14 lines · Jiri Olsa
Quoted 13 lines · Andi Kleen
Quoted 12 lines
tools/build/Makefile.feature FEATURE_TESTS_BASIC := \ · line 66
Quoted 10 lines
tools/build/Makefile.feature +1
-1@@ -63,7 +63,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \looks like you forgot to add xed in here? why the '\' ?
Quoted 8 lines
Quoted 6 lines
I removed it, but incompletely.
Quoted 1 line
anyway, please add it in here so it's visible under make VF=1
If I add it here then it is shown by default (even without VF=1). Arnaldo requested earlier that it shouldn't be shown.
if you put it to
FEATURE_TESTS_BASICthen it's displayed only for VF=1
It's already in FEATURE_TESTS_BASIC:
@ -63,7 +63,8 @@ FEATURE_TESTS_BASIC := \
lzma \
get_cpuid \
bpf \- sdt
+ sdt \
+ xed
-ANdi
Re: [PATCH 1/5] perf, tools: Add probing for xed
Quoted 30 lines · Andi Kleen
Quoted 14 lines · Jiri Olsa
Quoted 13 lines · Andi Kleen
Quoted 12 lines
tools/build/Makefile.feature FEATURE_TESTS_BASIC := \ · line 66
Quoted 10 lines
tools/build/Makefile.feature +1
-1@@ -63,7 +63,7 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \ - sdt + sdt \looks like you forgot to add xed in here? why the '\' ?
Quoted 8 lines
Quoted 6 lines
I removed it, but incompletely.
Quoted 1 line
anyway, please add it in here so it's visible under make VF=1
If I add it here then it is shown by default (even without VF=1). Arnaldo requested earlier that it shouldn't be shown.
if you put it to
FEATURE_TESTS_BASICthen it's displayed only for VF=1It's already in
FEATURE_TESTS_BASIC:@ -63,7 +63,8 @@ FEATURE_TESTS_BASIC := \ lzma \ get_cpuid \ bpf \
tools/build/Makefile.feature FEATURE_TESTS_BASIC := \
Quoted 3 lines
tools/build/Makefile.feature +2
-1- sdt + sdt \ + xed
I see that on FEATURE_TESTS_EXTRA in your xed-4 branch, unless that's different to what you sent out
jirka
PATCH 2/5 perf, tools: Add one liner warning for disabled features
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Add a one liner warning for perf features that need to be enabled explicitly by the user, so that they know they are missing something. Currently enabled for XED and BABELTRACE.
--- tools/perf/Makefile.config | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/perf/Makefile.config +10 -0
@@ -65,6 +65,8 @@ ifneq ($(ARCH),$(filter $(ARCH),x86 arm)) NO_LIBDW_DWARF_UNWIND := 1 endif +DISABLED_FEATURES = + ifeq ($(LIBUNWIND_LIBS),) NO_LIBUNWIND := 1 endif
@@ -696,6 +698,8 @@ ifdef XED EXTLIBS += -lxed $(call detected,CONFIG_XED) endif +else + DISABLED_FEATURES += XED endif ifndef NO_LZMA
@@ -770,6 +774,8 @@ ifdef LIBBABELTRACE else msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev); endif +else + DISABLED_FEATURES += LIBBABELTRACE endif ifndef NO_AUXTRACE
@@ -841,6 +847,10 @@ ifdef LIBCLANGLLVM endif endif +ifneq ($(DISABLED_FEATURES),) + $(warning Disabled features, need explicit enabling by user: $(DISABLED_FEATURES)) +endif + # Among the variables below, these: # perfexecdir # template_dir
Signature · 1 line
2.9.3
Re: [PATCH 2/5] perf, tools: Add one liner warning for disabled features
Quoted 7 lines · Andi Kleen
From: Andi Kleen <[email protected]>
Add a one liner warning for perf features that need to be enabled explicitly by the user, so that they know they are missing something. Currently enabled for XED and BABELTRACE.
Signed-off-by Andi Kleen <[email protected]>
thanks for doing this
jirka
PATCH 3/5 perf, tools: Add disassembler for x86 using the XED library
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Add a generic disassembler function for x86 using the XED library, and a fallback function for architectures that don't implement one. Other architectures can implement their own disassembler functions.
The previous version of this patch used udis86, but was rejected because udis86 was unmaintained and a runtime dependency. Using the recently released xed avoids both of these problems:
- XED is well maintained, uptodate, and used by many Intel tools
- XED is linked statically so there is no runtime dependency.
The XED library can be downloaded from http://github.com/intelxed/xed
v2: Clean up includes.
--- tools/perf/arch/x86/util/Build | 1 + tools/perf/arch/x86/util/dis.c | 86 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/Build | 1 + tools/perf/util/dis.c | 15 ++++++++ tools/perf/util/dis.h | 20 ++++++++++ 5 files changed, 123 insertions(+) create mode 100644 tools/perf/arch/x86/util/dis.c create mode 100644 tools/perf/util/dis.c create mode 100644 tools/perf/util/dis.h
tools/perf/arch/x86/util/Build +1 -0
@@ -14,3 +14,4 @@ libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o libperf-$(CONFIG_AUXTRACE) += auxtrace.o libperf-$(CONFIG_AUXTRACE) += intel-pt.o libperf-$(CONFIG_AUXTRACE) += intel-bts.o +libperf-$(CONFIG_XED) += dis.o
tools/perf/arch/x86/util/dis.c new file +86 -0
86 lines not on this page · raw message
tools/perf/util/Build +1 -0
@@ -88,6 +88,7 @@ libperf-y += mem-events.o libperf-y += vsprintf.o libperf-y += drv_configs.o libperf-y += time-utils.o +libperf-y += dis.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
tools/perf/util/dis.c new file +15 -0
@@ -0,0 +1,15 @@ +#include "perf.h" +#include "dis.h" +#include "util.h" + +/* Fallback for architectures with no disassembler */ + +__weak char *disas_inst (struct perf_dis *x,uint64_t ip__maybe_unused , +u8 *inbuf__maybe_unused ,int inlen__maybe_unused , +int *lenp) +{ +if (lenp) + *lenp =0 ; +strcpy (x->out,"?" ); +return x->out; +}
tools/perf/util/dis.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef DIS_H +#define DIS_H 1 + +#define MAXINSN 15 + +struct perf_dis { +/* Initialized by callers: */ +struct thread *thread; +u8 cpumode; +int cpu; +bool is64bit; +/* Temporary */ +char out[256 ]; +}; + +char *disas_inst (struct perf_dis *x,uint64_t ip,u8 *inbuf,int inlen, +int *lenp); + + +#endif
Signature · 1 line
2.9.3
PATCH 4/5 perf, tools, script: Add support for printing assembler
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
When dumping PT traces with perf script it is very useful to see the assembler for each sample, so that it is easily possible to follow the control flow.
As using objdump is difficult and inefficient from perf script this patch uses the Intel xed library to implement assembler output. The library can be downloaded from http://github.com/intelxed/xed
The previous version of this patch used udis86, but was rejected because udis86 was unmaintained and a runtime dependency. Using the recently released xed avoids both of these problems:
- XED is well maintained and used by many Intel tools
- XED is linked statically so there is no runtime dependency.
The library is probed as an external dependency in the usual way. Then perf script calls into it when needed, and handles callbacks to resolve symbols.
% perf record -e intel_pt//u true
% perf script -F sym,symoff,ip,asm --itrace=i0ns | head
7fc7188b4190 _start+0x0 mov %rsp, %rdi
7fc7188b4193 _start+0x3 call _dl_start
7fc7188b7710 _dl_start+0x0 push %rbp
7fc7188b7711 _dl_start+0x1 mov %rsp, %rbp
7fc7188b7714 _dl_start+0x4 push %r15
7fc7188b7716 _dl_start+0x6 push %r14
7fc7188b7718 _dl_start+0x8 push %r13
7fc7188b771a _dl_start+0xa push %r12
7fc7188b771c _dl_start+0xc mov %rdi, %r12
7fc7188b771f _dl_start+0xf push %rbxv2:
Converted to use XED instead of udis86.
Separate disassembler interface into separate arch specific file. Lots of cleanups and improvements.
--- tools/perf/Documentation/perf-script.txt | 4 +- tools/perf/builtin-script.c | 72 +++++++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 12 deletions(-)
tools/perf/Documentation/perf-script.txt +3 -1
@@ -116,7 +116,7 @@ OPTIONS --fields:: Comma separated list of fields to print. Options are: comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, - srcline, period, iregs, brstack, brstacksym, flags, bpf-output, + srcline, period, iregs, brstack, brstacksym, flags, bpf-output, asm. callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
@@ -198,6 +198,8 @@ OPTIONS The brstacksym is identical to brstack, except that the FROM and TO addresses are printed in a symbolic form if possible. + When asm is specified the assembler instruction of each sample is printed in disassembled form. + -k:: --vmlinux=<file>:: vmlinux pathname
tools/perf/builtin-script.c +61 -11
154 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH 5/5 perf, tools, script: Add brstackasm output for branch stacks
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Implement printing full disassembled sequences for branch stacks in perf script. This allows to directly print hot paths for individual samples, together with branch misprediction and cycle count / IPC information if available (on Skylake systems). This only works when no special branch filters are specified.
% perf record -b ...
% perf script -F brstackasm
...
000055b55d1147d0 pushq %rbp
000055b55d1147d1 pushq %r15
000055b55d1147d3 pushq %r14
000055b55d1147d5 pushq %r13
000055b55d1147d7 pushq %r12
000055b55d1147d9 pushq %rbx
000055b55d1147da sub $0x18, %rsp
000055b55d1147de mov %r8, %r13
000055b55d1147e1 mov %rcx, %rbp
000055b55d1147e4 mov %rdx, %r14
000055b55d1147e7 mov %rsi, %r15
000055b55d1147ea mov %rdi, %rbx
000055b55d1147ed movl $0x0, 0xc(%rsp)
000055b55d1147f5 movq (%rbp), %rax
000055b55d1147f9 test $0x1, %al
000055b55d1147fb jnz 0x55b55d114890 # PRED 4 cycles 3.75 IPC
000055b55d114890 mov %eax, %ecx
000055b55d114892 and $0x3, %ecx
000055b55d114895 cmp $0x1, %rcx
000055b55d114899 jnz 0x55b55d1148f8
000055b55d11489b movq -0x1(%rax), %rcx
000055b55d11489f cmpb $0x81, 0xb(%rcx)
000055b55d1148a3 jnz 0x55b55d1148fe # PRED 1 cycles 6.00 IPC...
Occasionally the path does not reach up to the sample IP, as the LBRs may be frozen before executing a final jump. In this case we print a special message.
v2:
Use low level abstracted disassembler interface.
Print symbols and source lines as labels.
Print first jump in LBR too.
Patch up blocks with filtered ring transfers.
Show IPC
Lots of cleanups and improvements.
v3:
Print special message for branches frozen early.
--- tools/perf/Documentation/perf-script.txt | 13 +- tools/perf/builtin-script.c | 267 +++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-script.txt +11 -2
@@ -116,7 +116,7 @@ OPTIONS --fields:: Comma separated list of fields to print. Options are: comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, - srcline, period, iregs, brstack, brstacksym, flags, bpf-output, asm. + srcline, period, iregs, brstack, brstacksym, flags, bpf-output, asm, brstackasm, callindent, insn, insnlen. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace
@@ -189,17 +189,22 @@ OPTIONS i.e., -F "" is not allowed. The brstack output includes branch related information with raw addresses using the - /v/v/v/v/ syntax in the following order: + /v/v/v/v/cycles syntax in the following order: FROM: branch source instruction TO : branch target instruction M/P/-: M=branch target mispredicted or branch direction was mispredicted, P=target predicted or direction predicted, -=not supported X/- : X=branch inside a transactional region, -=not in transaction region or not supported A/- : A=TSX abort entry, -=not aborted region or not supported + cycles The brstacksym is identical to brstack, except that the FROM and TO addresses are printed in a symbolic form if possible. When asm is specified the assembler instruction of each sample is printed in disassembled form. + When brstackasm is specified the full assembler sequences of branch sequences for each sample + is printed. This is the full execution path leading to the sample. This is only supported when the + sample was recorded with perf record -b or -j any. + -k:: --vmlinux=<file>:: vmlinux pathname
@@ -301,6 +306,10 @@ include::itrace.txt[] stop time is not given (i.e, time string is 'x.y,') then analysis goes to end of file. +--max-blocks:: + Set the maximum number of program blocks to print with brstackasm for + each sample. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +267 -0
309 lines not on this page · raw message
Signature · 1 line
2.9.3