linux-stable/tools/perf
Arnaldo Carvalho de Melo a6e8a58de6 perf disasm: Allow configuring what disassemblers to use
The perf tools annotation code used for a long time parsing the output
of binutils's objdump (or its reimplementations, like llvm's) to then
parse and augment it with samples, allow navigation, etc.

More recently disassemblers from the capstone and llvm (libraries, not
parsing the output of tools using those libraries to mimic binutils's
objdump output) were introduced.

So when all those methods are available, there is a static preference
for a series of attempts of disassembling a binary, with the 'llvm,
capstone, objdump' sequence being hard coded.

This patch allows users to change that sequence, specifying via a 'perf
config' 'annotate.disassemblers' entry which and in what order
disassemblers should be attempted.

As alluded to in the comments in the source code of this series, this
flexibility is useful for users and developers alike, elliminating the
requirement to rebuild the tool with some specific set of libraries to
see how the output of disassembling would be for one of these methods.

  root@x1:~# rm -f ~/.perfconfig
  root@x1:~# perf annotate -v --stdio2 update_load_avg
  <SNIP>
  symbol__disassemble:
    filename=/usr/lib/debug/lib/modules/6.11.4-201.fc40.x86_64/vmlinux,
    sym=update_load_avg, start=0xffffffffb6148fe0, en>
  annotating [0x6ff7170]
    /usr/lib/debug/lib/modules/6.11.4-201.fc40.x86_64/vmlinux :
    [0x7407ca0] update_load_avg
  Disassembled with llvm
  annotate.disassemblers=llvm,capstone,objdump
  Samples: 66  of event 'cpu_atom/cycles/P', 10000 Hz,
	Event count (approx.): 5185444, [percent: local period]
  update_load_avg()
    /usr/lib/debug/lib/modules/6.11.4-201.fc40.x86_64/vmlinux
  Percent       0xffffffff81148fe0 <update_load_avg>:
     1.61         pushq   %r15
                  pushq   %r14
     1.00         pushq   %r13
                  movl    %edx,%r13d
     1.90         pushq   %r12
                  pushq   %rbp
                  movq    %rsi,%rbp
                  pushq   %rbx
                  movq    %rdi,%rbx
                  subq    $0x18,%rsp
    15.14         movl    0x1a4(%rdi),%eax

  root@x1:~# perf config annotate.disassemblers=capstone
  root@x1:~# cat ~/.perfconfig
  # this file is auto-generated.
  [annotate]
	  disassemblers = capstone
  root@x1:~#
  root@x1:~# perf annotate -v --stdio2 update_load_avg
  <SNIP>
  Disassembled with capstone
  annotate.disassemblers=capstone
  Samples: 66  of event 'cpu_atom/cycles/P', 10000 Hz,
  Event count (approx.): 5185444, [percent: local period]
  update_load_avg()
  /usr/lib/debug/lib/modules/6.11.4-201.fc40.x86_64/vmlinux
  Percent       0xffffffff81148fe0 <update_load_avg>:
     1.61         pushq   %r15
                  pushq   %r14
     1.00         pushq   %r13
                  movl    %edx,%r13d
     1.90         pushq   %r12
                  pushq   %rbp
                  movq    %rsi,%rbp
                  pushq   %rbx
                  movq    %rdi,%rbx
                  subq    $0x18,%rsp
    15.14         movl    0x1a4(%rdi),%eax
  root@x1:~# perf config annotate.disassemblers=objdump,capstone
  root@x1:~# perf config annotate.disassemblers
  annotate.disassemblers=objdump,capstone
  root@x1:~# cat ~/.perfconfig
  # this file is auto-generated.
  [annotate]
	  disassemblers = objdump,capstone
  root@x1:~# perf annotate -v --stdio2 update_load_avg
  Executing: objdump  --start-address=0xffffffff81148fe0 \
		      --stop-address=0xffffffff811497aa  \
		      -d --no-show-raw-insn -S -C "$1"
  Disassembled with objdump
  annotate.disassemblers=objdump,capstone
  Samples: 66  of event 'cpu_atom/cycles/P', 10000 Hz,
  Event count (approx.): 5185444, [percent: local period]
  update_load_avg()
  /usr/lib/debug/lib/modules/6.11.4-201.fc40.x86_64/vmlinux
  Percent

                Disassembly of section .text:

                ffffffff81148fe0 <update_load_avg>:
                #define DO_ATTACH       0x4

                ffffffff81148fe0 <update_load_avg>:
                #define DO_ATTACH       0x4
                #define DO_DETACH       0x8

                /* Update task and its cfs_rq load average */
                static inline void update_load_avg(struct cfs_rq *cfs_rq,
						   struct sched_entity *se,
						   int flags)
                {
     1.61         push   %r15
                  push   %r14
     1.00         push   %r13
                  mov    %edx,%r13d
     1.90         push   %r12
                  push   %rbp
                  mov    %rsi,%rbp
                  push   %rbx
                  mov    %rdi,%rbx
                  sub    $0x18,%rsp
                }

                /* rq->task_clock normalized against any time
		   this cfs_rq has spent throttled */
                static inline u64 cfs_rq_clock_pelt(struct cfs_rq *cfs_rq)
                {
                if (unlikely(cfs_rq->throttle_count))
    15.14         mov    0x1a4(%rdi),%eax
  root@x1:~#

After adding a way to select the disassembler from the command line a
'perf test' comparing the output of the various diassemblers should be
introduced, to test these codebases.

Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Steinar H. Gunderson <sesse@google.com>
Link: https://lore.kernel.org/r/20241111151734.1018476-4-acme@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2024-11-13 16:27:35 -03:00
..
arch perf build: Remove PERF_HAVE_DWARF_REGS 2024-11-09 08:39:14 -08:00
bench perf tools: sched-pipe bench: add (-n) nonblocking benchmark 2024-10-21 21:23:01 -07:00
check-header_ignore_hunks/lib perf tools: Cope with differences for lib/list_sort.c copy from the kernel 2024-10-02 15:07:32 -03:00
dlfilters perf tools: Simplify evsel__add_modifier() 2024-10-22 09:52:11 -07:00
Documentation perf disasm: Allow configuring what disassemblers to use 2024-11-13 16:27:35 -03:00
include/perf perf dlfilter: Add al_cleanup() 2023-08-15 16:41:49 -03:00
jvmti
pmu-events perf vendor events arm64: Add i.MX91 DDR Performance Monitor metrics 2024-10-28 09:37:02 -07:00
python
scripts perf script python: Adjust objdump start/end per map pgoff parameter 2024-11-08 22:42:57 -08:00
tests perf test: Add hwmon "PMU" test 2024-11-09 08:28:03 -08:00
trace perf beauty: Update copy of linux/socket.h with the kernel sources 2024-09-30 17:23:38 -03:00
ui perf tools: Print lost samples due to BPF filter 2024-08-28 18:07:20 -03:00
util perf disasm: Allow configuring what disassemblers to use 2024-11-13 16:27:35 -03:00
.gitignore perf tools: Add the empty-pmu-events build to .gitignore 2024-11-07 10:51:56 -08:00
Build perf check: Introduce 'check' subcommand 2024-09-04 09:56:05 -03:00
builtin-annotate.c perf build: Rename HAVE_DWARF_SUPPORT to HAVE_LIBDW_SUPPORT 2024-10-18 10:17:40 -07:00
builtin-bench.c perf bench uprobe: Add uretprobe variant of uprobe benchmarks 2024-04-12 17:54:02 -03:00
builtin-buildid-cache.c perf dso: Add reference count checking and accessor functions 2024-05-06 15:28:49 -03:00
builtin-buildid-list.c perf buildid-list: Use perf_tool__init 2024-08-12 18:07:10 -03:00
builtin-c2c.c perf mem: Fix missed p-core mem events on ADL and RPL 2024-09-06 11:45:17 -03:00
builtin-check.c perf build: Rename HAVE_DWARF_SUPPORT to HAVE_LIBDW_SUPPORT 2024-10-18 10:17:40 -07:00
builtin-config.c perf path: Make mkpath thread safe, remove 16384 bytes from .bss 2023-05-28 10:24:14 -03:00
builtin-daemon.c perf daemon: Fix the build on more 32-bit architectures 2024-08-19 21:44:30 -03:00
builtin-data.c perf util: Move input_name to util 2023-04-10 19:21:31 -03:00
builtin-diff.c perf evsel: Add alternate_hw_config and use in evsel__match 2024-09-26 13:26:11 -07:00
builtin-evlist.c perf evlist: Print hint for group 2024-09-11 13:08:45 -03:00
builtin-ftrace.c perf ftrace latency: Fix unit on histogram first entry when using --use-nsec 2024-10-30 23:46:43 -07:00
builtin-help.c perf help: Fix a typo ("bellow") 2024-09-11 11:24:12 -03:00
builtin-inject.c perf callchain: Allow symbols to be optional when resolving a callchain 2024-09-10 17:32:47 -03:00
builtin-kallsyms.c perf dso: Add reference count checking and accessor functions 2024-05-06 15:28:49 -03:00
builtin-kmem.c perf build: Include libtraceevent headers directly indicated by pkg-config 2024-11-08 22:42:57 -08:00
builtin-kvm.c perf tools: Don't set attr.exclude_guest by default 2024-10-22 09:52:11 -07:00
builtin-kwork.c perf build: Include libtraceevent headers directly indicated by pkg-config 2024-11-08 22:42:57 -08:00
builtin-list.c perf tool_pmu: Factor tool events into their own PMU 2024-10-10 23:40:32 -07:00
builtin-lock.c libsubcmd: Don't free the usage string 2024-09-04 09:54:24 -03:00
builtin-mem.c perf mem: Fix the wrong reference in parse_record_events() 2024-09-06 11:45:28 -03:00
builtin-probe.c perf build: Rename HAVE_DWARF_SUPPORT to HAVE_LIBDW_SUPPORT 2024-10-18 10:17:40 -07:00
builtin-record.c perf record: Just use "cycles:P" as the default event 2024-10-22 09:55:08 -07:00
builtin-report.c perf build: Include libtraceevent headers directly indicated by pkg-config 2024-11-08 22:42:57 -08:00
builtin-sched.c perf color: Add printf format checking and resolve issues 2024-10-17 12:44:26 -07:00
builtin-script.c perf build: Include libtraceevent headers directly indicated by pkg-config 2024-11-08 22:42:57 -08:00
builtin-stat.c perf stat: Support inherit events during fork() for bperf 2024-11-01 23:31:08 -07:00
builtin-timechart.c perf build: Include libtraceevent headers directly indicated by pkg-config 2024-11-08 22:42:57 -08:00
builtin-top.c perf map: API clean up 2024-08-19 14:49:53 -03:00
builtin-trace.c perf build: Include libtraceevent headers directly indicated by pkg-config 2024-11-08 22:42:57 -08:00
builtin-version.c perf version: Update --build-options to use 'supported_features' array 2024-09-04 16:19:29 -03:00
builtin.h perf check: Introduce 'check' subcommand 2024-09-04 09:56:05 -03:00
check-headers.sh tools headers: Update the linux/unaligned.h copy with the kernel sources 2024-10-28 12:34:28 -03:00
command-list.txt perf help: Use HAVE_LIBTRACEEVENT to filter out unsupported commands 2023-01-02 11:51:53 -03:00
CREDITS
design.txt
Makefile perf tools: Fix wrong message when running "make JOBS=1" 2024-08-01 12:11:33 -03:00
Makefile.config perf build: Remove PERF_HAVE_DWARF_REGS 2024-11-09 08:39:14 -08:00
Makefile.perf perf build: Make libunwind opt-in rather than opt-out 2024-11-04 11:32:35 -08:00
MANIFEST tools perf: Add arm64 sysreg files to MANIFEST 2023-11-22 11:17:53 -08:00
perf-archive.sh perf build: Add shellcheck to tools/perf scripts 2024-04-12 17:54:02 -03:00
perf-completion.sh perf build: Add shellcheck to tools/perf scripts 2024-04-12 17:54:02 -03:00
perf-iostat.sh
perf-read-vdso.c
perf-sys.h
perf.c perf test: Remove C test wrapper for attr.py 2024-10-17 13:17:36 -07:00
perf.h perf util: Move perf_guest/host declarations 2023-04-10 19:22:05 -03:00