1. 02 3月, 2019 1 次提交
  2. 01 3月, 2019 3 次提交
    • J
      perf time-utils: Refactor time range parsing code · 284c4e18
      Jin Yao 提交于
      Jiri points out that we don't need any time checking and time string
      parsing if the --time option is not set. That makes sense.
      
      This patch refactors the time range parsing code, move the duplicated
      code from perf report and perf script to time_utils and check if --time
      option is set before parsing the time string. This patch is no logic
      change expected. So the usage of --time is same as before.
      
      For example:
      
      Select the first and second 10% time slices:
        perf report --time 10%/1,10%/2
        perf script --time 10%/1,10%/2
      
      Select the slices from 0% to 10% and from 30% to 40%:
        perf report --time 0%-10%,30%-40%
        perf script --time 0%-10%,30%-40%
      
      Select the time slices from timestamp 3971 to 3973
        perf report --time 3971,3973
        perf script --time 3971,3973
      
      Committer testing:
      
      Using the above examples, check before and after to see if it remains
      the same:
      
        $ perf record -F 10000 -- find . -name "*.[ch]" -exec cat {} + > /dev/null
        [ perf record: Woken up 3 times to write data ]
        [ perf record: Captured and wrote 1.626 MB perf.data (42392 samples) ]
        $
        $ perf report --time 10%/1,10%/2 > /tmp/report.before.1
        $ perf script --time 10%/1,10%/2 > /tmp/script.before.1
        $ perf report --time 0%-10%,30%-40% > /tmp/report.before.2
        $ perf script --time 0%-10%,30%-40% > /tmp/script.before.2
        $ perf report --time 180457.375844,180457.377717 > /tmp/report.before.3
        $ perf script --time 180457.375844,180457.377717 > /tmp/script.before.3
      
      For example, the 3rd test produces this slice:
      
        $ cat /tmp/script.before.3
              cat  3147 180457.375844:   2143 cycles:uppp:      7f79362590d9 cfree@GLIBC_2.2.5+0x9 (/usr/lib64/libc-2.28.so)
              cat  3147 180457.375986:   2245 cycles:uppp:      558b70f3d86e [unknown] (/usr/bin/cat)
              cat  3147 180457.376012:   2164 cycles:uppp:      7f7936257430 _int_malloc+0x8c0 (/usr/lib64/libc-2.28.so)
              cat  3147 180457.376140:   2921 cycles:uppp:      558b70f3a554 [unknown] (/usr/bin/cat)
              cat  3147 180457.376296:   2844 cycles:uppp:      7f7936258abe malloc+0x4e (/usr/lib64/libc-2.28.so)
              cat  3147 180457.376431:   2717 cycles:uppp:      558b70f3b0ca [unknown] (/usr/bin/cat)
              cat  3147 180457.376667:   2630 cycles:uppp:      558b70f3d86e [unknown] (/usr/bin/cat)
              cat  3147 180457.376795:   2442 cycles:uppp:      7f79362bff55 read+0x15 (/usr/lib64/libc-2.28.so)
              cat  3147 180457.376927:   2376 cycles:uppp:  ffffffff9aa00163 [unknown] ([unknown])
              cat  3147 180457.376954:   2307 cycles:uppp:      7f7936257438 _int_malloc+0x8c8 (/usr/lib64/libc-2.28.so)
              cat  3147 180457.377116:   3091 cycles:uppp:      7f7936258a70 malloc+0x0 (/usr/lib64/libc-2.28.so)
              cat  3147 180457.377362:   2945 cycles:uppp:      558b70f3a3b0 [unknown] (/usr/bin/cat)
              cat  3147 180457.377517:   2727 cycles:uppp:      558b70f3a9aa [unknown] (/usr/bin/cat)
        $
      
      Install 'coreutils-debuginfo' to see cat's guts (symbols), but then, the
      above chunk translates into this 'perf report' output:
      
        $ cat /tmp/report.before.3
        # To display the perf.data header info, please use --header/--header-only options.
        #
        #
        # Total Lost Samples: 0
        #
        # Samples: 13  of event 'cycles:uppp' (time slices: 180457.375844,180457.377717)
        # Event count (approx.): 33552
        #
        # Overhead  Command  Shared Object     Symbol
        # ........  .......  ................  ......................
        #
            17.69%  cat      libc-2.28.so      [.] malloc
            14.53%  cat      cat               [.] 0x000000000000586e
            13.33%  cat      libc-2.28.so      [.] _int_malloc
             8.78%  cat      cat               [.] 0x00000000000023b0
             8.71%  cat      cat               [.] 0x0000000000002554
             8.13%  cat      cat               [.] 0x00000000000029aa
             8.10%  cat      cat               [.] 0x00000000000030ca
             7.28%  cat      libc-2.28.so      [.] read
             7.08%  cat      [unknown]         [k] 0xffffffff9aa00163
             6.39%  cat      libc-2.28.so      [.] cfree@GLIBC_2.2.5
      
        #
        # (Tip: Order by the overhead of source file name and line number: perf report -s srcline)
        #
        $
      
      Now lets see after applying this patch, nothing should change:
      
        $ perf report --time 10%/1,10%/2 > /tmp/report.after.1
        $ perf script --time 10%/1,10%/2 > /tmp/script.after.1
        $ perf report --time 0%-10%,30%-40% > /tmp/report.after.2
        $ perf script --time 0%-10%,30%-40% > /tmp/script.after.2
        $ perf report --time 180457.375844,180457.377717 > /tmp/report.after.3
        $ perf script --time 180457.375844,180457.377717 > /tmp/script.after.3
        $ diff -u /tmp/report.before.1 /tmp/report.after.1
        $ diff -u /tmp/script.before.1 /tmp/script.after.1
        $ diff -u /tmp/report.before.2 /tmp/report.after.2
        --- /tmp/report.before.2	2019-03-01 11:01:53.526094883 -0300
        +++ /tmp/report.after.2	2019-03-01 11:09:18.231770467 -0300
        @@ -352,5 +352,5 @@
      
         #
        -# (Tip: Generate a script for your data: perf script -g <lang>)
        +# (Tip: Treat branches as callchains: perf report --branch-history)
         #
        $ diff -u /tmp/script.before.2 /tmp/script.after.2
        $ diff -u /tmp/report.before.3 /tmp/report.after.3
        --- /tmp/report.before.3	2019-03-01 11:03:08.890045588 -0300
        +++ /tmp/report.after.3	2019-03-01 11:09:40.660224002 -0300
        @@ -22,5 +22,5 @@
      
         #
        -# (Tip: Order by the overhead of source file name and line number: perf report -s srcline)
        +# (Tip: List events using substring match: perf list <keyword>)
         #
        $ diff -u /tmp/script.before.3 /tmp/script.after.3
        $
      
      Cool, just the 'perf report' tips changed, QED.
      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: Jin Yao <yao.jin@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/1551435186-6008-1-git-send-email-yao.jin@linux.intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      284c4e18
    • T
      tools lib traceevent: Fix buffer overflow in arg_eval · 7c5b019e
      Tony Jones 提交于
      Fix buffer overflow observed when running perf test.
      
      The overflow is when trying to evaluate "1ULL << (64 - 1)" which is
      resulting in -9223372036854775808 which overflows the 20 character
      buffer.
      
      If is possible this bug has been reported before but I still don't see
      any fix checked in:
      
      See: https://www.spinics.net/lists/linux-perf-users/msg07714.htmlReported-by: NMichael Sartain <mikesart@fastmail.com>
      Reported-by: NMathias Krause <minipli@googlemail.com>
      Signed-off-by: NTony Jones <tonyj@suse.de>
      Acked-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Fixes: f7d82350 ("tools/events: Add files to create libtraceevent.a")
      Link: http://lkml.kernel.org/r/20190228015532.8941-1-tonyj@suse.deSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      7c5b019e
    • A
      perf probe: Clarify error message about not finding kernel modules debuginfo · 4d6101f5
      Arnaldo Carvalho de Melo 提交于
      'perf probe' supports using just the kernel module name, but that will
      work only when the module is loaded, or using the full pathname to the
      file with the DWARF debug info, but the warning was cryptic:
      
      Before:
      
        # perf probe -m cls_flower -L fl_change
        Failed to find the path for cls_flower: No such file or directory
          Error: Failed to show lines.
        #
      
      After:
      
        # perf probe -m cls_flower -L fl_change
        Module cls_flower is not loaded, please specify its full path name.
          Error: Failed to show lines.
        # perf probe -m /lib/modules/5.0.0-rc7+/kernel/net/sched/cls_flower.ko -L fl_change | head -7
        <fl_change@/home/acme/git/linux/net/sched/cls_flower.c:0>
              0  static int fl_change(struct net *net, struct sk_buff *in_skb,
               		       struct tcf_proto *tp, unsigned long base,
               		       u32 handle, struct nlattr **tca,
               		       void **arg, bool ovr, struct netlink_ext_ack *extack)
              4  {
              5  	struct cls_fl_head *head = rtnl_dereference(tp->root);
        #
      
      The behaviour doesn't change when the module is loaded:
      
        # modprobe cls_flower
        # perf probe -m cls_flower -L fl_change | head -7
        <fl_change@/home/acme/git/linux/net/sched/cls_flower.c:0>
              0  static int fl_change(struct net *net, struct sk_buff *in_skb,
                                     struct tcf_proto *tp, unsigned long base,
                                     u32 handle, struct nlattr **tca,
                                     void **arg, bool ovr, struct netlink_ext_ack *extack)
              4  {
              5         struct cls_fl_head *head = rtnl_dereference(tp->root);
        #
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Marcelo Ricardo Leitner <mleitner@redhat.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-q4njvk9mshra00jacqjbzfn5@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      4d6101f5
  3. 26 2月, 2019 10 次提交
  4. 25 2月, 2019 9 次提交
  5. 24 2月, 2019 1 次提交
  6. 23 2月, 2019 14 次提交
  7. 22 2月, 2019 2 次提交
    • A
      bpf, lpm: fix lookup bug in map_delete_elem · 7c0cdf0b
      Alban Crequy 提交于
      trie_delete_elem() was deleting an entry even though it was not matching
      if the prefixlen was correct. This patch adds a check on matchlen.
      
      Reproducer:
      
      $ sudo bpftool map create /sys/fs/bpf/mylpm type lpm_trie key 8 value 1 entries 128 name mylpm flags 1
      $ sudo bpftool map update pinned /sys/fs/bpf/mylpm key hex 10 00 00 00 aa bb cc dd value hex 01
      $ sudo bpftool map dump pinned /sys/fs/bpf/mylpm
      key: 10 00 00 00 aa bb cc dd  value: 01
      Found 1 element
      $ sudo bpftool map delete pinned /sys/fs/bpf/mylpm key hex 10 00 00 00 ff ff ff ff
      $ echo $?
      0
      $ sudo bpftool map dump pinned /sys/fs/bpf/mylpm
      Found 0 elements
      
      A similar reproducer is added in the selftests.
      
      Without the patch:
      
      $ sudo ./tools/testing/selftests/bpf/test_lpm_map
      test_lpm_map: test_lpm_map.c:485: test_lpm_delete: Assertion `bpf_map_delete_elem(map_fd, key) == -1 && errno == ENOENT' failed.
      Aborted
      
      With the patch: test_lpm_map runs without errors.
      
      Fixes: e454cf59 ("bpf: Implement map_delete_elem for BPF_MAP_TYPE_LPM_TRIE")
      Cc: Craig Gallek <kraig@google.com>
      Signed-off-by: NAlban Crequy <alban@kinvolk.io>
      Acked-by: NCraig Gallek <kraig@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      7c0cdf0b
    • A
      perf thread-stack: Improve thread_stack__no_call_return() · 1f35cd65
      Adrian Hunter 提交于
      Improve thread_stack__no_call_return() to better handle 'returns' that
      do not match the stack i.e. 'no call'. See code comments for details.
      The example below shows how retpolines are affected:
      
      Example:
      
        $ cat simple-retpoline.c
        __attribute__((noinline)) int bar(void)
        {
                return -1;
        }
      
        int foo(void)
        {
                return bar() + 1;
        }
      
        __attribute__((indirect_branch("thunk"))) int main()
        {
                int (*volatile fn)(void) = foo;
      
                fn();
                return fn();
        }
        $ gcc -ggdb3 -Wall -Wextra -O2 -o simple-retpoline simple-retpoline.c
        $ objdump -d simple-retpoline
        <SNIP>
        0000000000001040 <main>:
            1040:       48 83 ec 18             sub    $0x18,%rsp
            1044:       48 8d 05 25 01 00 00    lea    0x125(%rip),%rax        # 1170 <foo>
            104b:       48 89 44 24 08          mov    %rax,0x8(%rsp)
            1050:       48 8b 44 24 08          mov    0x8(%rsp),%rax
            1055:       e8 1f 01 00 00          callq  1179 <__x86_indirect_thunk_rax>
            105a:       48 8b 44 24 08          mov    0x8(%rsp),%rax
            105f:       48 83 c4 18             add    $0x18,%rsp
            1063:       e9 11 01 00 00          jmpq   1179 <__x86_indirect_thunk_rax>
        <SNIP>
        0000000000001160 <bar>:
            1160:       b8 ff ff ff ff          mov    $0xffffffff,%eax
            1165:       c3                      retq
        <SNIP>
        0000000000001170 <foo>:
            1170:       e8 eb ff ff ff          callq  1160 <bar>
            1175:       83 c0 01                add    $0x1,%eax
            1178:       c3                      retq
        0000000000001179 <__x86_indirect_thunk_rax>:
            1179:       e8 07 00 00 00          callq  1185 <__x86_indirect_thunk_rax+0xc>
            117e:       f3 90                   pause
            1180:       0f ae e8                lfence
            1183:       eb f9                   jmp    117e <__x86_indirect_thunk_rax+0x5>
            1185:       48 89 04 24             mov    %rax,(%rsp)
            1189:       c3                      retq
        <SNIP>
        $ perf record -o simple-retpoline.perf.data -e intel_pt/cyc/u ./simple-retpoline
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0,017 MB simple-retpoline.perf.data ]
        $ perf script -i simple-retpoline.perf.data --itrace=be -s ~/libexec/perf-core/scripts/python/export-to-sqlite.py simple-retpoline.db branches calls
        2019-01-08 14:03:37.851655 Creating database...
        2019-01-08 14:03:37.863256 Writing records...
        2019-01-08 14:03:38.069750 Adding indexes
        2019-01-08 14:03:38.078799 Done
        $ ~/libexec/perf-core/scripts/python/exported-sql-viewer.py simple-retpoline.db
      
      Before:
      
          main
              -> __x86_indirect_thunk_rax
                  -> __x86_indirect_thunk_rax
                      -> __x86_indirect_thunk_rax
                          -> bar
      
      After:
      
          main
              -> __x86_indirect_thunk_rax
                  -> __x86_indirect_thunk_rax
                      -> foo
                          -> bar
      
      Committer testing:
      
      Chose "Reports", Then "Context-Sensitive Call Graph" and then go on
      expanding:
      
      Before:
      
      simple-retpolin
         PID:PID
            _start
               _start
                  __libc_start_main
                     main
                         __x86_indirect_thunk_rax
                            __x86_indirect_thunk_rax
                            bar
      
      After:
      
      Remove the "simple.retpoline.db" file, run again the 'perf script' line
      to regenerate the .db file and run the exported-sql-viewer.py again to
      get the same all the way to 'main', then, from there, including 'main':
      
                     main
                         __x86_indirect_thunk_rax
                             __x86_indirect_thunk_rax
                                 foo
                                     bar
      Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Acked-by: NJiri Olsa <jolsa@kernel.org>
      Link: http://lkml.kernel.org/r/20190109091835.5570-6-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1f35cd65