1. 22 11月, 2018 1 次提交
    • A
      tools build feature: Check if eventfd() is available · 11c6cbe7
      Arnaldo Carvalho de Melo 提交于
      A new 'perf bench epoll' will use this, and to disable it for older
      systems, add a feature test for this API.
      
      This is just a simple program that if successfully compiled, means that
      the feature is present, at least at the library level, in a build that
      sets the output directory to /tmp/build/perf (using O=/tmp/build/perf),
      we end up with:
      
        $ ls -la /tmp/build/perf/feature/test-eventfd*
        -rwxrwxr-x. 1 acme acme 8176 Nov 21 15:58 /tmp/build/perf/feature/test-eventfd.bin
        -rw-rw-r--. 1 acme acme  588 Nov 21 15:58 /tmp/build/perf/feature/test-eventfd.d
        -rw-rw-r--. 1 acme acme    0 Nov 21 15:58 /tmp/build/perf/feature/test-eventfd.make.output
        $ ldd /tmp/build/perf/feature/test-eventfd.bin
      	  linux-vdso.so.1 (0x00007fff3bf3f000)
      	  libc.so.6 => /lib64/libc.so.6 (0x00007fa984061000)
      	  /lib64/ld-linux-x86-64.so.2 (0x00007fa984417000)
        $ grep eventfd -A 2 -B 2 /tmp/build/perf/FEATURE-DUMP
        feature-dwarf=1
        feature-dwarf_getlocations=1
        feature-eventfd=1
        feature-fortify-source=1
        feature-sync-compare-and-swap=1
        $
      
      The main thing here is that in the end we'll have -DHAVE_EVENTFD in
      CFLAGS, and then the 'perf bench' entry needing that API can be
      selectively pruned.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Davidlohr Bueso <dbueso@suse.de>
      Cc: Jason Baron <jbaron@akamai.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-wkeldwob7dpx6jvtuzl8164k@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      11c6cbe7
  2. 21 11月, 2018 17 次提交
    • D
      perf bench: Move HAVE_PTHREAD_ATTR_SETAFFINITY_NP into bench.h · d47d77c3
      Davidlohr Bueso 提交于
      Both futex and epoll need this call, and can cause build failure on
      systems that don't have it pthread_attr_setaffinity_np().
      Signed-off-by: NDavidlohr Bueso <dbueso@suse.de>
      Reported-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Davidlohr Bueso <dbueso@suse.de>
      Cc: Jason Baron <jbaron@akamai.com>
      Link: http://lkml.kernel.org/r/20181109210719.pr7ohayuwqmfp2wl@linux-r8p5Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d47d77c3
    • M
      perf script: Share code and output format for uregs and iregs output · 9add8fe8
      Milian Wolff 提交于
      The iregs output was missing the newline at end as well as the leading
      ABI output. This made it hard to compare the iregs and uregs values.
      Instead, use a single function to output the register values and use it
      for both, iregs and uregs, to ensure the output is consistent.
      
      Before:
      
        perf  7049 [-01]  1343.354347:          1 cycles:ppp:
              ffffffffa7bc21ce perf_event_exec+0x18e (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7ead3 setup_new_exec+0xf3 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7cd7be5 load_elf_binary+0x395 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7e540 search_binary_handler+0x80 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7f1aa __do_execve_file.isra.13+0x58a (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7f561 do_execve+0x21 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7f596 __x64_sys_execve+0x26 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7a041cb do_syscall_64+0x5b (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa840008c entry_SYSCALL_64+0x7c (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
          AX:0x80000000    BX:0x0    CX:0x0    DX:0x7    SI:0xf    DI:0x286    BP:0xffff95bc8213a460    SP:0xffffacbf0ba97d18    IP:0xffffffffa7bc21cd FLAGS:0x28e    CS:0x10    SS:0x18    R8:0x2    R9:0x21440   R10:0x33816fb3b8c   R11:0x1   R12:0xffff95bc8213a460   R13:0xffff95bc8213a400   R14:0xffff95bc8213a400   R15:0x1  ABI:2    AX:0xffffffffffffffda    BX:0xffffffffffffffff    CX:0x7f84ad85798b    DX:0x560209699d50    SI:0x7ffe2c7a6820    DI:0x7ffe2c7a8c9b    BP:0x7ffe2c7a20d0    SP:0x7ffe2c7a2058    IP:0x7f84ad85798b FLAGS:0x206    CS:0x33    SS:0x2b    R8:0x7ffe2c7a2030    R9:0x7f84ae55f010   R10:0x8   R11:0x206   R12:0xffffffffffffffff   R13:0xffffffffffffffff   R14:0xffffffffffffffff   R15:0xffffffffffffffff
      
        perf  7049 [-01]  1343.354363:          1 cycles:ppp:
              ...
      
      After:
      
        perf  7049 [-01]  1343.354347:          1 cycles:ppp:
              ffffffffa7bc21ce perf_event_exec+0x18e (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7ead3 setup_new_exec+0xf3 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7cd7be5 load_elf_binary+0x395 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7e540 search_binary_handler+0x80 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7f1aa __do_execve_file.isra.13+0x58a (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7f561 do_execve+0x21 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7c7f596 __x64_sys_execve+0x26 (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa7a041cb do_syscall_64+0x5b (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
              ffffffffa840008c entry_SYSCALL_64+0x7c (/lib/modules/4.20.0-rc1perf-devel-05115-gc0bc98f76e39-dirty/build/vmlinux)
          ABI:2    AX:0x80000000    BX:0x0    CX:0x0    DX:0x7    SI:0xf    DI:0x286    BP:0xffff95bc8213a460    SP:0xffffacbf0ba97d18    IP:0xffffffffa7bc21cd FLAGS:0x28e    CS:0x10    SS:0x18    R8:0x2    R9:0x21440   R10:0x33816fb3b8c   R11:0x1   R12:0xffff95bc8213a460   R13:0xffff95bc8213a400   R14:0xffff95bc8213a400   R15:0x1
          ABI:2    AX:0xffffffffffffffda    BX:0xffffffffffffffff    CX:0x7f84ad85798b    DX:0x560209699d50    SI:0x7ffe2c7a6820    DI:0x7ffe2c7a8c9b    BP:0x7ffe2c7a20d0    SP:0x7ffe2c7a2058    IP:0x7f84ad85798b FLAGS:0x206    CS:0x33    SS:0x2b    R8:0x7ffe2c7a2030    R9:0x7f84ae55f010   R10:0x8   R11:0x206   R12:0xffffffffffffffff   R13:0xffffffffffffffff   R14:0xffffffffffffffff   R15:0xffffffffffffffff
      
        perf  7049 [-01]  1343.354363:          1 cycles:ppp:
              ...
      Signed-off-by: NMilian Wolff <milian.wolff@kdab.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Link: http://lkml.kernel.org/r/20181107223437.9071-1-milian.wolff@kdab.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      9add8fe8
    • A
      perf bpf: Reduce the hardcoded .max_entries for pid_maps · 0f7c2de5
      Arnaldo Carvalho de Melo 提交于
      While working on augmented syscalls I got into this error:
      
        # trace -vv --filter-pids 2469,1663 -e tools/perf/examples/bpf/augmented_raw_syscalls.c sleep 1
        <SNIP>
        libbpf: map 0 is "__augmented_syscalls__"
        libbpf: map 1 is "__bpf_stdout__"
        libbpf: map 2 is "pids_filtered"
        libbpf: map 3 is "syscalls"
        libbpf: collecting relocating info for: '.text'
        libbpf: relo for 13 value 84 name 133
        libbpf: relocation: insn_idx=3
        libbpf: relocation: find map 3 (pids_filtered) for insn 3
        libbpf: collecting relocating info for: 'raw_syscalls:sys_enter'
        libbpf: relo for 8 value 0 name 0
        libbpf: relocation: insn_idx=1
        libbpf: relo for 8 value 0 name 0
        libbpf: relocation: insn_idx=3
        libbpf: relo for 9 value 28 name 178
        libbpf: relocation: insn_idx=36
        libbpf: relocation: find map 1 (__augmented_syscalls__) for insn 36
        libbpf: collecting relocating info for: 'raw_syscalls:sys_exit'
        libbpf: relo for 8 value 0 name 0
        libbpf: relocation: insn_idx=0
        libbpf: relo for 8 value 0 name 0
        libbpf: relocation: insn_idx=2
        bpf: config program 'raw_syscalls:sys_enter'
        bpf: config program 'raw_syscalls:sys_exit'
        libbpf: create map __bpf_stdout__: fd=3
        libbpf: create map __augmented_syscalls__: fd=4
        libbpf: create map syscalls: fd=5
        libbpf: create map pids_filtered: fd=6
        libbpf: added 13 insn from .text to prog raw_syscalls:sys_enter
        libbpf: added 13 insn from .text to prog raw_syscalls:sys_exit
        libbpf: load bpf program failed: Operation not permitted
        libbpf: failed to load program 'raw_syscalls:sys_exit'
        libbpf: failed to load object 'tools/perf/examples/bpf/augmented_raw_syscalls.c'
        bpf: load objects failed: err=-4009: (Incorrect kernel version)
        event syntax error: 'tools/perf/examples/bpf/augmented_raw_syscalls.c'
                             \___ Failed to load program for unknown reason
      
        (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
      
      If I then try to use strace (perf trace'ing 'perf trace' needs some more work
      before its possible) to get a bit more info I get:
      
        # strace -e bpf trace --filter-pids 2469,1663 -e tools/perf/examples/bpf/augmented_raw_syscalls.c sleep 1
        bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=4, map_flags=0, inner_map_fd=0, map_name="__bpf_stdout__", map_ifindex=0}, 72) = 3
        bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=4, map_flags=0, inner_map_fd=0, map_name="__augmented_sys", map_ifindex=0}, 72) = 4
        bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, key_size=4, value_size=1, max_entries=500, map_flags=0, inner_map_fd=0, map_name="syscalls", map_ifindex=0}, 72) = 5
        bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_HASH, key_size=4, value_size=1, max_entries=512, map_flags=0, inner_map_fd=0, map_name="pids_filtered", map_ifindex=0}, 72) = 6
        bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=57, insns=0x1223f50, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(4, 18, 10), prog_flags=0, prog_name="sys_enter", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = 7
        bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=18, insns=0x1224120, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(4, 18, 10), prog_flags=0, prog_name="sys_exit", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = -1 EPERM (Operation not permitted)
        bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=18, insns=0x1224120, license="GPL", log_level=1, log_size=262144, log_buf="", kern_version=KERNEL_VERSION(4, 18, 10), prog_flags=0, prog_name="sys_exit", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = -1 EPERM (Operation not permitted)
        bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=18, insns=0x1224120, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(4, 18, 10), prog_flags=0, prog_name="sys_exit", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = -1 EPERM (Operation not permitted)
        event syntax error: 'tools/perf/examples/bpf/augmented_raw_syscalls.c'
                             \___ Failed to load program for unknown reason
        <SNIP similar output as without 'strace'>
        #
      
      I managed to create the maps, etc, but then installing the "sys_exit" hook into
      the "raw_syscalls:sys_exit" tracepoint somehow gets -EPERMed...
      
      I then go and try reducing the size of this new table:
      
        +++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
        @@ -47,6 +47,17 @@ struct augmented_filename {
         #define SYS_OPEN 2
         #define SYS_OPENAT 257
      
        +struct syscall {
        +       bool    filtered;
        +};
        +
        +struct bpf_map SEC("maps") syscalls = {
        +       .type        = BPF_MAP_TYPE_ARRAY,
        +       .key_size    = sizeof(int),
        +       .value_size  = sizeof(struct syscall),
        +       .max_entries = 500,
        +};
      
      And after reducing that .max_entries a tad, it works. So yeah, the "unknown
      reason" should be related to the number of bytes all this is taking, reduce the
      default for pid_map()s so that we can have a "syscalls" map with enough slots
      for all syscalls in most arches. And take notes about this error message,
      improve it :-)
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Edward Cree <ecree@solarflare.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Yonghong Song <yhs@fb.com>
      Link: https://lkml.kernel.org/n/tip-yjzhak8asumz9e9hts2dgplp@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      0f7c2de5
    • M
      perf script: Add newline after uregs output · b07d16f7
      Milian Wolff 提交于
      This change makes it much easier to easily distinguish between
      consecutive samples by keeping the empty line between them, like we see
      when we do not enable uregs output.
      
      Before:
      
        cpp-inlining 28298 [-01] 54837.342780:    3068085 cycles:pp:
                    7ffff7c96709 __hypot_finite+0xa9 (/usr/lib/libm-2.28.so)
                    ...
         ABI:2    AX:0x0    BX:0x40f56cf6    CX:0x294a3ae7    ...
        cpp-inlining 28298 [-01] 54837.344493:    2881929 cycles:pp:
                    7ffff7c96696 __hypot_finite+0x36 (/usr/lib/libm-2.28.so)
                    ...
         ABI:2    AX:0x40d440c7    BX:0x40d440c7    CX:0x4d45e5da    ...
      
      After:
      
        cpp-inlining 28298 [-01] 54837.342780:    3068085 cycles:pp:
                    7ffff7c96709 __hypot_finite+0xa9 (/usr/lib/libm-2.28.so)
                    ...
         ABI:2    AX:0x0    BX:0x40f56cf6    CX:0x294a3ae7    ...
      
        cpp-inlining 28298 [-01] 54837.344493:    2881929 cycles:pp:
                    7ffff7c96696 __hypot_finite+0x36 (/usr/lib/libm-2.28.so)
                    ...
         ABI:2    AX:0x40d440c7    BX:0x40d440c7    CX:0x4d45e5da    ...
      Signed-off-by: NMilian Wolff <milian.wolff@kdab.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Link: http://lkml.kernel.org/r/20181107093705.16346-1-milian.wolff@kdab.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b07d16f7
    • A
      Revert "perf augmented_syscalls: Drop 'write', 'poll' for testing without self pid filter" · 4aa792de
      Arnaldo Carvalho de Melo 提交于
      Now that we have the "filtered_pids" logic in place, no need to do this
      rough filter to avoid the feedback loop from 'perf trace's own syscalls,
      revert it.
      
      This reverts commit 7ed71f124284359676b6496ae7db724fee9da753.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-88vh02cnkam0vv5f9vp02o3h@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      4aa792de
    • A
      perf augmented_syscalls: Remove example hardcoded set of filtered pids · e312747b
      Arnaldo Carvalho de Melo 提交于
      Now that 'perf trace' fills in that "filtered_pids" BPF map, remove the
      set of filtered pids used as an example to test that feature.
      
      That feature works like this:
      
      Starting a system wide 'strace' like 'perf trace' augmented session we
      noticed that lots of events take place for a pid, which ends up being
      the feedback loop of perf trace's syscalls being processed by the
      'gnome-terminal' process:
      
        # perf trace -e tools/perf/examples/bpf/augmented_raw_syscalls.c
           0.391 ( 0.002 ms): gnome-terminal/2469 read(fd: 17</dev/ptmx>, buf: 0x564b79f750bc, count: 8176) = 453
           0.394 ( 0.001 ms): gnome-terminal/2469 read(fd: 17</dev/ptmx>, buf: 0x564b79f75280, count: 7724) = -1 EAGAIN Resource temporarily unavailable
           0.438 ( 0.001 ms): gnome-terminal/2469 read(fd: 4<anon_inode:[eventfd]>, buf: 0x7fffc696aeb0, count: 16) = 8
           0.519 ( 0.001 ms): gnome-terminal/2469 read(fd: 17</dev/ptmx>, buf: 0x564b79f75280, count: 7724) = 114
           0.522 ( 0.001 ms): gnome-terminal/2469 read(fd: 17</dev/ptmx>, buf: 0x564b79f752f1, count: 7611) = -1 EAGAIN Resource temporarily unavailable
        ^C
      
      So we can use --filter-pids to get rid of that one, and in this case what is
      being used to implement that functionality is that "filtered_pids" BPF map that
      the tools/perf/examples/bpf/augmented_raw_syscalls.c created and that 'perf trace'
      bpf loader noticed and created a "struct bpf_map" associated that then got populated
      by 'perf trace':
      
        # perf trace --filter-pids 2469 -e tools/perf/examples/bpf/augmented_raw_syscalls.c
           0.020 ( 0.002 ms): gnome-shell/1663 epoll_pwait(epfd: 12<anon_inode:[eventpoll]>, events: 0x7ffd8f3ef960, maxevents: 32, sigsetsize: 8) = 1
           0.025 ( 0.002 ms): gnome-shell/1663 read(fd: 24</dev/input/event4>, buf: 0x560c01bb8240, count: 8112) = 48
           0.029 ( 0.001 ms): gnome-shell/1663 read(fd: 24</dev/input/event4>, buf: 0x560c01bb8258, count: 8088) = -1 EAGAIN Resource temporarily unavailable
           0.032 ( 0.001 ms): gnome-shell/1663 read(fd: 24</dev/input/event4>, buf: 0x560c01bb8240, count: 8112) = -1 EAGAIN Resource temporarily unavailable
           0.040 ( 0.003 ms): gnome-shell/1663 recvmsg(fd: 46<socket:[35893]>, msg: 0x7ffd8f3ef950) = -1 EAGAIN Resource temporarily unavailable
          21.529 ( 0.002 ms): gnome-shell/1663 epoll_pwait(epfd: 5<anon_inode:[eventpoll]>, events: 0x7ffd8f3ef960, maxevents: 32, sigsetsize: 8) = 1
          21.533 ( 0.004 ms): gnome-shell/1663 recvmsg(fd: 82<socket:[42826]>, msg: 0x7ffd8f3ef7b0, flags: DONTWAIT|CMSG_CLOEXEC) = 236
          21.581 ( 0.006 ms): gnome-shell/1663 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_BUSY, arg: 0x7ffd8f3ef060) = 0
          21.605 ( 0.020 ms): gnome-shell/1663 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_CREATE, arg: 0x7ffd8f3eeea0) = 0
          21.626 ( 0.119 ms): gnome-shell/1663 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_SET_DOMAIN, arg: 0x7ffd8f3eee94) = 0
          21.746 ( 0.081 ms): gnome-shell/1663 ioctl(fd: 8</dev/dri/card0>, cmd: DRM_I915_GEM_PWRITE, arg: 0x7ffd8f3eeea0) = 0
        ^C
      
      Oops, yet another gnome process that is involved with the output that
      'perf trace' generates, lets filter that out too:
      
        # perf trace --filter-pids 2469,1663 -e tools/perf/examples/bpf/augmented_raw_syscalls.c
               ? (         ): wpa_supplicant/1366  ... [continued]: select()) = 0 Timeout
           0.006 ( 0.002 ms): wpa_supplicant/1366 clock_gettime(which_clock: BOOTTIME, tp: 0x7fffe5b1e430) = 0
           0.011 ( 0.001 ms): wpa_supplicant/1366 clock_gettime(which_clock: BOOTTIME, tp: 0x7fffe5b1e3e0) = 0
           0.014 ( 0.001 ms): wpa_supplicant/1366 clock_gettime(which_clock: BOOTTIME, tp: 0x7fffe5b1e430) = 0
               ? (         ): gmain/1791  ... [continued]: poll()) = 0 Timeout
           0.017 (         ): wpa_supplicant/1366 select(n: 6, inp: 0x55646fed3ad0, outp: 0x55646fed3b60, exp: 0x55646fed3bf0, tvp: 0x7fffe5b1e4a0) ...
         157.879 ( 0.019 ms): gmain/1791 inotify_add_watch(fd: 8<anon_inode:inotify>, pathname: , mask: 16789454) = -1 ENOENT No such file or directory
               ? (         ): cupsd/1001  ... [continued]: epoll_pwait()) = 0
               ? (         ): gsd-color/1908  ... [continued]: poll()) = 0 Timeout
         499.615 (         ): cupsd/1001 epoll_pwait(epfd: 4<anon_inode:[eventpoll]>, events: 0x557a21166500, maxevents: 4096, timeout: 1000, sigsetsize: 8) ...
         586.593 ( 0.004 ms): gsd-color/1908 recvmsg(fd: 3<socket:[38074]>, msg: 0x7ffdef34e800) = -1 EAGAIN Resource temporarily unavailable
               ? (         ): fwupd/2230  ... [continued]: poll()) = 0 Timeout
               ? (         ): rtkit-daemon/906  ... [continued]: poll()) = 0 Timeout
               ? (         ): rtkit-daemon/907  ... [continued]: poll()) = 1
         724.603 ( 0.007 ms): rtkit-daemon/907 read(fd: 6<anon_inode:[eventfd]>, buf: 0x7f05ff768d08, count: 8) = 8
               ? (         ): ssh/5461  ... [continued]: select()) = 1
         810.431 ( 0.002 ms): ssh/5461 clock_gettime(which_clock: BOOTTIME, tp: 0x7ffd7f39f870) = 0
         ^C
      
      Several syscall exit events for syscalls in flight when 'perf trace' started, etc. Saner :-)
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-c3tu5yg204p5mvr9kvwew07n@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e312747b
    • A
      perf trace: Fill in BPF "filtered_pids" map when present · a9964c43
      Arnaldo Carvalho de Melo 提交于
      This makes the augmented_syscalls support the --filter-pids and
      auto-filtered feedback loop pids just like when working without BPF,
      i.e. with just raw_syscalls:sys_{enter,exit} and tracepoint filters.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-zc5n453sxxm0tz1zfwwelyti@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a9964c43
    • A
      perf trace: See if there is a map named "filtered_pids" · 744fafc7
      Arnaldo Carvalho de Melo 提交于
      Lookup for the first map named "filtered_pids" and, if augmenting
      syscalls, i.e. if a BPF event is present and the
      "__augmented_syscalls__" is present, then fill in that map with the pids
      to filter, be it feedback loop ones (perf trace's pid, its father if it
      is "sshd", more auto-filtered in the future) or the ones explicitely
      stated in the tool command line via --filter-pids.
      
      The code to actually fill in the map comes next.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-rhzytmw7qpe6lqyjxi1ded9t@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      744fafc7
    • A
      perf trace: Add "_from_option" suffix to trace__set_filter() · 6a0b3aba
      Arnaldo Carvalho de Melo 提交于
      As we'll need that name for a new function to set filters for both
      tracepoints and BPF maps for filtering pids.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-mdkck6hf3fnd21rz2766280q@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6a0b3aba
    • A
      perf evlist: Rename perf_evlist__set_filter* to perf_evlist__set_tp_filter* · 7ad92a33
      Arnaldo Carvalho de Melo 提交于
      To better reflect that this is a tracepoint filter, as opposed, for
      instance to map based BPF filters.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-9138svli6ddcphrr3ymy9oy3@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7ad92a33
    • A
      perf augmented_syscalls: Use pid_filter · ed9a77ba
      Arnaldo Carvalho de Melo 提交于
      Just to test filtering a bunch of pids, now its time to go and get that
      hooked up in 'perf trace', right after we load the bpf program, if we
      find a "pids_filtered" map defined, we'll populate it with the filtered
      pids.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-1i9s27wqqdhafk3fappow84x@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ed9a77ba
    • A
      perf augmented_syscalls: Drop 'write', 'poll' for testing without self pid filter · 77ecb640
      Arnaldo Carvalho de Melo 提交于
      When testing system wide tracing without filtering the syscalls called
      by 'perf trace' itself we get into a feedback loop, drop for now those
      two syscalls, that are the ones that 'perf trace' does in its loop for
      writing the syscalls it intercepts, to help with testing till we get
      that filtering in place.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-rkbu536af66dbsfx51sr8yof@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      77ecb640
    • A
      perf bpf: Add simple pid_filter class accessible to BPF proggies · 8008aab0
      Arnaldo Carvalho de Melo 提交于
      Will be used in the augmented_raw_syscalls.c to implement 'perf trace
      --filter-pids'.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-9sybmz4vchlbpqwx2am13h9e@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8008aab0
    • A
      perf bpf: Add defines for map insertion/lookup · 382b55db
      Arnaldo Carvalho de Melo 提交于
      Starting with a helper for a basic pid_map(), a hash using a pid as a
      key.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-gdwvq53wltvq6b3g5tdmh0cw@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      382b55db
    • A
      perf augmented_syscalls: Remove needless linux/socket.h include · 66067538
      Arnaldo Carvalho de Melo 提交于
      Leftover from when we started augmented_raw_syscalls.c from
      tools/perf/examples/bpf/augmented_syscalls.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Fixes: e58a0322dbac ("perf examples bpf: Start augmenting raw_syscalls:sys_{start,exit}")
      Link: https://lkml.kernel.org/n/tip-pmts9ls2skh8n3zisb4txudd@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      66067538
    • A
      perf augmented_syscalls: Filter on a hard coded pid · 55f127b4
      Arnaldo Carvalho de Melo 提交于
      Just to show where we'll hook pid based filters, and what we use to
      obtain the current pid, using a BPF getpid() equivalent.
      
      Now we need to remove that hardcoded PID with a BPF hash map, so that we
      start by filtering 'perf trace's own PID, implement the --filter-pid
      functionality, etc.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-oshrcgcekiyhd0whwisxfvtv@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      55f127b4
    • A
      perf bpf: Add unistd.h to the headers accessible to bpf proggies · 1475d35c
      Arnaldo Carvalho de Melo 提交于
      Start with a getpid() function wrapping BPF_FUNC_get_current_pid_tgid,
      idea is to mimic the system headers.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-zo8hv22onidep7tm785dzxfk@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1475d35c
  3. 20 11月, 2018 6 次提交
    • A
      perf tools beauty ioctl: Support new ISO7816 commands · a4243e14
      Arnaldo Carvalho de Melo 提交于
      Introduced in:
      
        ad8c0eaa ("tty/serial_core: add ISO7816 infrastructure")
      
      Now 'perf trace' will be able to pretty-print the 'cmd' ioctl arg when
      used in capable systems with software emitting those commands.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-7bds48dhckfnleie08mit314@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a4243e14
    • A
      tools uapi asm-generic: Synchronize ioctls.h · 83d9bdea
      Arnaldo Carvalho de Melo 提交于
      To pick up the changes in:
      
        ad8c0eaa ("tty/serial_core: add ISO7816 infrastructure")
      
      That is a change that imply a change to be made in tools/perf/trace/beauty/ioctl.c to
      make 'perf trace' ioctl syscall argument beautifier to support these new
      commands:  TIOCGISO7816 and TIOCSISO7816.
      
      This is not yet done automatically by a script like is done for some
      other headers, for instance:
      
        $ tools/perf/trace/beauty/drm_ioctl.sh | head
        #ifndef DRM_COMMAND_BASE
        #define DRM_COMMAND_BASE                0x40
        #endif
        static const char *drm_ioctl_cmds[] = {
      	[0x00] = "VERSION",
      	[0x01] = "GET_UNIQUE",
      	[0x02] = "GET_MAGIC",
      	[0x03] = "IRQ_BUSID",
      	[0x04] = "GET_MAP",
      	[0x05] = "GET_CLIENT",
        $
      
      So we will need to change tools/perf/trace/beauty/ioctl.c in a follow up
      patch until we switch to a generator script.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-zin76fe6iykqsilvo6u47f9o@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      83d9bdea
    • A
      tools arch x86: Update tools's copy of cpufeatures.h · 65e259d5
      Arnaldo Carvalho de Melo 提交于
      To get the changes in the following csets:
      
        ace6485a ("x86/cpufeatures: Enumerate MOVDIR64B instruction")
        33823f4d ("x86/cpufeatures: Enumerate MOVDIRI instruction")
      
      No tools were affected, copy it to silence this perf tool build warning:
      
        Warning: Kernel ABI header at 'tools/arch/x86/include/asm/cpufeatures.h' differs from latest version at 'arch/x86/include/asm/cpufeatures.h'
        diff -u tools/arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/cpufeatures.h
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Link: https://lkml.kernel.org/n/tip-83kcyqa1qkxkhm1s7q3hbpel@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      65e259d5
    • A
      tools headers uapi: Synchronize i915_drm.h · 53f00f45
      Arnaldo Carvalho de Melo 提交于
      To pick up the changes in:
      
        900ccf30 ("drm/i915: Only force GGTT coherency w/a on required chipsets")
      
      No changes are required in tools/ nor does anything gets automatically
      generated to be used in the 'perf trace' syscall arg beautifiers.
      
      This silences this perf build warning:
      
        Warning: Kernel ABI header at 'tools/include/uapi/drm/i915_drm.h' differs from latest version at 'include/uapi/drm/i915_drm.h'
        diff -u tools/include/uapi/drm/i915_drm.h include/uapi/drm/i915_drm.h
      
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-t2vor2wegv41gt5n49095kly@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      53f00f45
    • J
      perf tools: Restore proper cwd on return from mnt namespace · b01c1f69
      Jiri Olsa 提交于
      When reporting on 'record' server we try to retrieve/use the mnt
      namespace of the profiled tasks. We use following API with cookie to
      hold the return namespace, roughly:
      
        nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc)
          setns(newns, 0);
        ...
        new ns related open..
        ...
        nsinfo__mountns_exit(struct nscookie *nc)
          setns(nc->oldns)
      
      Once finished we setns to old namespace, which also sets the current
      working directory (cwd) to "/", trashing the cwd we had.
      
      This is mostly fine, because we use absolute paths almost everywhere,
      but it screws up 'perf diff':
      
        # perf diff
        failed to open perf.data: No such file or directory  (try 'perf record' first)
        ...
      
      Adding the current working directory to be part of the cookie and
      restoring it in the nsinfo__mountns_exit call.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Krister Johansen <kjlx@templeofstupid.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Fixes: 843ff37b ("perf symbols: Find symbols in different mount namespace")
      Link: http://lkml.kernel.org/r/20181101170001.30019-1-jolsa@kernel.org
      [ No need to check for NULL args for free(), use zfree() for struct members ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      b01c1f69
    • A
      tools build feature: Check if get_current_dir_name() is available · 8feb8efe
      Arnaldo Carvalho de Melo 提交于
      As the namespace support code will use this, which is not available in
      some non _GNU_SOURCE libraries such as Android's bionic used in my
      container build tests (r12b and r15c at the moment).
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: https://lkml.kernel.org/n/tip-x56ypm940pwclwu45d7jfj47@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8feb8efe
  4. 15 11月, 2018 1 次提交
  5. 13 11月, 2018 1 次提交
  6. 12 11月, 2018 1 次提交
    • M
      selftests/powerpc: Fix wild_bctr test to work on ppc64 · 2c7645b0
      Michael Ellerman 提交于
      The selftest I recently added to test branching to an out-of-bounds
      NIP doesn't work on 64-bit big endian. It does fail but not in the
      right way. That is it SEGVs trying to load from the opd at BAD_NIP,
      but it never gets as far as branching to BAD_NIP.
      
      To fix it we need to create an opd which is reachable but which holds
      the bad address.
      
      Fixes: b7683fc6 ("selftests/powerpc: Add a test of wild bctr")
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      2c7645b0
  7. 06 11月, 2018 13 次提交
    • J
      perf tools: Do not zero sample_id_all for group members · 8e88c29b
      Jiri Olsa 提交于
      Andi reported following malfunction:
      
        # perf record -e '{ref-cycles,cycles}:S' -a sleep 1
        # perf script
        non matching sample_id_all
      
      That's because we disable sample_id_all bit for non-sampling group
      members. We can't do that, because it needs to be the same over the
      whole event list. This patch keeps it untouched again.
      Reported-by: NAndi Kleen <andi@firstfloor.org>
      Tested-by: NAndi Kleen <andi@firstfloor.org>
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/20180923150420.27327-1-jolsa@kernel.org
      Fixes: e9add8ba ("perf evsel: Disable write_backward for leader sampling group events")
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8e88c29b
    • M
      tools/testing/nvdimm: Fix the array size for dimm devices. · af31b04b
      Masayoshi Mizuma 提交于
      KASAN reports following global out of bounds access while
      nfit_test is being loaded. The out of bound access happens
      the following reference to dimm_fail_cmd_flags[dimm]. 'dimm' is
      over than the index value, NUM_DCR (==5).
      
        static int override_return_code(int dimm, unsigned int func, int rc)
        {
                if ((1 << func) & dimm_fail_cmd_flags[dimm]) {
      
      dimm_fail_cmd_flags[] definition:
        static unsigned long dimm_fail_cmd_flags[NUM_DCR];
      
      'dimm' is the return value of get_dimm(), and get_dimm() returns
      the index of handle[] array. The handle[] has 7 index. Let's use
      ARRAY_SIZE(handle) as the array size.
      
      KASAN report:
      
      ==================================================================
      BUG: KASAN: global-out-of-bounds in nfit_test_ctl+0x47bb/0x55b0 [nfit_test]
      Read of size 8 at addr ffffffffc10cbbe8 by task kworker/u41:0/8
      ...
      Call Trace:
       dump_stack+0xea/0x1b0
       ? dump_stack_print_info.cold.0+0x1b/0x1b
       ? kmsg_dump_rewind_nolock+0xd9/0xd9
       print_address_description+0x65/0x22e
       ? nfit_test_ctl+0x47bb/0x55b0 [nfit_test]
       kasan_report.cold.6+0x92/0x1a6
       nfit_test_ctl+0x47bb/0x55b0 [nfit_test]
      ...
      The buggy address belongs to the variable:
       dimm_fail_cmd_flags+0x28/0xffffffffffffa440 [nfit_test]
      ==================================================================
      
      Fixes: 39611e83 ("tools/testing/nvdimm: Make DSM failure code injection...")
      Signed-off-by: NMasayoshi Mizuma <m.mizuma@jp.fujitsu.com>
      Signed-off-by: NDan Williams <dan.j.williams@intel.com>
      af31b04b
    • G
      perf tools: Fix undefined symbol scnprintf in libperf-jvmti.so · 6ac22262
      Gustavo Romero 提交于
      Currently jvmti agent can not be used because function scnprintf is not
      present in the agent libperf-jvmti.so. As a result the JVM when using
      such agent to record JITed code profiling information will fail on
      looking up scnprintf:
      
        java: symbol lookup error: lib/libperf-jvmti.so: undefined symbol: scnprintf
      
      This commit fixes that by reverting to the use of snprintf, that can be
      looked up, instead of scnprintf, adding a proper check for the returned
      value in order to print a better error message when the jitdump file
      pathname is too long. Checking the returned value also helps to comply
      with some recent gcc versions, like gcc8, which will fail due to
      truncated writing checks related to the -Werror=format-truncation= flag.
      Signed-off-by: NGustavo Romero <gromero@linux.vnet.ibm.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      LPU-Reference: 1541117601-18937-2-git-send-email-gromero@linux.vnet.ibm.com
      Link: https://lkml.kernel.org/n/tip-mvpxxxy7wnzaj74cq75muw3f@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6ac22262
    • A
      perf beauty: Use SRCARCH, ARCH=x86_64 must map to "x86" to find the headers · e2c39f36
      Arnaldo Carvalho de Melo 提交于
      Guenter reported that using ARCH=x86_64 to build perf has regressed:
      
        $ make -C tools/perf O=/tmp/build/perf ARCH=x86_64
        make: Entering directory '/home/acme/git/perf/tools/perf'
          BUILD:   Doing 'make -j4' parallel build
          HOSTCC   /tmp/build/perf/fixdep.o
          HOSTLD   /tmp/build/perf/fixdep-in.o
          LINK     /tmp/build/perf/fixdep
      
        Auto-detecting system features:
        ...                         dwarf: [ on  ]
        <SNIP>
        ...                           bpf: [ on  ]
      
          GEN      /tmp/build/perf/common-cmds.h
        make[2]: *** No rule to make target '/home/acme/git/perf/tools/arch/x86_64/include/uapi/asm//mman.h', needed by '/tmp/build/perf/trace/beauty/generated/mmap_flags_array.c'.  Stop.
        make[2]: *** Waiting for unfinished jobs....
          PERF_VERSION = 4.19.gf6c23e3b
        make[1]: *** [Makefile.perf:207: sub-make] Error 2
        make: *** [Makefile:70: all] Error 2
        make: Leaving directory '/home/acme/git/perf/tools/perf'
        $
      
      This is because we must use $(SRCARCH) where we were using $(ARCH), so
      that, just like the top level Makefile, we get this done:
      
        # Additional ARCH settings for x86
        ifeq ($(ARCH),i386)
                SRCARCH := x86
        endif
        ifeq ($(ARCH),x86_64)
                SRCARCH := x86
        endif
      
      Which is done in tools/scripts/Makefile.arch, so switch to use
      $(SRCARCH).
      Reported-by: NGuenter Roeck <linux@roeck-us.net>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Clark Williams <williams@redhat.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Fixes: fbd7458d ("perf beauty: Wire up the mmap flags table generator to the Makefile")
      Link: https://lkml.kernel.org/r/20181105184612.GD7077@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      e2c39f36
    • A
      perf intel-pt: Add MTC and CYC timestamps to debug log · f6c23e3b
      Adrian Hunter 提交于
      One cause of decoding errors is un-synchronized side-band data.
      Timestamps are needed to debug such cases. TSC packet timestamps are
      logged. Log also MTC and CYC timestamps.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Link: http://lkml.kernel.org/r/20181105073505.8129-3-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f6c23e3b
    • A
      perf intel-pt: Add more event information to debug log · 93f8be27
      Adrian Hunter 提交于
      More event information is useful for debugging, especially MMAP events.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Link: http://lkml.kernel.org/r/20181105073505.8129-2-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      93f8be27
    • A
      perf scripts python: exported-sql-viewer.py: Fix table find when table re-ordered · 35fa1cee
      Adrian Hunter 提交于
      Table rows can be re-ordered by selecting a column to sort by. After
      re-ordering, the "find" operation was highlighting the wrong row, fix
      it.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/20181104151238.15947-5-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      35fa1cee
    • A
      perf scripts python: exported-sql-viewer.py: Add help window · 65b24292
      Adrian Hunter 提交于
      Add a window to display help. It is also possible to display the help
      only, by using the option "--help-only" instead of a database name.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/20181104151238.15947-4-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      65b24292
    • A
      perf scripts python: exported-sql-viewer.py: Add Selected branches report · 210cf1f9
      Adrian Hunter 提交于
      Fetching data from the database can be slow. Add a report that provides
      the ability to select a subset of branches.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/20181104151238.15947-3-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      210cf1f9
    • A
      perf scripts python: exported-sql-viewer.py: Fall back to /usr/local/lib/libxed.so · 5ed4419d
      Adrian Hunter 提交于
      Fall back to /usr/local/lib/libxed.so to cater for distributions that do
      not have /usr/local/lib in the library path by default.
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Link: http://lkml.kernel.org/r/20181104151238.15947-2-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5ed4419d
    • J
      perf top: Display the LBR stats in callchain entry · 590ac60d
      Jin Yao 提交于
      'perf report' has supported the displaying of LBR stats (such as cycles,
      predicted%) in callchain entry.
      
      For example:
      
        $ perf report --branch-history --stdio
      
        --1.01%--intel_idle mwait.h:29
                  intel_idle cpufeature.h:164 (cycles:5)
                  intel_idle cpufeature.h:164 (predicted:76.4%)
                  intel_idle mwait.h:102 (cycles:41)
                  intel_idle current.h:15
      
      While 'perf top' doesn't support that.
      
      For example:
      
        $ perf top -a -b --call-graph branch
      
        -   13.86%     0.23%  [kernel]		[k] __x86_indirect_thunk_rax
           - 13.65% __x86_indirect_thunk_rax
              + 1.69% do_syscall_64
              + 1.68% do_select
              + 1.41% ktime_get
              + 0.70% __schedule
              + 0.62% do_sys_poll
                0.58% __x86_indirect_thunk_rax
      
      Actually it's very easy to enable this feature in 'perf top'.
      
      With this patch, the result is:
      
        $ perf top -a -b --call-graph branch
      
        $ -   13.58%     0.00%  [kernel]		[k] __x86_indirect_thunk_rax
           $ - 13.57% __x86_indirect_thunk_rax (predicted:93.9%)
              $ + 1.78% do_select (cycles:2)
              $ + 1.68% perf_pmu_disable.part.99 (cycles:1)
              $ + 1.45% ___sys_recvmsg (cycles:25)
              $ + 0.81% unix_stream_sendmsg (cycles:18)
              $ + 0.80% ktime_get (cycles:400)
                $ 0.58% pick_next_task_fair (cycles:47)
              $ + 0.56% i915_request_retire (cycles:2)
              $ + 0.52% do_sys_poll (cycles:4)
      Signed-off-by: NJin Yao <yao.jin@linux.intel.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lkml.kernel.org/r/1540983995-20462-1-git-send-email-yao.jin@linux.intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      590ac60d
    • T
      perf stat: Handle different PMU names with common prefix · ea1fa48c
      Thomas Richter 提交于
      On s390 the CPU Measurement Facility for counters now supports
      2 PMUs named cpum_cf (CPU Measurement Facility for counters) and
      cpum_cf_diag (CPU Measurement Facility for diagnostic counters)
      for one and the same CPU.
      
      Running command
      
       [root@s35lp76 perf]# ./perf stat -e tx_c_tend \
      	 -- ~/mytests/cf-tx-events 1
      
       Measuring transactions
       TX_C_TABORT_NO_SPECIAL: 0 expected:0
       TX_C_TABORT_SPECIAL: 0 expected:0
       TX_C_TEND: 1 expected:1
       TX_NC_TABORT: 11 expected:11
       TX_NC_TEND: 1 expected:1
      
       Performance counter stats for '/root/mytests/cf-tx-events 1':
      
        2      tx_c_tend
      
            0.002120091 seconds time elapsed
      
            0.000121000 seconds user
            0.002127000 seconds sys
      
       [root@s35lp76 perf]#
      
      displays output which is unexpected (and wrong):
      
        2      tx_c_tend
      
      The test program definitely triggers only one transaction, as shown
      in line 'TX_C_TEND: 1 expected:1'.
      
      This is caused by the following call sequence:
      
      pmu_lookup() scans and installs a PMU.
      +--> pmu_aliases() parses all aliases in directory
      		.../<pmu-name>/events/* which are file names.
           +--> pmu_aliases_parse() Read each file in directory and create
                            an new alias entry. This is done with
                +--> perf_pmu__new_alias() and
      	       +--> __perf_pmu__new_alias() which also check for
      	                   identical alias names.
      
      After pmu_aliases() returns, a complete list of event names
      for this pmu has been created. Now function
      
      pmu_add_cpu_aliases()   is called to add the events listed in the json
      |                       files to the alias list of the cpu.
      +--> perf_pmu__find_map()  Returns a pointer to the json events.
      
      Now function pmu_add_cpu_aliases() scans through all events listed
      in the JSON files for this CPU.
      Each json event pmu name is compared with the current PMU being
      built up and if they mismatch, the json event is added to the
      current PMUs alias list.
      To avoid duplicate entries the following comparison is done:
      
      	if (!is_arm_pmu_core(name)) {
      	     pname = pe->pmu ? pe->pmu : "cpu";
      	     if (strncmp(pname, name, strlen(pname)))
      		     continue;
           }
      
      The culprit is the strncmp() function.
      
      Using current s390 PMU naming, the first PMU is 'cpum_cf'
      and a long list of events is added, among them 'tx_c_tend'
      
      When the second PMU named 'cpum_cf_diag' is added, only one event
      named 'CF_DIAG' is added by the pmu_aliases()  function.
      
      Now function pmu_add_cpu_aliases() is invoked for PMU 'cpum_cf_diag'.
      Since the CPUID string is the same for both PMUs, json file events
      for PMU named 'cpum_cf' are added to the PMU 'cpm_cf_diag'
      
      This happens because the strncmp() actually compares:
      
           strncmp("cpum_cf", "cpum_cf_diag", 6);
      
      The first parameter is the pmu name taken from the event in
      the json file. The second parameter is the pmu name of the PMU
      currently being built.
      They are different, but the length of the compare only tests the
      common prefix and this returns 0(true) when it should return false.
      
      Now all events for PMU cpum_cf are added to the alias list for pmu
      cpum_cf_diag.
      
      Later on in function parse_events_add_pmu() the event 'tx_c_end' is
      searched in all available PMUs and found twice, adding it two
      times to the evsel_list global variable which is the root
      of all events. This results in a counter value of 2 instead
      of 1.
      
      Output with this patch:
      
       [root@s35lp76 perf]# ./perf stat -e tx_c_tend \
      			-- ~/mytests/cf-tx-events 1
       Measuring transactions
       TX_C_TABORT_NO_SPECIAL: 0 expected:0
       TX_C_TABORT_SPECIAL: 0 expected:0
       TX_C_TEND: 1 expected:1
       TX_NC_TABORT: 11 expected:11
       TX_NC_TEND: 1 expected:1
      
       Performance counter stats for '/root/mytests/cf-tx-events 1':
      
                        1      tx_c_tend
      
            0.001815365 seconds time elapsed
      
            0.000123000 seconds user
            0.001756000 seconds sys
      
       [root@s35lp76 perf]#
      Signed-off-by: NThomas Richter <tmricht@linux.ibm.com>
      Reviewed-by: NHendrik Brueckner <brueckner@linux.ibm.com>
      Reviewed-by: NSebastien Boisvert <sboisvert@gydle.com>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
      Cc: stable@vger.kernel.org
      Fixes: 292c34c1 ("perf pmu: Fix core PMU alias list for X86 platform")
      Link: http://lkml.kernel.org/r/20181023151616.78193-1-tmricht@linux.ibm.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      ea1fa48c
    • A
      perf record: Support weak groups · cf99ad14
      Andi Kleen 提交于
      Implement a weak group fallback for 'perf record', similar to the
      existing 'perf stat' support.  This allows to use groups that might be
      longer than the available counters without failing.
      
      Before:
      
        $ perf record  -e '{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}' -a sleep 1
        Error:
        The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (cycles).
        /bin/dmesg | grep -i perf may provide additional information.
      
      After:
      
        $ ./perf record  -e '{cycles,cache-misses,cache-references,cpu_clk_unhalted.thread,cycles,cycles,cycles}:W' -a sleep 1
        WARNING: No sample_id_all support, falling back to unordered processing
        [ perf record: Woken up 3 times to write data ]
        [ perf record: Captured and wrote 8.136 MB perf.data (134069 samples) ]
      Signed-off-by: NAndi Kleen <ak@linux.intel.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Link: http://lkml.kernel.org/r/20181001195927.14211-2-andi@firstfloor.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      cf99ad14