Skip to contentSkip to conversation

perf/core improvements and fixes

GIT PULL New Arnaldo Carvalho de Melo 1 participant 53 messages May 2, 2018

Subsystems (5)
lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

Hi Ingo,

Please consider pulling, done on top of perf/urgent,

- Arnaldo

Test results at the end of this message, as usual.

The following changes since commit d4652f614f2163a56aee4c03a88af76f98d52161:

Merge tag 'perf-urgent-for-mingo-4.17-20180425' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent (2018-04-26 07:28:29 +0200)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-4.18-20180502

for you to fetch changes up to 107cad95ffd81afad295ed5c29d006e525f1f80f:

perf machine: Ditch find_kernel_function variants (2018-04-30 12:20:54 -0300)

----------------------------------------------------------------
perf/core improvements and fixes:

perf stat: (Jiri Olsa)

- Display time in precision based on std deviation

- Add --table option to display time of each run

- Display length strings of each run for --table option

perf buildid-cache: (Ravi Bangoria)

- Add --list and --purge-all options

perf test: (Hendrik Brueckner)

- Let 'perf test list' display subtests

Core libraries:

- Remove the splitting of maps into MAP__FUNCTION and MAP__VARIABLE. It isn't needed, adds complexity, so remove this split in a very granular fashion using better ways of detecting if a map is executable, using map->prot, etc. More is needed to further untangle map aspects from DSO ones and also to have arch specific stuff better isolated. (Arnaldo Carvalho de Melo)

- Fix spelling mistake: "builid" -> "buildid" in a jitdump error message (Colin Ian King)

Build system: (Jiri Olsa)

- Add support to check 2 independent files in check-headers.sh

Documentation: (Takashi Iwai)

- Support for asciidoctor, since 'asciidoc' wasn't so far ported to python3 and distros are ditching python2

----------------------------------------------------------------
Arnaldo Carvalho de Melo (42):
perf top: Use __map__is_kernel()
perf symbols: Use __map__is_kernel() instead of ad-hoc equivalent code perf dso: Add dso__has_symbols() method
perf map: Introduce map__has_symbols()
perf thread: Introduce thread__find_map()
perf thread: Introduce thread__find_symbol()
perf script: Use thread__find_symbol() instead of ad-hoc equivalent
perf thread: Make thread__find_map() return the map
perf thread: Make thread__find_symbol() return the symbol searched
perf map: Shorten map_groups__find_by_name() signature
perf machine: Introduce machine__kernel_maps()
perf machine: Shorten machine__load_kallsyms() signature
perf machine: Remove needless map_type from machine__load_vmlinux_path() perf tests vmlinux-kallsyms: Use machine__find_kernel_function(_by_name) perf tests vmlinux-kallsyms: Use map__for_each_symbol() instead of open coded equivalent perf map: Shorten map_groups__find() signature
perf ui stdio: Use map_groups__fprintf()
perf symbols: Shorten dso__(first|last)_symbol()
tools lib symbols: Introduce kallsyms__is_function()
perf tools: Use kallsyms__is_function()
perf symbols: Unexport symbol_type__is_a()
perf map: Remove enum_type arg to map_groups__first()
perf symbols: Remove map_type arg from dso__find_symbol()
perf thread: Remove addr_type arg from thread__find_cpumode_addr_location() perf machine: Use machine__find_kernel_function() instead of open coded version perf thread: Ditch __thread__find_symbol()
perf thread: Make thread__find_map() search all maps
perf map: Remove map_type arg from map_groups__find()
perf symbols: Store the ELF symbol type in the symbol struct
perf machine: Set PROT_EXEC for executable PERF_RECORD_MMAP records
perf sort: Use mmap->prot on "dcacheline" formatting
perf symbols: No need to special case MAP__FUNCTION in fixup
perf symbols: Use symbol type instead of map->type
perf map: Use map->prot in place of type=MAP__FUNCTION
perf symbols: Use map->prot in place of type=MAP__FUNCTION
perf symbols: Unify symbol maps
perf symbols: Remove needless goto
perf symbols: Split kernel symbol processing from dso__load_sym()
perf symbols: Remove unused dso__load_all_kallsyms() 'map' parameter
perf symbols: kallsyms__delta() needs the kmap, not the map
perf symbols: Move split_kallsyms to struct map_groups
perf machine: Ditch find_kernel_function variants

Colin Ian King (1):

      perf tools: Fix spelling mistake: "builid" -> "buildid"

Hendrik Brueckner (1):
perf tests: Let 'perf test list' display subtests

Jiri Olsa (5):
perf check-headers.sh: Simplify arguments passing perf check-headers.sh: Add support to check 2 independent files perf stat: Display time in precision based on std deviation perf stat: Add --table option to display time of each run perf stat: Display length strings of each run for --table option

Ravi Bangoria (2):

      perf buildid-cache: Support --list option
      perf buildid-cache: Support --purge-all option

Takashi Iwai (1):
perf Documentation: Support for asciidoctor

 tools/lib/symbol/kallsyms.c                        |   6 +
 tools/lib/symbol/kallsyms.h                        |   2 +
 tools/perf/Documentation/Makefile                  |  29 ++-
 tools/perf/Documentation/asciidoctor-extensions.rb |  29 +++
 tools/perf/Documentation/perf-buildid-cache.txt    |   7 +-
 tools/perf/Documentation/perf-stat.txt             |  16 ++
 tools/perf/arch/arm/tests/dwarf-unwind.c           |   2 +-
 tools/perf/arch/arm64/tests/dwarf-unwind.c         |   2 +-
 tools/perf/arch/powerpc/tests/dwarf-unwind.c       |   2 +-
 tools/perf/arch/powerpc/util/skip-callchain-idx.c  |   3 +-
 tools/perf/arch/x86/tests/dwarf-unwind.c           |   2 +-
 tools/perf/builtin-annotate.c                      |   2 +-
 tools/perf/builtin-buildid-cache.c                 |  77 +++++-
 tools/perf/builtin-inject.c                        |   4 +-
 tools/perf/builtin-kallsyms.c                      |   2 +-
 tools/perf/builtin-kmem.c                          |   6 +-
 tools/perf/builtin-report.c                        |  14 +-
 tools/perf/builtin-script.c                        |  30 +--
 tools/perf/builtin-stat.c                          |  92 ++++++-
 tools/perf/builtin-timechart.c                     |   8 +-
 tools/perf/builtin-top.c                           |   7 +-
 tools/perf/builtin-trace.c                         |   9 +-
 tools/perf/check-headers.sh                        |  30 ++-
 tools/perf/tests/builtin-test.c                    |   9 +
 tools/perf/tests/code-reading.c                    |   5 +-
 tools/perf/tests/hists_common.c                    |   6 +-
 tools/perf/tests/mmap-thread-lookup.c              |   7 +-
 tools/perf/tests/vmlinux-kallsyms.c                |  20 +-
 tools/perf/ui/browsers/map.c                       |   2 +-
 tools/perf/ui/stdio/hist.c                         |   3 +-
 tools/perf/util/auxtrace.c                         |  12 +-
 tools/perf/util/build-id.c                         |   4 +-
 tools/perf/util/cs-etm.c                           |   4 +-
 tools/perf/util/db-export.c                        |   7 +-
 tools/perf/util/dso.c                              |  34 +--
 tools/perf/util/dso.h                              |  37 +--
 tools/perf/util/event.c                            |  37 ++-
 tools/perf/util/genelf.c                           |   2 +-
 tools/perf/util/intel-bts.c                        |   3 +-
 tools/perf/util/intel-pt.c                         |   8 +-
 tools/perf/util/machine.c                          | 162 +++++-------
 tools/perf/util/machine.h                          |  47 ++--
 tools/perf/util/map.c                              |  99 +++-----
 tools/perf/util/map.h                              |  59 ++---
 tools/perf/util/probe-event.c                      |  29 +--
 tools/perf/util/session.c                          |  13 +-
 tools/perf/util/sort.c                             |   6 +-
 tools/perf/util/srcline.c                          |   1 +
 tools/perf/util/stat.h                             |   3 +-
 tools/perf/util/symbol-elf.c                       | 275 ++++++++++-----------
 tools/perf/util/symbol-minimal.c                   |   3 +-
 tools/perf/util/symbol.c                           | 205 +++++++--------
 tools/perf/util/symbol.h                           |  24 +-
 tools/perf/util/symbol_fprintf.c                   |   4 +-
 tools/perf/util/thread.c                           |  35 ++-
 tools/perf/util/thread.h                           |  13 +-
 tools/perf/util/unwind-libdw.c                     |  23 +-
 tools/perf/util/unwind-libunwind-local.c           |  19 +-
 tools/perf/util/vdso.c                             |   6 +-
 59 files changed, 794 insertions(+), 813 deletions(-)
 create mode 100644 tools/perf/Documentation/asciidoctor-extensions.rb

Test results:

The first ones are container (docker) based builds of tools/perf with and without libelf support. Where clang is available, it is also used to build perf with/without libelf, and building with LIBCLANGLLVM=1 (built-in clang) with gcc and clang when clang and its devel libraries are installed.

The objtool and samples/bpf/ builds are disabled now that I'm switching from using the sources in a local volume to fetching them from a http server to build it inside the container, to make it easier to build in a container cluster. Those will come back later.

Several are cross builds, the ones with -x-ARCH and the android one, and those may not have all the features built, due to lack of multi-arch devel packages, available and being used so far on just a few, like debian:experimental-x-{arm64,mipsel}.

The 'perf test' one will perform a variety of tests exercising tools/perf/util/, tools/lib/{bpf,traceevent,etc}, as well as run perf commands with a variety of command line event specifications to then intercept the sys_perf_event syscall to check that the perf_event_attr fields are set up as expected, among a variety of other unit tests.

Then there is the 'make -C tools/perf build-test' ones, that build tools/perf/ with a variety of feature sets, exercising the build with an incomplete set of features as well as with a complete one. It is planned to have it run on each of the containers mentioned above, using some container orchestration infrastructure. Get in contact if interested in helping having this in place.

   1 alpine:3.4                    : Ok   gcc (Alpine 5.3.0) 5.3.0
   2 alpine:3.5                    : Ok   gcc (Alpine 6.2.1) 6.2.1 20160822
   3 alpine:3.6                    : Ok   gcc (Alpine 6.3.0) 6.3.0
   4 alpine:3.7                    : Ok   gcc (Alpine 6.4.0) 6.4.0
   5 alpine:edge                   : Ok   gcc (Alpine 6.4.0) 6.4.0
   6 amazonlinux:1                 : Ok   gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
   7 amazonlinux:2                 : Ok   gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
   8 android-ndk:r12b-arm          : Ok   arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease)
   9 android-ndk:r15c-arm          : Ok   arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease)
  10 centos:5                      : Ok   gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55)
  11 centos:6                      : Ok   gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)
  12 centos:7                      : Ok   gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
  13 debian:7                      : Ok   gcc (Debian 4.7.2-5) 4.7.2
  14 debian:8                      : Ok   gcc (Debian 4.9.2-10+deb8u1) 4.9.2
  15 debian:9                      : Ok   gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
  16 debian:experimental           : Ok   gcc (Debian 7.3.0-15) 7.3.0
  17 debian:experimental-x-arm64   : Ok   aarch64-linux-gnu-gcc (Debian 7.3.0-15) 7.3.0
  18 debian:experimental-x-mips    : Ok   mips-linux-gnu-gcc (Debian 7.3.0-12) 7.3.0
  19 debian:experimental-x-mips64  : Ok   mips64-linux-gnuabi64-gcc (Debian 7.3.0-12) 7.3.0
  20 debian:experimental-x-mipsel  : Ok   mipsel-linux-gnu-gcc (Debian 7.3.0-12) 7.3.0
  21 fedora:20                     : Ok   gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7)
  22 fedora:21                     : Ok   gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
  23 fedora:22                     : Ok   gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
  24 fedora:23                     : Ok   gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
  25 fedora:24                     : Ok   gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)
  26 fedora:24-x-ARC-uClibc        : Ok   arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710
  27 fedora:25                     : Ok   gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1)
  28 fedora:26                     : Ok   gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2)
  29 fedora:27                     : Ok   gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
  30 fedora:28                     : Ok   gcc (GCC) 8.0.1 20180324 (Red Hat 8.0.1-0.20)
  31 fedora:rawhide                : Ok   gcc (GCC) 8.0.1 20180324 (Red Hat 8.0.1-0.20)
  32 gentoo-stage3-amd64:latest    : Ok   gcc (Gentoo 6.4.0-r1 p1.3) 6.4.0
  33 mageia:5                      : Ok   gcc (GCC) 4.9.2
  34 mageia:6                      : Ok   gcc (Mageia 5.5.0-1.mga6) 5.5.0
  35 opensuse:42.1                 : Ok   gcc (SUSE Linux) 4.8.5
  36 opensuse:42.2                 : Ok   gcc (SUSE Linux) 4.8.5
  37 opensuse:42.3                 : Ok   gcc (SUSE Linux) 4.8.5
  38 opensuse:tumbleweed           : Ok   gcc (SUSE Linux) 7.3.1 20180323 [gcc-7-branch revision 258812]
  39 oraclelinux:6                 : Ok   gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)
  40 oraclelinux:7                 : Ok   gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28.0.1)
  41 ubuntu:12.04.5                : Ok   gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
  42 ubuntu:14.04.4                : Ok   gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
  43 ubuntu:14.04.4-x-linaro-arm64 : Ok   aarch64-linux-gnu-gcc (Linaro GCC 5.4-2017.05) 5.4.1 20170404
  44 ubuntu:15.04                  : Ok   gcc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
  45 ubuntu:16.04                  : Ok   gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  46 ubuntu:16.04-x-arm            : Ok   arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  47 ubuntu:16.04-x-arm64          : Ok   aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  48 ubuntu:16.04-x-powerpc        : Ok   powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  49 ubuntu:16.04-x-powerpc64      : Ok   powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  50 ubuntu:16.04-x-powerpc64el    : Ok   powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  51 ubuntu:16.04-x-s390           : Ok   s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  52 ubuntu:16.10                  : Ok   gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
  53 ubuntu:17.04                  : Ok   gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
  54 ubuntu:17.10                  : Ok   gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0
  55 ubuntu:18.04                  : Ok   gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0

[root@seventh ~]# uname -a
Linux seventh 4.17.0-rc3-00005-gfff75eb2a08c #1 SMP Tue May 1 08:50:07 -03 2018 x86_64 x86_64 x86_64 GNU/Linux [root@seventh ~]# perf test

 1: vmlinux symtab matches kallsyms                       : Ok
 2: Detect openat syscall event                           : Ok
 3: Detect openat syscall event on all cpus               : Ok
 4: Read samples using the mmap interface                 : Ok
 5: Test data source output                               : Ok
 6: Parse event definition strings                        : Ok
 7: Simple expression parser                              : Ok
 8: PERF_RECORD_* events & perf_sample fields             : Ok
 9: Parse perf pmu format                                 : Ok
10: DSO data read                                         : Ok
11: DSO data cache                                        : Ok
12: DSO data reopen                                       : Ok
13: Roundtrip evsel->name                                 : Ok
14: Parse sched tracepoints fields                        : Ok
15: syscalls:sys_enter_openat event fields                : Ok
16: Setup struct perf_event_attr                          : Ok
17: Match and link multiple hists                         : Ok
18: 'import perf' in python                               : Ok
19: Breakpoint overflow signal handler                    : Ok
20: Breakpoint overflow sampling                          : Ok
21: Breakpoint accounting                                 : Ok
22: Number of exit events of a simple workload            : Ok
23: Software clock events period values                   : Ok
24: Object code reading                                   : Ok
25: Sample parsing                                        : Ok
26: Use a dummy software event to keep tracking           : Ok
27: Parse with no sample_id_all bit set                   : Ok
28: Filter hist entries                                   : Ok
29: Lookup mmap thread                                    : Ok
30: Share thread mg                                       : Ok
31: Sort output of hist entries                           : Ok
32: Cumulate child hist entries                           : Ok
33: Track with sched_switch                               : Ok
34: Filter fds with revents mask in a fdarray             : Ok
35: Add fd to a fdarray, making it autogrow               : Ok
36: kmod_path__parse                                      : Ok
37: Thread map                                            : Ok
38: LLVM search and compile                               :
38.1: Basic BPF llvm compile                              : Ok
38.2: kbuild searching                                    : Ok
38.3: Compile source for BPF prologue generation          : Ok
38.4: Compile source for BPF relocation                   : Ok
39: Session topology                                      : Ok
40: BPF filter                                            :
40.1: Basic BPF filtering                                 : Ok
40.2: BPF pinning                                         : Ok
40.3: BPF prologue generation                             : Ok
40.4: BPF relocation checker                              : Ok
41: Synthesize thread map                                 : Ok
42: Remove thread map                                     : Ok
43: Synthesize cpu map                                    : Ok
44: Synthesize stat config                                : Ok
45: Synthesize stat                                       : Ok
46: Synthesize stat round                                 : Ok
47: Synthesize attr update                                : Ok
48: Event times                                           : Ok
49: Read backward ring buffer                             : Ok
50: Print cpu map                                         : Ok
51: Probe SDT events                                      : Ok
52: is_printable_array                                    : Ok
53: Print bitmap                                          : Ok
54: perf hooks                                            : Ok
55: builtin clang support                                 : Skip (not compiled in)
56: unit_number__scnprintf                                : Ok
57: mem2node                                              : Ok
58: x86 rdpmc                                             : Ok
59: Convert perf time to TSC                              : Ok
60: DWARF unwind                                          : Ok
61: x86 instruction decoder - new instructions            : Ok
62: Use vfs_getname probe to get syscall args filenames   : Ok
63: Check open filename arg using perf trace + vfs_getname: Ok
64: probe libc's inet_pton & backtrace it with ping       : Ok
65: probe libc's inet_pton & backtrace it with ping       : Ok
66: Add vfs_getname probe to get syscall args filenames   : Ok

#

  $ make -C tools/perf build-test
  make: Entering directory '/home/acme/git/perf/tools/perf'
  - tarpkg: ./tests/perf-targz-src-pkg .
                make_install_O: make install
            make_no_demangle_O: make NO_DEMANGLE=1
                   make_help_O: make help
             make_no_libperl_O: make NO_LIBPERL=1
                   make_pure_O: make
                 make_perf_o_O: make perf.o
             make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
                make_minimal_O: make NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1
                   make_tags_O: make tags
                  make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
           make_no_libbionic_O: make NO_LIBBIONIC=1
  make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
        make_with_babeltrace_O: make LIBBABELTRACE=1
           make_no_libunwind_O: make NO_LIBUNWIND=1
            make_no_libaudit_O: make NO_LIBAUDIT=1
                make_no_gtk2_O: make NO_GTK2=1
                 make_static_O: make LDFLAGS=-static
              make_clean_all_O: make clean all
   make_install_prefix_slash_O: make install prefix=/tmp/krava/
             make_util_map_o_O: make util/map.o
       make_util_pmu_bison_o_O: make util/pmu-bison.o
         make_with_clangllvm_O: make LIBCLANGLLVM=1
           make_no_libpython_O: make NO_LIBPYTHON=1
                make_no_newt_O: make NO_NEWT=1
            make_no_auxtrace_O: make NO_AUXTRACE=1
             make_no_libnuma_O: make NO_LIBNUMA=1
         make_install_prefix_O: make install prefix=/tmp/krava
               make_no_slang_O: make NO_SLANG=1
           make_no_backtrace_O: make NO_BACKTRACE=1
                  make_debug_O: make DEBUG=1
              make_no_libbpf_O: make NO_LIBBPF=1
                    make_doc_O: make doc
            make_install_bin_O: make install-bin
              make_no_libelf_O: make NO_LIBELF=1
  OK
  make: Leaving directory '/home/acme/git/perf/tools/perf'
  $
author maintainer
#1 lore raw

PATCH 1/52 perf buildid-cache: Support --list option

From: Ravi Bangoria <[email protected]>

'perf buildid-cache' allows to add/remove files into cache but there is no option to list all cached files. Add --list option to list all _valid_ cached files.

Ex,

  # perf buildid-cache --add /tmp/a.out
  # perf buildid-cache -l
    8a86ef73e44067bca52cc3f6cd3e5446c783391c /tmp/a.out
Cc Alexander Shishkin <[email protected]>
Cc Kate Stewart <[email protected]>
Cc Krister Johansen <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Philippe Ombredanne <[email protected]>
Cc Sihyeon Jang <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 tools/perf/Documentation/perf-buildid-cache.txt |  4 ++-
 tools/perf/builtin-buildid-cache.c              | 43 +++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -1
index 73c2650bd0db..3f285ba6e1f9 100644
@@ -59,7 +59,9 @@ OPTIONS
 	exactly same build-id, that is replaced by new one. It can be used
 	to update kallsyms and kernel dso to vmlinux in order to support
 	annotation.
-
+-l::
+--list::
+	List all valid binaries from cache.
 -v::
 --verbose::
 	Be more verbose.
tools/perf/builtin-buildid-cache.c +40 -3

81 lines not on this page · raw message

Signature · 1 line
2.14.3
author maintainer
#2 lore raw

PATCH 2/52 perf buildid-cache: Support --purge-all option

In reply to Arnaldo Carvalho de Melo

From: Ravi Bangoria <[email protected]>

User can remove files from cache using --remove/--purge options but both needs list of files as an argument. It's not convenient when you want to flush out entire cache. Add an option to purge all files from cache.

Ex,

  # perf buildid-cache -l
    8a86ef73e44067bca52cc3f6cd3e5446c783391c /tmp/a.out
    ebe71fdcf4b366518cc154d570a33cd461a51c36 /tmp/a.out.1
  # perf buildid-cache -P -v
    Removing /tmp/a.out (8a86ef73e44067bca52cc3f6cd3e5446c783391c): Ok
    Removing /tmp/a.out.1 (ebe71fdcf4b366518cc154d570a33cd461a51c36): Ok
    Purged all: Ok
Cc Alexander Shishkin <[email protected]>
Cc Kate Stewart <[email protected]>
Cc Krister Johansen <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Philippe Ombredanne <[email protected]>
Cc Sihyeon Jang <[email protected]>
Cc Thomas Gleixner <[email protected]>
[ Initialize 'err' in build_id_cache__purge_all(), to fix build on debian:7, as it can be used uninitialized ]
---
 tools/perf/Documentation/perf-buildid-cache.txt |  3 +++
 tools/perf/builtin-buildid-cache.c              | 36 ++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-buildid-cache.txt +3 -0
index 3f285ba6e1f9..f6de0952ff3c 100644
@@ -48,6 +48,9 @@ OPTIONS
 --purge=::
         Purge all cached binaries including older caches which have specified
 	path from the cache.
+-P::
+--purge-all::
+	Purge all cached binaries. This will flush out entire cache.
 -M::
 --missing=::
 	List missing build ids in the cache for the specified file.
tools/perf/builtin-buildid-cache.c +35 -1
index fd0a08661b42..7a7403913b57 100644
@@ -240,6 +240,34 @@ static int build_id_cache__purge_path(const char *pathname, struct nsinfo *nsi)
 	return err;
 }
 
+static int build_id_cache__purge_all(void)
+{
+	struct strlist *list;
+	struct str_node *pos;
+	int err = 0;
+	char *buf;
+
+	list = build_id_cache__list_all(false);
+	if (!list) {
+		pr_debug("Failed to get buildids: -%d\n", errno);
+		return -EINVAL;
+	}
+
+	strlist__for_each_entry(pos, list) {
+		buf = build_id_cache__origname(pos->s);
+		err = build_id_cache__remove_s(pos->s);
+		pr_debug("Removing %s (%s): %s\n", buf, pos->s,
+			 err ? "FAIL" : "Ok");
+		free(buf);
+		if (err)
+			break;
+	}
+	strlist__delete(list);
+
+	pr_debug("Purged all: %s\n", err ? "FAIL" : "Ok");
+	return err;
+}
+
 static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
 {
 	char filename[PATH_MAX];
@@ -327,6 +355,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 	bool force = false;
 	bool list_files = false;
 	bool opts_flag = false;
+	bool purge_all = false;
 	char const *add_name_list_str = NULL,
 		   *remove_name_list_str = NULL,
 		   *purge_name_list_str = NULL,
@@ -350,6 +379,7 @@ int cmd_buildid_cache(int argc, const char **argv)
 		    "file(s) to remove"),
 	OPT_STRING('p', "purge", &purge_name_list_str, "file list",
 		    "file(s) to remove (remove old caches too)"),
+	OPT_BOOLEAN('P', "purge-all", &purge_all, "purge all cached files"),
 	OPT_BOOLEAN('l', "list", &list_files, "list all cached files"),
 	OPT_STRING('M', "missing", &missing_filename, "file",
 		   "to find missing build ids in the cache"),
@@ -370,7 +400,8 @@ int cmd_buildid_cache(int argc, const char **argv)
 
 	opts_flag = add_name_list_str || kcore_filename ||
 		remove_name_list_str || purge_name_list_str ||
-		missing_filename || update_name_list_str;
+		missing_filename || update_name_list_str ||
+		purge_all;
 
 	if (argc || !(list_files || opts_flag))
 		usage_with_options(buildid_cache_usage, buildid_cache_options);
@@ -457,6 +488,9 @@ int cmd_buildid_cache(int argc, const char **argv)
 		}
 	}
 
+	if (purge_all)
+		ret = build_id_cache__purge_all();
+
 	if (missing_filename)
 		ret = build_id_cache__fprintf_missing(session, stdout);
 
Signature · 1 line
2.14.3
author maintainer
#3 lore raw

PATCH 3/52 perf check-headers.sh: Simplify arguments passing

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

Passing whole string instead of parsing them after. It simplifies things for the next patches, that adds another function call, which makes it hard to pass arguments in the correct shape.

---
 tools/perf/check-headers.sh | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
tools/perf/check-headers.sh +5 -10
index 9aff89bc7535..88c5f9449809 100755
@@ -59,13 +59,8 @@ check () {
   file=$1
 
   shift
-  opts=
-  while [ -n "$*" ]; do
-    opts="$opts \"$1\""
-    shift
-  done
 
-  cmd="diff $opts ../$file ../../$file > /dev/null"
+  cmd="diff $* ../$file ../../$file > /dev/null"
 
   test -f ../../$file &&
   eval $cmd || echo "Warning: Kernel ABI header at 'tools/$file' differs from latest version at '$file'" >&2
@@ -83,7 +78,7 @@ for i in $HEADERS; do
 done
 
 # diff with extra ignore lines
-check arch/x86/lib/memcpy_64.S        -I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"
-check arch/x86/lib/memset_64.S        -I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"
-check include/uapi/asm-generic/mman.h -I "^#include <\(uapi/\)*asm-generic/mman-common.h>"
-check include/uapi/linux/mman.h       -I "^#include <\(uapi/\)*asm/mman.h>"
+check arch/x86/lib/memcpy_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"'
+check arch/x86/lib/memset_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>"'
+check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common.h>"'
+check include/uapi/linux/mman.h       '-I "^#include <\(uapi/\)*asm/mman.h>"'
Signature · 1 line
2.14.3
author maintainer
#4 lore raw

PATCH 4/52 perf check-headers.sh: Add support to check 2 independent files

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

Add 'check_2' function to check 2 different files, the 'check' function stays to check files that differs only in the prefix path.

In upcoming changes we need to check header files in locations which don't follow the prefix logic.

---
 tools/perf/check-headers.sh | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
tools/perf/check-headers.sh +13 -4
index 88c5f9449809..10f333e2e825 100755
@@ -55,17 +55,26 @@ include/uapi/asm-generic/ioctls.h
 include/uapi/asm-generic/mman-common.h
 '
 
-check () {
-  file=$1
+check_2 () {
+  file1=$1
+  file2=$2
 
+  shift
   shift
 
-  cmd="diff $* ../$file ../../$file > /dev/null"
+  cmd="diff $* $file1 $file2 > /dev/null"
 
-  test -f ../../$file &&
+  test -f $file2 &&
   eval $cmd || echo "Warning: Kernel ABI header at 'tools/$file' differs from latest version at '$file'" >&2
 }
 
+check () {
+  file=$1
+
+  shift
+
+  check_2 ../$file ../../$file $*
+}
 
 # Check if we have the kernel headers (tools/perf/../../include), else
 # we're probably on a detached tarball, so no point in trying to check
Signature · 1 line
2.14.3
author maintainer
#5 lore raw

PATCH 5/52 perf stat: Display time in precision based on std deviation

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

Ingo suggested to display elapsed time for multirun workload (perf stat -e) with precision based on the precision of the standard deviation.

In his own words:

Quoted 8 lines

This output is a slightly bit misleading:

Performance counter stats for 'make -j128' (10 runs):

     27.988995256 seconds time elapsed                  ( +-  0.39% )

The 9 significant digits in the result, while only 1 is valid, suggests accuracy where none exists.

Quoted 8 lines

It would be better if 'perf stat' would display elapsed time with a precision adjusted to stddev, it should display at most 2 more significant digits than the stddev inaccuracy.

I.e. in the above case 0.39% is 0.109, so we only have accuracy for 1 digit, and so we should only display 3:

27.988 seconds time elapsed ( +- 0.39% )

Plus a suggestion about the output, which is small enough and connected with the above change that I merged both changes together.

Quoted 4 lines

Small output style nit - I think it would be nice if with --repeat the stddev was also displayed in absolute values, besides percentage:

      27.988 +- 0.109 seconds time elapsed   ( +- 0.39% )

The output is now:

Performance counter stats for './perf bench sched pipe' (5 runs):
SNIP

           13.3667 +- 0.0256 seconds time elapsed  ( +-  0.19% )
---
 tools/perf/builtin-stat.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
tools/perf/builtin-stat.c +24 -6
index f17dc601b0f3..3a94647ef6bc 100644
@@ -1764,19 +1764,37 @@ static void print_header(int argc, const char **argv)
 	}
 }
 
+static int get_precision(double num)
+{
+	if (num > 1)
+		return 0;
+
+	return lround(ceil(-log10(num)));
+}
+
 static void print_footer(void)
 {
+	double avg = avg_stats(&walltime_nsecs_stats) / NSEC_PER_SEC;
 	FILE *output = stat_config.output;
 	int n;
 
 	if (!null_run)
 		fprintf(output, "\n");
-	fprintf(output, " %17.9f seconds time elapsed",
-			avg_stats(&walltime_nsecs_stats) / NSEC_PER_SEC);
-	if (run_count > 1) {
-		fprintf(output, "                                        ");
-		print_noise_pct(stddev_stats(&walltime_nsecs_stats),
-				avg_stats(&walltime_nsecs_stats));
+
+	if (run_count == 1) {
+		fprintf(output, " %17.9f seconds time elapsed", avg);
+	} else {
+		double sd = stddev_stats(&walltime_nsecs_stats) / NSEC_PER_SEC;
+		/*
+		 * Display at most 2 more significant
+		 * digits than the stddev inaccuracy.
+		 */
+		int precision = get_precision(sd) + 2;
+
+		fprintf(output, " %17.*f +- %.*f seconds time elapsed",
+			precision, avg, precision, sd);
+
+		print_noise_pct(sd, avg);
 	}
 	fprintf(output, "\n\n");
 
Signature · 1 line
2.14.3
author maintainer
#6 lore raw

PATCH 6/52 perf stat: Add --table option to display time of each run

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

Add --table option to display time for each run (-r option), like:

  $ perf stat --null -r 5 --table perf bench sched pipe

Performance counter stats for './perf bench sched pipe' (5 runs):

             # Table of individual measurements:
             5.379 (-0.176)
             5.243 (-0.311)
             5.238 (-0.317)
             5.536 (-0.019)
             6.377 (+0.823)

             # Final result:
             5.555 +- 0.213 seconds time elapsed  ( +-  3.83% )
Cc Alexander Shishkin <[email protected]>
Cc David Ahern <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ Document the new option in 'perf stat's man page ]
---
 tools/perf/Documentation/perf-stat.txt | 16 ++++++++++
 tools/perf/builtin-stat.c              | 56 +++++++++++++++++++++++++++++++---
 tools/perf/util/stat.h                 |  3 +-
 3 files changed, 69 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-stat.txt +16 -0
index e6c3b4e555c2..72a2414513bd 100644
@@ -116,6 +116,22 @@ Do not aggregate counts across all monitored CPUs.
 print counts using a CSV-style output to make it easy to import directly into
 spreadsheets. Columns are separated by the string specified in SEP.
 
+--table:: Display time for each run (-r option), in a table format, e.g.:
+
+  $ perf stat --null -r 5 --table perf bench sched pipe
+
+   Performance counter stats for 'perf bench sched pipe' (5 runs):
+
+             # Table of individual measurements:
+             5.379 (-0.176)
+             5.243 (-0.311)
+             5.238 (-0.317)
+             5.536 (-0.019)
+             6.377 (+0.823)
+
+             # Final result:
+             5.555 +- 0.213 seconds time elapsed  ( +-  3.83% )
+
 -G name::
 --cgroup name::
 monitor only in the container (cgroup) called "name". This option is available only
tools/perf/builtin-stat.c +52 -4

134 lines not on this page · raw message

tools/perf/util/stat.h +1 -2
index 8f56ba4fd258..36efb986f7fc 100644
@@ -7,8 +7,7 @@
 #include "xyarray.h"
 #include "rblist.h"
 
-struct stats
-{
+struct stats {
 	double n, mean, M2;
 	u64 max, min;
 };
Signature · 1 line
2.14.3
author maintainer
#7 lore raw

PATCH 7/52 perf stat: Display length strings of each run for --table option

In reply to Arnaldo Carvalho de Melo

From: Jiri Olsa <[email protected]>

Adding support to display visual aid 'length strings' to easily spot the biggest difference in time table.

  $ perf stat -r 10 --table perf bench sched pipe
  ...

Performance counter stats for './perf bench sched pipe' (5 runs):

             # Table of individual measurements:
             5.189 (-0.293) #
             5.189 (-0.294) #
             5.186 (-0.296) #
             5.663 (+0.181) ##
             6.186 (+0.703) ####

             # Final result:
             5.483 +- 0.198 seconds time elapsed  ( +-  3.62% )
---
 tools/perf/Documentation/perf-stat.txt | 12 ++++++------
 tools/perf/builtin-stat.c              |  8 +++++++-
 2 files changed, 13 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-stat.txt +6 -6
index 72a2414513bd..3a822f308e6d 100644
@@ -123,14 +123,14 @@ spreadsheets. Columns are separated by the string specified in SEP.
    Performance counter stats for 'perf bench sched pipe' (5 runs):
 
              # Table of individual measurements:
-             5.379 (-0.176)
-             5.243 (-0.311)
-             5.238 (-0.317)
-             5.536 (-0.019)
-             6.377 (+0.823)
+             5.189 (-0.293) #
+             5.189 (-0.294) #
+             5.186 (-0.296) #
+             5.663 (+0.181) ##
+             6.186 (+0.703) ####
 
              # Final result:
-             5.555 +- 0.213 seconds time elapsed  ( +-  3.83% )
+             5.483 +- 0.198 seconds time elapsed  ( +-  3.62% )
 
 -G name::
 --cgroup name::
tools/perf/builtin-stat.c +7 -1
index 72553937c010..a4f662a462c6 100644
@@ -1790,9 +1790,15 @@ static void print_table(FILE *output, int precision, double avg)
 
 	for (idx = 0; idx < run_count; idx++) {
 		double run = (double) walltime_run[idx] / NSEC_PER_SEC;
+		int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5);
 
-		fprintf(output, " %17.*f (%+.*f)\n",
+		fprintf(output, " %17.*f (%+.*f) ",
 			precision, run, precision, run - avg);
+
+		for (h = 0; h < n; h++)
+			fprintf(output, "#");
+
+		fprintf(output, "\n");
 	}
 
 	fprintf(output, "\n%*s# Final result:\n", indent, "");
Signature · 1 line
2.14.3
author maintainer
#8 lore raw

PATCH 8/52 perf top: Use __map__is_kernel()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Shorter form to figure out if a given map is the kernel one and also reduces the number of code accessing MAP__{FUNCTION,VARIABLE}, that should go away at some point.

---
 tools/perf/builtin-top.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-top.c +2 -2
index f39bd60d2708..4e975f3ee3be 100644
@@ -750,7 +750,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
 		machine->kptr_restrict_warned = true;
 	}
 
-	if (al.sym == NULL) {
+	if (al.sym == NULL && al.map != NULL) {
 		const char *msg = "Kernel samples will not be resolved.\n";
 		/*
 		 * As we do lazy loading of symtabs we only will know if the
@@ -764,7 +764,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
 		 * invalid --vmlinux ;-)
 		 */
 		if (!machine->kptr_restrict_warned && !top->vmlinux_warned &&
-		    al.map == machine->vmlinux_maps[MAP__FUNCTION] &&
+		    __map__is_kernel(al.map) &&
 		    RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) {
 			if (symbol_conf.vmlinux_name) {
 				char serr[256];
Signature · 1 line
2.14.3
author maintainer
#9 lore raw

PATCH 9/52 perf symbols: Use __map__is_kernel() instead of ad-hoc equivalent code

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Shorter, should be equivalent code, use it.

---
 tools/perf/util/symbol.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/symbol.c +1 -4
index 1466814ebada..2b6292cff719 100644
@@ -1163,7 +1163,6 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 			   const char *kallsyms_filename)
 {
 	struct map_groups *kmaps = map__kmaps(map);
-	struct machine *machine;
 	struct kcore_mapfn_data md;
 	struct map *old_map, *new_map, *replacement_map = NULL;
 	bool is_64_bit;
@@ -1174,10 +1173,8 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	if (!kmaps)
 		return -EINVAL;
 
-	machine = kmaps->machine;
-
 	/* This function requires that the map is the kernel map */
-	if (map != machine->vmlinux_maps[map->type])
+	if (!__map__is_kernel(map))
 		return -EINVAL;
 
 	if (!filename_from_kallsyms_filename(kcore_filename, "kcore",
Signature · 1 line
2.14.3
author maintainer
#10 lore raw

PATCH 10/52 perf dso: Add dso__has_symbols() method

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

To replace longer code sequences in various places.

---
 tools/perf/builtin-report.c | 2 +-
 tools/perf/builtin-top.c    | 4 ++--
 tools/perf/util/dso.h       | 5 +++++
 3 files changed, 8 insertions(+), 3 deletions(-)
tools/perf/builtin-report.c +1 -1
index 0f198f6d9b77..a4104e447f56 100644
@@ -525,7 +525,7 @@ static void report__warn_kptr_restrict(const struct report *rep)
 
 		if (kernel_map) {
 			const struct dso *kdso = kernel_map->dso;
-			if (!RB_EMPTY_ROOT(&kdso->symbols[MAP__FUNCTION])) {
+			if (dso__has_symbols(kdso, MAP__FUNCTION)) {
 				desc = "If some relocation was applied (e.g. "
 				       "kexec) symbols may be misresolved.";
 			}
tools/perf/builtin-top.c +2 -2
index 4e975f3ee3be..c11b46b411d5 100644
@@ -742,7 +742,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
 "Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n"
 "Check /proc/sys/kernel/kptr_restrict.\n\n"
 "Kernel%s samples will not be resolved.\n",
-			  al.map && !RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION]) ?
+			  al.map && dso__has_symbols(al.map->dso, MAP__FUNCTION) ?
 			  " modules" : "");
 			if (use_browser <= 0)
 				sleep(5);
@@ -765,7 +765,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
 		 */
 		if (!machine->kptr_restrict_warned && !top->vmlinux_warned &&
 		    __map__is_kernel(al.map) &&
-		    RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) {
+		    dso__has_symbols(al.map->dso, MAP__FUNCTION)) {
 			if (symbol_conf.vmlinux_name) {
 				char serr[256];
 				dso__strerror_load(al.map->dso, serr, sizeof(serr));
tools/perf/util/dso.h +5 -0
index c229dbe0277a..881d572be6aa 100644
@@ -233,6 +233,11 @@ static inline void __dso__zput(struct dso **dso)
 
 bool dso__loaded(const struct dso *dso, enum map_type type);
 
+static inline bool dso__has_symbols(const struct dso *dso, enum map_type type)
+{
+	return !RB_EMPTY_ROOT(&dso->symbols[type]);
+}
+
 bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
 void dso__set_sorted_by_name(struct dso *dso, enum map_type type);
 void dso__sort_by_name(struct dso *dso, enum map_type type);
Signature · 1 line
2.14.3
author maintainer
#11 lore raw

PATCH 11/52 perf map: Introduce map__has_symbols()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

To further simplify checking if symbols are available for a given map and to reduce the number of users of MAP__{FUNCTION,VARIABLE}.

---
 tools/perf/builtin-report.c | 9 +++------
 tools/perf/builtin-top.c    | 5 ++---
 tools/perf/util/map.c       | 5 +++++
 tools/perf/util/map.h       | 2 ++
 4 files changed, 12 insertions(+), 9 deletions(-)
tools/perf/builtin-report.c +3 -6
index a4104e447f56..68ea336bf311 100644
@@ -523,12 +523,9 @@ static void report__warn_kptr_restrict(const struct report *rep)
 		    "As no suitable kallsyms nor vmlinux was found, kernel samples\n"
 		    "can't be resolved.";
 
-		if (kernel_map) {
-			const struct dso *kdso = kernel_map->dso;
-			if (dso__has_symbols(kdso, MAP__FUNCTION)) {
-				desc = "If some relocation was applied (e.g. "
-				       "kexec) symbols may be misresolved.";
-			}
+		if (kernel_map && map__has_symbols(kernel_map)) {
+			desc = "If some relocation was applied (e.g. "
+			       "kexec) symbols may be misresolved.";
 		}
 
 		ui__warning(
tools/perf/builtin-top.c +2 -3
index c11b46b411d5..3c061c57afb6 100644
@@ -742,7 +742,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
 "Kernel address maps (/proc/{kallsyms,modules}) are restricted.\n\n"
 "Check /proc/sys/kernel/kptr_restrict.\n\n"
 "Kernel%s samples will not be resolved.\n",
-			  al.map && dso__has_symbols(al.map->dso, MAP__FUNCTION) ?
+			  al.map && map__has_symbols(al.map) ?
 			  " modules" : "");
 			if (use_browser <= 0)
 				sleep(5);
@@ -764,8 +764,7 @@ static void perf_event__process_sample(struct perf_tool *tool,
 		 * invalid --vmlinux ;-)
 		 */
 		if (!machine->kptr_restrict_warned && !top->vmlinux_warned &&
-		    __map__is_kernel(al.map) &&
-		    dso__has_symbols(al.map->dso, MAP__FUNCTION)) {
+		    __map__is_kernel(al.map) && map__has_symbols(al.map)) {
 			if (symbol_conf.vmlinux_name) {
 				char serr[256];
 				dso__strerror_load(al.map->dso, serr, sizeof(serr));
tools/perf/util/map.c +5 -0
index 8fe57031e1a8..f553e302bf9c 100644
@@ -259,6 +259,11 @@ bool __map__is_kernel(const struct map *map)
 	return __machine__kernel_map(map->groups->machine, map->type) == map;
 }
 
+bool map__has_symbols(const struct map *map)
+{
+	return dso__has_symbols(map->dso, map->type);
+}
+
 static void map__exit(struct map *map)
 {
 	BUG_ON(!RB_EMPTY_NODE(&map->rb_node));
tools/perf/util/map.h +2 -0
index 0e9bbe01b0ab..fc91bac8fed0 100644
@@ -264,4 +264,6 @@ static inline bool __map__is_kmodule(const struct map *map)
 	return !__map__is_kernel(map);
 }
 
+bool map__has_symbols(const struct map *map);
+
 #endif /* __PERF_MAP_H */
Signature · 1 line
2.14.3
author maintainer
#12 lore raw

PATCH 12/52 perf thread: Introduce thread__find_map()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Out of thread__find_add_map(..., MAP__FUNCTION, ...), idea here is to continue removing references to MAP__{FUNCTION,VARIABLE} ahead of getting both types of symbols in the same rbtree, as various places do two lookups, looking first at MAP__FUNCTION, then at MAP__VARIABLE.

So thread__find_map() will eventually do just that, and 'struct symbol' will have the symbol type, for code that cares about that.

---
 tools/perf/builtin-inject.c              |  2 +-
 tools/perf/builtin-script.c              | 19 +++++++++----------
 tools/perf/tests/code-reading.c          |  4 ++--
 tools/perf/tests/mmap-thread-lookup.c    |  7 +++----
 tools/perf/util/build-id.c               |  2 +-
 tools/perf/util/cs-etm.c                 |  2 +-
 tools/perf/util/event.c                  | 18 +++++++++---------
 tools/perf/util/intel-bts.c              |  2 +-
 tools/perf/util/intel-pt.c               |  4 ++--
 tools/perf/util/thread.h                 | 11 ++++++++---
 tools/perf/util/unwind-libdw.c           |  7 +++----
 tools/perf/util/unwind-libunwind-local.c |  7 +++----
 12 files changed, 43 insertions(+), 42 deletions(-)
tools/perf/builtin-inject.c +1 -1
index 40fe919bbcf3..92677d8f9eae 100644
@@ -440,7 +440,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
 		goto repipe;
 	}
 
-	thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, &al);
+	thread__find_map(thread, sample->cpumode, sample->ip, &al);
 
 	if (al.map != NULL) {
 		if (!al.map->dso->hit) {
tools/perf/builtin-script.c +9 -10
index e0a9845b6cbc..5ec1c73bbfaf 100644
@@ -717,8 +717,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,
 		if (PRINT_FIELD(DSO)) {
 			memset(&alf, 0, sizeof(alf));
 			memset(&alt, 0, sizeof(alt));
-			thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf);
-			thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
+			thread__find_map(thread, sample->cpumode, from, &alf);
+			thread__find_map(thread, sample->cpumode, to, &alt);
 		}
 
 		printed += fprintf(fp, " 0x%"PRIx64, from);
@@ -764,11 +764,11 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,
 		from = br->entries[i].from;
 		to   = br->entries[i].to;
 
-		thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf);
+		thread__find_map(thread, sample->cpumode, from, &alf);
 		if (alf.map)
 			alf.sym = map__find_symbol(alf.map, alf.addr);
 
-		thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
+		thread__find_map(thread, sample->cpumode, to, &alt);
 		if (alt.map)
 			alt.sym = map__find_symbol(alt.map, alt.addr);
 
@@ -814,11 +814,11 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
 		from = br->entries[i].from;
 		to   = br->entries[i].to;
 
-		thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf);
+		thread__find_map(thread, sample->cpumode, from, &alf);
 		if (alf.map && !alf.map->dso->adjust_symbols)
 			from = map__map_ip(alf.map, from);
 
-		thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt);
+		thread__find_map(thread, sample->cpumode, to, &alt);
 		if (alt.map && !alt.map->dso->adjust_symbols)
 			to = map__map_ip(alt.map, to);
 
@@ -882,7 +882,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
 		return 0;
 	}
 
-	thread__find_addr_map(thread, *cpumode, MAP__FUNCTION, start, &al);
+	thread__find_map(thread, *cpumode, start, &al);
 	if (!al.map || !al.map->dso) {
 		pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
 		return 0;
@@ -933,10 +933,9 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
 
 	memset(&al, 0, sizeof(al));
 
-	thread__find_addr_map(thread, cpumode, MAP__FUNCTION, addr, &al);
+	thread__find_map(thread, cpumode, addr, &al);
 	if (!al.map)
-		thread__find_addr_map(thread, cpumode, MAP__VARIABLE,
-				      addr, &al);
+		__thread__find_map(thread, cpumode, MAP__VARIABLE, addr, &al);
 	if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end)
 		return 0;
 
tools/perf/tests/code-reading.c +2 -2
index 99936352df4f..5b0a55499486 100644
@@ -236,14 +236,14 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 
 	pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
 
-	thread__find_addr_map(thread, cpumode, MAP__FUNCTION, addr, &al);
+	thread__find_map(thread, cpumode, addr, &al);
 	if (!al.map || !al.map->dso) {
 		if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
 			pr_debug("Hypervisor address can not be resolved - skipping\n");
 			return 0;
 		}
 
-		pr_debug("thread__find_addr_map failed\n");
+		pr_debug("thread__find_map failed\n");
 		return -1;
 	}
 
tools/perf/tests/mmap-thread-lookup.c +3 -4
index 868d82b501f4..b1af2499a3c9 100644
@@ -188,9 +188,8 @@ static int mmap_events(synth_cb synth)
 
 		pr_debug("looking for map %p\n", td->map);
 
-		thread__find_addr_map(thread,
-				      PERF_RECORD_MISC_USER, MAP__FUNCTION,
-				      (unsigned long) (td->map + 1), &al);
+		thread__find_map(thread, PERF_RECORD_MISC_USER,
+				 (unsigned long) (td->map + 1), &al);
 
 		thread__put(thread);
 
@@ -218,7 +217,7 @@ static int mmap_events(synth_cb synth)
  *   perf_event__synthesize_threads    (global)
  *
  * We test we can find all memory maps via:
- *   thread__find_addr_map
+ *   thread__find_map
  *
  * by using all thread objects.
  */
tools/perf/util/build-id.c +1 -1
index 537eadd81914..b512dc8fa6c3 100644
@@ -47,7 +47,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
 		return -1;
 	}
 
-	thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, &al);
+	thread__find_map(thread, sample->cpumode, sample->ip, &al);
 
 	if (al.map != NULL)
 		al.map->dso->hit = 1;
tools/perf/util/cs-etm.c +1 -1
index 40020b1ca54f..8fe573d040b6 100644
@@ -269,7 +269,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,
 		thread = etmq->etm->unknown_thread;
 	}
 
-	thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al);
+	thread__find_map(thread, cpumode, address, &al);
 
 	if (!al.map || !al.map->dso)
 		return 0;
tools/perf/util/event.c +9 -9
index 98ff3a6a3d50..baa97d0b6114 100644
@@ -1489,9 +1489,8 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
 	return machine__process_event(machine, event, sample);
 }
 
-void thread__find_addr_map(struct thread *thread, u8 cpumode,
-			   enum map_type type, u64 addr,
-			   struct addr_location *al)
+void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
+			u64 addr, struct addr_location *al)
 {
 	struct map_groups *mg = thread->mg;
 	struct machine *machine = mg->machine;
@@ -1569,7 +1568,7 @@ void thread__find_addr_location(struct thread *thread,
 				u8 cpumode, enum map_type type, u64 addr,
 				struct addr_location *al)
 {
-	thread__find_addr_map(thread, cpumode, type, addr, al);
+	__thread__find_map(thread, cpumode, type, addr, al);
 	if (al->map != NULL)
 		al->sym = map__find_symbol(al->map, al->addr);
 	else
@@ -1590,7 +1589,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
 		return -1;
 
 	dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid);
-	thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, al);
+	thread__find_map(thread, sample->cpumode, sample->ip, al);
 	dump_printf(" ...... dso: %s\n",
 		    al->map ? al->map->dso->long_name :
 			al->level == 'H' ? "[hypervisor]" : "<not found>");
@@ -1669,10 +1668,11 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)
 void thread__resolve(struct thread *thread, struct addr_location *al,
 		     struct perf_sample *sample)
 {
-	thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->addr, al);
-	if (!al->map)
-		thread__find_addr_map(thread, sample->cpumode, MAP__VARIABLE,
-				      sample->addr, al);
+	thread__find_map(thread, sample->cpumode, sample->addr, al);
+	if (!al->map) {
+		__thread__find_map(thread, sample->cpumode, MAP__VARIABLE,
+				   sample->addr, al);
+	}
 
 	al->cpu = sample->cpu;
 	al->sym = NULL;
tools/perf/util/intel-bts.c +1 -1
index 72db2744876d..ea0ce8572bf2 100644
@@ -335,7 +335,7 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip)
 	if (!thread)
 		return -1;
 
-	thread__find_addr_map(thread, cpumode, MAP__FUNCTION, ip, &al);
+	thread__find_map(thread, cpumode, ip, &al);
 	if (!al.map || !al.map->dso)
 		goto out_put;
 
tools/perf/util/intel-pt.c +2 -2
index 0effaff57020..441e681a46a0 100644
@@ -442,7 +442,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 	}
 
 	while (1) {
-		thread__find_addr_map(thread, cpumode, MAP__FUNCTION, *ip, &al);
+		thread__find_map(thread, cpumode, *ip, &al);
 		if (!al.map || !al.map->dso)
 			return -EINVAL;
 
@@ -596,7 +596,7 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data)
 	if (!thread)
 		return -EINVAL;
 
-	thread__find_addr_map(thread, cpumode, MAP__FUNCTION, ip, &al);
+	thread__find_map(thread, cpumode, ip, &al);
 	if (!al.map || !al.map->dso)
 		return -EINVAL;
 
tools/perf/util/thread.h +8 -3
index 14d44c3235b8..52c788f955de 100644
@@ -92,9 +92,14 @@ size_t thread__fprintf(struct thread *thread, FILE *fp);
 
 struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
 
-void thread__find_addr_map(struct thread *thread,
-			   u8 cpumode, enum map_type type, u64 addr,
-			   struct addr_location *al);
+void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
+			u64 addr, struct addr_location *al);
+
+static inline void thread__find_map(struct thread *thread, u8 cpumode,
+				    u64 addr, struct addr_location *al)
+{
+	__thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
+}
 
 void thread__find_addr_location(struct thread *thread,
 				u8 cpumode, enum map_type type, u64 addr,
tools/perf/util/unwind-libdw.c +3 -4
index 7bdd239c795c..1ce8744649b5 100644
@@ -103,16 +103,15 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr,
 	struct addr_location al;
 	ssize_t size;
 
-	thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
-			      MAP__FUNCTION, addr, &al);
+	thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al);
 	if (!al.map) {
 		/*
 		 * We've seen cases (softice) where DWARF unwinder went
 		 * through non executable mmaps, which we need to lookup
 		 * in MAP__VARIABLE tree.
 		 */
-		thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
-				      MAP__VARIABLE, addr, &al);
+		__thread__find_map(ui->thread, PERF_RECORD_MISC_USER,
+				   MAP__VARIABLE, addr, &al);
 	}
 
 	if (!al.map) {
tools/perf/util/unwind-libunwind-local.c +3 -4
index af873044d33a..33afca5c04f6 100644
@@ -367,16 +367,15 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
 {
 	struct addr_location al;
 
-	thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
-			      MAP__FUNCTION, ip, &al);
+	thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al);
 	if (!al.map) {
 		/*
 		 * We've seen cases (softice) where DWARF unwinder went
 		 * through non executable mmaps, which we need to lookup
 		 * in MAP__VARIABLE tree.
 		 */
-		thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER,
-				      MAP__VARIABLE, ip, &al);
+		__thread__find_map(ui->thread, PERF_RECORD_MISC_USER,
+				   MAP__VARIABLE, ip, &al);
 	}
 	return al.map;
 }
Signature · 1 line
2.14.3
author maintainer
#13 lore raw

PATCH 13/52 perf tests: Let 'perf test list' display subtests

In reply to Arnaldo Carvalho de Melo

From: Hendrik Brueckner <[email protected]>

The output of perf test and perf test list differ because perf test list does not display subtests. Correct this behavior and also let perf test list report subtests.

For example:

	$ ./perf test 2>&1 |wc -l
	65

Without this commit:

	$ ./perf test list 2>&1 |wc -l
	57

With this commit:

	$ ./perf test list 2>&1 |wc -l
	65

LPU-Reference: [email protected]

---
 tools/perf/tests/builtin-test.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/perf/tests/builtin-test.c +9 -0
index cac8f8889bc3..2bde505e2e7e 100644
@@ -654,6 +654,15 @@ static int perf_test__list(int argc, const char **argv)
 			continue;
 
 		pr_info("%2d: %s\n", i, t->desc);
+
+		if (t->subtest.get_nr) {
+			int subn = t->subtest.get_nr();
+			int subi;
+
+			for (subi = 0; subi < subn; subi++)
+				pr_info("%2d:%1d: %s\n", i, subi + 1,
+					t->subtest.get_desc(subi));
+		}
 	}
 
 	perf_test__list_shell(argc, argv, i);
Signature · 1 line
2.14.3
author maintainer
#14 lore raw

PATCH 14/52 perf thread: Introduce thread__find_symbol()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Out of thread__find_addr_location(..., MAP__FUNCTION, ...), idea here is to continue removing references to MAP__{FUNCTION,VARIABLE} ahead of getting both types of symbols in the same rbtree, as various places do two lookups, looking first at MAP__FUNCTION, then at MAP__VARIABLE.

So thread__find_symbol() will eventually do just that, and 'struct symbol' will have the symbol type, for code that cares about that.

---
 tools/perf/arch/powerpc/util/skip-callchain-idx.c |  3 +--
 tools/perf/builtin-timechart.c                    |  3 +--
 tools/perf/builtin-trace.c                        |  9 +++------
 tools/perf/util/event.c                           |  6 +++---
 tools/perf/util/machine.c                         |  7 +++----
 tools/perf/util/thread.c                          |  2 +-
 tools/perf/util/thread.h                          | 11 ++++++++---
 tools/perf/util/unwind-libdw.c                    |  9 +++++----
 tools/perf/util/unwind-libunwind-local.c          |  3 +--
 9 files changed, 26 insertions(+), 27 deletions(-)
tools/perf/arch/powerpc/util/skip-callchain-idx.c +1 -2
index 0c370f81e002..3598b8b75d27 100644
@@ -248,8 +248,7 @@ int arch_skip_callchain_idx(struct thread *thread, struct ip_callchain *chain)
 
 	ip = chain->ips[2];
 
-	thread__find_addr_location(thread, PERF_RECORD_MISC_USER,
-			MAP__FUNCTION, ip, &al);
+	thread__find_symbol(thread, PERF_RECORD_MISC_USER, ip, &al);
 
 	if (al.map)
 		dso = al.map->dso;
tools/perf/builtin-timechart.c +1 -2
index 813698a9b8c7..38fcbb5ddce8 100644
@@ -533,8 +533,7 @@ static const char *cat_backtrace(union perf_event *event,
 		}
 
 		tal.filtered = 0;
-		thread__find_addr_location(al.thread, cpumode,
-					   MAP__FUNCTION, ip, &tal);
+		thread__find_symbol(al.thread, cpumode, ip, &tal);
 
 		if (tal.sym)
 			fprintf(f, "..... %016" PRIx64 " %s\n", ip,
tools/perf/builtin-trace.c +3 -6
index 3ad17ee89403..afec6f9ffd89 100644
@@ -2024,8 +2024,7 @@ static int trace__pgfault(struct trace *trace,
 	if (trace->summary_only)
 		goto out;
 
-	thread__find_addr_location(thread, sample->cpumode, MAP__FUNCTION,
-			      sample->ip, &al);
+	thread__find_symbol(thread, sample->cpumode, sample->ip, &al);
 
 	trace__fprintf_entry_head(trace, thread, 0, true, sample->time, trace->output);
 
@@ -2037,12 +2036,10 @@ static int trace__pgfault(struct trace *trace,
 
 	fprintf(trace->output, "] => ");
 
-	thread__find_addr_location(thread, sample->cpumode, MAP__VARIABLE,
-				   sample->addr, &al);
+	__thread__find_symbol(thread, sample->cpumode, MAP__VARIABLE, sample->addr, &al);
 
 	if (!al.map) {
-		thread__find_addr_location(thread, sample->cpumode,
-					   MAP__FUNCTION, sample->addr, &al);
+		thread__find_symbol(thread, sample->cpumode, sample->addr, &al);
 
 		if (al.map)
 			map_type = 'x';
tools/perf/util/event.c +3 -3
index baa97d0b6114..2d860fbeb227 100644
@@ -1564,9 +1564,9 @@ void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
 	}
 }
 
-void thread__find_addr_location(struct thread *thread,
-				u8 cpumode, enum map_type type, u64 addr,
-				struct addr_location *al)
+void __thread__find_symbol(struct thread *thread, u8 cpumode,
+			   enum map_type type, u64 addr,
+			   struct addr_location *al)
 {
 	__thread__find_map(thread, cpumode, type, addr, al);
 	if (al->map != NULL)
tools/perf/util/machine.c +3 -4
index 32d50492505d..e354d94a68e8 100644
@@ -1681,14 +1681,14 @@ static void ip__resolve_data(struct thread *thread,
 
 	memset(&al, 0, sizeof(al));
 
-	thread__find_addr_location(thread, m, MAP__VARIABLE, addr, &al);
+	__thread__find_symbol(thread, m, MAP__VARIABLE, addr, &al);
 	if (al.map == NULL) {
 		/*
 		 * some shared data regions have execute bit set which puts
 		 * their mapping in the MAP__FUNCTION type array.
 		 * Check there as a fallback option before dropping the sample.
 		 */
-		thread__find_addr_location(thread, m, MAP__FUNCTION, addr, &al);
+		thread__find_symbol(thread, m, addr, &al);
 	}
 
 	ams->addr = addr;
@@ -1784,8 +1784,7 @@ static int add_callchain_ip(struct thread *thread,
 			}
 			return 0;
 		}
-		thread__find_addr_location(thread, *cpumode, MAP__FUNCTION,
-					   ip, &al);
+		thread__find_symbol(thread, *cpumode, ip, &al);
 	}
 
 	if (al.sym != NULL) {
tools/perf/util/thread.c +1 -1
index 68b65b10579b..2a3fb7c6b39d 100644
@@ -384,7 +384,7 @@ void thread__find_cpumode_addr_location(struct thread *thread,
 	};
 
 	for (i = 0; i < ARRAY_SIZE(cpumodes); i++) {
-		thread__find_addr_location(thread, cpumodes[i], type, addr, al);
+		__thread__find_symbol(thread, cpumodes[i], type, addr, al);
 		if (al->map)
 			break;
 	}
tools/perf/util/thread.h +8 -3
index 52c788f955de..b69e65c821f9 100644
@@ -101,9 +101,14 @@ static inline void thread__find_map(struct thread *thread, u8 cpumode,
 	__thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
 }
 
-void thread__find_addr_location(struct thread *thread,
-				u8 cpumode, enum map_type type, u64 addr,
-				struct addr_location *al);
+void __thread__find_symbol(struct thread *thread, u8 cpumode, enum map_type type,
+			   u64 addr, struct addr_location *al);
+
+static inline void thread__find_symbol(struct thread *thread, u8 cpumode,
+				       u64 addr, struct addr_location *al)
+{
+	return __thread__find_symbol(thread, cpumode, MAP__FUNCTION, addr, al);
+}
 
 void thread__find_cpumode_addr_location(struct thread *thread,
 					enum map_type type, u64 addr,
tools/perf/util/unwind-libdw.c +5 -4
index 1ce8744649b5..bdc22f1864df 100644
@@ -28,10 +28,11 @@ static int __report_module(struct addr_location *al, u64 ip,
 {
 	Dwfl_Module *mod;
 	struct dso *dso = NULL;
-
-	thread__find_addr_location(ui->thread,
-				   PERF_RECORD_MISC_USER,
-				   MAP__FUNCTION, ip, al);
+	/*
+	 * Some callers will use al->sym, so we can't just use the
+	 * cheaper thread__find_map() here.
+	 */
+	thread__find_symbol(ui->thread, PERF_RECORD_MISC_USER, ip, al);
 
 	if (al->map)
 		dso = al->map->dso;
tools/perf/util/unwind-libunwind-local.c +1 -2
index 33afca5c04f6..0007c64f3220 100644
@@ -585,8 +585,7 @@ static int entry(u64 ip, struct thread *thread,
 	struct unwind_entry e;
 	struct addr_location al;
 
-	thread__find_addr_location(thread, PERF_RECORD_MISC_USER,
-				   MAP__FUNCTION, ip, &al);
+	thread__find_symbol(thread, PERF_RECORD_MISC_USER, ip, &al);
 
 	e.ip = al.addr;
 	e.map = al.map;
Signature · 1 line
2.14.3
author maintainer
#15 lore raw

PATCH 15/52 perf script: Use thread__find_symbol() instead of ad-hoc equivalent

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

In dc323ce8e72d ("perf script: Enable printing of branch stack") it first tries to find the map for an address, then the symbol in the DSO backing that map, for that address, well, this is what thread__find_symbol() does, so just use it and make the code shorter.

---
 tools/perf/builtin-script.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
tools/perf/builtin-script.c +2 -7
index 5ec1c73bbfaf..ffd02faee87b 100644
@@ -764,13 +764,8 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,
 		from = br->entries[i].from;
 		to   = br->entries[i].to;
 
-		thread__find_map(thread, sample->cpumode, from, &alf);
-		if (alf.map)
-			alf.sym = map__find_symbol(alf.map, alf.addr);
-
-		thread__find_map(thread, sample->cpumode, to, &alt);
-		if (alt.map)
-			alt.sym = map__find_symbol(alt.map, alt.addr);
+		thread__find_symbol(thread, sample->cpumode, from, &alf);
+		thread__find_symbol(thread, sample->cpumode, to, &alt);
 
 		printed += symbol__fprintf_symname_offs(alf.sym, &alf, fp);
 		if (PRINT_FIELD(DSO)) {
Signature · 1 line
2.14.3
author maintainer
#16 lore raw

PATCH 16/52 perf thread: Make thread__find_map() return the map

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

It was returning the searched map just on the addr_location passed, with the function itself returning void.

Make it return the map so that we can make the code more compact.

---
 tools/perf/builtin-inject.c              |  4 +---
 tools/perf/builtin-script.c              | 14 ++++++--------
 tools/perf/tests/code-reading.c          |  3 +--
 tools/perf/util/build-id.c               |  4 +---
 tools/perf/util/cs-etm.c                 |  4 +---
 tools/perf/util/event.c                  | 16 ++++++++--------
 tools/perf/util/intel-bts.c              |  3 +--
 tools/perf/util/intel-pt.c               |  6 ++----
 tools/perf/util/thread.h                 | 10 +++++-----
 tools/perf/util/unwind-libdw.c           |  3 +--
 tools/perf/util/unwind-libunwind-local.c |  3 +--
 11 files changed, 28 insertions(+), 42 deletions(-)
tools/perf/builtin-inject.c +1 -3
index 92677d8f9eae..a3b346359ba0 100644
@@ -440,9 +440,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
 		goto repipe;
 	}
 
-	thread__find_map(thread, sample->cpumode, sample->ip, &al);
-
-	if (al.map != NULL) {
+	if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
 		if (!al.map->dso->hit) {
 			al.map->dso->hit = 1;
 			if (map__load(al.map) >= 0) {
tools/perf/builtin-script.c +6 -8
index ffd02faee87b..07cb083ac89c 100644
@@ -809,12 +809,12 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
 		from = br->entries[i].from;
 		to   = br->entries[i].to;
 
-		thread__find_map(thread, sample->cpumode, from, &alf);
-		if (alf.map && !alf.map->dso->adjust_symbols)
+		if (thread__find_map(thread, sample->cpumode, from, &alf) &&
+		    !alf.map->dso->adjust_symbols)
 			from = map__map_ip(alf.map, from);
 
-		thread__find_map(thread, sample->cpumode, to, &alt);
-		if (alt.map && !alt.map->dso->adjust_symbols)
+		if (thread__find_map(thread, sample->cpumode, to, &alt) &&
+		    !alt.map->dso->adjust_symbols)
 			to = map__map_ip(alt.map, to);
 
 		printed += fprintf(fp, " 0x%"PRIx64, from);
@@ -877,8 +877,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
 		return 0;
 	}
 
-	thread__find_map(thread, *cpumode, start, &al);
-	if (!al.map || !al.map->dso) {
+	if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) {
 		pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
 		return 0;
 	}
@@ -928,8 +927,7 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
 
 	memset(&al, 0, sizeof(al));
 
-	thread__find_map(thread, cpumode, addr, &al);
-	if (!al.map)
+	if (!thread__find_map(thread, cpumode, addr, &al))
 		__thread__find_map(thread, cpumode, MAP__VARIABLE, addr, &al);
 	if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end)
 		return 0;
tools/perf/tests/code-reading.c +1 -2
index 5b0a55499486..afa4ce21ba7c 100644
@@ -236,8 +236,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 
 	pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
 
-	thread__find_map(thread, cpumode, addr, &al);
-	if (!al.map || !al.map->dso) {
+	if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) {
 		if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
 			pr_debug("Hypervisor address can not be resolved - skipping\n");
 			return 0;
tools/perf/util/build-id.c +1 -3
index b512dc8fa6c3..04b1d53e4bf9 100644
@@ -47,9 +47,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
 		return -1;
 	}
 
-	thread__find_map(thread, sample->cpumode, sample->ip, &al);
-
-	if (al.map != NULL)
+	if (thread__find_map(thread, sample->cpumode, sample->ip, &al))
 		al.map->dso->hit = 1;
 
 	thread__put(thread);
tools/perf/util/cs-etm.c +1 -3
index 8fe573d040b6..6533b1adb50b 100644
@@ -269,9 +269,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,
 		thread = etmq->etm->unknown_thread;
 	}
 
-	thread__find_map(thread, cpumode, address, &al);
-
-	if (!al.map || !al.map->dso)
+	if (!thread__find_map(thread, cpumode, address, &al) || !al.map->dso)
 		return 0;
 
 	if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
tools/perf/util/event.c +8 -8
index 2d860fbeb227..48e4b252f6ff 100644
@@ -1489,8 +1489,8 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
 	return machine__process_event(machine, event, sample);
 }
 
-void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
-			u64 addr, struct addr_location *al)
+struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
+			       u64 addr, struct addr_location *al)
 {
 	struct map_groups *mg = thread->mg;
 	struct machine *machine = mg->machine;
@@ -1504,7 +1504,7 @@ void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
 
 	if (machine == NULL) {
 		al->map = NULL;
-		return;
+		return NULL;
 	}
 
 	if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
@@ -1532,7 +1532,7 @@ void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
 			!perf_host)
 			al->filtered |= (1 << HIST_FILTER__HOST);
 
-		return;
+		return NULL;
 	}
 try_again:
 	al->map = map_groups__find(mg, type, al->addr);
@@ -1562,14 +1562,15 @@ void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
 			map__load(al->map);
 		al->addr = al->map->map_ip(al->map, al->addr);
 	}
+
+	return al->map;
 }
 
 void __thread__find_symbol(struct thread *thread, u8 cpumode,
 			   enum map_type type, u64 addr,
 			   struct addr_location *al)
 {
-	__thread__find_map(thread, cpumode, type, addr, al);
-	if (al->map != NULL)
+	if (__thread__find_map(thread, cpumode, type, addr, al))
 		al->sym = map__find_symbol(al->map, al->addr);
 	else
 		al->sym = NULL;
@@ -1668,8 +1669,7 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)
 void thread__resolve(struct thread *thread, struct addr_location *al,
 		     struct perf_sample *sample)
 {
-	thread__find_map(thread, sample->cpumode, sample->addr, al);
-	if (!al->map) {
+	if (!thread__find_map(thread, sample->cpumode, sample->addr, al)) {
 		__thread__find_map(thread, sample->cpumode, MAP__VARIABLE,
 				   sample->addr, al);
 	}
tools/perf/util/intel-bts.c +1 -2
index ea0ce8572bf2..7f0c83b6332b 100644
@@ -335,8 +335,7 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip)
 	if (!thread)
 		return -1;
 
-	thread__find_map(thread, cpumode, ip, &al);
-	if (!al.map || !al.map->dso)
+	if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
 		goto out_put;
 
 	len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf,
tools/perf/util/intel-pt.c +2 -4
index 441e681a46a0..a272b35f6c5a 100644
@@ -442,8 +442,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 	}
 
 	while (1) {
-		thread__find_map(thread, cpumode, *ip, &al);
-		if (!al.map || !al.map->dso)
+		if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso)
 			return -EINVAL;
 
 		if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
@@ -596,8 +595,7 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data)
 	if (!thread)
 		return -EINVAL;
 
-	thread__find_map(thread, cpumode, ip, &al);
-	if (!al.map || !al.map->dso)
+	if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
 		return -EINVAL;
 
 	offset = al.map->map_ip(al.map, ip);
tools/perf/util/thread.h +5 -5
index b69e65c821f9..1961e4bc1c2c 100644
@@ -92,13 +92,13 @@ size_t thread__fprintf(struct thread *thread, FILE *fp);
 
 struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
 
-void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
-			u64 addr, struct addr_location *al);
+struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
+			       u64 addr, struct addr_location *al);
 
-static inline void thread__find_map(struct thread *thread, u8 cpumode,
-				    u64 addr, struct addr_location *al)
+static inline struct map *thread__find_map(struct thread *thread, u8 cpumode,
+					   u64 addr, struct addr_location *al)
 {
-	__thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
+	return __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
 }
 
 void __thread__find_symbol(struct thread *thread, u8 cpumode, enum map_type type,
tools/perf/util/unwind-libdw.c +1 -2
index bdc22f1864df..17401922cd42 100644
@@ -104,8 +104,7 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr,
 	struct addr_location al;
 	ssize_t size;
 
-	thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al);
-	if (!al.map) {
+	if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al)) {
 		/*
 		 * We've seen cases (softice) where DWARF unwinder went
 		 * through non executable mmaps, which we need to lookup
tools/perf/util/unwind-libunwind-local.c +1 -2
index 0007c64f3220..4662590ef091 100644
@@ -367,8 +367,7 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
 {
 	struct addr_location al;
 
-	thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al);
-	if (!al.map) {
+	if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al)) {
 		/*
 		 * We've seen cases (softice) where DWARF unwinder went
 		 * through non executable mmaps, which we need to lookup
Signature · 1 line
2.14.3
author maintainer
#17 lore raw

PATCH 17/52 perf thread: Make thread__find_symbol() return the symbol searched

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Instead of just returning it in al.sym, allowing for some simplification in its users, and to make it consistent with thread__find_map().

---
 tools/perf/builtin-timechart.c           |  7 ++-----
 tools/perf/util/event.c                  | 10 +++++-----
 tools/perf/util/thread.h                 |  8 ++++----
 tools/perf/util/unwind-libunwind-local.c |  4 +---
 4 files changed, 12 insertions(+), 17 deletions(-)
tools/perf/builtin-timechart.c +2 -5
index 38fcbb5ddce8..a827919c6263 100644
@@ -533,11 +533,8 @@ static const char *cat_backtrace(union perf_event *event,
 		}
 
 		tal.filtered = 0;
-		thread__find_symbol(al.thread, cpumode, ip, &tal);
-
-		if (tal.sym)
-			fprintf(f, "..... %016" PRIx64 " %s\n", ip,
-				tal.sym->name);
+		if (thread__find_symbol(al.thread, cpumode, ip, &tal))
+			fprintf(f, "..... %016" PRIx64 " %s\n", ip, tal.sym->name);
 		else
 			fprintf(f, "..... %016" PRIx64 "\n", ip);
 	}
tools/perf/util/event.c +5 -5
index 48e4b252f6ff..9d94c59046d1 100644
@@ -1566,14 +1566,14 @@ struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type
 	return al->map;
 }
 
-void __thread__find_symbol(struct thread *thread, u8 cpumode,
-			   enum map_type type, u64 addr,
-			   struct addr_location *al)
+struct symbol *__thread__find_symbol(struct thread *thread, u8 cpumode,
+				     enum map_type type, u64 addr,
+				     struct addr_location *al)
 {
+	al->sym = NULL;
 	if (__thread__find_map(thread, cpumode, type, addr, al))
 		al->sym = map__find_symbol(al->map, al->addr);
-	else
-		al->sym = NULL;
+	return al->sym;
 }
 
 /*
tools/perf/util/thread.h +4 -4
index 1961e4bc1c2c..1b130b0a4a48 100644
@@ -101,11 +101,11 @@ static inline struct map *thread__find_map(struct thread *thread, u8 cpumode,
 	return __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
 }
 
-void __thread__find_symbol(struct thread *thread, u8 cpumode, enum map_type type,
-			   u64 addr, struct addr_location *al);
+struct symbol *__thread__find_symbol(struct thread *thread, u8 cpumode, enum map_type type,
+				     u64 addr, struct addr_location *al);
 
-static inline void thread__find_symbol(struct thread *thread, u8 cpumode,
-				       u64 addr, struct addr_location *al)
+static inline struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
+						 u64 addr, struct addr_location *al)
 {
 	return __thread__find_symbol(thread, cpumode, MAP__FUNCTION, addr, al);
 }
tools/perf/util/unwind-libunwind-local.c +1 -3
index 4662590ef091..2afb22b0a1a9 100644
@@ -584,11 +584,9 @@ static int entry(u64 ip, struct thread *thread,
 	struct unwind_entry e;
 	struct addr_location al;
 
-	thread__find_symbol(thread, PERF_RECORD_MISC_USER, ip, &al);
-
+	e.sym = thread__find_symbol(thread, PERF_RECORD_MISC_USER, ip, &al);
 	e.ip = al.addr;
 	e.map = al.map;
-	e.sym = al.sym;
 
 	pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
 		 al.sym ? al.sym->name : "''",
Signature · 1 line
2.14.3
author maintainer
#18 lore raw

PATCH 18/52 perf map: Shorten map_groups__find_by_name() signature

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Another step in the road to elliminate the MAP_{FUNCTION,VARIABLE} separation, reducing the exposure to these details in the tools using the symbol APIs.

---
 tools/perf/tests/vmlinux-kallsyms.c | 2 +-
 tools/perf/util/machine.c           | 6 ++----
 tools/perf/util/map.h               | 8 ++++++--
 tools/perf/util/probe-event.c       | 2 +-
 tools/perf/util/symbol-elf.c        | 2 +-
 tools/perf/util/symbol.c            | 6 ++----
 6 files changed, 13 insertions(+), 13 deletions(-)
tools/perf/tests/vmlinux-kallsyms.c +1 -1
index 1e5adb65632a..d80416e07f4b 100644
@@ -183,7 +183,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 		 * so use the short name, less descriptive but the same ("[kernel]" in
 		 * both cases.
 		 */
-		pair = map_groups__find_by_name(&kallsyms.kmaps, type,
+		pair = map_groups__find_by_name(&kallsyms.kmaps,
 						(map->dso->kernel ?
 							map->dso->short_name :
 							map->dso->name));
tools/perf/util/machine.c +2 -4
index e354d94a68e8..fc71f2c69c8b 100644
@@ -673,8 +673,7 @@ struct map *machine__findnew_module_map(struct machine *machine, u64 start,
 	if (kmod_path__parse_name(&m, filename))
 		return NULL;
 
-	map = map_groups__find_by_name(&machine->kmaps, MAP__FUNCTION,
-				       m.name);
+	map = map_groups__find_by_name(&machine->kmaps, m.name);
 	if (map) {
 		/*
 		 * If the map's dso is an offline module, give dso__load()
@@ -1055,10 +1054,9 @@ static bool is_kmod_dso(struct dso *dso)
 static int map_groups__set_module_path(struct map_groups *mg, const char *path,
 				       struct kmod_path *m)
 {
-	struct map *map;
 	char *long_name;
+	struct map *map = map_groups__find_by_name(mg, m->name);
 
-	map = map_groups__find_by_name(mg, MAP__FUNCTION, m->name);
 	if (map == NULL)
 		return 0;
 
tools/perf/util/map.h +6 -2
index fc91bac8fed0..8ff75be0a965 100644
@@ -254,8 +254,12 @@ struct symbol *map_groups__find_function_by_name(struct map_groups *mg,
 int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map,
 				   FILE *fp);
 
-struct map *map_groups__find_by_name(struct map_groups *mg,
-				     enum map_type type, const char *name);
+struct map *__map_groups__find_by_name(struct map_groups *mg, enum map_type type, const char *name);
+
+static inline struct map *map_groups__find_by_name(struct map_groups *mg, const char *name)
+{
+	return __map_groups__find_by_name(mg, MAP__FUNCTION, name);
+}
 
 bool __map__is_kernel(const struct map *map);
 
tools/perf/util/probe-event.c +1 -1
index e1dbc9821617..d5e2516d5981 100644
@@ -341,7 +341,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso)
 		char module_name[128];
 
 		snprintf(module_name, sizeof(module_name), "[%s]", module);
-		map = map_groups__find_by_name(&host_machine->kmaps, MAP__FUNCTION, module_name);
+		map = map_groups__find_by_name(&host_machine->kmaps, module_name);
 		if (map) {
 			dso = map->dso;
 			goto found;
tools/perf/util/symbol-elf.c +1 -1
index 2de770511e70..75f578f3ed8e 100644
@@ -1042,7 +1042,7 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 			snprintf(dso_name, sizeof(dso_name),
 				 "%s%s", dso->short_name, section_name);
 
-			curr_map = map_groups__find_by_name(kmaps, map->type, dso_name);
+			curr_map = __map_groups__find_by_name(kmaps, map->type, dso_name);
 			if (curr_map == NULL) {
 				u64 start = sym.st_value;
 
tools/perf/util/symbol.c +2 -4
index 2b6292cff719..0bf4cf76f36a 100644
@@ -792,8 +792,7 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
 							curr_map->type);
 				}
 
-				curr_map = map_groups__find_by_name(kmaps,
-							map->type, module);
+				curr_map = __map_groups__find_by_name(kmaps, map->type, module);
 				if (curr_map == NULL) {
 					pr_debug("%s/proc/{kallsyms,modules} "
 					         "inconsistency while looking "
@@ -1667,8 +1666,7 @@ int dso__load(struct dso *dso, struct map *map)
 	return ret;
 }
 
-struct map *map_groups__find_by_name(struct map_groups *mg,
-				     enum map_type type, const char *name)
+struct map *__map_groups__find_by_name(struct map_groups *mg, enum map_type type, const char *name)
 {
 	struct maps *maps = &mg->maps[type];
 	struct map *map;
Signature · 1 line
2.14.3
author maintainer
#19 lore raw

PATCH 19/52 perf Documentation: Support for asciidoctor

In reply to Arnaldo Carvalho de Melo

From: Takashi Iwai <[email protected]>

The asciidoc package seems behind the recent big wave of python3 conversion, and we were advised to switch to asciidoctor instead. It's almost compatible but some extensions used for perf documentation don't work with it. Here is the patch to cover them, and add the proper support for asciidoctor.

Pass USE_ASCIIDOCTOR=yes to make for using asciidoctor instead of asciidoc. The man source and manual attributes are passed via command options. The support for these attributes have been fixed in the latest asciidoctor code.

Since asciidoctor can covert to a man page and an HTML directly, we can omit the dependency on xmlto when USE_ASCIIDOCTOR is set.

---
 tools/perf/Documentation/Makefile                  | 29 ++++++++++++++++++----
 tools/perf/Documentation/asciidoctor-extensions.rb | 29 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 5 deletions(-)
 create mode 100644 tools/perf/Documentation/asciidoctor-extensions.rb
tools/perf/Documentation/Makefile +24 -5
index db11478e30b4..42261a9b280e 100644
@@ -47,7 +47,8 @@ man5dir=$(mandir)/man5
 man7dir=$(mandir)/man7
 
 ASCIIDOC=asciidoc
-ASCIIDOC_EXTRA = --unsafe
+ASCIIDOC_EXTRA = --unsafe -f asciidoc.conf
+ASCIIDOC_HTML = xhtml11
 MANPAGE_XSL = manpage-normal.xsl
 XMLTO_EXTRA =
 INSTALL?=install
@@ -55,6 +56,14 @@ RM ?= rm -f
 DOC_REF = origin/man
 HTML_REF = origin/html
 
+ifdef USE_ASCIIDOCTOR
+ASCIIDOC = asciidoctor
+ASCIIDOC_EXTRA = -a compat-mode
+ASCIIDOC_EXTRA += -I. -rasciidoctor-extensions
+ASCIIDOC_EXTRA += -a mansource="perf" -a manmanual="perf Manual"
+ASCIIDOC_HTML = xhtml5
+endif
+
 infodir?=$(prefix)/share/info
 MAKEINFO=makeinfo
 INSTALL_INFO=install-info
@@ -73,10 +82,12 @@ ifeq ($(_tmp_tool_path),)
 	missing_tools = $(ASCIIDOC)
 endif
 
+ifndef USE_ASCIIDOCTOR
 _tmp_tool_path := $(call get-executable,$(XMLTO))
 ifeq ($(_tmp_tool_path),)
 	missing_tools += $(XMLTO)
 endif
+endif
 
 #
 # For asciidoc ...
@@ -264,9 +275,17 @@ clean:
 
 $(MAN_HTML): $(OUTPUT)%.html : %.txt
 	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
-	$(ASCIIDOC) -b xhtml11 -d manpage -f asciidoc.conf \
+	$(ASCIIDOC) -b $(ASCIIDOC_HTML) -d manpage \
+		$(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \
+	mv $@+ $@
+
+ifdef USE_ASCIIDOCTOR
+$(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : $(OUTPUT)%.txt
+	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
+	$(ASCIIDOC) -b manpage -d manpage \
 		$(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \
 	mv $@+ $@
+endif
 
 $(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : $(OUTPUT)%.xml
 	$(QUIET_XMLTO)$(RM) $@ && \
@@ -274,7 +293,7 @@ $(OUTPUT)%.1 $(OUTPUT)%.5 $(OUTPUT)%.7 : $(OUTPUT)%.xml
 
 $(OUTPUT)%.xml : %.txt
 	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
-	$(ASCIIDOC) -b docbook -d manpage -f asciidoc.conf \
+	$(ASCIIDOC) -b docbook -d manpage \
 		$(ASCIIDOC_EXTRA) -aperf_version=$(PERF_VERSION) -o $@+ $< && \
 	mv $@+ $@
 
@@ -321,13 +340,13 @@ howto-index.txt: howto-index.sh $(wildcard howto/*.txt)
 	mv $@+ $@
 
 $(patsubst %,%.html,$(ARTICLES)) : %.html : %.txt
-	$(QUIET_ASCIIDOC)$(ASCIIDOC) -b xhtml11 $*.txt
+	$(QUIET_ASCIIDOC)$(ASCIIDOC) -b $(ASCIIDOC_HTML) $*.txt
 
 WEBDOC_DEST = /pub/software/tools/perf/docs
 
 $(patsubst %.txt,%.html,$(wildcard howto/*.txt)): %.html : %.txt
 	$(QUIET_ASCIIDOC)$(RM) $@+ $@ && \
-	sed -e '1,/^$$/d' $< | $(ASCIIDOC) -b xhtml11 - >$@+ && \
+	sed -e '1,/^$$/d' $< | $(ASCIIDOC) -b $(ASCIIDOC_HTML) - >$@+ && \
 	mv $@+ $@
 
 # UNIMPLEMENTED
tools/perf/Documentation/asciidoctor-extensions.rb new file +29 -0
new file mode 100644
index 000000000000..d148fe95c0c4
@@ -0,0 +1,29 @@
+require 'asciidoctor'
+require 'asciidoctor/extensions'
+
+module Perf
+  module Documentation
+    class LinkPerfProcessor < Asciidoctor::Extensions::InlineMacroProcessor
+      use_dsl
+
+      named :chrome
+
+      def process(parent, target, attrs)
+        if parent.document.basebackend? 'html'
+          %(<a href="#{target}.html">#{target}(#{attrs[1]})</a>\n)
+        elsif parent.document.basebackend? 'manpage'
+          "#{target}(#{attrs[1]})"
+        elsif parent.document.basebackend? 'docbook'
+          "<citerefentry>\n" \
+            "<refentrytitle>#{target}</refentrytitle>" \
+            "<manvolnum>#{attrs[1]}</manvolnum>\n" \
+          "</citerefentry>\n"
+        end
+      end
+    end
+  end
+end
+
+Asciidoctor::Extensions.register do
+  inline_macro Perf::Documentation::LinkPerfProcessor, :linkperf
+end
Signature · 1 line
2.14.3
author maintainer
#20 lore raw

PATCH 20/52 perf machine: Introduce machine__kernel_maps()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

That returns the a data structure contained the ordered list of kernel modules + the main kernel maps, one more step in removing the MAP__{FUNCTION,VARIABLE} split.

---
 tools/perf/tests/vmlinux-kallsyms.c |  4 ++--
 tools/perf/util/event.c             |  3 +--
 tools/perf/util/machine.h           | 12 ++++++++++++
 tools/perf/util/probe-event.c       |  3 +--
 4 files changed, 16 insertions(+), 6 deletions(-)
tools/perf/tests/vmlinux-kallsyms.c +2 -2
index d80416e07f4b..9bb84fe365e2 100644
@@ -20,7 +20,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 	struct map *kallsyms_map, *vmlinux_map, *map;
 	struct machine kallsyms, vmlinux;
 	enum map_type type = MAP__FUNCTION;
-	struct maps *maps = &vmlinux.kmaps.maps[type];
+	struct maps *maps = machine__kernel_maps(&vmlinux);
 	u64 mem_start, mem_end;
 	bool header_printed;
 
@@ -228,7 +228,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 
 	header_printed = false;
 
-	maps = &kallsyms.kmaps.maps[type];
+	maps = machine__kernel_maps(&kallsyms);
 
 	for (map = maps__first(maps); map; map = map__next(map)) {
 		if (!map->priv) {
tools/perf/util/event.c +1 -2
index 9d94c59046d1..542bd5b79e48 100644
@@ -464,8 +464,7 @@ int perf_event__synthesize_modules(struct perf_tool *tool,
 {
 	int rc = 0;
 	struct map *pos;
-	struct map_groups *kmaps = &machine->kmaps;
-	struct maps *maps = &kmaps->maps[MAP__FUNCTION];
+	struct maps *maps = machine__kernel_maps(machine);
 	union perf_event *event = zalloc((sizeof(event->mmap) +
 					  machine->id_hdr_size));
 	if (event == NULL) {
tools/perf/util/machine.h +12 -0
index 66cc200ef86f..92303ac718a6 100644
@@ -70,12 +70,24 @@ struct map *__machine__kernel_map(struct machine *machine, enum map_type type)
 	return machine->vmlinux_maps[type];
 }
 
+/*
+ * The main kernel (vmlinux) map
+ */
 static inline
 struct map *machine__kernel_map(struct machine *machine)
 {
 	return __machine__kernel_map(machine, MAP__FUNCTION);
 }
 
+/*
+ * kernel (the one returned by machine__kernel_map()) plus kernel modules maps
+ */
+static inline
+struct maps *machine__kernel_maps(struct machine *machine)
+{
+	return &machine->kmaps.maps[MAP__FUNCTION];
+}
+
 int machine__get_kernel_start(struct machine *machine);
 
 static inline u64 machine__kernel_start(struct machine *machine)
tools/perf/util/probe-event.c +1 -2
index d5e2516d5981..50139764c6d7 100644
@@ -161,8 +161,7 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
 
 static struct map *kernel_get_module_map(const char *module)
 {
-	struct map_groups *grp = &host_machine->kmaps;
-	struct maps *maps = &grp->maps[MAP__FUNCTION];
+	struct maps *maps = machine__kernel_maps(host_machine);
 	struct map *pos;
 
 	/* A file path -- this is an offline module */
Signature · 1 line
2.14.3
author maintainer
#21 lore raw

PATCH 21/52 perf machine: Shorten machine__load_kallsyms() signature

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

So far the only use is for MAP__FUNCTION, and since we're going to remove that split, remove the map_type argument in machine__load_kallsyms().

---
 tools/perf/tests/vmlinux-kallsyms.c |  2 +-
 tools/perf/util/machine.c           |  8 +++-----
 tools/perf/util/machine.h           | 10 ++++++++--
 3 files changed, 12 insertions(+), 8 deletions(-)
tools/perf/tests/vmlinux-kallsyms.c +1 -1
index 9bb84fe365e2..b99e60593664 100644
@@ -56,7 +56,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 	 * be compacted against the list of modules found in the "vmlinux"
 	 * code and with the one got from /proc/modules from the "kallsyms" code.
 	 */
-	if (machine__load_kallsyms(&kallsyms, "/proc/kallsyms", type) <= 0) {
+	if (machine__load_kallsyms(&kallsyms, "/proc/kallsyms") <= 0) {
 		pr_debug("dso__load_kallsyms ");
 		goto out;
 	}
tools/perf/util/machine.c +3 -5
index fc71f2c69c8b..d39432c7db86 100644
@@ -137,13 +137,11 @@ struct machine *machine__new_kallsyms(void)
 	struct machine *machine = machine__new_host();
 	/*
 	 * FIXME:
-	 * 1) MAP__FUNCTION will go away when we stop loading separate maps for
-	 *    functions and data objects.
-	 * 2) We should switch to machine__load_kallsyms(), i.e. not explicitely
+	 * 1) We should switch to machine__load_kallsyms(), i.e. not explicitely
 	 *    ask for not using the kcore parsing code, once this one is fixed
 	 *    to create a map per module.
 	 */
-	if (machine && machine__load_kallsyms(machine, "/proc/kallsyms", MAP__FUNCTION) <= 0) {
+	if (machine && machine__load_kallsyms(machine, "/proc/kallsyms") <= 0) {
 		machine__delete(machine);
 		machine = NULL;
 	}
@@ -988,7 +986,7 @@ int machines__create_kernel_maps(struct machines *machines, pid_t pid)
 	return machine__create_kernel_maps(machine);
 }
 
-int machine__load_kallsyms(struct machine *machine, const char *filename,
+int __machine__load_kallsyms(struct machine *machine, const char *filename,
 			     enum map_type type)
 {
 	struct map *map = machine__kernel_map(machine);
tools/perf/util/machine.h +8 -2
index 92303ac718a6..dc95404959ee 100644
@@ -237,8 +237,14 @@ struct map *machine__findnew_module_map(struct machine *machine, u64 start,
 					const char *filename);
 int arch__fix_module_text_start(u64 *start, const char *name);
 
-int machine__load_kallsyms(struct machine *machine, const char *filename,
-			   enum map_type type);
+int __machine__load_kallsyms(struct machine *machine, const char *filename,
+			     enum map_type type);
+
+static inline int machine__load_kallsyms(struct machine *machine, const char *filename)
+{
+	return __machine__load_kallsyms(machine, filename, MAP__FUNCTION);
+}
+
 int machine__load_vmlinux_path(struct machine *machine, enum map_type type);
 
 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
Signature · 1 line
2.14.3
author maintainer
#22 lore raw

PATCH 22/52 perf machine: Remove needless map_type from machine__load_vmlinux_path()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Since it uses machine__kernel_map() and this function always returns the MAP__FUNCTION map, it doesn't make sense to call it with MAP__VARIABLE.

And also this is a step in the direction of nuking the MAP__{FUNCTION,VARIABLE} split.

---
 tools/perf/tests/vmlinux-kallsyms.c | 2 +-
 tools/perf/util/machine.c           | 4 ++--
 tools/perf/util/machine.h           | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/tests/vmlinux-kallsyms.c +1 -1
index b99e60593664..4e6c804a3ab4 100644
@@ -94,7 +94,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 	 * maps__reloc_vmlinux will notice and set proper ->[un]map_ip routines
 	 * to fixup the symbols.
 	 */
-	if (machine__load_vmlinux_path(&vmlinux, type) <= 0) {
+	if (machine__load_vmlinux_path(&vmlinux) <= 0) {
 		pr_debug("Couldn't find a vmlinux that matches the kernel running on this machine, skipping test\n");
 		err = TEST_SKIP;
 		goto out;
tools/perf/util/machine.c +2 -2
index d39432c7db86..0017c4a1fb97 100644
@@ -1005,13 +1005,13 @@ int __machine__load_kallsyms(struct machine *machine, const char *filename,
 	return ret;
 }
 
-int machine__load_vmlinux_path(struct machine *machine, enum map_type type)
+int machine__load_vmlinux_path(struct machine *machine)
 {
 	struct map *map = machine__kernel_map(machine);
 	int ret = dso__load_vmlinux_path(map->dso, map);
 
 	if (ret > 0)
-		dso__set_loaded(map->dso, type);
+		dso__set_loaded(map->dso, map->type);
 
 	return ret;
 }
tools/perf/util/machine.h +1 -1
index dc95404959ee..ac3b8403df2e 100644
@@ -245,7 +245,7 @@ static inline int machine__load_kallsyms(struct machine *machine, const char *fi
 	return __machine__load_kallsyms(machine, filename, MAP__FUNCTION);
 }
 
-int machine__load_vmlinux_path(struct machine *machine, enum map_type type);
+int machine__load_vmlinux_path(struct machine *machine);
 
 size_t machine__fprintf_dsos_buildid(struct machine *machine, FILE *fp,
 				     bool (skip)(struct dso *dso, int parm), int parm);
Signature · 1 line
2.14.3
author maintainer
#23 lore raw

PATCH 23/52 perf tests vmlinux-kallsyms: Use machine__find_kernel_function(_by_name)

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

We had this for ages, IIRC for 'perf probe' use initially, so use them instead of the variants that pass the map_type, that is going away.

---
 tools/perf/tests/vmlinux-kallsyms.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/tests/vmlinux-kallsyms.c +2 -3
index 4e6c804a3ab4..c7f43afd5f89 100644
@@ -119,8 +119,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 		mem_start = vmlinux_map->unmap_ip(vmlinux_map, sym->start);
 		mem_end = vmlinux_map->unmap_ip(vmlinux_map, sym->end);
 
-		first_pair = machine__find_kernel_symbol(&kallsyms, type,
-							 mem_start, NULL);
+		first_pair = machine__find_kernel_function(&kallsyms, mem_start, NULL);
 		pair = first_pair;
 
 		if (pair && UM(pair->start) == mem_start) {
@@ -149,7 +148,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 				 */
 				continue;
 			} else {
-				pair = machine__find_kernel_symbol_by_name(&kallsyms, type, sym->name, NULL);
+				pair = machine__find_kernel_function_by_name(&kallsyms, sym->name, NULL);
 				if (pair) {
 					if (UM(pair->start) == mem_start)
 						goto next_pair;
Signature · 1 line
2.14.3
author maintainer
#24 lore raw

PATCH 24/52 perf tests vmlinux-kallsyms: Use map__for_each_symbol() instead of open coded equivalent

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

We had this much shorter map__for_each_symbol() helper for ages, use it and kill one more map_type use outside the code, in the tools.

---
 tools/perf/tests/vmlinux-kallsyms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/vmlinux-kallsyms.c +1 -1
index c7f43afd5f89..a99b0c118541 100644
@@ -108,7 +108,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 	 * in the kallsyms dso. For the ones that are in both, check its names and
 	 * end addresses too.
 	 */
-	for (nd = rb_first(&vmlinux_map->dso->symbols[type]); nd; nd = rb_next(nd)) {
+	map__for_each_symbol(vmlinux_map, sym, nd) {
 		struct symbol *pair, *first_pair;
 
 		sym  = rb_entry(nd, struct symbol, rb_node);
Signature · 1 line
2.14.3
author maintainer
#25 lore raw

PATCH 25/52 perf map: Shorten map_groups__find() signature

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Removing the map_type, that is going away.

---
 tools/perf/arch/arm/tests/dwarf-unwind.c     | 2 +-
 tools/perf/arch/arm64/tests/dwarf-unwind.c   | 2 +-
 tools/perf/arch/powerpc/tests/dwarf-unwind.c | 2 +-
 tools/perf/arch/x86/tests/dwarf-unwind.c     | 2 +-
 tools/perf/tests/vmlinux-kallsyms.c          | 3 +--
 tools/perf/util/event.c                      | 2 +-
 tools/perf/util/map.c                        | 5 ++---
 tools/perf/util/map.h                        | 9 +++++++--
 tools/perf/util/symbol.c                     | 2 +-
 9 files changed, 16 insertions(+), 13 deletions(-)
tools/perf/arch/arm/tests/dwarf-unwind.c +1 -1
index 8cb347760233..7d7a65ca2e8d 100644
@@ -25,7 +25,7 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_ARM_SP];
 
-	map = map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
+	map = __map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		free(buf);
tools/perf/arch/arm64/tests/dwarf-unwind.c +1 -1
index e907f0f4c20c..f053eae3b6eb 100644
@@ -25,7 +25,7 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_ARM64_SP];
 
-	map = map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
+	map = __map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		free(buf);
tools/perf/arch/powerpc/tests/dwarf-unwind.c +1 -1
index 30cbbd6d5be0..b22d643cb602 100644
@@ -26,7 +26,7 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_POWERPC_R1];
 
-	map = map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
+	map = __map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		free(buf);
tools/perf/arch/x86/tests/dwarf-unwind.c +1 -1
index 95036c7a59e8..7da845026323 100644
@@ -26,7 +26,7 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_X86_SP];
 
-	map = map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
+	map = __map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		free(buf);
tools/perf/tests/vmlinux-kallsyms.c +1 -2
index a99b0c118541..702cea7371ac 100644
@@ -19,7 +19,6 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 	struct symbol *sym;
 	struct map *kallsyms_map, *vmlinux_map, *map;
 	struct machine kallsyms, vmlinux;
-	enum map_type type = MAP__FUNCTION;
 	struct maps *maps = machine__kernel_maps(&vmlinux);
 	u64 mem_start, mem_end;
 	bool header_printed;
@@ -205,7 +204,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 		mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
 		mem_end = vmlinux_map->unmap_ip(vmlinux_map, map->end);
 
-		pair = map_groups__find(&kallsyms.kmaps, type, mem_start);
+		pair = map_groups__find(&kallsyms.kmaps, mem_start);
 		if (pair == NULL || pair->priv)
 			continue;
 
tools/perf/util/event.c +1 -1
index 542bd5b79e48..a8739cd0d8ca 100644
@@ -1534,7 +1534,7 @@ struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type
 		return NULL;
 	}
 try_again:
-	al->map = map_groups__find(mg, type, al->addr);
+	al->map = __map_groups__find(mg, type, al->addr);
 	if (al->map == NULL) {
 		/*
 		 * If this is outside of all known maps, and is a negative
tools/perf/util/map.c +2 -3
index f553e302bf9c..91e2afb010f8 100644
@@ -574,7 +574,7 @@ struct symbol *map_groups__find_symbol(struct map_groups *mg,
 				       enum map_type type, u64 addr,
 				       struct map **mapp)
 {
-	struct map *map = map_groups__find(mg, type, addr);
+	struct map *map = __map_groups__find(mg, type, addr);
 
 	/* Ensure map is loaded before using map->map_ip */
 	if (map != NULL && map__load(map) >= 0) {
@@ -627,8 +627,7 @@ int map_groups__find_ams(struct addr_map_symbol *ams)
 	if (ams->addr < ams->map->start || ams->addr >= ams->map->end) {
 		if (ams->map->groups == NULL)
 			return -1;
-		ams->map = map_groups__find(ams->map->groups, ams->map->type,
-					    ams->addr);
+		ams->map = __map_groups__find(ams->map->groups, ams->map->type, ams->addr);
 		if (ams->map == NULL)
 			return -1;
 	}
tools/perf/util/map.h +7 -2
index 8ff75be0a965..b4bcf569a131 100644
@@ -214,12 +214,17 @@ static inline void map_groups__remove(struct map_groups *mg, struct map *map)
 	maps__remove(&mg->maps[map->type], map);
 }
 
-static inline struct map *map_groups__find(struct map_groups *mg,
-					   enum map_type type, u64 addr)
+static inline struct map *__map_groups__find(struct map_groups *mg,
+					     enum map_type type, u64 addr)
 {
 	return maps__find(&mg->maps[type], addr);
 }
 
+static inline struct map *map_groups__find(struct map_groups *mg, u64 addr)
+{
+	return __map_groups__find(mg, MAP__FUNCTION, addr);
+}
+
 static inline struct map *map_groups__first(struct map_groups *mg,
 					    enum map_type type)
 {
tools/perf/util/symbol.c +1 -1
index 0bf4cf76f36a..25701078beab 100644
@@ -723,7 +723,7 @@ static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map)
 		if (module)
 			*module = '\0';
 
-		curr_map = map_groups__find(kmaps, map->type, pos->start);
+		curr_map = __map_groups__find(kmaps, map->type, pos->start);
 
 		if (!curr_map) {
 			symbol__delete(pos);
Signature · 1 line
2.14.3
author maintainer
#26 lore raw

PATCH 26/52 perf ui stdio: Use map_groups__fprintf()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Instead of the variant that allows asking for just a specific map_type, because that map_type split will go away.

---
 tools/perf/ui/stdio/hist.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/ui/stdio/hist.c +1 -2
index 6832fcb2e6ff..c1eb476da91b 100644
@@ -819,8 +819,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
 		}
 
 		if (h->ms.map == NULL && verbose > 1) {
-			__map_groups__fprintf_maps(h->thread->mg,
-						   MAP__FUNCTION, fp);
+			map_groups__fprintf(h->thread->mg, fp);
 			fprintf(fp, "%.10s end\n", graph_dotted_line);
 		}
 	}
Signature · 1 line
2.14.3
author maintainer
#27 lore raw

PATCH 27/52 perf symbols: Shorten dso__(first|last)_symbol()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

All users want MAP__FUNCTION, and this split is going away.

---
 tools/perf/util/auxtrace.c |  8 ++++----
 tools/perf/util/intel-pt.c |  2 +-
 tools/perf/util/symbol.c   | 16 +++++++++++++---
 tools/perf/util/symbol.h   |  4 ++--
 4 files changed, 20 insertions(+), 10 deletions(-)
tools/perf/util/auxtrace.c +4 -4
index 857de69a5361..eaf1e10ae755 100644
@@ -1915,7 +1915,7 @@ static void print_duplicate_syms(struct dso *dso, const char *sym_name)
 
 	pr_err("Multiple symbols with name '%s'\n", sym_name);
 
-	sym = dso__first_symbol(dso, MAP__FUNCTION);
+	sym = dso__first_symbol(dso);
 	while (sym) {
 		if (dso_sym_match(sym, sym_name, &cnt, -1)) {
 			pr_err("#%d\t0x%"PRIx64"\t%c\t%s\n",
@@ -1945,7 +1945,7 @@ static int find_dso_sym(struct dso *dso, const char *sym_name, u64 *start,
 	*start = 0;
 	*size = 0;
 
-	sym = dso__first_symbol(dso, MAP__FUNCTION);
+	sym = dso__first_symbol(dso);
 	while (sym) {
 		if (*start) {
 			if (!*size)
@@ -1972,8 +1972,8 @@ static int find_dso_sym(struct dso *dso, const char *sym_name, u64 *start,
 
 static int addr_filter__entire_dso(struct addr_filter *filt, struct dso *dso)
 {
-	struct symbol *first_sym = dso__first_symbol(dso, MAP__FUNCTION);
-	struct symbol *last_sym = dso__last_symbol(dso, MAP__FUNCTION);
+	struct symbol *first_sym = dso__first_symbol(dso);
+	struct symbol *last_sym = dso__last_symbol(dso);
 
 	if (!first_sym || !last_sym) {
 		pr_err("Failed to determine filter for %s\nNo symbols found.\n",
tools/perf/util/intel-pt.c +1 -1
index a272b35f6c5a..492986a25ef6 100644
@@ -1563,7 +1563,7 @@ static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
 	if (map__load(map))
 		return 0;
 
-	start = dso__first_symbol(map->dso, MAP__FUNCTION);
+	start = dso__first_symbol(map->dso);
 
 	for (sym = start; sym; sym = dso__next_symbol(sym)) {
 		if (sym->binding == STB_GLOBAL &&
tools/perf/util/symbol.c +13 -3
index 25701078beab..7aa32372f08c 100644
@@ -515,16 +515,26 @@ struct symbol *dso__find_symbol(struct dso *dso,
 	return dso->last_find_result[type].symbol;
 }
 
-struct symbol *dso__first_symbol(struct dso *dso, enum map_type type)
+static struct symbol *__dso__first_symbol(struct dso *dso, enum map_type type)
 {
 	return symbols__first(&dso->symbols[type]);
 }
 
-struct symbol *dso__last_symbol(struct dso *dso, enum map_type type)
+struct symbol *dso__first_symbol(struct dso *dso)
+{
+	return __dso__first_symbol(dso, MAP__FUNCTION);
+}
+
+static struct symbol *__dso__last_symbol(struct dso *dso, enum map_type type)
 {
 	return symbols__last(&dso->symbols[type]);
 }
 
+struct symbol *dso__last_symbol(struct dso *dso)
+{
+	return __dso__last_symbol(dso, MAP__FUNCTION);
+}
+
 struct symbol *dso__next_symbol(struct symbol *sym)
 {
 	return symbols__next(sym);
@@ -1218,7 +1228,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	}
 
 	/* Find the kernel map using the first symbol */
-	sym = dso__first_symbol(dso, map->type);
+	sym = __dso__first_symbol(dso, map->type);
 	list_for_each_entry(new_map, &md.maps, node) {
 		if (sym && sym->start >= new_map->start &&
 		    sym->start < new_map->end) {
tools/perf/util/symbol.h +2 -2
index 70c16741f50a..0e95d9478783 100644
@@ -268,8 +268,8 @@ struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
 					const char *name);
 struct symbol *symbol__next_by_name(struct symbol *sym);
 
-struct symbol *dso__first_symbol(struct dso *dso, enum map_type type);
-struct symbol *dso__last_symbol(struct dso *dso, enum map_type type);
+struct symbol *dso__first_symbol(struct dso *dso);
+struct symbol *dso__last_symbol(struct dso *dso);
 struct symbol *dso__next_symbol(struct symbol *sym);
 
 enum dso_type dso__type_fd(int fd);
Signature · 1 line
2.14.3
author maintainer
#28 lore raw

PATCH 28/52 tools lib symbols: Introduce kallsyms__is_function()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Out of symbol_type__is_a(type, MAP__FUNCTION), which is the only variant used so far, useful in a kallsyms library and one more step in ditching the MAP__FUNCTION/VARIABLE split.

---
 tools/lib/symbol/kallsyms.c | 6 ++++++
 tools/lib/symbol/kallsyms.h | 2 ++
 2 files changed, 8 insertions(+)
tools/lib/symbol/kallsyms.c +6 -0
index 689b6a130dd7..96d830545bbb 100644
@@ -10,6 +10,12 @@ u8 kallsyms2elf_type(char type)
 	return (type == 't' || type == 'w') ? STT_FUNC : STT_OBJECT;
 }
 
+bool kallsyms__is_function(char symbol_type)
+{
+	symbol_type = toupper(symbol_type);
+	return symbol_type == 'T' || symbol_type == 'W';
+}
+
 int kallsyms__parse(const char *filename, void *arg,
 		    int (*process_symbol)(void *arg, const char *name,
 					  char type, u64 start))
tools/lib/symbol/kallsyms.h +2 -0
index bc40101d72c1..72ab9870454b 100644
@@ -20,6 +20,8 @@ static inline u8 kallsyms2elf_binding(char type)
 
 u8 kallsyms2elf_type(char type);
 
+bool kallsyms__is_function(char symbol_type);
+
 int kallsyms__parse(const char *filename, void *arg,
 		    int (*process_symbol)(void *arg, const char *name,
 					  char type, u64 start));
Signature · 1 line
2.14.3
author maintainer
#29 lore raw

PATCH 29/52 perf tools: Use kallsyms__is_function()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Replacing equivalent, the equivalent and longer variation:

	 symbol__is_a(type, MAP__FUNCTION);
---
 tools/perf/util/auxtrace.c   | 4 ++--
 tools/perf/util/event.c      | 2 +-
 tools/perf/util/symbol-elf.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/auxtrace.c +2 -2
index eaf1e10ae755..d056447520a2 100644
@@ -1679,7 +1679,7 @@ struct sym_args {
 static bool kern_sym_match(struct sym_args *args, const char *name, char type)
 {
 	/* A function with the same name, and global or the n'th found or any */
-	return symbol_type__is_a(type, MAP__FUNCTION) &&
+	return kallsyms__is_function(type) &&
 	       !strcmp(name, args->name) &&
 	       ((args->global && isupper(type)) ||
 		(args->selected && ++(args->cnt) == args->idx) ||
@@ -1784,7 +1784,7 @@ static int find_entire_kern_cb(void *arg, const char *name __maybe_unused,
 {
 	struct sym_args *args = arg;
 
-	if (!symbol_type__is_a(type, MAP__FUNCTION))
+	if (!kallsyms__is_function(type))
 		return 0;
 
 	if (!args->started) {
tools/perf/util/event.c +1 -1
index a8739cd0d8ca..241d3c827fae 100644
@@ -868,7 +868,7 @@ static int find_symbol_cb(void *arg, const char *name, char type,
 	 * Must be a function or at least an alias, as in PARISC64, where "_text" is
 	 * an 'A' to the same address as "_stext".
 	 */
-	if (!(symbol_type__is_a(type, MAP__FUNCTION) ||
+	if (!(kallsyms__is_function(type) ||
 	      type == 'A') || strcmp(name, args->name))
 		return 0;
 
tools/perf/util/symbol-elf.c +1 -1
index 75f578f3ed8e..b6be6062cae0 100644
@@ -1413,7 +1413,7 @@ static int kcore_copy__process_kallsyms(void *arg, const char *name, char type,
 {
 	struct kcore_copy_info *kci = arg;
 
-	if (!symbol_type__is_a(type, MAP__FUNCTION))
+	if (!kallsyms__is_function(type))
 		return 0;
 
 	if (strchr(name, '[')) {
Signature · 1 line
2.14.3
author maintainer
#30 lore raw

PATCH 30/52 perf symbols: Unexport symbol_type__is_a()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Now this is only used in the symbols.c file, where it will finally disappear when we remove the MAP_{FUNCTION,VARIABLE} split.

---
 tools/perf/util/symbol.c | 2 +-
 tools/perf/util/symbol.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/symbol.c +1 -1
index 7aa32372f08c..8d9967357354 100644
@@ -70,7 +70,7 @@ static enum dso_binary_type binary_type_symtab[] = {
 
 #define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab)
 
-bool symbol_type__is_a(char symbol_type, enum map_type map_type)
+static bool symbol_type__is_a(char symbol_type, enum map_type map_type)
 {
 	symbol_type = toupper(symbol_type);
 
tools/perf/util/symbol.h +0 -1
index 0e95d9478783..924f465307b1 100644
@@ -300,7 +300,6 @@ size_t __symbol__fprintf_symname(const struct symbol *sym,
 				 bool unknown_as_addr, FILE *fp);
 size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
 size_t symbol__fprintf(struct symbol *sym, FILE *fp);
-bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 bool symbol__restricted_filename(const char *filename,
 				 const char *restricted_filename);
 int symbol__config_symfs(const struct option *opt __maybe_unused,
Signature · 1 line
2.14.3
author maintainer
#31 lore raw

PATCH 31/52 perf map: Remove enum_type arg to map_groups__first()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Only the symbol core needs to use that, so provide a __ variant for that case, that will end up removed when we ditch the MAP__ split.

---
 tools/perf/util/map.h    |  6 +-----
 tools/perf/util/symbol.c | 14 ++++++++++++--
 tools/perf/util/vdso.c   |  6 ++----
 3 files changed, 15 insertions(+), 11 deletions(-)
tools/perf/util/map.h +1 -5
index b4bcf569a131..579ad7d2711d 100644
@@ -225,11 +225,7 @@ static inline struct map *map_groups__find(struct map_groups *mg, u64 addr)
 	return __map_groups__find(mg, MAP__FUNCTION, addr);
 }
 
-static inline struct map *map_groups__first(struct map_groups *mg,
-					    enum map_type type)
-{
-	return maps__first(&mg->maps[type]);
-}
+struct map *map_groups__first(struct map_groups *mg);
 
 static inline struct map *map_groups__next(struct map *map)
 {
tools/perf/util/symbol.c +12 -2
index 8d9967357354..5d77c60e63bf 100644
@@ -1044,6 +1044,16 @@ int compare_proc_modules(const char *from, const char *to)
 	return ret;
 }
 
+static struct map *__map_groups__first(struct map_groups *mg, enum map_type type)
+{
+	return maps__first(&mg->maps[type]);
+}
+
+struct map *map_groups__first(struct map_groups *mg)
+{
+	return __map_groups__first(mg, MAP__FUNCTION);
+}
+
 static int do_validate_kcore_modules(const char *filename, struct map *map,
 				  struct map_groups *kmaps)
 {
@@ -1055,7 +1065,7 @@ static int do_validate_kcore_modules(const char *filename, struct map *map,
 	if (err)
 		return err;
 
-	old_map = map_groups__first(kmaps, map->type);
+	old_map = __map_groups__first(kmaps, map->type);
 	while (old_map) {
 		struct map *next = map_groups__next(old_map);
 		struct module_info *mi;
@@ -1218,7 +1228,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	}
 
 	/* Remove old maps */
-	old_map = map_groups__first(kmaps, map->type);
+	old_map = __map_groups__first(kmaps, map->type);
 	while (old_map) {
 		struct map *next = map_groups__next(old_map);
 
tools/perf/util/vdso.c +2 -4
index 0acb1ec0e2f0..741af209b19d 100644
@@ -139,12 +139,10 @@ static enum dso_type machine__thread_dso_type(struct machine *machine,
 					      struct thread *thread)
 {
 	enum dso_type dso_type = DSO__TYPE_UNKNOWN;
-	struct map *map;
-	struct dso *dso;
+	struct map *map = map_groups__first(thread->mg);
 
-	map = map_groups__first(thread->mg, MAP__FUNCTION);
 	for (; map ; map = map_groups__next(map)) {
-		dso = map->dso;
+		struct dso *dso = map->dso;
 		if (!dso || dso->long_name[0] != '/')
 			continue;
 		dso_type = dso__type(dso, machine);
Signature · 1 line
2.14.3
author maintainer
#32 lore raw

PATCH 32/52 perf symbols: Remove map_type arg from dso__find_symbol()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

One more step to ditch MAP__{VARIABLE,FUNCTION}

---
 tools/perf/util/db-export.c |  3 +--
 tools/perf/util/map.c       |  4 ++--
 tools/perf/util/symbol.c    | 10 +++++-----
 tools/perf/util/symbol.h    | 12 ++++++++----
 4 files changed, 16 insertions(+), 13 deletions(-)
tools/perf/util/db-export.c +1 -2
index b0c2b5c5d337..04fb1a99c737 100644
@@ -315,8 +315,7 @@ static struct call_path *call_path_from_sample(struct db_export *dbe,
 		al.addr = node->ip;
 
 		if (al.map && !al.sym)
-			al.sym = dso__find_symbol(al.map->dso, MAP__FUNCTION,
-						  al.addr);
+			al.sym = dso__find_symbol(al.map->dso, al.addr);
 
 		db_ids_from_al(dbe, &al, &dso_db_id, &sym_db_id, &offset);
 
tools/perf/util/map.c +2 -2
index 91e2afb010f8..ab12f2bc7669 100644
@@ -353,7 +353,7 @@ struct symbol *map__find_symbol(struct map *map, u64 addr)
 	if (map__load(map) < 0)
 		return NULL;
 
-	return dso__find_symbol(map->dso, map->type, addr);
+	return __dso__find_symbol(map->dso, map->type, addr);
 }
 
 struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
@@ -364,7 +364,7 @@ struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
 	if (!dso__sorted_by_name(map->dso, map->type))
 		dso__sort_by_name(map->dso, map->type);
 
-	return dso__find_symbol_by_name(map->dso, map->type, name);
+	return __dso__find_symbol_by_name(map->dso, map->type, name);
 }
 
 struct map *map__clone(struct map *from)
tools/perf/util/symbol.c +5 -5
index 5d77c60e63bf..2b81ccc94a7e 100644
@@ -504,8 +504,8 @@ void dso__insert_symbol(struct dso *dso, enum map_type type, struct symbol *sym)
 	}
 }
 
-struct symbol *dso__find_symbol(struct dso *dso,
-				enum map_type type, u64 addr)
+struct symbol *__dso__find_symbol(struct dso *dso,
+				  enum map_type type, u64 addr)
 {
 	if (dso->last_find_result[type].addr != addr || dso->last_find_result[type].symbol == NULL) {
 		dso->last_find_result[type].addr   = addr;
@@ -549,10 +549,10 @@ struct symbol *symbol__next_by_name(struct symbol *sym)
 }
 
  /*
-  * Teturns first symbol that matched with @name.
+  * Returns first symbol that matched with @name.
   */
-struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
-					const char *name)
+struct symbol *__dso__find_symbol_by_name(struct dso *dso, enum map_type type,
+					  const char *name)
 {
 	struct symbol *s = symbols__find_by_name(&dso->symbol_names[type], name,
 						 SYMBOL_TAG_INCLUDE__NONE);
tools/perf/util/symbol.h +8 -4
index 924f465307b1..2b985ff2e725 100644
@@ -262,10 +262,14 @@ int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map);
 void dso__insert_symbol(struct dso *dso, enum map_type type,
 			struct symbol *sym);
 
-struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
-				u64 addr);
-struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
-					const char *name);
+struct symbol *__dso__find_symbol(struct dso *dso, enum map_type type, u64 addr);
+struct symbol *__dso__find_symbol_by_name(struct dso *dso, enum map_type type, const char *name);
+
+static inline struct symbol *dso__find_symbol(struct dso *dso, u64 addr)
+{
+	return __dso__find_symbol(dso, MAP__FUNCTION, addr);
+}
+
 struct symbol *symbol__next_by_name(struct symbol *sym);
 
 struct symbol *dso__first_symbol(struct dso *dso);
Signature · 1 line
2.14.3
author maintainer
#33 lore raw

PATCH 33/52 perf thread: Remove addr_type arg from thread__find_cpumode_addr_location()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

All callers are for MAP__FUNCTION, so just ditch it and use thread__find_symbol(), that already ditched MAP__FUNCTION, i.e. internally uses it till we ditch it for good.

---
 tools/perf/util/machine.c | 5 ++---
 tools/perf/util/thread.c  | 5 ++---
 tools/perf/util/thread.h  | 3 +--
 3 files changed, 5 insertions(+), 8 deletions(-)
tools/perf/util/machine.c +2 -3
index 0017c4a1fb97..10364e829aba 100644
@@ -1660,7 +1660,7 @@ static void ip__resolve_ams(struct thread *thread,
 	 * Thus, we have to try consecutively until we find a match
 	 * or else, the symbol is unknown
 	 */
-	thread__find_cpumode_addr_location(thread, MAP__FUNCTION, ip, &al);
+	thread__find_cpumode_addr_location(thread, ip, &al);
 
 	ams->addr = ip;
 	ams->al_addr = al.addr;
@@ -1754,8 +1754,7 @@ static int add_callchain_ip(struct thread *thread,
 	al.filtered = 0;
 	al.sym = NULL;
 	if (!cpumode) {
-		thread__find_cpumode_addr_location(thread, MAP__FUNCTION,
-						   ip, &al);
+		thread__find_cpumode_addr_location(thread, ip, &al);
 	} else {
 		if (ip >= PERF_CONTEXT_MAX) {
 			switch (ip) {
tools/perf/util/thread.c +2 -3
index 2a3fb7c6b39d..ddbf0470b048 100644
@@ -371,8 +371,7 @@ int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp)
 	return thread__clone_map_groups(thread, parent);
 }
 
-void thread__find_cpumode_addr_location(struct thread *thread,
-					enum map_type type, u64 addr,
+void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
 					struct addr_location *al)
 {
 	size_t i;
@@ -384,7 +383,7 @@ void thread__find_cpumode_addr_location(struct thread *thread,
 	};
 
 	for (i = 0; i < ARRAY_SIZE(cpumodes); i++) {
-		__thread__find_symbol(thread, cpumodes[i], type, addr, al);
+		thread__find_symbol(thread, cpumodes[i], addr, al);
 		if (al->map)
 			break;
 	}
tools/perf/util/thread.h +1 -2
index 1b130b0a4a48..d6209c73f32d 100644
@@ -110,8 +110,7 @@ static inline struct symbol *thread__find_symbol(struct thread *thread, u8 cpumo
 	return __thread__find_symbol(thread, cpumode, MAP__FUNCTION, addr, al);
 }
 
-void thread__find_cpumode_addr_location(struct thread *thread,
-					enum map_type type, u64 addr,
+void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
 					struct addr_location *al);
 
 static inline void *thread__priv(struct thread *thread)
Signature · 1 line
2.14.3
author maintainer
#34 lore raw

PATCH 34/52 perf machine: Use machine__find_kernel_function() instead of open coded version

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

We have that equivalent, shorter helper, use it.

---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/machine.c +1 -1
index 10364e829aba..a00e82b83e0a 100644
@@ -2367,7 +2367,7 @@ char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, ch
 {
 	struct machine *machine = vmachine;
 	struct map *map;
-	struct symbol *sym = map_groups__find_symbol(&machine->kmaps, MAP__FUNCTION, *addrp, &map);
+	struct symbol *sym = machine__find_kernel_function(machine, *addrp, &map);
 
 	if (sym == NULL)
 		return NULL;
Signature · 1 line
2.14.3
author maintainer
#35 lore raw

PATCH 35/52 perf thread: Ditch __thread__find_symbol()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Simulate having all symbols in just one tree by searching the still existing two trees.

---
 tools/perf/builtin-trace.c |  2 +-
 tools/perf/util/event.c    |  8 ++++----
 tools/perf/util/machine.c  | 10 +---------
 tools/perf/util/thread.h   | 10 ++--------
 4 files changed, 8 insertions(+), 22 deletions(-)
tools/perf/builtin-trace.c +1 -1
index afec6f9ffd89..c7effcfc40ed 100644
@@ -2036,7 +2036,7 @@ static int trace__pgfault(struct trace *trace,
 
 	fprintf(trace->output, "] => ");
 
-	__thread__find_symbol(thread, sample->cpumode, MAP__VARIABLE, sample->addr, &al);
+	thread__find_symbol(thread, sample->cpumode, sample->addr, &al);
 
 	if (!al.map) {
 		thread__find_symbol(thread, sample->cpumode, sample->addr, &al);
tools/perf/util/event.c +4 -4
index 241d3c827fae..7b67771cd478 100644
@@ -1565,12 +1565,12 @@ struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type
 	return al->map;
 }
 
-struct symbol *__thread__find_symbol(struct thread *thread, u8 cpumode,
-				     enum map_type type, u64 addr,
-				     struct addr_location *al)
+struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
+				   u64 addr, struct addr_location *al)
 {
 	al->sym = NULL;
-	if (__thread__find_map(thread, cpumode, type, addr, al))
+	if (__thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al) ||
+	    __thread__find_map(thread, cpumode, MAP__VARIABLE, addr, al))
 		al->sym = map__find_symbol(al->map, al->addr);
 	return al->sym;
 }
tools/perf/util/machine.c +1 -9
index a00e82b83e0a..3422ef67ec21 100644
@@ -1677,15 +1677,7 @@ static void ip__resolve_data(struct thread *thread,
 
 	memset(&al, 0, sizeof(al));
 
-	__thread__find_symbol(thread, m, MAP__VARIABLE, addr, &al);
-	if (al.map == NULL) {
-		/*
-		 * some shared data regions have execute bit set which puts
-		 * their mapping in the MAP__FUNCTION type array.
-		 * Check there as a fallback option before dropping the sample.
-		 */
-		thread__find_symbol(thread, m, addr, &al);
-	}
+	thread__find_symbol(thread, m, addr, &al);
 
 	ams->addr = addr;
 	ams->al_addr = al.addr;
tools/perf/util/thread.h +2 -8
index d6209c73f32d..54aa24d6151e 100644
@@ -101,14 +101,8 @@ static inline struct map *thread__find_map(struct thread *thread, u8 cpumode,
 	return __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
 }
 
-struct symbol *__thread__find_symbol(struct thread *thread, u8 cpumode, enum map_type type,
-				     u64 addr, struct addr_location *al);
-
-static inline struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
-						 u64 addr, struct addr_location *al)
-{
-	return __thread__find_symbol(thread, cpumode, MAP__FUNCTION, addr, al);
-}
+struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
+				   u64 addr, struct addr_location *al);
 
 void thread__find_cpumode_addr_location(struct thread *thread, u64 addr,
 					struct addr_location *al);
Signature · 1 line
2.14.3
author maintainer
#36 lore raw

PATCH 36/52 perf thread: Make thread__find_map() search all maps

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

We still have the split internally, but users don't see it anymore, simplifying the growing number of cases where we end up searching in the MAP__VARIABLE maps.

This further paves the way for ditching the split.

---
 tools/perf/builtin-script.c              |  4 ++--
 tools/perf/util/event.c                  | 19 +++++++++++--------
 tools/perf/util/thread.h                 | 10 ++--------
 tools/perf/util/unwind-libdw.c           | 10 ----------
 tools/perf/util/unwind-libunwind-local.c | 12 +-----------
 5 files changed, 16 insertions(+), 39 deletions(-)
tools/perf/builtin-script.c +2 -2
index 07cb083ac89c..fa2c7a288750 100644
@@ -927,8 +927,8 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
 
 	memset(&al, 0, sizeof(al));
 
-	if (!thread__find_map(thread, cpumode, addr, &al))
-		__thread__find_map(thread, cpumode, MAP__VARIABLE, addr, &al);
+	thread__find_map(thread, cpumode, addr, &al);
+
 	if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end)
 		return 0;
 
tools/perf/util/event.c +11 -8
index 7b67771cd478..7831c2266118 100644
@@ -1488,8 +1488,8 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
 	return machine__process_event(machine, event, sample);
 }
 
-struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
-			       u64 addr, struct addr_location *al)
+static struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
+				      u64 addr, struct addr_location *al)
 {
 	struct map_groups *mg = thread->mg;
 	struct machine *machine = mg->machine;
@@ -1565,12 +1565,18 @@ struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type
 	return al->map;
 }
 
+struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
+			     struct addr_location *al)
+{
+	struct map *map = __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
+	return map ?: __thread__find_map(thread, cpumode, MAP__VARIABLE, addr, al);
+}
+
 struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
 				   u64 addr, struct addr_location *al)
 {
 	al->sym = NULL;
-	if (__thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al) ||
-	    __thread__find_map(thread, cpumode, MAP__VARIABLE, addr, al))
+	if (thread__find_map(thread, cpumode, addr, al))
 		al->sym = map__find_symbol(al->map, al->addr);
 	return al->sym;
 }
@@ -1668,10 +1674,7 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)
 void thread__resolve(struct thread *thread, struct addr_location *al,
 		     struct perf_sample *sample)
 {
-	if (!thread__find_map(thread, sample->cpumode, sample->addr, al)) {
-		__thread__find_map(thread, sample->cpumode, MAP__VARIABLE,
-				   sample->addr, al);
-	}
+	thread__find_map(thread, sample->cpumode, sample->addr, al);
 
 	al->cpu = sample->cpu;
 	al->sym = NULL;
tools/perf/util/thread.h +2 -8
index 54aa24d6151e..07606aa6998d 100644
@@ -92,14 +92,8 @@ size_t thread__fprintf(struct thread *thread, FILE *fp);
 
 struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
 
-struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
-			       u64 addr, struct addr_location *al);
-
-static inline struct map *thread__find_map(struct thread *thread, u8 cpumode,
-					   u64 addr, struct addr_location *al)
-{
-	return __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
-}
+struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
+			     struct addr_location *al);
 
 struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
 				   u64 addr, struct addr_location *al);
tools/perf/util/unwind-libdw.c +0 -10
index 17401922cd42..538db4e5d1e6 100644
@@ -105,16 +105,6 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr,
 	ssize_t size;
 
 	if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al)) {
-		/*
-		 * We've seen cases (softice) where DWARF unwinder went
-		 * through non executable mmaps, which we need to lookup
-		 * in MAP__VARIABLE tree.
-		 */
-		__thread__find_map(ui->thread, PERF_RECORD_MISC_USER,
-				   MAP__VARIABLE, addr, &al);
-	}
-
-	if (!al.map) {
 		pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
 		return -1;
 	}
tools/perf/util/unwind-libunwind-local.c +1 -11
index 2afb22b0a1a9..6a11bc7e6b27 100644
@@ -366,17 +366,7 @@ static int read_unwind_spec_debug_frame(struct dso *dso,
 static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
 {
 	struct addr_location al;
-
-	if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al)) {
-		/*
-		 * We've seen cases (softice) where DWARF unwinder went
-		 * through non executable mmaps, which we need to lookup
-		 * in MAP__VARIABLE tree.
-		 */
-		__thread__find_map(ui->thread, PERF_RECORD_MISC_USER,
-				   MAP__VARIABLE, ip, &al);
-	}
-	return al.map;
+	return thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al);
 }
 
 static int
Signature · 1 line
2.14.3
author maintainer
#37 lore raw

PATCH 37/52 perf map: Remove map_type arg from map_groups__find()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

One more step in ditching the split.

---
 tools/perf/arch/arm/tests/dwarf-unwind.c     | 2 +-
 tools/perf/arch/arm64/tests/dwarf-unwind.c   | 2 +-
 tools/perf/arch/powerpc/tests/dwarf-unwind.c | 2 +-
 tools/perf/arch/x86/tests/dwarf-unwind.c     | 2 +-
 tools/perf/util/map.h                        | 3 ++-
 5 files changed, 6 insertions(+), 5 deletions(-)
tools/perf/arch/arm/tests/dwarf-unwind.c +1 -1
index 7d7a65ca2e8d..9a0242e74cfc 100644
@@ -25,7 +25,7 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_ARM_SP];
 
-	map = __map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
+	map = map_groups__find(thread->mg, (u64)sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		free(buf);
tools/perf/arch/arm64/tests/dwarf-unwind.c +1 -1
index f053eae3b6eb..5522ce384723 100644
@@ -25,7 +25,7 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_ARM64_SP];
 
-	map = __map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
+	map = map_groups__find(thread->mg, (u64)sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		free(buf);
tools/perf/arch/powerpc/tests/dwarf-unwind.c +1 -1
index b22d643cb602..5f39efef0856 100644
@@ -26,7 +26,7 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_POWERPC_R1];
 
-	map = __map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
+	map = map_groups__find(thread->mg, (u64)sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		free(buf);
tools/perf/arch/x86/tests/dwarf-unwind.c +1 -1
index 7da845026323..7879df34569a 100644
@@ -26,7 +26,7 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_X86_SP];
 
-	map = __map_groups__find(thread->mg, MAP__VARIABLE, (u64) sp);
+	map = map_groups__find(thread->mg, (u64)sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		free(buf);
tools/perf/util/map.h +2 -1
index 579ad7d2711d..d035d8f0d5b2 100644
@@ -222,7 +222,8 @@ static inline struct map *__map_groups__find(struct map_groups *mg,
 
 static inline struct map *map_groups__find(struct map_groups *mg, u64 addr)
 {
-	return __map_groups__find(mg, MAP__FUNCTION, addr);
+	struct map *map = __map_groups__find(mg, MAP__FUNCTION, addr);
+	return map ?: __map_groups__find(mg, MAP__VARIABLE, addr);
 }
 
 struct map *map_groups__first(struct map_groups *mg);
Signature · 1 line
2.14.3
author maintainer
#38 lore raw

PATCH 38/52 perf symbols: Store the ELF symbol type in the symbol struct

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

There is code that needs to see if a resolved address is a function, so, since we're going to ditch the MAP__{FUNCTION,VARIABLE} split, store that info in the per symbol struct.

---
 tools/perf/tests/hists_common.c | 2 +-
 tools/perf/util/db-export.c     | 2 +-
 tools/perf/util/srcline.c       | 1 +
 tools/perf/util/symbol-elf.c    | 7 ++++---
 tools/perf/util/symbol.c        | 7 ++++---
 tools/perf/util/symbol.h        | 5 +++--
 6 files changed, 14 insertions(+), 10 deletions(-)
tools/perf/tests/hists_common.c +1 -1
index f7c5b613d667..d0366fde72a3 100644
@@ -138,7 +138,7 @@ struct machine *setup_fake_machine(struct machines *machines)
 			struct fake_sym *fsym = &fake_symbols[i].syms[k];
 
 			sym = symbol__new(fsym->start, fsym->length,
-					  STB_GLOBAL, fsym->name);
+					  STB_GLOBAL, STT_FUNC, fsym->name);
 			if (sym == NULL) {
 				dso__put(dso);
 				goto out;
tools/perf/util/db-export.c +1 -1
index 04fb1a99c737..12d60703c8fc 100644
@@ -247,7 +247,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,
 		*dso_db_id = dso->db_id;
 
 		if (!al->sym) {
-			al->sym = symbol__new(al->addr, 0, 0, "unknown");
+			al->sym = symbol__new(al->addr, 0, 0, 0, "unknown");
 			if (al->sym)
 				dso__insert_symbol(dso, al->map->type, al->sym);
 		}
tools/perf/util/srcline.c +1 -0
index 3c21fd059b64..09d6746e6ec8 100644
@@ -103,6 +103,7 @@ static struct symbol *new_inline_sym(struct dso *dso,
 		inline_sym = symbol__new(base_sym ? base_sym->start : 0,
 					 base_sym ? base_sym->end : 0,
 					 base_sym ? base_sym->binding : 0,
+					 base_sym ? base_sym->type : 0,
 					 funcname);
 		if (inline_sym)
 			inline_sym->inlined = 1;
tools/perf/util/symbol-elf.c +4 -3
index b6be6062cae0..88f6f3050665 100644
@@ -364,7 +364,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss, struct map *
 			free(demangled);
 
 			f = symbol__new(plt_offset, plt_entry_size,
-					STB_GLOBAL, sympltname);
+					STB_GLOBAL, STT_FUNC, sympltname);
 			if (!f)
 				goto out_elf_end;
 
@@ -390,7 +390,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss, struct map *
 			free(demangled);
 
 			f = symbol__new(plt_offset, plt_entry_size,
-					STB_GLOBAL, sympltname);
+					STB_GLOBAL, STT_FUNC, sympltname);
 			if (!f)
 				goto out_elf_end;
 
@@ -1102,7 +1102,8 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 			elf_name = demangled;
 
 		f = symbol__new(sym.st_value, sym.st_size,
-				GELF_ST_BIND(sym.st_info), elf_name);
+				GELF_ST_BIND(sym.st_info),
+				GELF_ST_TYPE(sym.st_info), elf_name);
 		free(demangled);
 		if (!f)
 			goto out_elf_end;
tools/perf/util/symbol.c +4 -3
index 2b81ccc94a7e..e1fd236c96d3 100644
@@ -256,7 +256,7 @@ void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
 	up_write(&maps->lock);
 }
 
-struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
+struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *name)
 {
 	size_t namelen = strlen(name) + 1;
 	struct symbol *sym = calloc(1, (symbol_conf.priv_size +
@@ -274,6 +274,7 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
 
 	sym->start   = start;
 	sym->end     = len ? start + len : start;
+	sym->type    = type;
 	sym->binding = binding;
 	sym->namelen = namelen - 1;
 
@@ -682,7 +683,7 @@ static int map__process_kallsym_symbol(void *arg, const char *name,
 	 * symbols, setting length to 0, and rely on
 	 * symbols__fixup_end() to fix it up.
 	 */
-	sym = symbol__new(start, 0, kallsyms2elf_binding(type), name);
+	sym = symbol__new(start, 0, kallsyms2elf_binding(type), kallsyms2elf_type(type), name);
 	if (sym == NULL)
 		return -ENOMEM;
 	/*
@@ -1395,7 +1396,7 @@ static int dso__load_perf_map(const char *map_path, struct dso *dso,
 		if (len + 2 >= line_len)
 			continue;
 
-		sym = symbol__new(start, size, STB_GLOBAL, line + len);
+		sym = symbol__new(start, size, STB_GLOBAL, STT_FUNC, line + len);
 
 		if (sym == NULL)
 			goto out_delete_line;
tools/perf/util/symbol.h +3 -2
index 2b985ff2e725..3e2ac485c6d9 100644
@@ -57,7 +57,8 @@ struct symbol {
 	u64		start;
 	u64		end;
 	u16		namelen;
-	u8		binding;
+	u8		type:4;
+	u8		binding:4;
 	u8		idle:1;
 	u8		ignore:1;
 	u8		inlined:1;
@@ -292,7 +293,7 @@ void symbol__exit(void);
 void symbol__elf_init(void);
 int symbol__annotation_init(void);
 
-struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
+struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *name);
 size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
 				      const struct addr_location *al,
 				      bool unknown_as_addr,
Signature · 1 line
2.14.3
author maintainer
#39 lore raw

PATCH 39/52 perf machine: Set PROT_EXEC for executable PERF_RECORD_MMAP records

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

The kernel doesn't fill the map 'prot' field for PERF_RECORD_MMAP records, and we will use that info to replace checking for MAP__VARIABLE, so store that when processing the PERF_RECORD_MISC_MMAP_DATA perf_event_attr.header.misc bit.

---
 tools/perf/util/machine.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/machine.c +6 -2
index 3422ef67ec21..53bc2fb88be4 100644
@@ -24,6 +24,7 @@
 
 #include "sane_ctype.h"
 #include <symbol/kallsyms.h>
+#include <linux/mman.h>
 
 static void __machine__remove_thread(struct machine *machine, struct thread *th, bool lock);
 
@@ -1457,6 +1458,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
 	struct thread *thread;
 	struct map *map;
 	enum map_type type;
+	u32 prot = 0;
 	int ret = 0;
 
 	if (dump_trace)
@@ -1477,12 +1479,14 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
 
 	if (event->header.misc & PERF_RECORD_MISC_MMAP_DATA)
 		type = MAP__VARIABLE;
-	else
+	else {
 		type = MAP__FUNCTION;
+		prot = PROT_EXEC;
+	}
 
 	map = map__new(machine, event->mmap.start,
 			event->mmap.len, event->mmap.pgoff,
-			0, 0, 0, 0, 0, 0,
+			0, 0, 0, 0, prot, 0,
 			event->mmap.filename,
 			type, thread);
 
Signature · 1 line
2.14.3
author maintainer
#40 lore raw

PATCH 40/52 perf sort: Use mmap->prot on "dcacheline" formatting

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

To match the kernel when setting the PERF_RECORD_MISC_MMAP_DATA bit in perf_event_attr.header.misc, that gets set when VM_EXEC is not set in the vm_flags.

---
 tools/perf/util/sort.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/sort.c +2 -2
index 26a68dfd8a4f..49a41b4b59cf 100644
@@ -2,7 +2,7 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <regex.h>
-#include <sys/mman.h>
+#include <linux/mman.h>
 #include "sort.h"
 #include "hist.h"
 #include "comm.h"
@@ -1211,7 +1211,7 @@ static int hist_entry__dcacheline_snprintf(struct hist_entry *he, char *bf,
 
 		/* print [s] for shared data mmaps */
 		if ((he->cpumode != PERF_RECORD_MISC_KERNEL) &&
-		     map && (map->type == MAP__VARIABLE) &&
+		     map && !(map->prot & PROT_EXEC) &&
 		    (map->flags & MAP_SHARED) &&
 		    (map->maj || map->min || map->ino ||
 		     map->ino_generation))
Signature · 1 line
2.14.3
author maintainer
#41 lore raw

PATCH 41/52 perf symbols: No need to special case MAP__FUNCTION in fixup

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

In 39b12f781271 ("perf tools: Make it possible to read object code from vmlinux") we special case MAP__FUNCTION maps inconsistently, the first test tests the map type while the following tests added by this patch don't do that, be consistent and elliminate this special case.

---
 tools/perf/util/sort.c       | 2 +-
 tools/perf/util/symbol-elf.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/sort.c +1 -1
index 49a41b4b59cf..e65903a695a6 100644
@@ -282,7 +282,7 @@ static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym,
 
 	ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", level);
 	if (sym && map) {
-		if (map->type == MAP__VARIABLE) {
+		if (sym->type == STT_OBJECT) {
 			ret += repsep_snprintf(bf + ret, size - ret, "%s", sym->name);
 			ret += repsep_snprintf(bf + ret, size - ret, "+0x%llx",
 					ip - map->unmap_ip(map, sym->start));
tools/perf/util/symbol-elf.c +3 -3
index 88f6f3050665..cf2e6f428bb4 100644
@@ -921,10 +921,10 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 
 	dso->adjust_symbols = runtime_ss->adjust_symbols || ref_reloc(kmap);
 	/*
-	 * Initial kernel and module mappings do not map to the dso.  For
-	 * function mappings, flag the fixups.
+	 * Initial kernel and module mappings do not map to the dso.
+	 * Flag the fixups.
 	 */
-	if (map->type == MAP__FUNCTION && (dso->kernel || kmodule)) {
+	if (dso->kernel || kmodule) {
 		remap_kernel = true;
 		adjust_kernel_syms = dso->adjust_symbols;
 	}
Signature · 1 line
2.14.3
author maintainer
#42 lore raw

PATCH 42/52 perf symbols: Use symbol type instead of map->type

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

map->type is going away, we can derive it from map->prot, so use the same logic as in the kernel's arch/arm/kernel/module.c file:

  ELF32_ST_TYPE(sym->st_info) == STT_FUNC && !(sym->st_value & 1))

This was introduced in b2f8fb237e9c ("perf symbols: Fix annotation of thumb code"), that fix is maintained with this change.

---
 tools/perf/util/symbol-elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/symbol-elf.c +1 -1
index cf2e6f428bb4..82a1aadc245f 100644
@@ -982,7 +982,7 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 		/* On ARM, symbols for thumb functions have 1 added to
 		 * the symbol address as a flag - remove it */
 		if ((ehdr.e_machine == EM_ARM) &&
-		    (map->type == MAP__FUNCTION) &&
+		    (GELF_ST_TYPE(sym.st_info) == STT_FUNC) &&
 		    (sym.st_value & 1))
 			--sym.st_value;
 
Signature · 1 line
2.14.3
author maintainer
#43 lore raw

PATCH 43/52 perf map: Use map->prot in place of type==MAP__FUNCTION

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Equivalent, one step more in ditching enum map_type.

---
 tools/perf/util/map.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/map.c +2 -2
index ab12f2bc7669..a164e1ed5462 100644
@@ -173,7 +173,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 		map->flags = flags;
 		nsi = nsinfo__get(thread->nsinfo);
 
-		if ((anon || no_dso) && nsi && type == MAP__FUNCTION) {
+		if ((anon || no_dso) && nsi && (prot & PROT_EXEC)) {
 			snprintf(newfilename, sizeof(newfilename),
 				 "/tmp/perf-%d.map", nsi->pid);
 			filename = newfilename;
@@ -213,7 +213,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
 			 * functions still return NULL, and we avoid the
 			 * unnecessary map__load warning.
 			 */
-			if (type != MAP__FUNCTION)
+			if (!(prot & PROT_EXEC))
 				dso__set_loaded(dso, map->type);
 		}
 		dso->nsinfo = nsi;
Signature · 1 line
2.14.3
author maintainer
#44 lore raw

PATCH 44/52 perf symbols: Use map->prot in place of type==MAP__FUNCTION

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Its equivalent, one less use of enum map_type.

---
 tools/perf/util/symbol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/symbol.c +3 -2
index e1fd236c96d3..fe0e0d84a586 100644
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <linux/kernel.h>
+#include <linux/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
@@ -1217,7 +1218,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	}
 
 	/* Read new maps into temporary lists */
-	err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md,
+	err = file__read_maps(fd, map->prot & PROT_EXEC, kcore_mapfn, &md,
 			      &is_64_bit);
 	if (err)
 		goto out_err;
@@ -1285,7 +1286,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 
 	close(fd);
 
-	if (map->type == MAP__FUNCTION)
+	if (map->prot & PROT_EXEC)
 		pr_debug("Using %s for kernel object code\n", kcore_filename);
 	else
 		pr_debug("Using %s for kernel data\n", kcore_filename);
Signature · 1 line
2.14.3
author maintainer
#45 lore raw

PATCH 45/52 perf symbols: Unify symbol maps

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Remove the split of symbol tables for data (MAP__VARIABLE) and for functions (MAP__FUNCTION), its unneeded and there were various places doing two lookups to find a symbol, so simplify this.

We still will consider only the symbols that matched the filters in place, i.e. see the (elf_(sec,sym)|symbol_type)__filter() routines in the patch, just so that we consider only the same symbols as before, to reduce the possibility of regressions.

All the tests on 50-something build environments, in varios versions of lots of distros and cross build environments were performed without build regressions, as usual with all pull requests the other tests were also performed: 'perf test' and 'make -C tools/perf build-test'.

Also this was done at a great granularity so that regressions can be bisected more easily.

---
 tools/perf/builtin-annotate.c    |   2 +-
 tools/perf/builtin-report.c      |   5 +-
 tools/perf/tests/hists_common.c  |   4 +-
 tools/perf/ui/browsers/map.c     |   2 +-
 tools/perf/util/db-export.c      |   2 +-
 tools/perf/util/dso.c            |  34 ++++------
 tools/perf/util/dso.h            |  36 +++++-----
 tools/perf/util/event.c          |  13 +---
 tools/perf/util/machine.c        | 124 +++++++++++++----------------------
 tools/perf/util/machine.h        |  32 +++------
 tools/perf/util/map.c            |  91 ++++++++------------------
 tools/perf/util/map.h            |  54 ++++-----------
 tools/perf/util/probe-event.c    |   9 ++-
 tools/perf/util/session.c        |  13 ++--
 tools/perf/util/symbol-elf.c     |  51 +++++----------
 tools/perf/util/symbol-minimal.c |   3 +-
 tools/perf/util/symbol.c         | 138 +++++++++++++++------------------------
 tools/perf/util/symbol.h         |  16 ++---
 tools/perf/util/symbol_fprintf.c |   4 +-
 tools/perf/util/thread.c         |  30 ++++-----
 20 files changed, 232 insertions(+), 431 deletions(-)
tools/perf/builtin-annotate.c +1 -1
index 51709a961496..6e5d9f718154 100644
@@ -228,7 +228,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
 		 */
 		if (al->sym != NULL) {
 			rb_erase(&al->sym->rb_node,
-				 &al->map->dso->symbols[al->map->type]);
+				 &al->map->dso->symbols);
 			symbol__delete(al->sym);
 			dso__reset_find_symbol_cache(al->map->dso);
 		}
tools/perf/builtin-report.c +1 -4
index 68ea336bf311..4c931afb2e80 100644
@@ -715,10 +715,7 @@ static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
 
 static int map_groups__fprintf_task(struct map_groups *mg, int indent, FILE *fp)
 {
-	int printed = 0, i;
-	for (i = 0; i < MAP__NR_TYPES; ++i)
-		printed += maps__fprintf_task(&mg->maps[i], indent, fp);
-	return printed;
+	return maps__fprintf_task(&mg->maps, indent, fp);
 }
 
 static void task__print_level(struct task *task, FILE *fp, int level)
tools/perf/tests/hists_common.c +2 -2
index d0366fde72a3..b889a28fd80b 100644
@@ -131,7 +131,7 @@ struct machine *setup_fake_machine(struct machines *machines)
 			goto out;
 
 		/* emulate dso__load() */
-		dso__set_loaded(dso, MAP__FUNCTION);
+		dso__set_loaded(dso);
 
 		for (k = 0; k < fake_symbols[i].nr_syms; k++) {
 			struct symbol *sym;
@@ -144,7 +144,7 @@ struct machine *setup_fake_machine(struct machines *machines)
 				goto out;
 			}
 
-			symbols__insert(&dso->symbols[MAP__FUNCTION], sym);
+			symbols__insert(&dso->symbols, sym);
 		}
 
 		dso__put(dso);
tools/perf/ui/browsers/map.c +1 -1
index e03fa75f108a..5b8b8c637686 100644
@@ -104,7 +104,7 @@ int map__browse(struct map *map)
 {
 	struct map_browser mb = {
 		.b = {
-			.entries = &map->dso->symbols[map->type],
+			.entries = &map->dso->symbols,
 			.refresh = ui_browser__rb_tree_refresh,
 			.seek	 = ui_browser__rb_tree_seek,
 			.write	 = map_browser__write,
tools/perf/util/db-export.c +1 -1
index 12d60703c8fc..7123746edcf4 100644
@@ -249,7 +249,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,
 		if (!al->sym) {
 			al->sym = symbol__new(al->addr, 0, 0, 0, "unknown");
 			if (al->sym)
-				dso__insert_symbol(dso, al->map->type, al->sym);
+				dso__insert_symbol(dso, al->sym);
 		}
 
 		if (al->sym) {
tools/perf/util/dso.c +13 -21
index 36ef45b2e89d..cdfc2e5f55f5 100644
@@ -1014,7 +1014,7 @@ struct map *dso__new_map(const char *name)
 	struct dso *dso = dso__new(name);
 
 	if (dso)
-		map = map__new2(0, dso, MAP__FUNCTION);
+		map = map__new2(0, dso);
 
 	return map;
 }
@@ -1176,19 +1176,19 @@ int dso__name_len(const struct dso *dso)
 	return dso->short_name_len;
 }
 
-bool dso__loaded(const struct dso *dso, enum map_type type)
+bool dso__loaded(const struct dso *dso)
 {
-	return dso->loaded & (1 << type);
+	return dso->loaded;
 }
 
-bool dso__sorted_by_name(const struct dso *dso, enum map_type type)
+bool dso__sorted_by_name(const struct dso *dso)
 {
-	return dso->sorted_by_name & (1 << type);
+	return dso->sorted_by_name;
 }
 
-void dso__set_sorted_by_name(struct dso *dso, enum map_type type)
+void dso__set_sorted_by_name(struct dso *dso)
 {
-	dso->sorted_by_name |= (1 << type);
+	dso->sorted_by_name = true;
 }
 
 struct dso *dso__new(const char *name)
@@ -1196,12 +1196,10 @@ struct dso *dso__new(const char *name)
 	struct dso *dso = calloc(1, sizeof(*dso) + strlen(name) + 1);
 
 	if (dso != NULL) {
-		int i;
 		strcpy(dso->name, name);
 		dso__set_long_name(dso, dso->name, false);
 		dso__set_short_name(dso, dso->name, false);
-		for (i = 0; i < MAP__NR_TYPES; ++i)
-			dso->symbols[i] = dso->symbol_names[i] = RB_ROOT;
+		dso->symbols = dso->symbol_names = RB_ROOT;
 		dso->data.cache = RB_ROOT;
 		dso->inlined_nodes = RB_ROOT;
 		dso->srclines = RB_ROOT;
@@ -1231,8 +1229,6 @@ struct dso *dso__new(const char *name)
 
 void dso__delete(struct dso *dso)
 {
-	int i;
-
 	if (!RB_EMPTY_NODE(&dso->rb_node))
 		pr_err("DSO %s is still in rbtree when being deleted!\n",
 		       dso->long_name);
@@ -1240,8 +1236,7 @@ void dso__delete(struct dso *dso)
 	/* free inlines first, as they reference symbols */
 	inlines__tree_delete(&dso->inlined_nodes);
 	srcline__tree_delete(&dso->srclines);
-	for (i = 0; i < MAP__NR_TYPES; ++i)
-		symbols__delete(&dso->symbols[i]);
+	symbols__delete(&dso->symbols);
 
 	if (dso->short_name_allocated) {
 		zfree((char **)&dso->short_name);
@@ -1451,9 +1446,7 @@ size_t __dsos__fprintf(struct list_head *head, FILE *fp)
 	size_t ret = 0;
 
 	list_for_each_entry(pos, head, node) {
-		int i;
-		for (i = 0; i < MAP__NR_TYPES; ++i)
-			ret += dso__fprintf(pos, i, fp);
+		ret += dso__fprintf(pos, fp);
 	}
 
 	return ret;
@@ -1467,18 +1460,17 @@ size_t dso__fprintf_buildid(struct dso *dso, FILE *fp)
 	return fprintf(fp, "%s", sbuild_id);
 }
 
-size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp)
+size_t dso__fprintf(struct dso *dso, FILE *fp)
 {
 	struct rb_node *nd;
 	size_t ret = fprintf(fp, "dso: %s (", dso->short_name);
 
 	if (dso->short_name != dso->long_name)
 		ret += fprintf(fp, "%s, ", dso->long_name);
-	ret += fprintf(fp, "%s, %sloaded, ", map_type__name[type],
-		       dso__loaded(dso, type) ? "" : "NOT ");
+	ret += fprintf(fp, "%sloaded, ", dso__loaded(dso) ? "" : "NOT ");
 	ret += dso__fprintf_buildid(dso, fp);
 	ret += fprintf(fp, ")\n");
-	for (nd = rb_first(&dso->symbols[type]); nd; nd = rb_next(nd)) {
+	for (nd = rb_first(&dso->symbols); nd; nd = rb_next(nd)) {
 		struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
 		ret += symbol__fprintf(pos, fp);
 	}
tools/perf/util/dso.h +17 -19
index 881d572be6aa..ef69de2e69ea 100644
@@ -140,14 +140,14 @@ struct dso {
 	struct list_head node;
 	struct rb_node	 rb_node;	/* rbtree node sorted by long name */
 	struct rb_root	 *root;		/* root of rbtree that rb_node is in */
-	struct rb_root	 symbols[MAP__NR_TYPES];
-	struct rb_root	 symbol_names[MAP__NR_TYPES];
+	struct rb_root	 symbols;
+	struct rb_root	 symbol_names;
 	struct rb_root	 inlined_nodes;
 	struct rb_root	 srclines;
 	struct {
 		u64		addr;
 		struct symbol	*symbol;
-	} last_find_result[MAP__NR_TYPES];
+	} last_find_result;
 	void		 *a2l;
 	char		 *symsrc_filename;
 	unsigned int	 a2l_fails;
@@ -164,8 +164,8 @@ struct dso {
 	u8		 short_name_allocated:1;
 	u8		 long_name_allocated:1;
 	u8		 is_64_bit:1;
-	u8		 sorted_by_name;
-	u8		 loaded;
+	bool		 sorted_by_name;
+	bool		 loaded;
 	u8		 rel;
 	u8		 build_id[BUILD_ID_SIZE];
 	u64		 text_offset;
@@ -202,14 +202,13 @@ struct dso {
  * @dso: the 'struct dso *' in which symbols itereated
  * @pos: the 'struct symbol *' to use as a loop cursor
  * @n: the 'struct rb_node *' to use as a temporary storage
- * @type: the 'enum map_type' type of symbols
  */
-#define dso__for_each_symbol(dso, pos, n, type)	\
-	symbols__for_each_entry(&(dso)->symbols[(type)], pos, n)
+#define dso__for_each_symbol(dso, pos, n)	\
+	symbols__for_each_entry(&(dso)->symbols, pos, n)
 
-static inline void dso__set_loaded(struct dso *dso, enum map_type type)
+static inline void dso__set_loaded(struct dso *dso)
 {
-	dso->loaded |= (1 << type);
+	dso->loaded = true;
 }
 
 struct dso *dso__new(const char *name);
@@ -231,16 +230,16 @@ static inline void __dso__zput(struct dso **dso)
 
 #define dso__zput(dso) __dso__zput(&dso)
 
-bool dso__loaded(const struct dso *dso, enum map_type type);
+bool dso__loaded(const struct dso *dso);
 
-static inline bool dso__has_symbols(const struct dso *dso, enum map_type type)
+static inline bool dso__has_symbols(const struct dso *dso)
 {
-	return !RB_EMPTY_ROOT(&dso->symbols[type]);
+	return !RB_EMPTY_ROOT(&dso->symbols);
 }
 
-bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
-void dso__set_sorted_by_name(struct dso *dso, enum map_type type);
-void dso__sort_by_name(struct dso *dso, enum map_type type);
+bool dso__sorted_by_name(const struct dso *dso);
+void dso__set_sorted_by_name(struct dso *dso);
+void dso__sort_by_name(struct dso *dso);
 
 void dso__set_build_id(struct dso *dso, void *build_id);
 bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
@@ -354,9 +353,8 @@ size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
 size_t __dsos__fprintf(struct list_head *head, FILE *fp);
 
 size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
-size_t dso__fprintf_symbols_by_name(struct dso *dso,
-				    enum map_type type, FILE *fp);
-size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
+size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
+size_t dso__fprintf(struct dso *dso, FILE *fp);
 
 static inline bool dso__is_vmlinux(struct dso *dso)
 {
tools/perf/util/event.c +3 -10
index 7831c2266118..244135b5ea43 100644
@@ -1488,8 +1488,8 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
 	return machine__process_event(machine, event, sample);
 }
 
-static struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
-				      u64 addr, struct addr_location *al)
+struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
+			     struct addr_location *al)
 {
 	struct map_groups *mg = thread->mg;
 	struct machine *machine = mg->machine;
@@ -1534,7 +1534,7 @@ static struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum ma
 		return NULL;
 	}
 try_again:
-	al->map = __map_groups__find(mg, type, al->addr);
+	al->map = map_groups__find(mg, al->addr);
 	if (al->map == NULL) {
 		/*
 		 * If this is outside of all known maps, and is a negative
@@ -1565,13 +1565,6 @@ static struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum ma
 	return al->map;
 }
 
-struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
-			     struct addr_location *al)
-{
-	struct map *map = __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
-	return map ?: __thread__find_map(thread, cpumode, MAP__VARIABLE, addr, al);
-}
-
 struct symbol *thread__find_symbol(struct thread *thread, u8 cpumode,
 				   u64 addr, struct addr_location *al)
 {
tools/perf/util/machine.c +44 -80

233 lines not on this page · raw message

tools/perf/util/machine.h +9 -23
index ac3b8403df2e..a625a0a6330d 100644
@@ -49,7 +49,7 @@ struct machine {
 	struct perf_env   *env;
 	struct dsos	  dsos;
 	struct map_groups kmaps;
-	struct map	  *vmlinux_maps[MAP__NR_TYPES];
+	struct map	  *vmlinux_map;
 	u64		  kernel_start;
 	pid_t		  *current_tid;
 	union { /* Tool specific area */
@@ -64,19 +64,13 @@ static inline struct threads *machine__threads(struct machine *machine, pid_t ti
 	return &machine->threads[(unsigned int)tid % THREADS__TABLE_SIZE];
 }
 
-static inline
-struct map *__machine__kernel_map(struct machine *machine, enum map_type type)
-{
-	return machine->vmlinux_maps[type];
-}
-
 /*
  * The main kernel (vmlinux) map
  */
 static inline
 struct map *machine__kernel_map(struct machine *machine)
 {
-	return __machine__kernel_map(machine, MAP__FUNCTION);
+	return machine->vmlinux_map;
 }
 
 /*
@@ -85,7 +79,7 @@ struct map *machine__kernel_map(struct machine *machine)
 static inline
 struct maps *machine__kernel_maps(struct machine *machine)
 {
-	return &machine->kmaps.maps[MAP__FUNCTION];
+	return &machine->kmaps.maps;
 }
 
 int machine__get_kernel_start(struct machine *machine);
@@ -202,27 +196,25 @@ struct dso *machine__findnew_dso(struct machine *machine, const char *filename);
 size_t machine__fprintf(struct machine *machine, FILE *fp);
 
 static inline
-struct symbol *machine__find_kernel_symbol(struct machine *machine,
-					   enum map_type type, u64 addr,
+struct symbol *machine__find_kernel_symbol(struct machine *machine, u64 addr,
 					   struct map **mapp)
 {
-	return map_groups__find_symbol(&machine->kmaps, type, addr, mapp);
+	return map_groups__find_symbol(&machine->kmaps, addr, mapp);
 }
 
 static inline
 struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine,
-						   enum map_type type, const char *name,
+						   const char *name,
 						   struct map **mapp)
 {
-	return map_groups__find_symbol_by_name(&machine->kmaps, type, name, mapp);
+	return map_groups__find_symbol_by_name(&machine->kmaps, name, mapp);
 }
 
 static inline
 struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
 					     struct map **mapp)
 {
-	return machine__find_kernel_symbol(machine, MAP__FUNCTION, addr,
-					   mapp);
+	return machine__find_kernel_symbol(machine,  addr, mapp);
 }
 
 static inline
@@ -237,13 +229,7 @@ struct map *machine__findnew_module_map(struct machine *machine, u64 start,
 					const char *filename);
 int arch__fix_module_text_start(u64 *start, const char *name);
 
-int __machine__load_kallsyms(struct machine *machine, const char *filename,
-			     enum map_type type);
-
-static inline int machine__load_kallsyms(struct machine *machine, const char *filename)
-{
-	return __machine__load_kallsyms(machine, filename, MAP__FUNCTION);
-}
+int machine__load_kallsyms(struct machine *machine, const char *filename);
 
 int machine__load_vmlinux_path(struct machine *machine);
 
tools/perf/util/map.c +28 -63

246 lines not on this page · raw message

tools/perf/util/map.h +14 -40

133 lines not on this page · raw message

tools/perf/util/probe-event.c +4 -5
index 50139764c6d7..fefe2fdd1b83 100644
@@ -3503,19 +3503,18 @@ int show_available_funcs(const char *target, struct nsinfo *nsi,
 			       (target) ? : "kernel");
 		goto end;
 	}
-	if (!dso__sorted_by_name(map->dso, map->type))
-		dso__sort_by_name(map->dso, map->type);
+	if (!dso__sorted_by_name(map->dso))
+		dso__sort_by_name(map->dso);
 
 	/* Show all (filtered) symbols */
 	setup_pager();
 
-        for (nd = rb_first(&map->dso->symbol_names[map->type]); nd; nd = rb_next(nd)) {
+	for (nd = rb_first(&map->dso->symbol_names); nd; nd = rb_next(nd)) {
 		struct symbol_name_rb_node *pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 
 		if (strfilter__compare(_filter, pos->sym.name))
 			printf("%s\n", pos->sym.name);
-        }
-
+	}
 end:
 	map__put(map);
 	exit_probe_symbol_maps();
tools/perf/util/session.c +4 -9
index f4a7a437ee87..b998bb475589 100644
@@ -1973,12 +1973,11 @@ bool perf_session__has_traces(struct perf_session *session, const char *msg)
 	return false;
 }
 
-int maps__set_kallsyms_ref_reloc_sym(struct map **maps,
-				     const char *symbol_name, u64 addr)
+int map__set_kallsyms_ref_reloc_sym(struct map *map, const char *symbol_name, u64 addr)
 {
 	char *bracket;
-	int i;
 	struct ref_reloc_sym *ref;
+	struct kmap *kmap;
 
 	ref = zalloc(sizeof(struct ref_reloc_sym));
 	if (ref == NULL)
@@ -1996,13 +1995,9 @@ int maps__set_kallsyms_ref_reloc_sym(struct map **maps,
 
 	ref->addr = addr;
 
-	for (i = 0; i < MAP__NR_TYPES; ++i) {
-		struct kmap *kmap = map__kmap(maps[i]);
-
-		if (!kmap)
-			continue;
+	kmap = map__kmap(map);
+	if (kmap)
 		kmap->ref_reloc_sym = ref;
-	}
 
 	return 0;
 }
tools/perf/util/symbol-elf.c +18 -33

136 lines not on this page · raw message

tools/perf/util/symbol-minimal.c +1 -2
index ff48d0d49584..7119df77dc0b 100644
@@ -288,8 +288,7 @@ void symsrc__destroy(struct symsrc *ss)
 }
 
 int dso__synthesize_plt_symbols(struct dso *dso __maybe_unused,
-				struct symsrc *ss __maybe_unused,
-				struct map *map __maybe_unused)
+				struct symsrc *ss __maybe_unused)
 {
 	return 0;
 }
tools/perf/util/symbol.c +52 -86

349 lines not on this page · raw message

tools/perf/util/symbol.h +5 -11
index 3e2ac485c6d9..1a16438eb3ce 100644
@@ -260,16 +260,11 @@ int __dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
 			 bool no_kcore);
 int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map);
 
-void dso__insert_symbol(struct dso *dso, enum map_type type,
+void dso__insert_symbol(struct dso *dso,
 			struct symbol *sym);
 
-struct symbol *__dso__find_symbol(struct dso *dso, enum map_type type, u64 addr);
-struct symbol *__dso__find_symbol_by_name(struct dso *dso, enum map_type type, const char *name);
-
-static inline struct symbol *dso__find_symbol(struct dso *dso, u64 addr)
-{
-	return __dso__find_symbol(dso, MAP__FUNCTION, addr);
-}
+struct symbol *dso__find_symbol(struct dso *dso, u64 addr);
+struct symbol *dso__find_symbol_by_name(struct dso *dso, const char *name);
 
 struct symbol *symbol__next_by_name(struct symbol *sym);
 
@@ -312,8 +307,7 @@ int symbol__config_symfs(const struct option *opt __maybe_unused,
 
 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 		  struct symsrc *runtime_ss, int kmodule);
-int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
-				struct map *map);
+int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss);
 
 char *dso__demangle_sym(struct dso *dso, int kmodule, const char *elf_name);
 
@@ -321,7 +315,7 @@ void __symbols__insert(struct rb_root *symbols, struct symbol *sym, bool kernel)
 void symbols__insert(struct rb_root *symbols, struct symbol *sym);
 void symbols__fixup_duplicate(struct rb_root *symbols);
 void symbols__fixup_end(struct rb_root *symbols);
-void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
+void map_groups__fixup_end(struct map_groups *mg);
 
 typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data);
 int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
tools/perf/util/symbol_fprintf.c +2 -2
index 6dd2cb88ccbe..ed0205cc7942 100644
@@ -58,13 +58,13 @@ size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
 }
 
 size_t dso__fprintf_symbols_by_name(struct dso *dso,
-				    enum map_type type, FILE *fp)
+				    FILE *fp)
 {
 	size_t ret = 0;
 	struct rb_node *nd;
 	struct symbol_name_rb_node *pos;
 
-	for (nd = rb_first(&dso->symbol_names[type]); nd; nd = rb_next(nd)) {
+	for (nd = rb_first(&dso->symbol_names); nd; nd = rb_next(nd)) {
 		pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 		fprintf(fp, "%s\n", pos->sym.name);
 	}
tools/perf/util/thread.c +12 -18
index ddbf0470b048..2048d393ece6 100644
@@ -302,23 +302,20 @@ int thread__insert_map(struct thread *thread, struct map *map)
 static int __thread__prepare_access(struct thread *thread)
 {
 	bool initialized = false;
-	int i, err = 0;
-
-	for (i = 0; i < MAP__NR_TYPES; ++i) {
-		struct maps *maps = &thread->mg->maps[i];
-		struct map *map;
+	int err = 0;
+	struct maps *maps = &thread->mg->maps;
+	struct map *map;
 
-		down_read(&maps->lock);
+	down_read(&maps->lock);
 
-		for (map = maps__first(maps); map; map = map__next(map)) {
-			err = unwind__prepare_access(thread, map, &initialized);
-			if (err || initialized)
-				break;
-		}
-
-		up_read(&maps->lock);
+	for (map = maps__first(maps); map; map = map__next(map)) {
+		err = unwind__prepare_access(thread, map, &initialized);
+		if (err || initialized)
+			break;
 	}
 
+	up_read(&maps->lock);
+
 	return err;
 }
 
@@ -335,8 +332,6 @@ static int thread__prepare_access(struct thread *thread)
 static int thread__clone_map_groups(struct thread *thread,
 				    struct thread *parent)
 {
-	int i;
-
 	/* This is new thread, we share map groups for process. */
 	if (thread->pid_ == parent->pid_)
 		return thread__prepare_access(thread);
@@ -348,9 +343,8 @@ static int thread__clone_map_groups(struct thread *thread,
 	}
 
 	/* But this one is new process, copy maps. */
-	for (i = 0; i < MAP__NR_TYPES; ++i)
-		if (map_groups__clone(thread, parent->mg, i) < 0)
-			return -ENOMEM;
+	if (map_groups__clone(thread, parent->mg) < 0)
+		return -ENOMEM;
 
 	return 0;
 }
Signature · 1 line
2.14.3
author maintainer
#46 lore raw

PATCH 46/52 perf symbols: Remove needless goto

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

We can plain use the an else to the if block that is right after that goto, so simplify it.

---
 tools/perf/util/symbol-elf.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
tools/perf/util/symbol-elf.c +2 -6
index 5fd81c19eebf..0b230f1a31c4 100644
@@ -1069,12 +1069,8 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 				dso__set_loaded(curr_dso);
 			} else
 				curr_dso = curr_map->dso;
-
-			goto new_symbol;
-		}
-
-		if ((used_opd && runtime_ss->adjust_symbols)
-				|| (!used_opd && syms_ss->adjust_symbols)) {
+		} else if ((used_opd && runtime_ss->adjust_symbols) ||
+			   (!used_opd && syms_ss->adjust_symbols)) {
 			pr_debug4("%s: adjusting symbol: st_value: %#" PRIx64 " "
 				  "sh_addr: %#" PRIx64 " sh_offset: %#" PRIx64 "\n", __func__,
 				  (u64)sym.st_value, (u64)shdr.sh_addr,
Signature · 1 line
2.14.3
author maintainer
#47 lore raw

PATCH 47/52 perf symbols: Split kernel symbol processing from dso__load_sym()

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

More should be done to split this function, removing stuff map relocation steps from the actual symbol table loading.

Arch specific stuff also should go elsewhere, to tools/arch/ and we should have it keyed by data from the perf_env either in the perf.data header or from the running environment.

---
 tools/perf/util/symbol-elf.c | 205 +++++++++++++++++++++++--------------------
 1 file changed, 108 insertions(+), 97 deletions(-)
tools/perf/util/symbol-elf.c +108 -97
index 0b230f1a31c4..48943b834f11 100644
@@ -797,6 +797,110 @@ static u64 ref_reloc(struct kmap *kmap)
 void __weak arch__sym_update(struct symbol *s __maybe_unused,
 		GElf_Sym *sym __maybe_unused) { }
 
+static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
+				      GElf_Sym *sym, GElf_Shdr *shdr,
+				      struct map_groups *kmaps, struct kmap *kmap,
+				      struct dso **curr_dsop, struct map **curr_mapp,
+				      const char *section_name,
+				      bool adjust_kernel_syms, bool kmodule, bool *remap_kernel)
+{
+	struct dso *curr_dso = *curr_dsop;
+	struct map *curr_map;
+	char dso_name[PATH_MAX];
+
+	/* Adjust symbol to map to file offset */
+	if (adjust_kernel_syms)
+		sym->st_value -= shdr->sh_addr - shdr->sh_offset;
+
+	if (strcmp(section_name, (curr_dso->short_name + dso->short_name_len)) == 0)
+		return 0;
+
+	if (strcmp(section_name, ".text") == 0) {
+		/*
+		 * The initial kernel mapping is based on
+		 * kallsyms and identity maps.  Overwrite it to
+		 * map to the kernel dso.
+		 */
+		if (*remap_kernel && dso->kernel) {
+			*remap_kernel = false;
+			map->start = shdr->sh_addr + ref_reloc(kmap);
+			map->end = map->start + shdr->sh_size;
+			map->pgoff = shdr->sh_offset;
+			map->map_ip = map__map_ip;
+			map->unmap_ip = map__unmap_ip;
+			/* Ensure maps are correctly ordered */
+			if (kmaps) {
+				map__get(map);
+				map_groups__remove(kmaps, map);
+				map_groups__insert(kmaps, map);
+				map__put(map);
+			}
+		}
+
+		/*
+		 * The initial module mapping is based on
+		 * /proc/modules mapped to offset zero.
+		 * Overwrite it to map to the module dso.
+		 */
+		if (*remap_kernel && kmodule) {
+			*remap_kernel = false;
+			map->pgoff = shdr->sh_offset;
+		}
+
+		*curr_mapp = map;
+		*curr_dsop = dso;
+		return 0;
+	}
+
+	if (!kmap)
+		return 0;
+
+	snprintf(dso_name, sizeof(dso_name), "%s%s", dso->short_name, section_name);
+
+	curr_map = map_groups__find_by_name(kmaps, dso_name);
+	if (curr_map == NULL) {
+		u64 start = sym->st_value;
+
+		if (kmodule)
+			start += map->start + shdr->sh_offset;
+
+		curr_dso = dso__new(dso_name);
+		if (curr_dso == NULL)
+			return -1;
+		curr_dso->kernel = dso->kernel;
+		curr_dso->long_name = dso->long_name;
+		curr_dso->long_name_len = dso->long_name_len;
+		curr_map = map__new2(start, curr_dso);
+		dso__put(curr_dso);
+		if (curr_map == NULL)
+			return -1;
+
+		if (adjust_kernel_syms) {
+			curr_map->start  = shdr->sh_addr + ref_reloc(kmap);
+			curr_map->end	 = curr_map->start + shdr->sh_size;
+			curr_map->pgoff	 = shdr->sh_offset;
+		} else {
+			curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
+		}
+		curr_dso->symtab_type = dso->symtab_type;
+		map_groups__insert(kmaps, curr_map);
+		/*
+		 * Add it before we drop the referece to curr_map, i.e. while
+		 * we still are sure to have a reference to this DSO via
+		 * *curr_map->dso.
+		 */
+		dsos__add(&map->groups->machine->dsos, curr_dso);
+		/* kmaps already got it */
+		map__put(curr_map);
+		dso__set_loaded(curr_dso);
+		*curr_mapp = curr_map;
+		*curr_dsop = curr_dso;
+	} else
+		*curr_dsop = curr_map->dso;
+
+	return 0;
+}
+
 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 		  struct symsrc *runtime_ss, int kmodule)
 {
@@ -973,102 +1077,9 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 			--sym.st_value;
 
 		if (dso->kernel || kmodule) {
-			char dso_name[PATH_MAX];
-
-			/* Adjust symbol to map to file offset */
-			if (adjust_kernel_syms)
-				sym.st_value -= shdr.sh_addr - shdr.sh_offset;
-
-			if (strcmp(section_name,
-				   (curr_dso->short_name +
-				    dso->short_name_len)) == 0)
-				goto new_symbol;
-
-			if (strcmp(section_name, ".text") == 0) {
-				/*
-				 * The initial kernel mapping is based on
-				 * kallsyms and identity maps.  Overwrite it to
-				 * map to the kernel dso.
-				 */
-				if (remap_kernel && dso->kernel) {
-					remap_kernel = false;
-					map->start = shdr.sh_addr +
-						     ref_reloc(kmap);
-					map->end = map->start + shdr.sh_size;
-					map->pgoff = shdr.sh_offset;
-					map->map_ip = map__map_ip;
-					map->unmap_ip = map__unmap_ip;
-					/* Ensure maps are correctly ordered */
-					if (kmaps) {
-						map__get(map);
-						map_groups__remove(kmaps, map);
-						map_groups__insert(kmaps, map);
-						map__put(map);
-					}
-				}
-
-				/*
-				 * The initial module mapping is based on
-				 * /proc/modules mapped to offset zero.
-				 * Overwrite it to map to the module dso.
-				 */
-				if (remap_kernel && kmodule) {
-					remap_kernel = false;
-					map->pgoff = shdr.sh_offset;
-				}
-
-				curr_map = map;
-				curr_dso = dso;
-				goto new_symbol;
-			}
-
-			if (!kmap)
-				goto new_symbol;
-
-			snprintf(dso_name, sizeof(dso_name),
-				 "%s%s", dso->short_name, section_name);
-
-			curr_map = map_groups__find_by_name(kmaps, dso_name);
-			if (curr_map == NULL) {
-				u64 start = sym.st_value;
-
-				if (kmodule)
-					start += map->start + shdr.sh_offset;
-
-				curr_dso = dso__new(dso_name);
-				if (curr_dso == NULL)
-					goto out_elf_end;
-				curr_dso->kernel = dso->kernel;
-				curr_dso->long_name = dso->long_name;
-				curr_dso->long_name_len = dso->long_name_len;
-				curr_map = map__new2(start, curr_dso);
-				dso__put(curr_dso);
-				if (curr_map == NULL) {
-					goto out_elf_end;
-				}
-				if (adjust_kernel_syms) {
-					curr_map->start = shdr.sh_addr +
-							  ref_reloc(kmap);
-					curr_map->end = curr_map->start +
-							shdr.sh_size;
-					curr_map->pgoff = shdr.sh_offset;
-				} else {
-					curr_map->map_ip = identity__map_ip;
-					curr_map->unmap_ip = identity__map_ip;
-				}
-				curr_dso->symtab_type = dso->symtab_type;
-				map_groups__insert(kmaps, curr_map);
-				/*
-				 * Add it before we drop the referece to curr_map,
-				 * i.e. while we still are sure to have a reference
-				 * to this DSO via curr_map->dso.
-				 */
-				dsos__add(&map->groups->machine->dsos, curr_dso);
-				/* kmaps already got it */
-				map__put(curr_map);
-				dso__set_loaded(curr_dso);
-			} else
-				curr_dso = curr_map->dso;
+			if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &curr_dso, &curr_map,
+						       section_name, adjust_kernel_syms, kmodule, &remap_kernel))
+				goto out_elf_end;
 		} else if ((used_opd && runtime_ss->adjust_symbols) ||
 			   (!used_opd && syms_ss->adjust_symbols)) {
 			pr_debug4("%s: adjusting symbol: st_value: %#" PRIx64 " "
@@ -1077,7 +1088,7 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
 				  (u64)shdr.sh_offset);
 			sym.st_value -= shdr.sh_addr - shdr.sh_offset;
 		}
-new_symbol:
+
 		demangled = demangle_sym(dso, kmodule, elf_name);
 		if (demangled != NULL)
 			elf_name = demangled;
Signature · 1 line
2.14.3
author maintainer
#48 lore raw

PATCH 48/52 perf symbols: Remove unused dso__load_all_kallsyms() 'map' parameter

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Only the 'dso' is needed, so ditch the struct used to pass (map, dso), passing just the used 'dso' pointer.

---
 tools/perf/util/symbol.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
tools/perf/util/symbol.c +5 -12
index efc16a3e0b45..2517f2c2454f 100644
@@ -608,11 +608,6 @@ int modules__parse(const char *filename, void *arg,
 	return err;
 }
 
-struct process_kallsyms_args {
-	struct map *map;
-	struct dso *dso;
-};
-
 /*
  * These are symbols in the kernel image, so make sure that
  * sym is from a kernel DSO.
@@ -648,8 +643,8 @@ static int map__process_kallsym_symbol(void *arg, const char *name,
 				       char type, u64 start)
 {
 	struct symbol *sym;
-	struct process_kallsyms_args *a = arg;
-	struct rb_root *root = &a->dso->symbols;
+	struct dso *dso = arg;
+	struct rb_root *root = &dso->symbols;
 
 	if (!symbol_type__filter(type))
 		return 0;
@@ -676,11 +671,9 @@ static int map__process_kallsym_symbol(void *arg, const char *name,
  * so that we can in the next step set the symbol ->end address and then
  * call kernel_maps__split_kallsyms.
  */
-static int dso__load_all_kallsyms(struct dso *dso, const char *filename,
-				  struct map *map)
+static int dso__load_all_kallsyms(struct dso *dso, const char *filename)
 {
-	struct process_kallsyms_args args = { .map = map, .dso = dso, };
-	return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
+	return kallsyms__parse(filename, dso, map__process_kallsym_symbol);
 }
 
 static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map)
@@ -1300,7 +1293,7 @@ int __dso__load_kallsyms(struct dso *dso, const char *filename,
 	if (symbol__restricted_filename(filename, "/proc/kallsyms"))
 		return -1;
 
-	if (dso__load_all_kallsyms(dso, filename, map) < 0)
+	if (dso__load_all_kallsyms(dso, filename) < 0)
 		return -1;
 
 	if (kallsyms__delta(map, filename, &delta))
Signature · 1 line
2.14.3
author maintainer
#49 lore raw

PATCH 49/52 perf symbols: kallsyms__delta() needs the kmap, not the map

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

It was only using the map to obtain its kmap, so do the validation in its called, __dso__load_kallsyms() and pass the kmap, that will be used in the following patches in similar simplifications.

---
 tools/perf/util/symbol.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/util/symbol.c +6 -6
index 2517f2c2454f..76de63cecf98 100644
@@ -1267,14 +1267,10 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
  * If the kernel is relocated at boot time, kallsyms won't match.  Compute the
  * delta based on the relocation reference symbol.
  */
-static int kallsyms__delta(struct map *map, const char *filename, u64 *delta)
+static int kallsyms__delta(struct kmap *kmap, const char *filename, u64 *delta)
 {
-	struct kmap *kmap = map__kmap(map);
 	u64 addr;
 
-	if (!kmap)
-		return -1;
-
 	if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->name)
 		return 0;
 
@@ -1288,15 +1284,19 @@ static int kallsyms__delta(struct map *map, const char *filename, u64 *delta)
 int __dso__load_kallsyms(struct dso *dso, const char *filename,
 			 struct map *map, bool no_kcore)
 {
+	struct kmap *kmap = map__kmap(map);
 	u64 delta = 0;
 
 	if (symbol__restricted_filename(filename, "/proc/kallsyms"))
 		return -1;
 
+	if (!kmap || !kmap->kmaps)
+		return -1;
+
 	if (dso__load_all_kallsyms(dso, filename) < 0)
 		return -1;
 
-	if (kallsyms__delta(map, filename, &delta))
+	if (kallsyms__delta(kmap, filename, &delta))
 		return -1;
 
 	symbols__fixup_end(&dso->symbols);
Signature · 1 line
2.14.3
author maintainer
#50 lore raw

PATCH 50/52 perf symbols: Move split_kallsyms to struct map_groups

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Since it mainly will populate symtabs of its maps (kernel modules).

While looking at this I wonder if map_groups__split_kallsyms_for_kcore() shouldn't be all that we need, seems much simpler.

---
 tools/perf/util/symbol.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
tools/perf/util/symbol.c +13 -14
index 76de63cecf98..f48dc157c2bd 100644
@@ -676,9 +676,8 @@ static int dso__load_all_kallsyms(struct dso *dso, const char *filename)
 	return kallsyms__parse(filename, dso, map__process_kallsym_symbol);
 }
 
-static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map)
+static int map_groups__split_kallsyms_for_kcore(struct map_groups *kmaps, struct dso *dso)
 {
-	struct map_groups *kmaps = map__kmaps(map);
 	struct map *curr_map;
 	struct symbol *pos;
 	int count = 0;
@@ -728,11 +727,11 @@ static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map)
  * kernel range is broken in several maps, named [kernel].N, as we don't have
  * the original ELF section names vmlinux have.
  */
-static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
+static int map_groups__split_kallsyms(struct map_groups *kmaps, struct dso *dso, u64 delta,
+				      struct map *initial_map)
 {
-	struct map_groups *kmaps = map__kmaps(map);
 	struct machine *machine;
-	struct map *curr_map = map;
+	struct map *curr_map = initial_map;
 	struct symbol *pos;
 	int count = 0, moved = 0;
 	struct rb_root *root = &dso->symbols;
@@ -758,7 +757,7 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
 			*module++ = '\0';
 
 			if (strcmp(curr_map->dso->short_name, module)) {
-				if (curr_map != map &&
+				if (curr_map != initial_map &&
 				    dso->kernel == DSO_TYPE_GUEST_KERNEL &&
 				    machine__is_default_guest(machine)) {
 					/*
@@ -777,7 +776,7 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
 					         "inconsistency while looking "
 						 "for \"%s\" module!\n",
 						 machine->root_dir, module);
-					curr_map = map;
+					curr_map = initial_map;
 					goto discard_symbol;
 				}
 
@@ -787,11 +786,11 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
 			}
 			/*
 			 * So that we look just like we get from .ko files,
-			 * i.e. not prelinked, relative to map->start.
+			 * i.e. not prelinked, relative to initial_map->start.
 			 */
 			pos->start = curr_map->map_ip(curr_map, pos->start);
 			pos->end   = curr_map->map_ip(curr_map, pos->end);
-		} else if (curr_map != map) {
+		} else if (curr_map != initial_map) {
 			char dso_name[PATH_MAX];
 			struct dso *ndso;
 
@@ -802,7 +801,7 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
 			}
 
 			if (count == 0) {
-				curr_map = map;
+				curr_map = initial_map;
 				goto add_symbol;
 			}
 
@@ -836,7 +835,7 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
 			pos->end -= delta;
 		}
 add_symbol:
-		if (curr_map != map) {
+		if (curr_map != initial_map) {
 			rb_erase(&pos->rb_node, root);
 			symbols__insert(&curr_map->dso->symbols, pos);
 			++moved;
@@ -849,7 +848,7 @@ static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
 		symbol__delete(pos);
 	}
 
-	if (curr_map != map &&
+	if (curr_map != initial_map &&
 	    dso->kernel == DSO_TYPE_GUEST_KERNEL &&
 	    machine__is_default_guest(kmaps->machine)) {
 		dso__set_loaded(curr_map->dso);
@@ -1308,9 +1307,9 @@ int __dso__load_kallsyms(struct dso *dso, const char *filename,
 		dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS;
 
 	if (!no_kcore && !dso__load_kcore(dso, map, filename))
-		return dso__split_kallsyms_for_kcore(dso, map);
+		return map_groups__split_kallsyms_for_kcore(kmap->kmaps, dso);
 	else
-		return dso__split_kallsyms(dso, map, delta);
+		return map_groups__split_kallsyms(kmap->kmaps, dso, delta, map);
 }
 
 int dso__load_kallsyms(struct dso *dso, const char *filename,
Signature · 1 line
2.14.3
author maintainer
#51 lore raw

PATCH 51/52 perf tools: Fix spelling mistake: "builid" -> "buildid"

In reply to Arnaldo Carvalho de Melo

From: Colin Ian King <[email protected]>

Trivial fix to spelling mistake in error message text

---
 tools/perf/util/genelf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/genelf.c +1 -1
index c540d47583e7..aafbe54fd3fa 100644
@@ -114,7 +114,7 @@ gen_build_id(struct buildid_note *note,
 
 	fd = open("/dev/urandom", O_RDONLY);
 	if (fd = -1)
-		err(1, "cannot access /dev/urandom for builid");
+		err(1, "cannot access /dev/urandom for buildid");
 
 	sret = read(fd, note->build_id, sz);
 
Signature · 1 line
2.14.3
author maintainer
#52 lore raw

PATCH 52/52 perf machine: Ditch find_kernel_function variants

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Since we do not have split symtabs anymore, no need to have explicit find_kernel_function variants, use the find_kernel_symbol ones.

---
 tools/perf/builtin-kallsyms.c       |  2 +-
 tools/perf/builtin-kmem.c           |  6 +++---
 tools/perf/tests/vmlinux-kallsyms.c |  4 ++--
 tools/perf/util/machine.c           |  2 +-
 tools/perf/util/machine.h           | 15 ---------------
 tools/perf/util/map.h               |  7 -------
 tools/perf/util/probe-event.c       | 15 ++-------------
 7 files changed, 9 insertions(+), 42 deletions(-)
tools/perf/builtin-kallsyms.c +1 -1
index bcfb363112d3..90d1a2305b72 100644
@@ -27,7 +27,7 @@ static int __cmd_kallsyms(int argc, const char **argv)
 
 	for (i = 0; i < argc; ++i) {
 		struct map *map;
-		struct symbol *symbol = machine__find_kernel_function_by_name(machine, argv[i], &map);
+		struct symbol *symbol = machine__find_kernel_symbol_by_name(machine, argv[i], &map);
 
 		if (symbol == NULL) {
 			printf("%s: not found\n", argv[i]);
tools/perf/builtin-kmem.c +3 -3
index ae11e4c3516a..54d3f21b0e62 100644
@@ -1004,7 +1004,7 @@ static void __print_slab_result(struct rb_root *root,
 		if (is_caller) {
 			addr = data->call_site;
 			if (!raw_ip)
-				sym = machine__find_kernel_function(machine, addr, &map);
+				sym = machine__find_kernel_symbol(machine, addr, &map);
 		} else
 			addr = data->ptr;
 
@@ -1068,7 +1068,7 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines)
 		char *caller = buf;
 
 		data = rb_entry(next, struct page_stat, node);
-		sym = machine__find_kernel_function(machine, data->callsite, &map);
+		sym = machine__find_kernel_symbol(machine, data->callsite, &map);
 		if (sym)
 			caller = sym->name;
 		else
@@ -1110,7 +1110,7 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines
 		char *caller = buf;
 
 		data = rb_entry(next, struct page_stat, node);
-		sym = machine__find_kernel_function(machine, data->callsite, &map);
+		sym = machine__find_kernel_symbol(machine, data->callsite, &map);
 		if (sym)
 			caller = sym->name;
 		else
tools/perf/tests/vmlinux-kallsyms.c +2 -2
index 702cea7371ac..7691980b7df1 100644
@@ -118,7 +118,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 		mem_start = vmlinux_map->unmap_ip(vmlinux_map, sym->start);
 		mem_end = vmlinux_map->unmap_ip(vmlinux_map, sym->end);
 
-		first_pair = machine__find_kernel_function(&kallsyms, mem_start, NULL);
+		first_pair = machine__find_kernel_symbol(&kallsyms, mem_start, NULL);
 		pair = first_pair;
 
 		if (pair && UM(pair->start) == mem_start) {
@@ -147,7 +147,7 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 				 */
 				continue;
 			} else {
-				pair = machine__find_kernel_function_by_name(&kallsyms, sym->name, NULL);
+				pair = machine__find_kernel_symbol_by_name(&kallsyms, sym->name, NULL);
 				if (pair) {
 					if (UM(pair->start) == mem_start)
 						goto next_pair;
tools/perf/util/machine.c +1 -1
index b707041f9a22..72a351613d85 100644
@@ -2327,7 +2327,7 @@ char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, ch
 {
 	struct machine *machine = vmachine;
 	struct map *map;
-	struct symbol *sym = machine__find_kernel_function(machine, *addrp, &map);
+	struct symbol *sym = machine__find_kernel_symbol(machine, *addrp, &map);
 
 	if (sym == NULL)
 		return NULL;
tools/perf/util/machine.h +0 -15
index a625a0a6330d..388fb4741c54 100644
@@ -210,21 +210,6 @@ struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine,
 	return map_groups__find_symbol_by_name(&machine->kmaps, name, mapp);
 }
 
-static inline
-struct symbol *machine__find_kernel_function(struct machine *machine, u64 addr,
-					     struct map **mapp)
-{
-	return machine__find_kernel_symbol(machine,  addr, mapp);
-}
-
-static inline
-struct symbol *machine__find_kernel_function_by_name(struct machine *machine,
-						     const char *name,
-						     struct map **mapp)
-{
-	return map_groups__find_function_by_name(&machine->kmaps, name, mapp);
-}
-
 struct map *machine__findnew_module_map(struct machine *machine, u64 start,
 					const char *filename);
 int arch__fix_module_text_start(u64 *start, const char *name);
tools/perf/util/map.h +0 -7
index 6eaa9f19dd47..f1afe1ab6ff7 100644
@@ -225,13 +225,6 @@ struct addr_map_symbol;
 
 int map_groups__find_ams(struct addr_map_symbol *ams);
 
-static inline
-struct symbol *map_groups__find_function_by_name(struct map_groups *mg,
-						 const char *name, struct map **mapp)
-{
-	return map_groups__find_symbol_by_name(mg, name, mapp);
-}
-
 int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map,
 				   FILE *fp);
 
tools/perf/util/probe-event.c +2 -13
index fefe2fdd1b83..3094f11e7d81 100644
@@ -111,17 +111,6 @@ void exit_probe_symbol_maps(void)
 	symbol__exit();
 }
 
-static struct symbol *__find_kernel_function_by_name(const char *name,
-						     struct map **mapp)
-{
-	return machine__find_kernel_function_by_name(host_machine, name, mapp);
-}
-
-static struct symbol *__find_kernel_function(u64 addr, struct map **mapp)
-{
-	return machine__find_kernel_function(host_machine, addr, mapp);
-}
-
 static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void)
 {
 	/* kmap->ref_reloc_sym should be set if host_machine is initialized */
@@ -149,7 +138,7 @@ static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
 	if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
 		*addr = (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr;
 	else {
-		sym = __find_kernel_function_by_name(name, &map);
+		sym = machine__find_kernel_symbol_by_name(host_machine, name, &map);
 		if (!sym)
 			return -ENOENT;
 		*addr = map->unmap_ip(map, sym->start) -
@@ -2097,7 +2086,7 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
 		}
 		if (addr) {
 			addr += tp->offset;
-			sym = __find_kernel_function(addr, &map);
+			sym = machine__find_kernel_symbol(host_machine, addr, &map);
 		}
 	}
 
Signature · 1 line
2.14.3