1. 07 3月, 2019 17 次提交
  2. 06 3月, 2019 2 次提交
    • Y
      perf clang: Remove needless extra semicolon · a53837a5
      Yang Wei 提交于
      Delete a superfluous semicolon in getBPFObjectFromModule().
      Signed-off-by: NYang Wei <yang.wei9@zte.com.cn>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Yang Wei <albin_yang@163.com>
      Link: http://lkml.kernel.org/r/1551710174-3349-1-git-send-email-albin_yang@163.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      a53837a5
    • A
      perf bpf: Automatically add BTF ELF markers · 3163613c
      Arnaldo Carvalho de Melo 提交于
      The libbpf loader expects that some __btf_map_<MAP_NAME> structs be in
      place with the keys and values types of maps so that one can store the
      struct definitions and have them sent to the kernel via sys_bpf(fd, cmd
      = BTF_LOAD) and then later be retrievable via sys_bpf(fd, cmd =
      BPF_OBJ_GET_INFO_BY_FD) for use by tools such as 'bpftool map dump id
      MAP_ID'.
      
      Since we already have this for defining maps in 'perf trace' BPF events:
      
         bpf_map(name, _type, type_key, type_val, _max_entries)
      
      As used in the tools/perf/examples/bpf/augmented_raw_syscalls.c:
      
       --- 8< ---
      
      struct syscall {
              bool    enabled;
      };
      
      bpf_map(syscalls, ARRAY, int, struct syscall, 512);
      
       --- 8< ---
      
      All we need is to get all that already available info, piggyback on the
      'bpf_map' define in tools/perf/include/bpf/bpf.h, that is included by
      'perf trace' BPF programs and do that without requiring changes to the
      BPF programs already defining maps using 'bpf_map()'.
      
      So this is what we have before this patch:
      
      1) With this in ~/.perfconfig to dump .c events as .o, aka save a copy
         so that we can use the .o later as a pre-compiled BPF bytecode:
      
        # grep '\[llvm\]' -A2 ~/.perfconfig
        [llvm]
      	dump-obj = true
      	clang-opt = -g
      
        #
        # clang --version
        clang version 9.0.0 (https://git.llvm.org/git/clang.git/ 7906282d3afec5dfdc2b27943fd6c0309086c507) (https://git.llvm.org/git/llvm.git/ a1b5de1ff8ae8bc79dc8e86e1f82565229bd0500)
        Target: x86_64-unknown-linux-gnu
        Thread model: posix
        InstalledDir: /opt/llvm/bin
      
      2) Note the -g there so that we get clang to generate debuginfo, and
         since the target is 'bpf' it will generate the BTF info in this
         clang version (9.0).
      
      3) Run a simple 'perf record' specifiying as an event the augmented_raw_syscalls.c
         source code:
      
        # perf record -e /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c sleep 1
        LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        [ perf record: Woken up 1 times to write data ]
        [ perf record: Captured and wrote 0.025 MB perf.data ]
      
        # file /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o: ELF 64-bit LSB relocatable, eBPF, version 1 (SYSV), with debug_info, not stripped
      
      4) Look at the BTF structs encoded in it:
      
        # pahole -F btf --sizes /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        syscall_enter_args	64	0
        augmented_filename	264	0
        syscall	1	0
        syscall_exit_args	24	0
        bpf_map	28	0
        #
        # pahole -F btf -C syscalls /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        # pahole -F btf -C syscall /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        struct syscall {
      	  bool                       enabled;              /*     0     1 */
      
      	  /* size: 1, cachelines: 1, members: 1 */
      	  /* last cacheline: 1 bytes */
        };
        #
      
      5) Ok, with just this we don't have the markers expected by the libbpf
         loader and when we run with this BPF bytecode, because we have:
      
        # grep '\[trace\]' -A1 ~/.perfconfig
        [trace]
      	add_events = /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        #
      
      6) Lets do a 'perf trace' system wide session using this BPF program:
      
         # perf trace -e *mmsg,open*
        Cache2 I/O/6885 openat(AT_FDCWD, "/home/acme/.cache/mozilla/firefox/ina67tev.default/cache2/entries/BA220AB2914006A7AE96D27BE6EA13DD77519FCA", O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR) = 106
        Cache2 I/O/6885 openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 121
        Cache2 I/O/6885 openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 121
        Cache2 I/O/6885 openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 121
        Cache2 I/O/6885 openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 121
        DNS Res~ver #3/23340 openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 106
        DNS Res~ver #3/23340 sendmmsg(106<socket:[3482690]>, 0x7f252f1fcaf0, 2, MSG_NOSIGNAL) = 2
        Cache2 I/O/6885 openat(AT_FDCWD, "/home/acme/.cache/mozilla/firefox/ina67tev.default/cache2/entries/BA220AB2914006A7AE96D27BE6EA13DD77519FCA", O_RDWR) = 106
        lighttpd/18915 openat(AT_FDCWD, "/proc/loadavg", O_RDONLY) = 12
      
      7) While it runs lets see the maps that 'perf trace' + libbpf's BPF
        loader loaded into the kernel via sys_bpf(fd, BPF_BTF_LOAD, ...):
      
        # bpftool map list | tail -6
        149: perf_event_array  name __augmented_sys  flags 0x0
      	  key 4B  value 4B  max_entries 8  memlock 4096B
        150: array  name syscalls  flags 0x0
      	  key 4B  value 1B  max_entries 512  memlock 8192B
        151: hash  name pids_filtered  flags 0x0
      	  key 4B  value 1B  max_entries 64  memlock 8192B
        #
      
      8) Dump the "pids_filtered", map, that will have one entry per PID that
         'perf trace' wants filtered, which includes its own, to avoid a
         tracing feedback loop (perf trace shows the syscalls it does which
         generates more syscalls that it has to show that...), it also
         auto-filters the 'gnome-terminal' and 'sshd' parent PIDs, for the
         same reason:
      
        # bpftool map dump id 151
        key: a5 0c 00 00  value: 01
        key: 14 63 00 00  value: 01
        Found 2 elements
        #
      
      9) Since there is no BTF info available, it does a generic hex dump :-\
      
      10) Now, with this patch applied, we'll do steps 3 to 6 again and look
          with pahole if there are extra structs encoded in BTF:
      
        # pahole -F btf --sizes /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        syscall_enter_args	64	0
        augmented_filename	264	0
        syscall	1	0
        syscall_exit_args	24	0
        bpf_map	28	0
        ____btf_map___augmented_syscalls__	8	0
        ____btf_map_syscalls	8	0
        ____btf_map_pids_filtered	8	0
        #
      
      11) Yes, those __btf_map_ + the map names, lets see how they look like:
      
        # pahole -F btf -C ____btf_map_syscalls /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
        struct ____btf_map_syscalls {
      	  int                        key;                  /*     0     4 */
      	  struct syscall             value;                /*     4     1 */
      
      	  /* size: 8, cachelines: 1, members: 2 */
      	  /* padding: 3 */
      	  /* last cacheline: 8 bytes */
        };
        #
      
      12) Lets repeat step 7 to get the new map ids:
      
        # bpftool map list | tail -6
        155: perf_event_array  name __augmented_sys  flags 0x0
      	  key 4B  value 4B  max_entries 8  memlock 4096B
        156: array  name syscalls  flags 0x0
      	  key 4B  value 1B  max_entries 512  memlock 8192B
        157: hash  name pids_filtered  flags 0x0
      	  key 4B  value 1B  max_entries 64  memlock 8192B
        #
      
      13) And finally lets dump the 'pids_filtered':
      
        # bpftool map dump id 157
        [{
              "key": 3237,
              "value": true
          },{
              "key": 26435,
              "value": true
          }
        ]
        #
      
      Looks much better! BTF info was used to interpret the key as an integer
      and the value as a struct with just one boolean member, so to make it
      more compact, show just the 'true' value where we saw '01'.
      
      Now to make 'perf trace --dump-map' to use BTF!
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexei Starovoitov <ast@fb.com>
      Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Wang Nan <wangnan0@huawei.com>
      Cc: Yonghong Song <yhs@fb.com>
      Link: https://lkml.kernel.org/n/tip-ybuf9wpkm30xk28iq7jbwb40@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      3163613c
  3. 02 3月, 2019 11 次提交
  4. 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
    • J
      tools: libbpf: add a correctly named define for map iteration · f74a53d9
      Jakub Kicinski 提交于
      For historical reasons the helper to loop over maps in an object
      is called bpf_map__for_each while it really should be called
      bpf_object__for_each_map.  Rename and add a correctly named
      define for backward compatibility.
      
      Switch all in-tree users to the correct name (Quentin).
      Signed-off-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Reviewed-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      f74a53d9
    • 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
  5. 26 2月, 2019 7 次提交