kernel_optimize_test/tools/perf
Adrian Hunter f08046cb30 perf thread-stack: Represent jmps to the start of a different symbol
The compiler might optimize a call/ret combination by making it a jmp.
However the thread-stack does not presently cater for that, so that such
control flow is not visible in the call graph. Make it visible by
recording on the stack a branch to the start of a different symbol.
Note, that means when a ret pops the stack, all jmps must be popped off
first.

Example:

  $ cat jmp-to-fn.c
  __attribute__((noinline)) int bar(void)
  {
          return -1;
  }

  __attribute__((noinline)) int foo(void)
  {
          return bar() + 1;
  }

  int main()
  {
          return foo();
  }
  $ gcc -ggdb3 -Wall -Wextra -O2 -o jmp-to-fn jmp-to-fn.c
  $ objdump -d jmp-to-fn
  <SNIP>
  0000000000001040 <main>:
      1040:       31 c0                   xor    %eax,%eax
      1042:       e9 09 01 00 00          jmpq   1150 <foo>
  <SNIP>
  0000000000001140 <bar>:
      1140:       b8 ff ff ff ff          mov    $0xffffffff,%eax
      1145:       c3                      retq
  <SNIP>
  0000000000001150 <foo>:
      1150:       31 c0                   xor    %eax,%eax
      1152:       e8 e9 ff ff ff          callq  1140 <bar>
      1157:       83 c0 01                add    $0x1,%eax
      115a:       c3                      retq
  <SNIP>
  $ perf record -o jmp-to-fn.perf.data -e intel_pt/cyc/u ./jmp-to-fn
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0,017 MB jmp-to-fn.perf.data ]
  $ perf script -i jmp-to-fn.perf.data --itrace=be -s ~/libexec/perf-core/scripts/python/export-to-sqlite.py jmp-to-fn.db branches calls
  2019-01-08 13:24:58.783069 Creating database...
  2019-01-08 13:24:58.794650 Writing records...
  2019-01-08 13:24:59.008050 Adding indexes
  2019-01-08 13:24:59.015802 Done
  $  ~/libexec/perf-core/scripts/python/exported-sql-viewer.py jmp-to-fn.db

Before:

    main
        -> bar

After:

    main
        -> foo
            -> bar

Committer testing:

Install the python2-pyside package, then select these menu options
on the GUI:

   "Reports"
      "Context sensitive callgraphs"

Then go on expanding the symbols, to get, full picture when doing this
on a fedora:29 with gcc version 8.2.1 20181215 (Red Hat 8.2.1-6) (GCC):

jmp-to-fn
  PID:TID
    _start                (ld-2.28.so)
      __libc_start_main
        main
          foo
            bar

To verify that indeed, this fixes the problem.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20190109091835.5570-5-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-02-06 10:00:40 -03:00
..
arch perf coresight: Remove set_drv_config() API 2019-02-06 10:00:39 -03:00
bench
Documentation perf tools: Add documentation for BPF event selection 2019-02-06 10:00:40 -03:00
examples/bpf perf augmented_syscalls: Convert to bpf_map() 2019-01-25 15:12:11 +01:00
include/bpf perf bpf: Convert pid_map() to bpf_map() 2019-01-25 15:12:10 +01:00
jvmti
pmu-events perf vendor events intel: Fix Load_Miss_Real_Latency on CLX 2019-02-06 10:00:40 -03:00
python
scripts perf thread-stack: Represent jmps to the start of a different symbol 2019-02-06 10:00:40 -03:00
tests perf tests pmu: Add missing headers 2019-02-06 10:00:38 -03:00
trace perf beauty: Switch from using uapi/linux/fs.h to uapi/linux/mount.h 2019-01-08 14:09:33 -03:00
ui perf tools: Add missing include <callchain.h> in various places 2019-02-06 10:00:38 -03:00
util perf thread-stack: Represent jmps to the start of a different symbol 2019-02-06 10:00:40 -03:00
.gitignore
Build
builtin-annotate.c pref tools: Add missing map.h includes 2019-02-06 10:00:38 -03:00
builtin-bench.c
builtin-buildid-cache.c
builtin-buildid-list.c
builtin-c2c.c perf hists: Add argument to hists__resort_cb_t callback 2019-02-06 10:00:39 -03:00
builtin-config.c
builtin-data.c
builtin-diff.c perf hist: Use cached rbtrees 2019-01-25 15:12:10 +01:00
builtin-evlist.c
builtin-ftrace.c
builtin-help.c
builtin-inject.c perf tools: Add missing include for symbols.h 2019-02-06 10:00:38 -03:00
builtin-kallsyms.c pref tools: Add missing map.h includes 2019-02-06 10:00:38 -03:00
builtin-kmem.c pref tools: Add missing map.h includes 2019-02-06 10:00:38 -03:00
builtin-kvm.c
builtin-list.c
builtin-lock.c
builtin-mem.c pref tools: Add missing map.h includes 2019-02-06 10:00:38 -03:00
builtin-probe.c perf namespaces: Remove namespaces.h from .h headers 2019-01-25 15:12:09 +01:00
builtin-record.c perf record: Apply affinity masks when reading mmap buffers 2019-02-06 10:00:39 -03:00
builtin-report.c perf report: Move symbol annotation to the resort phase 2019-02-06 10:00:40 -03:00
builtin-sched.c perf sched: Use cached rbtrees 2019-01-25 15:12:10 +01:00
builtin-script.c pref tools: Add missing map.h includes 2019-02-06 10:00:38 -03:00
builtin-stat.c perf pmu: Remove set_drv_config API 2019-02-06 10:00:39 -03:00
builtin-timechart.c
builtin-top.c perf pmu: Remove set_drv_config API 2019-02-06 10:00:39 -03:00
builtin-trace.c perf tools: Add missing include for symbols.h 2019-02-06 10:00:38 -03:00
builtin-version.c
builtin.h
check-headers.sh tools headers powerpc: Remove unistd.h 2019-01-10 10:42:08 -03:00
command-list.txt
CREDITS
design.txt perf/doc: Update design.txt for exclude_{host|guest} flags 2019-01-21 11:01:18 +01:00
Makefile
Makefile.config
Makefile.perf perf script python: Remove explicit shebang from Python scripts 2019-01-25 15:12:10 +01:00
MANIFEST
perf-archive.sh
perf-completion.sh
perf-read-vdso.c perf tools: Make find_vdso_map() more modular 2019-01-08 13:28:13 -03:00
perf-sys.h
perf-with-kcore.sh
perf.c
perf.h perf record: Allocate affinity masks 2019-02-06 10:00:39 -03:00