Skip to contentSkip to conversation

perf/core improvements and fixes

GIT PULL In review Arnaldo Carvalho de Melo 4 participants 18 messages May 16, 2018 – May 18, 2018

Subsystems (3)
lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

Hi Ingo,

Please consider pulling, more to come as I go thru Adrian's x86
PTI series and the C++ support improvements to 'perf probe', from Holger,

Best Regards,

- Arnaldo

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

The following changes since commit 291c161f6c65530092903fbea58eb07a62b220ba:

Merge remote-tracking branch 'tip/perf/urgent' into perf/core (2018-05-15 10:30:17 -0300)

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-20180516

for you to fetch changes up to 7a36a287de9fbb1ba906e70573d3f2315f7fd609:

perf bpf: Fix NULL return handling in bpf__prepare_load() (2018-05-16 10:01:55 -0300)

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

- Add '-e intel_pt//u' test to the 'parse-events' 'perf test' entry, to help avoiding regressions in the events parser such as one that caused a revert in v4.17-rc (Arnaldo Carvalho de Melo)

- Fix NULL return handling in bpf__prepare_load() (YueHaibing)

- Warn about 'perf buildid-cache --purge-all' failures (Ravi Bangoria)

- Add infrastructure to help in writing eBPF C programs to be used with '-e name.c' type events in tools such as 'record' and 'trace', with headers for common constructs and an examples directory that will get populated as we add more such helpers and the 'perf bpf' branch that Jiri Olsa has been working on (Arnaldo Carvalho de Melo)

- Handle uncore event aliases in small groups properly (Kan Liang)

- Use the "_stest" symbol to identify the kernel map when loading kcore (Adrian Hunter)

----------------------------------------------------------------
Adrian Hunter (1):
perf tools: Use the "_stest" symbol to identify the kernel map when loading kcore

Arnaldo Carvalho de Melo (7):
perf tests parse-events: Add intel_pt parse test perf llvm-utils: Add bpf include path to clang command line perf bpf: Add 'examples' directories
perf bpf: Add bpf.h to be used in eBPF proggies perf bpf: Add kprobe example to catch 5s naps perf bpf: Add license(NAME) helper
perf bpf: Add probe() helper to reduce kprobes boilerplate

Kan Liang (1):
perf parse-events: Handle uncore event aliases in small groups properly

Ravi Bangoria (1):

      perf buildid-cache: Warn --purge-all failures

YueHaibing (1):
perf bpf: Fix NULL return handling in bpf__prepare_load()

 tools/perf/Makefile.config         |  14 ++++
 tools/perf/Makefile.perf           |   8 +++
 tools/perf/builtin-buildid-cache.c |   8 ++-
 tools/perf/examples/bpf/5sec.c     |  49 ++++++++++++++
 tools/perf/examples/bpf/empty.c    |   3 +
 tools/perf/include/bpf/bpf.h       |  13 ++++
 tools/perf/tests/parse-events.c    |  13 ++++
 tools/perf/util/Build              |   2 +
 tools/perf/util/bpf-loader.c       |   6 +-
 tools/perf/util/evsel.h            |   1 +
 tools/perf/util/llvm-utils.c       |  19 ++++--
 tools/perf/util/parse-events.c     | 130 ++++++++++++++++++++++++++++++++++++-
 tools/perf/util/parse-events.h     |   7 +-
 tools/perf/util/parse-events.y     |   8 +--
 tools/perf/util/symbol.c           |  16 ++---
 15 files changed, 270 insertions(+), 27 deletions(-)
 create mode 100644 tools/perf/examples/bpf/5sec.c
 create mode 100644 tools/perf/examples/bpf/empty.c
 create mode 100644 tools/perf/include/bpf/bpf.h

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.

  # dm
   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-28)
   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-18) 7.3.0
  17 debian:experimental-x-arm64   : Ok   aarch64-linux-gnu-gcc (Debian 7.3.0-18) 7.3.0
  18 debian:experimental-x-mips    : Ok   mips-linux-gnu-gcc (Debian 7.3.0-18) 7.3.0
  19 debian:experimental-x-mips64  : Ok   mips64-linux-gnuabi64-gcc (Debian 7.3.0-18) 7.3.0
  20 debian:experimental-x-mipsel  : Ok   mipsel-linux-gnu-gcc (Debian 7.3.0-18) 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.1.1 20180502 (Red Hat 8.1.1-1)
  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.0.7)
  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.5-2017.10) 5.5.0
  44 ubuntu:16.04                  : Ok   gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  45 ubuntu:16.04-x-arm            : Ok   arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  46 ubuntu:16.04-x-arm64          : Ok   aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  47 ubuntu:16.04-x-powerpc        : Ok   powerpc-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  48 ubuntu:16.04-x-powerpc64      : Ok   powerpc64-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  49 ubuntu:16.04-x-powerpc64el    : Ok   powerpc64le-linux-gnu-gcc (Ubuntu/IBM 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  50 ubuntu:16.04-x-s390           : Ok   s390x-linux-gnu-gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
  51 ubuntu:16.10                  : Ok   gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
  52 ubuntu:17.04                  : Ok   gcc (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
  53 ubuntu:17.10                  : Ok   gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0
  54 ubuntu:18.04                  : Ok   gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0
  #
  # uname -a
  Linux jouet 4.17.0-rc5 #21 SMP Mon May 14 15:35:35 -03 2018 x86_64 x86_64 x86_64 GNU/Linux
  # 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: 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_with_babeltrace_O: make LIBBABELTRACE=1
                 make_static_O: make LDFLAGS=-static
                   make_tags_O: make tags
                make_install_O: make install
                    make_doc_O: make doc
              make_no_libelf_O: make NO_LIBELF=1
              make_no_libbpf_O: make NO_LIBBPF=1
            make_no_demangle_O: make NO_DEMANGLE=1
              make_clean_all_O: make clean all
               make_no_slang_O: make NO_SLANG=1
             make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
         make_with_clangllvm_O: make LIBCLANGLLVM=1
                make_no_newt_O: make NO_NEWT=1
             make_no_libnuma_O: make NO_LIBNUMA=1
  make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
           make_no_libbionic_O: make NO_LIBBIONIC=1
             make_no_libperl_O: make NO_LIBPERL=1
           make_no_libpython_O: make NO_LIBPYTHON=1
           make_no_libunwind_O: make NO_LIBUNWIND=1
           make_no_backtrace_O: make NO_BACKTRACE=1
   make_install_prefix_slash_O: make install prefix=/tmp/krava/
                  make_debug_O: make DEBUG=1
             make_util_map_o_O: make util/map.o
                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_install_prefix_O: make install prefix=/tmp/krava
                   make_pure_O: make
                 make_perf_o_O: make perf.o
                   make_help_O: make help
                make_no_gtk2_O: make NO_GTK2=1
            make_no_libaudit_O: make NO_LIBAUDIT=1
       make_util_pmu_bison_o_O: make util/pmu-bison.o
                  make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
            make_install_bin_O: make install-bin
            make_no_auxtrace_O: make NO_AUXTRACE=1
  OK
  make: Leaving directory '/home/acme/git/perf/tools/perf'
  $ 
author maintainer
#1 lore raw

PATCH 1/11 perf tests parse-events: Add intel_pt parse test

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

To avoid regressions such as the one fixed by 4a35a9027f64 ("Revert "perf pmu: Fix pmu events parsing rule""), where '-e intel_pt//u' got broken, with this new entry in this 'perf tests' subtest, we would have caught it before pushing upstream.

---
 tools/perf/tests/parse-events.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/perf/tests/parse-events.c +13 -0
index 18b06444f230..6829dd416a99 100644
@@ -1309,6 +1309,14 @@ static int test__checkevent_config_cache(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__intel_pt(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "intel_pt//u") == 0);
+	return 0;
+}
+
 static int count_tracepoints(void)
 {
 	struct dirent *events_ent;
@@ -1637,6 +1645,11 @@ static struct evlist_test test__events[] = {
 		.check = test__checkevent_config_cache,
 		.id    = 51,
 	},
+	{
+		.name  = "intel_pt//u",
+		.check = test__intel_pt,
+		.id    = 52,
+	},
 };
 
 static struct evlist_test test__events_pmu[] = {
Signature · 1 line
2.14.3
#2 lore raw

Re: [PATCH 01/11] perf tests parse-events: Add intel_pt parse test

Quoted 19 lines · On Wed, 16 May 2018 11:48:58 -0300 Arnaldo Carvalho de Melo <[email protected]>…

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

To avoid regressions such as the one fixed by 4a35a9027f64 ("Revert "perf pmu: Fix pmu events parsing rule""), where '-e intel_pt//u' got broken, with this new entry in this 'perf tests' subtest, we would have caught it before pushing upstream.

Quoted 1 line

---

This causes a SEGV on Arm, and an Intel box without Intel-PT h/w:

(gdb) run test -F -v 6
Starting program: /home/kimphi01/git/linux-perf-acme/tools/perf/perf test -F -v 6 [Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
6: Parse event definition strings :
--- start ---
running test 0 'syscalls:sys_enter_openat'
Using CPUID GenuineIntel-6-3C
<SNIP>
running test 51 'L1-dcache-misses/name=cachepmu/'
running test 52 'intel_pt//u'

Program received signal SIGSEGV, Segmentation fault.
__GI___vasprintf_chk (result_ptr=0x8, flags=1, format=<optimized out>, args=args@entry=0x7fffffffbf30)
at vasprintf_chk.c:88
88 vasprintf_chk.c: No such file or directory.
(gdb) bt
#0 __GI___vasprintf_chk (result_ptr=0x8, flags=1, format=<optimized out>, args=args@entry=0x7fffffffbf30)
at vasprintf_chk.c:88
#1 0x00007ffff6456e6f in __asprintf_chk (result_ptr=result_ptr@entry=0x8, flags=flags@entry=1,

    format=format@entry=0x555555992e80 "Cannot find PMU `%s'. Missing kernel support?") at asprintf_chk.c:32
#2  0x0000555555766836 in asprintf (__fmt=0x555555992e80 "Cannot find PMU `%s'. Missing kernel support?", __ptr=0x8)
    at /usr/include/x86_64-linux-gnu/bits/stdio2.h:178

#3 parse_events_add_pmu (parse_state=parse_state@entry=0x7fffffffdda0, list=list@entry=0x555555e137d0,
name=0x5555563e84e0 "intel_pt", head_config=0x0, auto_merge_stats=auto_merge_stats@entry=false, use_alias=use_alias@entry=false) at util/parse-events.c:1236
#4 0x00005555557aaaae in parse_events_parse (_parse_state=_parse_state@entry=0x7fffffffdda0, scanner=0x555555d38c40)

    at util/parse-events.y:235
#5  0x0000555555761ccf in parse_events__scanner (start_token=258, parse_state=0x7fffffffdda0, str=<optimized out>)
    at util/parse-events.c:1796
#6  parse_events (evlist=evlist@entry=0x555555d381f0, str=<optimized out>, err=err@entry=0x0)
    at util/parse-events.c:1836
#7  0x000055555571eb65 in test_event (e=0x555555bf4f80 <test.events+1248>, e=0x555555bf4f80 <test.events+1248>)
    at tests/parse-events.c:1695

#8 test_events (events=0x555555bf4aa0 <test.events>, cnt=53) at tests/parse-events.c:1717
#9 test__parse_events (test=<optimized out>, subtest=<optimized out>) at tests/parse-events.c:1837 #10 0x0000555555716a11 in run_test (subtest=-1, test=0x555555bfca78 <generic_tests+280>) at tests/builtin-test.c:348 #11 test_and_print (t=t@entry=0x555555bfca78 <generic_tests+280>, force_skip=force_skip@entry=false,
subtest=subtest@entry=-1) at tests/builtin-test.c:378
#12 0x0000555555717e2f in __cmd_test (skiplist=0x0, argv=0x7fffffffe5c0, argc=1) at tests/builtin-test.c:570 #13 cmd_test (argc=1, argv=0x7fffffffe5c0) at tests/builtin-test.c:709
#14 0x0000555555738b41 in run_builtin (p=0x555555bfd848 <commands+552>, argc=4, argv=0x7fffffffe5c0) at perf.c:303 #15 0x0000555555738e3e in handle_internal_command (argc=4, argv=0x7fffffffe5c0) at perf.c:355
#16 0x00005555556b3901 in run_argv (argcp=<synthetic pointer>, argv=<synthetic pointer>) at perf.c:399 #17 main (argc=<optimized out>, argv=0x7fffffffe5c0) at perf.c:543
(gdb)

Thanks,

Kim

author maintainer
#3 lore raw

Re: [PATCH 01/11] perf tests parse-events: Add intel_pt parse test

Em Wed, May 16, 2018 at 04:33:55PM -0500, Kim Phillips escreveu:

Quoted 46 lines
Quoted 19 lines · On Wed, 16 May 2018 11:48:58 -0300 Arnaldo Carvalho de Melo <[email protected]>…

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

To avoid regressions such as the one fixed by 4a35a9027f64 ("Revert "perf pmu: Fix pmu events parsing rule""), where '-e intel_pt//u' got broken, with this new entry in this 'perf tests' subtest, we would have caught it before pushing upstream.

Quoted 1 line

---

This causes a SEGV on Arm, and an Intel box without Intel-PT h/w:

(gdb) run test -F -v 6
Starting program: /home/kimphi01/git/linux-perf-acme/tools/perf/perf test -F -v 6 [Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
6: Parse event definition strings :
--- start ---
running test 0 'syscalls:sys_enter_openat'
Using CPUID GenuineIntel-6-3C
<SNIP>
running test 51 'L1-dcache-misses/name=cachepmu/'
running test 52 'intel_pt//u'

Program received signal SIGSEGV, Segmentation fault.
__GI___vasprintf_chk (result_ptr=0x8, flags=1, format=<optimized out>, args=args@entry=0x7fffffffbf30)
at vasprintf_chk.c:88
88 vasprintf_chk.c: No such file or directory.
(gdb) bt
#0 __GI___vasprintf_chk (result_ptr=0x8, flags=1, format=<optimized out>, args=args@entry=0x7fffffffbf30)
at vasprintf_chk.c:88
#1 0x00007ffff6456e6f in __asprintf_chk (result_ptr=result_ptr@entry=0x8, flags=flags@entry=1,

Quoted 6 lines
    format=format@entry=0x555555992e80 "Cannot find PMU `%s'. Missing kernel support?") at asprintf_chk.c:32
#2  0x0000555555766836 in asprintf (__fmt=0x555555992e80 "Cannot find PMU `%s'. Missing kernel support?", __ptr=0x8)
    at /usr/include/x86_64-linux-gnu/bits/stdio2.h:178

#3 parse_events_add_pmu (parse_state=parse_state@entry=0x7fffffffdda0, list=list@entry=0x555555e137d0,
name=0x5555563e84e0 "intel_pt", head_config=0x0, auto_merge_stats=auto_merge_stats@entry=false, use_alias=use_alias@entry=false) at util/parse-events.c:1236

Humm:

        struct parse_events_error *err = parse_state->error;

        pmu = perf_pmu__find(name);
        if (!pmu) {
                if (asprintf(&err->str,
                                "Cannot find PMU `%s'. Missing kernel support?",
                                name) < 0)
$ pahole -C parse_events_error ~/bin/perf
struct parse_events_error {
	int                        idx;                  /*     0     4 */
	/* XXX 4 bytes hole, try to pack */

	char *                     str;                  /*     8     8 */
	char *                     help;                 /*    16     8 */

	/* size: 24, cachelines: 1, members: 3 */
	/* sum members: 20, holes: 1, sum holes: 4 */
	/* last cacheline: 24 bytes */
};

$

So parse_state->error == NULL, Jiri, ideas?

- Arnaldo

Quoted 24 lines

#4 0x00005555557aaaae in parse_events_parse (_parse_state=_parse_state@entry=0x7fffffffdda0, scanner=0x555555d38c40)

    at util/parse-events.y:235
#5  0x0000555555761ccf in parse_events__scanner (start_token=258, parse_state=0x7fffffffdda0, str=<optimized out>)
    at util/parse-events.c:1796
#6  parse_events (evlist=evlist@entry=0x555555d381f0, str=<optimized out>, err=err@entry=0x0)
    at util/parse-events.c:1836
#7  0x000055555571eb65 in test_event (e=0x555555bf4f80 <test.events+1248>, e=0x555555bf4f80 <test.events+1248>)
    at tests/parse-events.c:1695

#8 test_events (events=0x555555bf4aa0 <test.events>, cnt=53) at tests/parse-events.c:1717
#9 test__parse_events (test=<optimized out>, subtest=<optimized out>) at tests/parse-events.c:1837 #10 0x0000555555716a11 in run_test (subtest=-1, test=0x555555bfca78 <generic_tests+280>) at tests/builtin-test.c:348 #11 test_and_print (t=t@entry=0x555555bfca78 <generic_tests+280>, force_skip=force_skip@entry=false,
subtest=subtest@entry=-1) at tests/builtin-test.c:378
#12 0x0000555555717e2f in __cmd_test (skiplist=0x0, argv=0x7fffffffe5c0, argc=1) at tests/builtin-test.c:570 #13 cmd_test (argc=1, argv=0x7fffffffe5c0) at tests/builtin-test.c:709
#14 0x0000555555738b41 in run_builtin (p=0x555555bfd848 <commands+552>, argc=4, argv=0x7fffffffe5c0) at perf.c:303 #15 0x0000555555738e3e in handle_internal_command (argc=4, argv=0x7fffffffe5c0) at perf.c:355
#16 0x00005555556b3901 in run_argv (argcp=<synthetic pointer>, argv=<synthetic pointer>) at perf.c:399 #17 main (argc=<optimized out>, argv=0x7fffffffe5c0) at perf.c:543
(gdb)

Thanks,

Kim

#4 lore raw

Re: [PATCH 01/11] perf tests parse-events: Add intel_pt parse test

Quoted 78 lines · Arnaldo Carvalho de Melo

Em Wed, May 16, 2018 at 04:33:55PM -0500, Kim Phillips escreveu:

Quoted 46 lines
Quoted 19 lines · On Wed, 16 May 2018 11:48:58 -0300 Arnaldo Carvalho de Melo <[email protected]>…

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

To avoid regressions such as the one fixed by 4a35a9027f64 ("Revert "perf pmu: Fix pmu events parsing rule""), where '-e intel_pt//u' got broken, with this new entry in this 'perf tests' subtest, we would have caught it before pushing upstream.

Quoted 1 line

---

This causes a SEGV on Arm, and an Intel box without Intel-PT h/w:

(gdb) run test -F -v 6
Starting program: /home/kimphi01/git/linux-perf-acme/tools/perf/perf test -F -v 6 [Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
6: Parse event definition strings :
--- start ---
running test 0 'syscalls:sys_enter_openat'
Using CPUID GenuineIntel-6-3C
<SNIP>
running test 51 'L1-dcache-misses/name=cachepmu/'
running test 52 'intel_pt//u'

Program received signal SIGSEGV, Segmentation fault.
__GI___vasprintf_chk (result_ptr=0x8, flags=1, format=<optimized out>, args=args@entry=0x7fffffffbf30)
at vasprintf_chk.c:88
88 vasprintf_chk.c: No such file or directory.
(gdb) bt
#0 __GI___vasprintf_chk (result_ptr=0x8, flags=1, format=<optimized out>, args=args@entry=0x7fffffffbf30)
at vasprintf_chk.c:88
#1 0x00007ffff6456e6f in __asprintf_chk (result_ptr=result_ptr@entry=0x8, flags=flags@entry=1,

Quoted 6 lines
    format=format@entry=0x555555992e80 "Cannot find PMU `%s'. Missing kernel support?") at asprintf_chk.c:32
#2  0x0000555555766836 in asprintf (__fmt=0x555555992e80 "Cannot find PMU `%s'. Missing kernel support?", __ptr=0x8)
    at /usr/include/x86_64-linux-gnu/bits/stdio2.h:178

#3 parse_events_add_pmu (parse_state=parse_state@entry=0x7fffffffdda0, list=list@entry=0x555555e137d0,
name=0x5555563e84e0 "intel_pt", head_config=0x0, auto_merge_stats=auto_merge_stats@entry=false, use_alias=use_alias@entry=false) at util/parse-events.c:1236

Humm:

        struct parse_events_error *err = parse_state->error;

        pmu = perf_pmu__find(name);
        if (!pmu) {
                if (asprintf(&err->str,
                                "Cannot find PMU `%s'. Missing kernel support?",
                                name) < 0)
$ pahole -C parse_events_error ~/bin/perf
struct parse_events_error {
	int                        idx;                  /*     0     4 */
	/* XXX 4 bytes hole, try to pack */

	char *                     str;                  /*     8     8 */
	char *                     help;                 /*    16     8 */

	/* size: 24, cachelines: 1, members: 3 */
	/* sum members: 20, holes: 1, sum holes: 4 */
	/* last cacheline: 24 bytes */
};
Quoted 3 lines

$

So parse_state->error == NULL, Jiri, ideas?

yep, we don't use it in tests.. and when trying intel_pt on system without that pmu, the parse_events_add_pmu fails and store the error to NULL.. we should check on that err pointer

wrt to the test itself, how about we add callback to check if the test is valid before we run it, something like below
jirka

---

tools/perf/tests/parse-events.c +19 -5
index 6829dd416a99..8efefead2c04 100644
@@ -1309,6 +1309,11 @@ static int test__checkevent_config_cache(struct perf_evlist *evlist)
 	return 0;
 }
 
+static bool test__intel_pt_valid(void)
+{
+	return !!perf_pmu__find("intel_pt");
+}
+
 static int test__intel_pt(struct perf_evlist *evlist)
 {
 	struct perf_evsel *evsel = perf_evlist__first(evlist);
@@ -1374,6 +1379,7 @@ struct evlist_test {
 	const char *name;
 	__u32 type;
 	const int id;
+	bool (*valid)(void);
 	int (*check)(struct perf_evlist *evlist);
 };
 
@@ -1647,6 +1653,7 @@ static struct evlist_test test__events[] = {
 	},
 	{
 		.name  = "intel_pt//u",
+		.valid = test__intel_pt_valid,
 		.check = test__intel_pt,
 		.id    = 52,
 	},
@@ -1685,17 +1692,23 @@ static struct terms_test test__terms[] = {
 
 static int test_event(struct evlist_test *e)
 {
+	struct parse_events_error err;
 	struct perf_evlist *evlist;
 	int ret;
 
+	if (e->valid && !e->valid()) {
+		pr_debug("... SKIP");
+		return 0;
+	}
+
 	evlist = perf_evlist__new();
 	if (evlist == NULL)
 		return -ENOMEM;
 
-	ret = parse_events(evlist, e->name, NULL);
+	ret = parse_events(evlist, e->name, &err);
 	if (ret) {
-		pr_debug("failed to parse event '%s', err %d\n",
-			 e->name, ret);
+		pr_debug("failed to parse event '%s', err %d, str '%s'\n",
+			 e->name, ret, err.str);
 	} else {
 		ret = e->check(evlist);
 	}
@@ -1713,10 +1726,11 @@ static int test_events(struct evlist_test *events, unsigned cnt)
 	for (i = 0; i < cnt; i++) {
 		struct evlist_test *e = &events[i];
 
-		pr_debug("running test %d '%s'\n", e->id, e->name);
+		pr_debug("running test %d '%s'", e->id, e->name);
 		ret1 = test_event(e);
 		if (ret1)
 			ret2 = ret1;
+		pr_debug("\n");
 	}
 
 	return ret2;
@@ -1798,7 +1812,7 @@ static int test_pmu_events(void)
 	}
 
 	while (!ret && (ent = readdir(dir))) {
-		struct evlist_test e;
+		struct evlist_test e = { };
 		char name[2 * NAME_MAX + 1 + 12 + 3];
 
 		/* Names containing . are special and cannot be used directly */
Tested-by
#5 lore raw

Re: [PATCH 01/11] perf tests parse-events: Add intel_pt parse test

Quoted 11 lines · On Thu, 17 May 2018 22:58:11 +0200 Jiri Olsa <[email protected]> wrote:
Quoted 1 line · Arnaldo Carvalho de Melo

So parse_state->error == NULL, Jiri, ideas?

yep, we don't use it in tests.. and when trying intel_pt on system without that pmu, the parse_events_add_pmu fails and store the error to NULL.. we should check on that err pointer

wrt to the test itself, how about we add callback to check if the test is valid before we run it, something like below
jirka

That diff makes this test pass again on x86 without an intel_pt, and on Arm32/64 (the intel_pt test gets skipped on those machines):

Thanks,

Kim

author maintainer
#6 lore raw

Re: [PATCH 01/11] perf tests parse-events: Add intel_pt parse test

Em Thu, May 17, 2018 at 05:54:10PM -0500, Kim Phillips escreveu:

Quoted 6 lines
Quoted 3 lines · On Thu, 17 May 2018 22:58:11 +0200 Jiri Olsa <[email protected]> wrote:
Quoted 1 line · Arnaldo Carvalho de Melo

So parse_state->error == NULL, Jiri, ideas?

Quoted 7 lines
Quoted 7 lines

yep, we don't use it in tests.. and when trying intel_pt on system without that pmu, the parse_events_add_pmu fails and store the error to NULL.. we should check on that err pointer

wrt to the test itself, how about we add callback to check if the test is valid before we run it, something like below

As Kim says, that is ok, but then, I think that the test would better reflect reality if it tested all the error paths, i.e. if it, in the face of a missing PMU, would fill in the error structs, that would then be checked for validity, etc.

So if instead of checking if the intel_pt PMU is present to perform the test it would run the test, with te error struct passed as expected, then, when it fails, check that the failure indicates that indeed, that PMU is not there by checking that routine you used to bypass the test, huh?

Thanks,

- Arnaldo

Quoted 10 lines
Quoted 1 line

jirka

That diff makes this test pass again on x86 without an intel_pt, and on Arm32/64 (the intel_pt test gets skipped on those machines):

Thanks,

Kim

author maintainer
#7 lore raw

PATCH 2/11 perf buildid-cache: Warn --purge-all failures

In reply to Arnaldo Carvalho de Melo

From: Ravi Bangoria <[email protected]>

Warn perf buildid-cache --purge-all failures in non verbose mode.

Ex.:

  $ sudo chown root:root /home/ravi/.debug -R
  $ sudo chmod 700 /home/ravi/.debug/ -R
  $ ./perf buildid-cache -P
    Couldn't remove some caches. Error: Permission denied.
---
 tools/perf/builtin-buildid-cache.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/builtin-buildid-cache.c +6 -2
index 7a7403913b57..115110a4796a 100644
@@ -488,8 +488,12 @@ int cmd_buildid_cache(int argc, const char **argv)
 		}
 	}
 
-	if (purge_all)
-		ret = build_id_cache__purge_all();
+	if (purge_all) {
+		if (build_id_cache__purge_all()) {
+			pr_warning("Couldn't remove some caches. Error: %s.\n",
+				str_error_r(errno, sbuf, sizeof(sbuf)));
+		}
+	}
 
 	if (missing_filename)
 		ret = build_id_cache__fprintf_missing(session, stdout);
Signature · 1 line
2.14.3
author maintainer
#8 lore raw

PATCH 3/11 perf llvm-utils: Add bpf include path to clang command line

In reply to Arnaldo Carvalho de Melo

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

We'll start putting headers for helpers to be used in eBPF proggies in there:

  # perf trace -v --no-syscalls -e empty.c |& grep "llvm compiling command : "
  llvm compiling command : /usr/lib64/ccache/clang -D__KERNEL__ -D__NR_CPUS__=4 -DLINUX_VERSION_CODE=0x41100   -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h  -I/home/acme/lib/include/perf/bpf -Wno-unused-value -Wno-pointer-sign -working-directory /lib/modules/4.17.0-rc3-00034-gf4ef6a438cee/build -c /home/acme/bpf/empty.c -target bpf -O2 -o -
  #

Notice the "-I/home/acme/lib/include/perf/bpf"

---
 tools/perf/Makefile.config   |  7 +++++++
 tools/perf/Makefile.perf     |  4 ++++
 tools/perf/util/Build        |  2 ++
 tools/perf/util/llvm-utils.c | 19 ++++++++++++++-----
 4 files changed, 27 insertions(+), 5 deletions(-)
tools/perf/Makefile.config +7 -0
index ae7dc46e8f8a..3bca9a733f0e 100644
@@ -885,6 +885,7 @@ endif
 
 # Among the variables below, these:
 #   perfexecdir
+#   perf_include_dir
 #   template_dir
 #   mandir
 #   infodir
@@ -904,6 +905,7 @@ bindir = $(abspath $(prefix)/$(bindir_relative))
 mandir = share/man
 infodir = share/info
 perfexecdir = libexec/perf-core
+perf_include_dir = lib/include/perf
 sharedir = $(prefix)/share
 template_dir = share/perf-core/templates
 STRACE_GROUPS_DIR = share/perf-core/strace/groups
@@ -934,6 +936,7 @@ bindir_SQ = $(subst ','\'',$(bindir))
 mandir_SQ = $(subst ','\'',$(mandir))
 infodir_SQ = $(subst ','\'',$(infodir))
 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
+perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 htmldir_SQ = $(subst ','\'',$(htmldir))
 tipdir_SQ = $(subst ','\'',$(tipdir))
@@ -944,14 +947,17 @@ srcdir_SQ = $(subst ','\'',$(srcdir))
 
 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
 perfexec_instdir = $(perfexecdir)
+perf_include_instdir = $(perf_include_dir)
 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
 tip_instdir = $(tipdir)
 else
 perfexec_instdir = $(prefix)/$(perfexecdir)
+perf_include_instdir = $(prefix)/$(perf_include_dir)
 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
 tip_instdir = $(prefix)/$(tipdir)
 endif
 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
+perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
 
@@ -999,6 +1005,7 @@ $(call detected_var,ETC_PERFCONFIG_SQ)
 $(call detected_var,STRACE_GROUPS_DIR_SQ)
 $(call detected_var,prefix_SQ)
 $(call detected_var,perfexecdir_SQ)
+$(call detected_var,perf_include_dir_SQ)
 $(call detected_var,tipdir_SQ)
 $(call detected_var,srcdir_SQ)
 $(call detected_var,LIBDIR)
tools/perf/Makefile.perf +4 -0
index 83e453de36f8..d9663b1cf43e 100644
@@ -767,6 +767,10 @@ ifndef NO_JVMTI
 endif
 	$(call QUIET_INSTALL, libexec) \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
+ifndef NO_LIBBPF
+	$(call QUIET_INSTALL, lib) \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
+endif
 	$(call QUIET_INSTALL, perf-archive) \
 		$(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
 	$(call QUIET_INSTALL, perf-with-kcore) \
tools/perf/util/Build +2 -0
index 8052373bcd6a..5d4c45b76895 100644
@@ -152,6 +152,8 @@ libperf-y += perf-hooks.o
 libperf-$(CONFIG_CXX) += c++/
 
 CFLAGS_config.o   += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
+CFLAGS_llvm-utils.o += -DPERF_INCLUDE_DIR="BUILD_STR($(perf_include_dir_SQ))"
+
 # avoid compiler warnings in 32-bit mode
 CFLAGS_genelf_debug.o  += -Wno-packed
 
tools/perf/util/llvm-utils.c +14 -5
index 1cca0a2fa641..976e658e38dc 100644
@@ -14,11 +14,12 @@
 #include "config.h"
 #include "util.h"
 #include <sys/wait.h>
+#include <subcmd/exec-cmd.h>
 
 #define CLANG_BPF_CMD_DEFAULT_TEMPLATE				\
 		"$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
 		"-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE "	\
-		"$CLANG_OPTIONS $KERNEL_INC_OPTIONS "		\
+		"$CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS " \
 		"-Wno-unused-value -Wno-pointer-sign "		\
 		"-working-directory $WORKING_DIR "		\
 		"-c \"$CLANG_SOURCE\" -target bpf -O2 -o -"
@@ -212,7 +213,7 @@ version_notice(void)
 "     \t\thttp://llvm.org/apt\n\n"
 "     \tIf you are using old version of clang, change 'clang-bpf-cmd-template'\n"
 "     \toption in [llvm] section of ~/.perfconfig to:\n\n"
-"     \t  \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS \\\n"
+"     \t  \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS \\\n"
 "     \t     -working-directory $WORKING_DIR -c $CLANG_SOURCE \\\n"
 "     \t     -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -\"\n"
 "     \t(Replace /path/to/llc with path to your llc)\n\n"
@@ -431,9 +432,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 	const char *clang_opt = llvm_param.clang_opt;
 	char clang_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64];
 	char serr[STRERR_BUFSIZE];
-	char *kbuild_dir = NULL, *kbuild_include_opts = NULL;
+	char *kbuild_dir = NULL, *kbuild_include_opts = NULL,
+	     *perf_bpf_include_opts = NULL;
 	const char *template = llvm_param.clang_bpf_cmd_template;
-	char *command_echo, *command_out;
+	char *command_echo = NULL, *command_out;
+	char *perf_include_dir = system_path(PERF_INCLUDE_DIR);
 
 	if (path[0] != '-' && realpath(path, abspath) == NULL) {
 		err = errno;
@@ -471,12 +474,14 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 
 	snprintf(linux_version_code_str, sizeof(linux_version_code_str),
 		 "0x%x", kernel_version);
-
+	if (asprintf(&perf_bpf_include_opts, "-I%s/bpf", perf_include_dir) < 0)
+		goto errout;
 	force_set_env("NR_CPUS", nr_cpus_avail_str);
 	force_set_env("LINUX_VERSION_CODE", linux_version_code_str);
 	force_set_env("CLANG_EXEC", clang_path);
 	force_set_env("CLANG_OPTIONS", clang_opt);
 	force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);
+	force_set_env("PERF_BPF_INC_OPTIONS", perf_bpf_include_opts);
 	force_set_env("WORKING_DIR", kbuild_dir ? : ".");
 
 	/*
@@ -512,6 +517,8 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 	free(command_out);
 	free(kbuild_dir);
 	free(kbuild_include_opts);
+	free(perf_bpf_include_opts);
+	free(perf_include_dir);
 
 	if (!p_obj_buf)
 		free(obj_buf);
@@ -526,6 +533,8 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 	free(kbuild_dir);
 	free(kbuild_include_opts);
 	free(obj_buf);
+	free(perf_bpf_include_opts);
+	free(perf_include_dir);
 	if (p_obj_buf)
 		*p_obj_buf = NULL;
 	if (p_obj_buf_sz)
Signature · 1 line
2.14.3
author maintainer
#9 lore raw

PATCH 4/11 perf bpf: Add 'examples' directories

In reply to Arnaldo Carvalho de Melo

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

The first one is the bare minimum that bpf infrastructure accepts before it expects actual events to be set up:

  $ cat tools/perf/examples/bpf/empty.c
  char _license[] __attribute__((section("license"), used)) = "GPL";
  int _version __attribute__((section("version"), used)) = LINUX_VERSION_CODE;
  $

If you remove that "version" line, then it will be refused with:

  # perf trace -e tools/perf/examples/bpf/empty.c
  event syntax error: 'tools/perf/examples/bpf/empty.c'
                       \___ Failed to load tools/perf/examples/bpf/empty.c from source: 'version' section incorrect or lost

(add -v to see detail)
Run 'perf list' for a list of valid events

Usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]

-e, --event <event> event/syscall selector. use 'perf list' to list available events
#

The next ones will, step by step, show simple filters, then the needs for headers will be made clear, it will be put in place and tested with new examples, rinse, repeat.

Back to using this first one to test the perf+bpf infrastructure:

If we run it will fail, as no functions are present connecting with, say, a tracepoint or a function using the kprobes or uprobes infrastructure:

  # perf trace -e tools/perf/examples/bpf/empty.c
  WARNING: event parser found nothing
  invalid or unsupported event: 'tools/perf/examples/bpf/empty.c'
  Run 'perf list' for a list of valid events

Usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]

-e, --event <event> event/syscall selector. use 'perf list' to list available events
#

But, if we set things up to dump the generated object file to a file, and do this after having run 'make install', still on the developer's $HOME directory:

  # cat ~/.perfconfig
  [llvm]

dump-obj = true
#

  # perf trace -e ~acme/lib/examples/perf/bpf/empty.c
  LLVM: dumping /home/acme/lib/examples/perf/bpf/empty.o
  WARNING: event parser found nothing
  invalid or unsupported event: '/home/acme/lib/examples/perf/bpf/empty.c'
  <SNIP>
  #

We can look at the dumped object file:

  # ls -la ~acme/lib/examples/perf/bpf/empty.o
  -rw-r--r--. 1 root root 576 May  4 12:10 /home/acme/lib/examples/perf/bpf/empty.o
  # file ~acme/lib/examples/perf/bpf/empty.o
  /home/acme/lib/examples/perf/bpf/empty.o: ELF 64-bit LSB relocatable, *unknown arch 0xf7* version 1 (SYSV), not stripped
  # readelf -sw ~acme/lib/examples/perf/bpf/empty.o

Symbol table '.symtab' contains 3 entries:

     Num:    Value          Size Type    Bind   Vis      Ndx Name
       0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
       1: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    3 _license
       2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    4 _version
  #
  # tools/bpf/bpftool/bpftool --pretty ~acme/lib/examples/perf/bpf/empty.o
  null
  #
---
 tools/perf/Makefile.config      | 7 +++++++
 tools/perf/Makefile.perf        | 3 +++
 tools/perf/examples/bpf/empty.c | 2 ++
 3 files changed, 12 insertions(+)
 create mode 100644 tools/perf/examples/bpf/empty.c
tools/perf/Makefile.config +7 -0
index 3bca9a733f0e..b5ac356ba323 100644
@@ -886,6 +886,7 @@ endif
 # Among the variables below, these:
 #   perfexecdir
 #   perf_include_dir
+#   perf_examples_dir
 #   template_dir
 #   mandir
 #   infodir
@@ -906,6 +907,7 @@ mandir = share/man
 infodir = share/info
 perfexecdir = libexec/perf-core
 perf_include_dir = lib/include/perf
+perf_examples_dir = lib/examples/perf
 sharedir = $(prefix)/share
 template_dir = share/perf-core/templates
 STRACE_GROUPS_DIR = share/perf-core/strace/groups
@@ -937,6 +939,7 @@ mandir_SQ = $(subst ','\'',$(mandir))
 infodir_SQ = $(subst ','\'',$(infodir))
 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
 perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
+perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 htmldir_SQ = $(subst ','\'',$(htmldir))
 tipdir_SQ = $(subst ','\'',$(tipdir))
@@ -948,16 +951,19 @@ srcdir_SQ = $(subst ','\'',$(srcdir))
 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
 perfexec_instdir = $(perfexecdir)
 perf_include_instdir = $(perf_include_dir)
+perf_examples_instdir = $(perf_examples_dir)
 STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
 tip_instdir = $(tipdir)
 else
 perfexec_instdir = $(prefix)/$(perfexecdir)
 perf_include_instdir = $(prefix)/$(perf_include_dir)
+perf_examples_instdir = $(prefix)/$(perf_examples_dir)
 STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
 tip_instdir = $(prefix)/$(tipdir)
 endif
 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
 perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
+perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
 STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
 tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
 
@@ -1006,6 +1012,7 @@ $(call detected_var,STRACE_GROUPS_DIR_SQ)
 $(call detected_var,prefix_SQ)
 $(call detected_var,perfexecdir_SQ)
 $(call detected_var,perf_include_dir_SQ)
+$(call detected_var,perf_examples_dir_SQ)
 $(call detected_var,tipdir_SQ)
 $(call detected_var,srcdir_SQ)
 $(call detected_var,LIBDIR)
tools/perf/Makefile.perf +3 -0
index d9663b1cf43e..9343b7d945bb 100644
@@ -770,6 +770,9 @@ endif
 ifndef NO_LIBBPF
 	$(call QUIET_INSTALL, lib) \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
+	$(call QUIET_INSTALL, lib) \
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
+		$(INSTALL) examples/bpf/*.c '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
 endif
 	$(call QUIET_INSTALL, perf-archive) \
 		$(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
tools/perf/examples/bpf/empty.c new file +2 -0
new file mode 100644
index 000000000000..78754df53ac1
@@ -0,0 +1,2 @@
+char _license[] __attribute__((section("license"), used)) = "GPL";
+int _version __attribute__((section("version"), used)) = LINUX_VERSION_CODE;
Signature · 1 line
2.14.3
author maintainer
#10 lore raw

PATCH 5/11 perf bpf: Add bpf.h to be used in eBPF proggies

In reply to Arnaldo Carvalho de Melo

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

So, the first helper is the one shortening a variable/function section attribute, from, for instance:

  char _license[] __attribute__((section("license"), used)) = "GPL";

to:

  char _license[] SEC("license") = "GPL";

Convert empty.c to that and it becomes:

  # cat ~acme/lib/examples/perf/bpf/empty.c
  #include <bpf.h>
  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  #
---
 tools/perf/Makefile.perf        | 1 +
 tools/perf/examples/bpf/empty.c | 6 ++++--
 tools/perf/include/bpf/bpf.h    | 5 +++++
 3 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 tools/perf/include/bpf/bpf.h
tools/perf/Makefile.perf +1 -0
index 9343b7d945bb..c63a3971d719 100644
@@ -770,6 +770,7 @@ endif
 ifndef NO_LIBBPF
 	$(call QUIET_INSTALL, lib) \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
+		$(INSTALL) include/bpf/*.h '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
 	$(call QUIET_INSTALL, lib) \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
 		$(INSTALL) examples/bpf/*.c '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
tools/perf/examples/bpf/empty.c +4 -2
index 78754df53ac1..86f97763355d 100644
@@ -1,2 +1,4 @@
-char _license[] __attribute__((section("license"), used)) = "GPL";
-int _version __attribute__((section("version"), used)) = LINUX_VERSION_CODE;
+#include <bpf.h>
+
+char _license[] SEC("license") = "GPL";
+int _version SEC("version") = LINUX_VERSION_CODE;
tools/perf/include/bpf/bpf.h new file +5 -0
new file mode 100644
index 000000000000..003afcab4e51
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef _PERF_BPF_H
+#define _PERF_BPF_H
+#define SEC(NAME) __attribute__((section(NAME),  used))
+#endif /* _PERF_BPF_H */
Signature · 1 line
2.14.3
author maintainer
#11 lore raw

PATCH 6/11 perf bpf: Add kprobe example to catch 5s naps

In reply to Arnaldo Carvalho de Melo

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

Description:

. Disable strace like syscall tracing (--no-syscalls), or try tracing
just some (-e *sleep).

. Attach a filter function to a kernel function, returning when it should
be considered, i.e. appear on the output:

  $ cat tools/perf/examples/bpf/5sec.c
  #include <bpf.h>

SEC("func=hrtimer_nanosleep rqtp->tv_sec")
int func(void *ctx, int err, long sec)

  {
	  return sec == 5;

}

  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  $

. Run it system wide, so that any sleep of >= 5 seconds and < than 6
seconds gets caught.

. Ask for callgraphs using DWARF info, so that userspace can be unwound

. While this is running, run something like "sleep 5s".

  # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c/call-graph=dwarf/
     0.000 perf_bpf_probe:func:(ffffffff9811b5f0) tv_sec=5
                                       hrtimer_nanosleep ([kernel.kallsyms])
                                       __x64_sys_nanosleep ([kernel.kallsyms])
                                       do_syscall_64 ([kernel.kallsyms])
                                       entry_SYSCALL_64 ([kernel.kallsyms])
                                       __GI___nanosleep (/usr/lib64/libc-2.26.so)
                                       rpl_nanosleep (/usr/bin/sleep)
                                       xnanosleep (/usr/bin/sleep)
                                       main (/usr/bin/sleep)
                                       __libc_start_main (/usr/lib64/libc-2.26.so)
                                       _start (/usr/bin/sleep)
  ^C#
---
 tools/perf/examples/bpf/5sec.c | 44 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 tools/perf/examples/bpf/5sec.c
tools/perf/examples/bpf/5sec.c new file +44 -0
new file mode 100644
index 000000000000..3d1ed34aec8b
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+    Description:
+
+    . Disable strace like syscall tracing (--no-syscalls), or try tracing
+      just some (-e *sleep).
+
+    . Attach a filter function to a kernel function, returning when it should
+      be considered, i.e. appear on the output.
+
+    . Run it system wide, so that any sleep of >= 5 seconds and < than 6
+      seconds gets caught.
+
+    . Ask for callgraphs using DWARF info, so that userspace can be unwound
+
+    . While this is running, run something like "sleep 5s".
+
+    # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c/call-graph=dwarf/
+         0.000 perf_bpf_probe:func:(ffffffff9811b5f0) tv_sec=5
+                                           hrtimer_nanosleep ([kernel.kallsyms])
+                                           __x64_sys_nanosleep ([kernel.kallsyms])
+                                           do_syscall_64 ([kernel.kallsyms])
+                                           entry_SYSCALL_64 ([kernel.kallsyms])
+                                           __GI___nanosleep (/usr/lib64/libc-2.26.so)
+                                           rpl_nanosleep (/usr/bin/sleep)
+                                           xnanosleep (/usr/bin/sleep)
+                                           main (/usr/bin/sleep)
+                                           __libc_start_main (/usr/lib64/libc-2.26.so)
+                                           _start (/usr/bin/sleep)
+    ^C#
+
+   Copyright (C) 2018 Red Hat, Inc., Arnaldo Carvalho de Melo <[email protected]>
+*/
+
+#include <bpf.h>
+
+SEC("func=hrtimer_nanosleep rqtp->tv_sec")
+int func(void *ctx, int err, long sec)
+{
+	return sec == 5;
+}
+
+char _license[] SEC("license") = "GPL";
+int _version SEC("version") = LINUX_VERSION_CODE;
Signature · 1 line
2.14.3
author maintainer
#12 lore raw

PATCH 7/11 perf bpf: Add license(NAME) helper

In reply to Arnaldo Carvalho de Melo

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

To further reduce boilerplate.

---
 tools/perf/examples/bpf/5sec.c  | 3 +--
 tools/perf/examples/bpf/empty.c | 3 +--
 tools/perf/include/bpf/bpf.h    | 5 +++++
 3 files changed, 7 insertions(+), 4 deletions(-)
tools/perf/examples/bpf/5sec.c +1 -2
index 3d1ed34aec8b..6fc3697ac749 100644
@@ -40,5 +40,4 @@ int func(void *ctx, int err, long sec)
 	return sec == 5;
 }
 
-char _license[] SEC("license") = "GPL";
-int _version SEC("version") = LINUX_VERSION_CODE;
+license(GPL);
tools/perf/examples/bpf/empty.c +1 -2
index 86f97763355d..3776d26db9e7 100644
@@ -1,4 +1,3 @@
 #include <bpf.h>
 
-char _license[] SEC("license") = "GPL";
-int _version SEC("version") = LINUX_VERSION_CODE;
+license(GPL);
tools/perf/include/bpf/bpf.h +5 -0
index 003afcab4e51..cdfd18b9c318 100644
@@ -2,4 +2,9 @@
 #ifndef _PERF_BPF_H
 #define _PERF_BPF_H
 #define SEC(NAME) __attribute__((section(NAME),  used))
+
+#define license(name) \
+char _license[] SEC("license") = #name; \
+int _version SEC("version") = LINUX_VERSION_CODE;
+
 #endif /* _PERF_BPF_H */
Signature · 1 line
2.14.3
author maintainer
#13 lore raw

PATCH 8/11 perf bpf: Add probe() helper to reduce kprobes boilerplate

In reply to Arnaldo Carvalho de Melo

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

So that kprobe definitions become:

int probe(function, variables)(void *ctx, int err, var1, var2, ...)

The existing 5sec.c, got converted and goes from:

  SEC("func=hrtimer_nanosleep rqtp->tv_sec")
  int func(void *ctx, int err, long sec)
  {
  }

To:

  int probe(hrtimer_nanosleep, rqtp->tv_sec)(void *ctx, int err, long sec)
  {
  }

If we decide to add tv_nsec as well, then it becomes:

  $ cat tools/perf/examples/bpf/5sec.c
  #include <bpf.h>

int probe(hrtimer_nanosleep, rqtp->tv_sec rqtp->tv_nsec)(void *ctx, int err, long sec, long nsec)

  {
	  return sec == 5;

}

  license(GPL);
  $

And if we run it, system wide as before and run some 'sleep' with values for the tv_nsec field, we get:

  # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c
     0.000 perf_bpf_probe:hrtimer_nanosleep:(ffffffff9811b5f0) tv_sec=5 tv_nsec=100000000
  9641.650 perf_bpf_probe:hrtimer_nanosleep:(ffffffff9811b5f0) tv_sec=5 tv_nsec=123450001
  ^C#
---
 tools/perf/examples/bpf/5sec.c | 10 ++++++++--
 tools/perf/include/bpf/bpf.h   |  3 +++
 2 files changed, 11 insertions(+), 2 deletions(-)
tools/perf/examples/bpf/5sec.c +8 -2
index 6fc3697ac749..b9c203219691 100644
@@ -15,6 +15,13 @@
 
     . While this is running, run something like "sleep 5s".
 
+    . If we decide to add tv_nsec as well, then it becomes:
+
+      int probe(hrtimer_nanosleep, rqtp->tv_sec rqtp->tv_nsec)(void *ctx, int err, long sec, long nsec)
+
+      I.e. add where it comes from (rqtp->tv_nsec) and where it will be
+      accessible in the function body (nsec)
+
     # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c/call-graph=dwarf/
          0.000 perf_bpf_probe:func:(ffffffff9811b5f0) tv_sec=5
                                            hrtimer_nanosleep ([kernel.kallsyms])
@@ -34,8 +41,7 @@
 
 #include <bpf.h>
 
-SEC("func=hrtimer_nanosleep rqtp->tv_sec")
-int func(void *ctx, int err, long sec)
+int probe(hrtimer_nanosleep, rqtp->tv_sec)(void *ctx, int err, long sec)
 {
 	return sec == 5;
 }
tools/perf/include/bpf/bpf.h +3 -0
index cdfd18b9c318..dd764ad5efdf 100644
@@ -3,6 +3,9 @@
 #define _PERF_BPF_H
 #define SEC(NAME) __attribute__((section(NAME),  used))
 
+#define probe(function, vars) \
+	SEC(#function "=" #function " " #vars) function
+
 #define license(name) \
 char _license[] SEC("license") = #name; \
 int _version SEC("version") = LINUX_VERSION_CODE;
Signature · 1 line
2.14.3
author maintainer
#14 lore raw

PATCH 9/11 perf tools: Use the "_stest" symbol to identify the kernel map when loading kcore

In reply to Arnaldo Carvalho de Melo

From: Adrian Hunter <[email protected]>

The first symbol is not necessarily in the kernel text. Instead of using the first symbol, use the _stest symbol to identify the kernel map when loading kcore.

This allows for the introduction of symbols to identify the x86_64 PTI entry trampolines.

Cc Alexander Shishkin <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Dave Hansen <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Joerg Roedel <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 tools/perf/util/symbol.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
tools/perf/util/symbol.c +8 -8
index f48dc157c2bd..4a39f4d0a174 100644
@@ -1149,7 +1149,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	bool is_64_bit;
 	int err, fd;
 	char kcore_filename[PATH_MAX];
-	struct symbol *sym;
+	u64 stext;
 
 	if (!kmaps)
 		return -EINVAL;
@@ -1198,13 +1198,13 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 		old_map = next;
 	}
 
-	/* Find the kernel map using the first symbol */
-	sym = dso__first_symbol(dso);
-	list_for_each_entry(new_map, &md.maps, node) {
-		if (sym && sym->start >= new_map->start &&
-		    sym->start < new_map->end) {
-			replacement_map = new_map;
-			break;
+	/* Find the kernel map using the '_stext' symbol */
+	if (!kallsyms__get_function_start(kallsyms_filename, "_stext", &stext)) {
+		list_for_each_entry(new_map, &md.maps, node) {
+			if (stext >= new_map->start && stext < new_map->end) {
+				replacement_map = new_map;
+				break;
+			}
 		}
 	}
 
Signature · 1 line
2.14.3
author maintainer
#15 lore raw

PATCH 10/11 perf parse-events: Handle uncore event aliases in small groups properly

In reply to Arnaldo Carvalho de Melo

From: Kan Liang <[email protected]>

Perf stat doesn't count the uncore event aliases from the same uncore block in a group, for example:

perf stat -e '{unc_m_cas_count.all,unc_m_clockticks}' -a -I 1000
# time counts unit events

       1.000447342      <not counted>      unc_m_cas_count.all
       1.000447342      <not counted>      unc_m_clockticks
       2.000740654      <not counted>      unc_m_cas_count.all
       2.000740654      <not counted>      unc_m_clockticks

The output is very misleading. It gives a wrong impression that the uncore event doesn't work.

An uncore block could be composed by several PMUs. An uncore event alias is a joint name which means the same event runs on all PMUs of a block. Perf doesn't support mixed events from different PMUs in the same group. It is wrong to put uncore event aliases in a big group.

The right way is to split the big group into multiple small groups which only include the events from the same PMU.

Only uncore event aliases from the same uncore block should be specially handled here. It doesn't make sense to mix the uncore events with other uncore events from different blocks or even core events in a group.

With the patch:
# time counts unit events

     1.001557653            140,833      unc_m_cas_count.all
     1.001557653      1,330,231,332      unc_m_clockticks
     2.002709483             85,007      unc_m_cas_count.all
     2.002709483      1,429,494,563      unc_m_clockticks
---
 tools/perf/util/evsel.h        |   1 +
 tools/perf/util/parse-events.c | 130 ++++++++++++++++++++++++++++++++++++++++-
 tools/perf/util/parse-events.h |   7 ++-
 tools/perf/util/parse-events.y |   8 +--
 4 files changed, 137 insertions(+), 9 deletions(-)
tools/perf/util/evsel.h +1 -0
index 92ec009a292d..b13f5f234c8f 100644
@@ -127,6 +127,7 @@ struct perf_evsel {
 	bool			precise_max;
 	bool			ignore_missing_thread;
 	bool			forced_leader;
+	bool			use_uncore_alias;
 	/* parse modifier helper */
 	int			exclude_GH;
 	int			nr_members;
tools/perf/util/parse-events.c +127 -3

177 lines not on this page · raw message

tools/perf/util/parse-events.h +5 -2
index 5015cfd58277..4473dac27aee 100644
@@ -167,7 +167,9 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,
 				void *ptr, char *type, u64 len);
 int parse_events_add_pmu(struct parse_events_state *parse_state,
 			 struct list_head *list, char *name,
-			 struct list_head *head_config, bool auto_merge_stats);
+			 struct list_head *head_config,
+			 bool auto_merge_stats,
+			 bool use_alias);
 
 int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
 			       char *str,
@@ -178,7 +180,8 @@ int parse_events_copy_term_list(struct list_head *old,
 
 enum perf_pmu_event_symbol_type
 perf_pmu__parse_check(const char *name);
-void parse_events__set_leader(char *name, struct list_head *list);
+void parse_events__set_leader(char *name, struct list_head *list,
+			      struct parse_events_state *parse_state);
 void parse_events_update_lists(struct list_head *list_event,
 			       struct list_head *list_all);
 void parse_events_evlist_error(struct parse_events_state *parse_state,
tools/perf/util/parse-events.y +4 -4
index 7afeb80cc39e..e37608a87dba 100644
@@ -161,7 +161,7 @@ PE_NAME '{' events '}'
 	struct list_head *list = $3;
 
 	inc_group_count(list, _parse_state);
-	parse_events__set_leader($1, list);
+	parse_events__set_leader($1, list, _parse_state);
 	$$ = list;
 }
 |
@@ -170,7 +170,7 @@ PE_NAME '{' events '}'
 	struct list_head *list = $2;
 
 	inc_group_count(list, _parse_state);
-	parse_events__set_leader(NULL, list);
+	parse_events__set_leader(NULL, list, _parse_state);
 	$$ = list;
 }
 
@@ -232,7 +232,7 @@ PE_NAME opt_event_config
 		YYABORT;
 
 	ALLOC_LIST(list);
-	if (parse_events_add_pmu(_parse_state, list, $1, $2, false)) {
+	if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
 		struct perf_pmu *pmu = NULL;
 		int ok = 0;
 		char *pattern;
@@ -251,7 +251,7 @@ PE_NAME opt_event_config
 					free(pattern);
 					YYABORT;
 				}
-				if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true))
+				if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
 					ok++;
 				parse_events_terms__delete(terms);
 			}
Signature · 1 line
2.14.3
author maintainer
#16 lore raw

PATCH 11/11 perf bpf: Fix NULL return handling in bpf__prepare_load()

In reply to Arnaldo Carvalho de Melo

From: YueHaibing <[email protected]>

bpf_object__open()/bpf_object__open_buffer can return error pointer or NULL, check the return values with IS_ERR_OR_NULL() in bpf__prepare_load and bpf__prepare_load_buffer

---
 tools/perf/util/bpf-loader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/bpf-loader.c +3 -3
index af7ad814b2c3..cee658733e2c 100644
@@ -66,7 +66,7 @@ bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name)
 	}
 
 	obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name);
-	if (IS_ERR(obj)) {
+	if (IS_ERR_OR_NULL(obj)) {
 		pr_debug("bpf: failed to load buffer\n");
 		return ERR_PTR(-EINVAL);
 	}
@@ -102,14 +102,14 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
 			pr_debug("bpf: successfull builtin compilation\n");
 		obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename);
 
-		if (!IS_ERR(obj) && llvm_param.dump_obj)
+		if (!IS_ERR_OR_NULL(obj) && llvm_param.dump_obj)
 			llvm__dump_obj(filename, obj_buf, obj_buf_sz);
 
 		free(obj_buf);
 	} else
 		obj = bpf_object__open(filename);
 
-	if (IS_ERR(obj)) {
+	if (IS_ERR_OR_NULL(obj)) {
 		pr_debug("bpf: failed to load %s\n", filename);
 		return obj;
 	}
Signature · 1 line
2.14.3
#17 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 80 lines · Arnaldo Carvalho de Melo

Hi Ingo,

Please consider pulling, more to come as I go thru Adrian's x86
PTI series and the C++ support improvements to 'perf probe', from Holger,

Best Regards,

- Arnaldo

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

The following changes since commit 291c161f6c65530092903fbea58eb07a62b220ba:

Merge remote-tracking branch 'tip/perf/urgent' into perf/core (2018-05-15 10:30:17 -0300)

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-20180516

for you to fetch changes up to 7a36a287de9fbb1ba906e70573d3f2315f7fd609:

perf bpf: Fix NULL return handling in bpf__prepare_load() (2018-05-16 10:01:55 -0300)

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

- Add '-e intel_pt//u' test to the 'parse-events' 'perf test' entry, to help avoiding regressions in the events parser such as one that caused a revert in v4.17-rc (Arnaldo Carvalho de Melo)

- Fix NULL return handling in bpf__prepare_load() (YueHaibing)

- Warn about 'perf buildid-cache --purge-all' failures (Ravi Bangoria)

- Add infrastructure to help in writing eBPF C programs to be used with '-e name.c' type events in tools such as 'record' and 'trace', with headers for common constructs and an examples directory that will get populated as we add more such helpers and the 'perf bpf' branch that Jiri Olsa has been working on (Arnaldo Carvalho de Melo)

- Handle uncore event aliases in small groups properly (Kan Liang)

- Use the "_stest" symbol to identify the kernel map when loading kcore (Adrian Hunter)

----------------------------------------------------------------
Adrian Hunter (1):
perf tools: Use the "_stest" symbol to identify the kernel map when loading kcore

Arnaldo Carvalho de Melo (7):
perf tests parse-events: Add intel_pt parse test perf llvm-utils: Add bpf include path to clang command line perf bpf: Add 'examples' directories
perf bpf: Add bpf.h to be used in eBPF proggies perf bpf: Add kprobe example to catch 5s naps perf bpf: Add license(NAME) helper
perf bpf: Add probe() helper to reduce kprobes boilerplate

Kan Liang (1):
perf parse-events: Handle uncore event aliases in small groups properly

Ravi Bangoria (1):

      perf buildid-cache: Warn --purge-all failures

YueHaibing (1):
perf bpf: Fix NULL return handling in bpf__prepare_load()

 tools/perf/Makefile.config         |  14 ++++
 tools/perf/Makefile.perf           |   8 +++
 tools/perf/builtin-buildid-cache.c |   8 ++-
 tools/perf/examples/bpf/5sec.c     |  49 ++++++++++++++
 tools/perf/examples/bpf/empty.c    |   3 +
 tools/perf/include/bpf/bpf.h       |  13 ++++
 tools/perf/tests/parse-events.c    |  13 ++++
 tools/perf/util/Build              |   2 +
 tools/perf/util/bpf-loader.c       |   6 +-
 tools/perf/util/evsel.h            |   1 +
 tools/perf/util/llvm-utils.c       |  19 ++++--
Quoted 8 lines
 tools/perf/util/parse-events.c     | 130 ++++++++++++++++++++++++++++++++++++-
 tools/perf/util/parse-events.h     |   7 +-
 tools/perf/util/parse-events.y     |   8 +--
 tools/perf/util/symbol.c           |  16 ++---
 15 files changed, 270 insertions(+), 27 deletions(-)
 create mode 100644 tools/perf/examples/bpf/5sec.c
 create mode 100644 tools/perf/examples/bpf/empty.c
 create mode 100644 tools/perf/include/bpf/bpf.h

Pulled, thanks a lot Arnaldo!

Ingo