1. 29 3月, 2019 1 次提交
    • J
      perf evsel: Fix max perf_event_attr.precise_ip detection · 4e8a5c15
      Jiri Olsa 提交于
      After a discussion with Andi, move the perf_event_attr.precise_ip
      detection for maximum precise config (via :P modifier or for default
      cycles event) to perf_evsel__open().
      
      The current detection in perf_event_attr__set_max_precise_ip() is
      tricky, because precise_ip config is specific for given event and it
      currently checks only hw cycles.
      
      We now check for valid precise_ip value right after failing
      sys_perf_event_open() for specific event, before any of the
      perf_event_attr fallback code gets executed.
      
      This way we get the proper config in perf_event_attr together with
      allowed precise_ip settings.
      
      We can see that code activity with -vv, like:
      
        $ perf record -vv ls
        ...
        ------------------------------------------------------------
        perf_event_attr:
          size                             112
          { sample_period, sample_freq }   4000
          ...
          precise_ip                       3
          sample_id_all                    1
          exclude_guest                    1
          mmap2                            1
          comm_exec                        1
          ksymbol                          1
        ------------------------------------------------------------
        sys_perf_event_open: pid 9926  cpu 0  group_fd -1  flags 0x8
        sys_perf_event_open failed, error -95
        decreasing precise_ip by one (2)
        ------------------------------------------------------------
        perf_event_attr:
          size                             112
          { sample_period, sample_freq }   4000
          ...
          precise_ip                       2
          sample_id_all                    1
          exclude_guest                    1
          mmap2                            1
          comm_exec                        1
          ksymbol                          1
        ------------------------------------------------------------
        sys_perf_event_open: pid 9926  cpu 0  group_fd -1  flags 0x8 = 4
        ...
      Suggested-by: NAndi Kleen <ak@linux.intel.com>
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Link: http://lkml.kernel.org/n/tip-dkvxxbeg7lu74155d4jhlmc9@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      4e8a5c15
  2. 21 3月, 2019 1 次提交
    • S
      perf evlist: Introduce side band thread · 657ee553
      Song Liu 提交于
      This patch introduces side band thread that captures extended
      information for events like PERF_RECORD_BPF_EVENT.
      
      This new thread uses its own evlist that uses ring buffer with very low
      watermark for lower latency.
      
      To use side band thread, we need to:
      
      1. add side band event(s) by calling perf_evlist__add_sb_event();
      2. calls perf_evlist__start_sb_thread();
      3. at the end of perf run, perf_evlist__stop_sb_thread().
      
      In the next patch, we use this thread to handle PERF_RECORD_BPF_EVENT.
      
      Committer notes:
      
      Add fix by Jiri Olsa for when te sb_tread can't get started and then at
      the end the stop_sb_thread() segfaults when joining the (non-existing)
      thread.
      
      That can happen when running 'perf top' or 'perf record' as a normal
      user, for instance.
      
      Further checks need to be done on top of this to more graciously handle
      these possible failure scenarios.
      Signed-off-by: NSong Liu <songliubraving@fb.com>
      Reviewed-by: NJiri Olsa <jolsa@kernel.org>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stanislav Fomichev <sdf@google.com>
      Link: http://lkml.kernel.org/r/20190312053051.2690567-15-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      657ee553
  3. 07 3月, 2019 1 次提交
    • J
      perf evsel: Probe for precise_ip with simple attr · 5b61adb1
      Jiri Olsa 提交于
      Currently we probe for precise_ip with user specified perf_event_attr,
      which might fail because of unsupported kernel features, which would get
      disabled during the open time anyway.
      
      Switching the probe to take place on simple hw cycles, so the following
      record sets proper precise_ip:
      
        # perf record -e cycles:P ls
        # perf evlist -v
        cycles:P: size: 112, ... precise_ip: 3, ...
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de>
      Cc: Nageswara R Sastry <nasastry@in.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
      Link: http://lkml.kernel.org/r/20190305152536.21035-7-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5b61adb1
  4. 06 2月, 2019 1 次提交
  5. 18 12月, 2018 3 次提交
  6. 21 11月, 2018 1 次提交
  7. 06 11月, 2018 1 次提交
  8. 22 10月, 2018 1 次提交
  9. 20 8月, 2018 1 次提交
  10. 22 5月, 2018 1 次提交
  11. 08 3月, 2018 1 次提交
  12. 05 3月, 2018 1 次提交
  13. 17 2月, 2018 1 次提交
  14. 15 2月, 2018 1 次提交
  15. 25 1月, 2018 1 次提交
  16. 12 1月, 2018 1 次提交
  17. 27 12月, 2017 1 次提交
  18. 06 12月, 2017 6 次提交
    • W
      perf tools: Rename 'backward' to 'overwrite' in evlist, mmap and record · 0b72d69a
      Wang Nan 提交于
      Remove the backward/forward concept to make it uniform with user
      interface (the '--overwrite' option).
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Acked-by: NNamhyung Kim <namhyung@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Cc: Mengting Zhang <zhangmengting@huawei.com>
      Link: http://lkml.kernel.org/r/20171204165107.95327-4-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      0b72d69a
    • W
      perf mmap: Fix perf backward recording · 71f566a3
      Wang Nan 提交于
      'perf record' backward recording doesn't work as we expected: it never
      overwrites when ring buffer gets full.
      
      Test:
      
      Run a busy python printing task background like this:
      
       while True:
           print 123
      
      send SIGUSR2 to perf to capture snapshot, then:
      
       # ./perf record --overwrite -e raw_syscalls:sys_enter -e raw_syscalls:sys_exit --exclude-perf -a --switch-output
       [ perf record: dump data: Woken up 1 times ]
       [ perf record: Dump perf.data.2017110101520743 ]
       [ perf record: dump data: Woken up 1 times ]
       [ perf record: Dump perf.data.2017110101521251 ]
       [ perf record: dump data: Woken up 1 times ]
       [ perf record: Dump perf.data.2017110101521692 ]
       ^C[ perf record: Woken up 1 times to write data ]
       [ perf record: Dump perf.data.2017110101521936 ]
       [ perf record: Captured and wrote 0.826 MB perf.data.<timestamp> ]
      
       # ./perf script -i ./perf.data.2017110101520743 | head -n3
                   perf  2717 [000] 12449.310785: raw_syscalls:sys_enter: NR 16 (5, 2400, 0, 59, 100, 0)
                   perf  2717 [000] 12449.310790: raw_syscalls:sys_enter: NR 7 (4112340, 2, ffffffff, 3df, 100, 0)
                 python  2545 [000] 12449.310800:  raw_syscalls:sys_exit: NR 1 = 4
       # ./perf script -i ./perf.data.2017110101521251 | head -n3
                   perf  2717 [000] 12449.310785: raw_syscalls:sys_enter: NR 16 (5, 2400, 0, 59, 100, 0)
                   perf  2717 [000] 12449.310790: raw_syscalls:sys_enter: NR 7 (4112340, 2, ffffffff, 3df, 100, 0)
                 python  2545 [000] 12449.310800:  raw_syscalls:sys_exit: NR 1 = 4
       # ./perf script -i ./perf.data.2017110101521692 | head -n3
                   perf  2717 [000] 12449.310785: raw_syscalls:sys_enter: NR 16 (5, 2400, 0, 59, 100, 0)
                   perf  2717 [000] 12449.310790: raw_syscalls:sys_enter: NR 7 (4112340, 2, ffffffff, 3df, 100, 0)
                 python  2545 [000] 12449.310800:  raw_syscalls:sys_exit: NR 1 = 4
      
      Timestamps never change, but my background task is a dead loop, can
      easily overwhelm the ring buffer.
      
      This patch fixes it by forcing unsetting PROT_WRITE for a backward ring
      buffer, so all backward ring buffers become overwrite ring buffers.
      
      Test result:
      
       # ./perf record --overwrite -e raw_syscalls:sys_enter -e raw_syscalls:sys_exit --exclude-perf -a --switch-output
       [ perf record: dump data: Woken up 1 times ]
       [ perf record: Dump perf.data.2017110101285323 ]
       [ perf record: dump data: Woken up 1 times ]
       [ perf record: Dump perf.data.2017110101290053 ]
       [ perf record: dump data: Woken up 1 times ]
       [ perf record: Dump perf.data.2017110101290446 ]
       ^C[ perf record: Woken up 1 times to write data ]
       [ perf record: Dump perf.data.2017110101290837 ]
       [ perf record: Captured and wrote 0.826 MB perf.data.<timestamp> ]
       # ./perf script -i ./perf.data.2017110101285323 | head -n3
                 python  2545 [000] 11064.268083:  raw_syscalls:sys_exit: NR 1 = 4
                 python  2545 [000] 11064.268084: raw_syscalls:sys_enter: NR 1 (1, 12cc330, 4, 7fc237280370, 7fc2373d0700, 2c7b0)
                 python  2545 [000] 11064.268086:  raw_syscalls:sys_exit: NR 1 = 4
       # ./perf script -i ./perf.data.2017110101290 | head -n3
       failed to open ./perf.data.2017110101290: No such file or directory
       # ./perf script -i ./perf.data.2017110101290053 | head -n3
                 python  2545 [000] 11071.564062: raw_syscalls:sys_enter: NR 1 (1, 12cc330, 4, 7fc237280370, 7fc2373d0700, 2c7b0)
                 python  2545 [000] 11071.564064:  raw_syscalls:sys_exit: NR 1 = 4
                 python  2545 [000] 11071.564066: raw_syscalls:sys_enter: NR 1 (1, 12cc330, 4, 7fc237280370, 7fc2373d0700, 2c7b0)
       # ./perf script -i ./perf.data.2017110101290 | head -n3
       perf.data.2017110101290053  perf.data.2017110101290446  perf.data.2017110101290837
       # ./perf script -i ./perf.data.2017110101290446 | head -n3
                   sshd  1321 [000] 11075.499473:  raw_syscalls:sys_exit: NR 14 = 0
                   sshd  1321 [000] 11075.499474: raw_syscalls:sys_enter: NR 14 (2, 7ffe98899490, 0, 8, 0, 3000)
                   sshd  1321 [000] 11075.499474:  raw_syscalls:sys_exit: NR 14 = 0
       # ./perf script -i ./perf.data.2017110101290837 | head -n3
                 python  2545 [000] 11079.280844:  raw_syscalls:sys_exit: NR 1 = 4
                 python  2545 [000] 11079.280847: raw_syscalls:sys_enter: NR 1 (1, 12cc330, 4, 7fc237280370, 7fc2373d0700, 2c7b0)
                 python  2545 [000] 11079.280850:  raw_syscalls:sys_exit: NR 1 = 4
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Acked-by: NNamhyung Kim <namhyung@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Cc: Mengting Zhang <zhangmengting@huawei.com>
      Link: http://lkml.kernel.org/r/20171204165107.95327-2-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      71f566a3
    • W
      perf mmap: Remove overwrite and check_messup from mmap read · 8eb7a1fe
      Wang Nan 提交于
      All perf_mmap__read_forward() read from read-write ring buffer, so no
      need check_messup. Reading from backward ring buffer doesn't require
      check_messup because it never mess up. Cleanup arguments lists.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Acked-by: NNamhyung Kim <namhyung@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Link: http://lkml.kernel.org/r/20171203020044.81680-6-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      8eb7a1fe
    • W
      perf evlist: Remove evlist->overwrite · 144b9a4f
      Wang Nan 提交于
      evlist->overwrite is set to false in all users. It can be removed.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Acked-by: NNamhyung Kim <namhyung@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Link: http://lkml.kernel.org/r/20171203020044.81680-4-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      144b9a4f
    • W
      perf evlist: Remove 'overwrite' parameter from perf_evlist__mmap_ex · 7a276ff6
      Wang Nan 提交于
      All users of perf_evlist__mmap_ex set !overwrite. Remove it from its
      arguments list.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Acked-by: NNamhyung Kim <namhyung@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Link: http://lkml.kernel.org/r/20171203020044.81680-3-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7a276ff6
    • W
      perf evlist: Remove 'overwrite' parameter from perf_evlist__mmap · f74b9d3a
      Wang Nan 提交于
      Now all perf_evlist__mmap's users doesn't set 'overwrite'. Remove it
      from arguments list.
      Signed-off-by: NWang Nan <wangnan0@huawei.com>
      Acked-by: NNamhyung Kim <namhyung@kernel.org>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Kan Liang <kan.liang@intel.com>
      Link: http://lkml.kernel.org/r/20171203020044.81680-2-wangnan0@huawei.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f74b9d3a
  19. 29 11月, 2017 2 次提交
    • A
      perf evlist: Add helper to check if attr.exclude_kernel is set in all evsels · 5b0d1cb4
      Arnaldo Carvalho de Melo 提交于
      The warning about kptr_restrict needs to be emitted only when it is set
      and we ask for kernel space samples, so add a helper to help with that.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: David Ahern <dsahern@gmail.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Wang Nan <wangnan0@huawei.com>
      Link: http://lkml.kernel.org/n/tip-fh7drty6yljei9gxxzer6eup@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      5b0d1cb4
    • A
      perf evlist: Set the correct idx when adding dummy events · 555b4ec4
      Arnaldo Carvalho de Melo 提交于
      The evsel->idx field is used mainly to access the right bucket in
      per-event arrays such as the annotation ones, but also to set
      evsel->tracking, that in turn will decide what of the events will ask
      for PERF_RECORD_{MMAP,COMM,EXEC} to be generated, i.e. which
      perf_event_attr will have its mmap, etc fields set.
      
      When we were adding the "dummy" event using perf_evlist__add_dummy() we
      were not setting it correctly, which could result in multiple tracking
      events.
      
      Now that I'll try using a dummy event to be the tracking one when using
      'perf record --delay', i.e. when we process the --delay
      setting we may already have the evlist set up, like with:
      
        perf record -e cycles,instructions --delay 1000 ./workload
      
      We will need to add a "dummy" event, then reset evsel->tracking for the
      first event, "cycles", and set it instead to the dummy one, and also
      setting its attr.enable_on_exec, so that we get the PERF_RECORD_MMAP,
      etc metadata events while waiting to enable the explicitely requested
      events, so lets get this straight and set the right evsel->idx.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Bram Stolk <b.stolk@gmail.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: http://lkml.kernel.org/n/tip-nrdfchshqxf7diszhxcecqb9@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      555b4ec4
  20. 17 11月, 2017 2 次提交
  21. 13 11月, 2017 1 次提交
    • A
      perf evlist: Set the correct idx when adding dummy events · 640d5175
      Arnaldo Carvalho de Melo 提交于
      The evsel->idx field is used mainly to access the right bucket in
      per-event arrays such as the annotation ones, but also to set
      evsel->tracking, that in turn will decide what of the events will ask
      for PERF_RECORD_{MMAP,COMM,EXEC} to be generated, i.e. which
      perf_event_attr will have its mmap, etc fields set.
      
      When we were adding the "dummy" event using perf_evlist__add_dummy() we
      were not setting it correctly, which could result in multiple tracking
      events.
      
      Now that I'll try using a dummy event to be the tracking one when using
      'perf record --delay', i.e. when we process the --delay
      setting we may already have the evlist set up, like with:
      
        perf record -e cycles,instructions --delay 1000 ./workload
      
      We will need to add a "dummy" event, then reset evsel->tracking for the
      first event, "cycles", and set it instead to the dummy one, and also
      setting its attr.enable_on_exec, so that we get the PERF_RECORD_MMAP,
      etc metadata events while waiting to enable the explicitely requested
      events, so lets get this straight and set the right evsel->idx.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Bram Stolk <b.stolk@gmail.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: http://lkml.kernel.org/n/tip-nrdfchshqxf7diszhxcecqb9@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      640d5175
  22. 23 10月, 2017 1 次提交
  23. 22 8月, 2017 1 次提交
    • A
      perf evsel: Fix buffer overflow while freeing events · 475fb533
      Andi Kleen 提交于
      Fix buffer overflow for:
      
        % perf stat -e msr/tsc/,cstate_core/c7-residency/ true
      
      that causes glibc free list corruption. For some reason it doesn't
      trigger in valgrind, but it is visible in AS:
      
        =================================================================
        ==32681==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000003f5c at pc 0x0000005671ef bp 0x7ffdaaac9ac0 sp 0x7ffdaaac9ab0
        READ of size 4 at 0x603000003f5c thread T0
          #0 0x5671ee in perf_evsel__close_fd util/evsel.c:1196
          #1 0x56c57a in perf_evsel__close util/evsel.c:1717
          #2 0x55ed5f in perf_evlist__close util/evlist.c:1631
          #3 0x4647e1 in __run_perf_stat /home/ak/hle/linux-hle-2.6/tools/perf/builtin-stat.c:749
          #4 0x4648e3 in run_perf_stat /home/ak/hle/linux-hle-2.6/tools/perf/builtin-stat.c:767
          #5 0x46e1bc in cmd_stat /home/ak/hle/linux-hle-2.6/tools/perf/builtin-stat.c:2785
          #6 0x52f83d in run_builtin /home/ak/hle/linux-hle-2.6/tools/perf/perf.c:296
          #7 0x52fd49 in handle_internal_command /home/ak/hle/linux-hle-2.6/tools/perf/perf.c:348
          #8 0x5300de in run_argv /home/ak/hle/linux-hle-2.6/tools/perf/perf.c:392
          #9 0x5308f3 in main /home/ak/hle/linux-hle-2.6/tools/perf/perf.c:530
          #10 0x7f0672d13400 in __libc_start_main (/lib64/libc.so.6+0x20400)
          #11 0x428419 in _start (/home/ak/hle/obj-perf/perf+0x428419)
      
        0x603000003f5c is located 0 bytes to the right of 28-byte region [0x603000003f40,0x603000003f5c)
        allocated by thread T0 here:
          #0 0x7f0675139020 in calloc (/lib64/libasan.so.3+0xc7020)
          #1 0x648a2d in zalloc util/util.h:23
          #2 0x648a88 in xyarray__new util/xyarray.c:9
          #3 0x566419 in perf_evsel__alloc_fd util/evsel.c:1039
          #4 0x56b427 in perf_evsel__open util/evsel.c:1529
          #5 0x56c620 in perf_evsel__open_per_thread util/evsel.c:1730
          #6 0x461dea in create_perf_stat_counter /home/ak/hle/linux-hle-2.6/tools/perf/builtin-stat.c:263
          #7 0x4637d7 in __run_perf_stat /home/ak/hle/linux-hle-2.6/tools/perf/builtin-stat.c:600
          #8 0x4648e3 in run_perf_stat /home/ak/hle/linux-hle-2.6/tools/perf/builtin-stat.c:767
          #9 0x46e1bc in cmd_stat /home/ak/hle/linux-hle-2.6/tools/perf/builtin-stat.c:2785
          #10 0x52f83d in run_builtin /home/ak/hle/linux-hle-2.6/tools/perf/perf.c:296
          #11 0x52fd49 in handle_internal_command /home/ak/hle/linux-hle-2.6/tools/perf/perf.c:348
          #12 0x5300de in run_argv /home/ak/hle/linux-hle-2.6/tools/perf/perf.c:392
          #13 0x5308f3 in main /home/ak/hle/linux-hle-2.6/tools/perf/perf.c:530
          #14 0x7f0672d13400 in __libc_start_main (/lib64/libc.so.6+0x20400)
      
      The event is allocated with cpus == 1, but freed with cpus == real number
      When the evsel close function walks the file descriptors it exceeds the
      fd xyarray boundaries and reads random memory.
      
      v2:
      
      Now that xyarrays save their original dimensions we can use these to
      iterate the two dimensional fd arrays. Fix some users (close, ioctl) in
      evsel.c to use these fields directly. This allows simplifying the code
      and dropping quite a few function arguments. Adjust all callers by
      removing the unneeded arguments.
      
      The actual perf event reading still uses the original values from the
      evsel list.
      Signed-off-by: NAndi Kleen <ak@linux.intel.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Link: http://lkml.kernel.org/r/20170811232634.30465-2-andi@firstfloor.org
      [ Fix up xy_max_[xy]() -> xyarray__max_[xy]() ]
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      475fb533
  24. 19 7月, 2017 2 次提交
  25. 25 4月, 2017 1 次提交
  26. 21 4月, 2017 2 次提交
  27. 20 4月, 2017 2 次提交
  28. 04 3月, 2017 1 次提交