1. 20 5月, 2022 1 次提交
    • A
      perf build: Fix check for btf__load_from_kernel_by_id() in libbpf · 0ae065a5
      Arnaldo Carvalho de Melo 提交于
      Avi Kivity reported a problem where the __weak
      btf__load_from_kernel_by_id() in tools/perf/util/bpf-event.c was being
      used and it called btf__get_from_id() in tools/lib/bpf/btf.c that in
      turn called back to btf__load_from_kernel_by_id(), resulting in an
      endless loop.
      
      Fix this by adding a feature test to check if
      btf__load_from_kernel_by_id() is available when building perf with
      LIBBPF_DYNAMIC=1, and if not then provide the fallback to the old
      btf__get_from_id(), that doesn't call back to btf__load_from_kernel_by_id()
      since at that time it didn't exist at all.
      
      Tested on Fedora 35 where we have libbpf-devel 0.4.0 with LIBBPF_DYNAMIC
      where we don't have btf__load_from_kernel_by_id() and thus its feature
      test fail, not defining HAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID:
      
        $ cat /tmp/build/perf-urgent/feature/test-libbpf-btf__load_from_kernel_by_id.make.output
        test-libbpf-btf__load_from_kernel_by_id.c: In function ‘main’:
        test-libbpf-btf__load_from_kernel_by_id.c:6:16: error: implicit declaration of function ‘btf__load_from_kernel_by_id’ [-Werror=implicit-function-declaration]
            6 |         return btf__load_from_kernel_by_id(20151128, NULL);
              |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
        cc1: all warnings being treated as errors
        $
      
        $ nm /tmp/build/perf-urgent/perf | grep btf__load_from_kernel_by_id
        00000000005ba180 T btf__load_from_kernel_by_id
        $
      
        $ objdump --disassemble=btf__load_from_kernel_by_id -S /tmp/build/perf-urgent/perf
      
        /tmp/build/perf-urgent/perf:     file format elf64-x86-64
        <SNIP>
        00000000005ba180 <btf__load_from_kernel_by_id>:
        #include "record.h"
        #include "util/synthetic-events.h"
      
        #ifndef HAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
        struct btf *btf__load_from_kernel_by_id(__u32 id)
        {
          5ba180:	55                   	push   %rbp
          5ba181:	48 89 e5             	mov    %rsp,%rbp
          5ba184:	48 83 ec 10          	sub    $0x10,%rsp
          5ba188:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
          5ba18f:	00 00
          5ba191:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
          5ba195:	31 c0                	xor    %eax,%eax
               struct btf *btf;
        #pragma GCC diagnostic push
        #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
               int err = btf__get_from_id(id, &btf);
          5ba197:	48 8d 75 f0          	lea    -0x10(%rbp),%rsi
          5ba19b:	e8 a0 57 e5 ff       	call   40f940 <btf__get_from_id@plt>
          5ba1a0:	89 c2                	mov    %eax,%edx
        #pragma GCC diagnostic pop
      
               return err ? ERR_PTR(err) : btf;
          5ba1a2:	48 98                	cltq
          5ba1a4:	85 d2                	test   %edx,%edx
          5ba1a6:	48 0f 44 45 f0       	cmove  -0x10(%rbp),%rax
        }
        <SNIP>
      
      Fixes: 218e7b77 ("perf bpf: Provide a weak btf__load_from_kernel_by_id() for older libbpf versions")
      Reported-by: NAvi Kivity <avi@scylladb.com>
      Link: https://lore.kernel.org/linux-perf-users/f0add43b-3de5-20c5-22c4-70aff4af959f@scylladb.com
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/linux-perf-users/YobjjFOblY4Xvwo7@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      0ae065a5
  2. 15 2月, 2022 2 次提交
    • I
      perf maps: Use a pointer for kmaps · 1a97cee6
      Ian Rogers 提交于
      struct maps is reference counted, using a pointer is more idiomatic.
      
      Committer notes:
      
      Delay:
      
         maps = machine__kernel_maps(&vmlinux);
      
      To after:
      
        machine__init(&vmlinux, "", HOST_KERNEL_ID);
      
      To avoid this on f34:
      
        In file included from /var/home/acme/git/perf/tools/perf/util/build-id.h:10,
                         from /var/home/acme/git/perf/tools/perf/util/dso.h:13,
                         from tests/vmlinux-kallsyms.c:8:
        In function ‘machine__kernel_maps’,
            inlined from ‘test__vmlinux_matches_kallsyms’ at tests/vmlinux-kallsyms.c:122:22:
        /var/home/acme/git/perf/tools/perf/util/machine.h:86:23: error: ‘vmlinux.kmaps’ is used uninitialized [-Werror=uninitialized]
           86 |         return machine->kmaps;
              |                ~~~~~~~^~~~~~~
        tests/vmlinux-kallsyms.c: In function ‘test__vmlinux_matches_kallsyms’:
        tests/vmlinux-kallsyms.c:121:34: note: ‘vmlinux’ declared here
          121 |         struct machine kallsyms, vmlinux;
              |                                  ^~~~~~~
        cc1: all warnings being treated as errors
      Signed-off-by: NIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: André Almeida <andrealmeid@collabora.com>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Darren Hart <dvhart@infradead.org>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Dmitriy Vyukov <dvyukov@google.com>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: German Gomez <german.gomez@arm.com>
      Cc: Hao Luo <haoluo@google.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jin Yao <yao.jin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.garry@huawei.com>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Miaoqian Lin <linmq006@gmail.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Riccardo Mancini <rickyman7@gmail.com>
      Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
      Cc: Song Liu <song@kernel.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
      Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Cc: Yury Norov <yury.norov@gmail.com>
      Link: http://lore.kernel.org/lkml/20220211103415.2737789-6-irogers@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      1a97cee6
    • C
      perf bpf: Stop using deprecated bpf_load_program() API · 710f6c38
      Christy Lee 提交于
      bpf_load_program() API is deprecated, remove perf's usage of the
      deprecated function. Add a __weak function declaration for libbpf
      version compatibility.
      Signed-off-by: NChristy Lee <christylee@fb.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: bpf@vger.kernel.org
      Cc: kernel-team@fb.com
      Link: https://lore.kernel.org/bpf/20220212073054.1052880-2-andrii@kernel.orgSigned-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      710f6c38
  3. 14 11月, 2021 2 次提交
    • J
      perf tools: Add more weak libbpf functions · 2a4898fc
      Jiri Olsa 提交于
      We hit the window where perf uses libbpf functions, that did not make it
      to the official libbpf release yet and it's breaking perf build with
      dynamicly linked libbpf.
      
      Fixing this by providing the new interface as weak functions which calls
      the original libbpf functions. Fortunatelly the changes were just
      renames.
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andrii Nakryiko <andrii@kernel.org>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: http://lore.kernel.org/lkml/20211109140707.1689940-2-jolsa@kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      2a4898fc
    • I
      perf bpf: Avoid memory leak from perf_env__insert_btf() · 4924b1f7
      Ian Rogers 提交于
      perf_env__insert_btf() doesn't insert if a duplicate BTF id is
      encountered and this causes a memory leak. Modify the function to return
      a success/error value and then free the memory if insertion didn't
      happen.
      
      v2. Adds a return -1 when the insertion error occurs in
          perf_env__fetch_btf. This doesn't affect anything as the result is
          never checked.
      
      Fixes: 3792cb2f ("perf bpf: Save BTF in a rbtree in perf_env")
      Signed-off-by: NIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Andrii Nakryiko <andrii@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John Fastabend <john.fastabend@gmail.com>
      Cc: KP Singh <kpsingh@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
      Cc: Yonghong Song <yhs@fb.com>
      Cc: bpf@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20211112074525.121633-1-irogers@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      4924b1f7
  4. 07 11月, 2021 1 次提交
    • I
      perf bpf: Add missing free to bpf_event__print_bpf_prog_info() · 88c42f4d
      Ian Rogers 提交于
      If btf__new() is called then there needs to be a corresponding btf__free().
      
      Fixes: f8dfeae0 ("perf bpf: Show more BPF program info in print_bpf_prog_info()")
      Signed-off-by: NIan Rogers <irogers@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Andrii Nakryiko <andrii@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@redhat.com>
      Cc: John Fastabend <john.fastabend@gmail.com>
      Cc: KP Singh <kpsingh@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <songliubraving@fb.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
      Cc: Yonghong Song <yhs@fb.com>
      Cc: bpf@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20211106053733.3580931-2-irogers@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      88c42f4d
  5. 04 11月, 2021 1 次提交
  6. 02 11月, 2021 1 次提交
  7. 23 10月, 2021 1 次提交
  8. 19 9月, 2021 1 次提交
  9. 16 9月, 2021 1 次提交
  10. 11 9月, 2021 1 次提交
  11. 01 9月, 2021 1 次提交
  12. 30 7月, 2021 2 次提交
  13. 16 3月, 2021 1 次提交
  14. 30 11月, 2020 1 次提交
  15. 06 5月, 2020 1 次提交
  16. 16 4月, 2020 1 次提交
    • J
      perf tools: Synthesize bpf_trampoline/dispatcher ksymbol event · 943930e4
      Jiri Olsa 提交于
      Synthesize bpf images (trampolines/dispatchers) on start, as ksymbol
      events from /proc/kallsyms. Having this perf can recognize samples from
      those images and perf report and top shows them correctly.
      
      The rest of the ksymbol handling is already in place from for the bpf
      programs monitoring, so only the initial state was needed.
      
      perf report output:
      
        # Overhead  Command     Shared Object                  Symbol
      
          12.37%  test_progs  [kernel.vmlinux]                 [k] entry_SYSCALL_64
          11.80%  test_progs  [kernel.vmlinux]                 [k] syscall_return_via_sysret
           9.63%  test_progs  bpf_prog_bcf7977d3b93787c_prog2  [k] bpf_prog_bcf7977d3b93787c_prog2
           6.90%  test_progs  bpf_trampoline_24456             [k] bpf_trampoline_24456
           6.36%  test_progs  [kernel.vmlinux]                 [k] memcpy_erms
      
      Committer notes:
      
      Use scnprintf() instead of strncpy() to overcome this on fedora:32,
      rawhide and OpenMandriva Cooker:
      
          CC       /tmp/build/perf/util/bpf-event.o
        In file included from /usr/include/string.h:495,
                         from /git/linux/tools/lib/bpf/libbpf_common.h:12,
                         from /git/linux/tools/lib/bpf/bpf.h:31,
                         from util/bpf-event.c:4:
        In function 'strncpy',
            inlined from 'process_bpf_image' at util/bpf-event.c:323:2,
            inlined from 'kallsyms_process_symbol' at util/bpf-event.c:358:9:
        /usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 256 equals destination size [-Werror=stringop-truncation]
          106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
              |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        cc1: all warnings being treated as errors
      Signed-off-by: NJiri Olsa <jolsa@kernel.org>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Andrii Nakryiko <andriin@fb.com>
      Cc: Björn Töpel <bjorn.topel@intel.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: David S. Miller <davem@redhat.com>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Jesper Dangaard Brouer <hawk@kernel.org>
      Cc: John Fastabend <john.fastabend@gmail.com>
      Cc: Martin KaFai Lau <kafai@fb.com>
      Cc: Yonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20200312195610.346362-14-jolsa@kernel.org/Signed-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      943930e4
  17. 26 11月, 2019 1 次提交
    • A
      perf maps: Merge 'struct maps' with 'struct map_groups' · 79b6bb73
      Arnaldo Carvalho de Melo 提交于
      And pick the shortest name: 'struct maps'.
      
      The split existed because we used to have two groups of maps, one for
      functions and one for variables, but that only complicated things,
      sometimes we needed to figure out what was at some address and then had
      to first try it on the functions group and if that failed, fall back to
      the variables one.
      
      That split is long gone, so for quite a while we had only one struct
      maps per struct map_groups, simplify things by combining those structs.
      
      First patch is the minimum needed to merge both, follow up patches will
      rename 'thread->mg' to 'thread->maps', etc.
      
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lkml.kernel.org/n/tip-hom6639ro7020o708trhxh59@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      79b6bb73
  18. 20 9月, 2019 1 次提交
  19. 01 9月, 2019 1 次提交
  20. 27 8月, 2019 4 次提交
  21. 26 8月, 2019 1 次提交
  22. 30 7月, 2019 1 次提交
  23. 21 3月, 2019 4 次提交
    • S
      perf bpf: Show more BPF program info in print_bpf_prog_info() · f8dfeae0
      Song Liu 提交于
      This patch enables showing bpf program name, address, and size in the
      header.
      
      Before the patch:
      
        perf report --header-only
        ...
        # bpf_prog_info of id 9
        # bpf_prog_info of id 10
        # bpf_prog_info of id 13
      
      After the patch:
      
        # bpf_prog_info 9: bpf_prog_7be49e3934a125ba addr 0xffffffffa0024947 size 229
        # bpf_prog_info 10: bpf_prog_2a142ef67aaad174 addr 0xffffffffa007c94d size 229
        # bpf_prog_info 13: bpf_prog_47368425825d7384_task__task_newt addr 0xffffffffa0251137 size 369
      
      Committer notes:
      
      Fix the fallback definition when HAVE_LIBBPF_SUPPORT is not defined,
      i.e. add the missing 'static inline' and add the __maybe_unused to the
      args. Also add stdio.h since we now use FILE * in bpf-event.h.
      Signed-off-by: NSong Liu <songliubraving@fb.com>
      Tested-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stanislav Fomichev <sdf@google.com>
      Link: http://lkml.kernel.org/r/20190319165454.1298742-3-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      f8dfeae0
    • S
      perf bpf: Extract logic to create program names from perf_event__synthesize_one_bpf_prog() · fc462ac7
      Song Liu 提交于
      Extract logic to create program names to synthesize_bpf_prog_name(), so
      that it can be reused in header.c:print_bpf_prog_info().
      
      This commit doesn't change the behavior.
      Signed-off-by: NSong Liu <songliubraving@fb.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stanislav Fomichev <sdf@google.com>
      Link: http://lkml.kernel.org/r/20190319165454.1298742-2-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      fc462ac7
    • S
      perf tools: Save bpf_prog_info and BTF of new BPF programs · d56354dc
      Song Liu 提交于
      To fully annotate BPF programs with source code mapping, 4 different
      information are needed:
      
          1) PERF_RECORD_KSYMBOL
          2) PERF_RECORD_BPF_EVENT
          3) bpf_prog_info
          4) btf
      
      This patch handles 3) and 4) for BPF programs loaded after 'perf
      record|top'.
      
      For timely process of these information, a dedicated event is added to
      the side band evlist.
      
      When PERF_RECORD_BPF_EVENT is received via the side band event, the
      polling thread gathers 3) and 4) vis sys_bpf and store them in perf_env.
      
      This information is saved to perf.data at the end of 'perf record'.
      
      Committer testing:
      
      The 'wakeup_watermark' member in 'struct perf_event_attr' is inside a
      unnamed union, so can't be used in a struct designated initialization
      with older gccs, get it out of that, isolating as 'attr.wakeup_watermark
      = 1;' to work with all gcc versions.
      
      We also need to add '--no-bpf-event' to the 'perf record'
      perf_event_attr tests in 'perf test', as the way that that test goes is
      to intercept the events being setup and looking if they match the fields
      described in the control files, since now it finds first the side band
      event used to catch the PERF_RECORD_BPF_EVENT, they all fail.
      
      With these issues fixed:
      
      Same scenario as for testing BPF programs loaded before 'perf record' or
      'perf top' starts, only start the BPF programs after 'perf record|top',
      so that its information get collected by the sideband threads, the rest
      works as for the programs loaded before start monitoring.
      
      Add missing 'inline' to the bpf_event__add_sb_event() when
      HAVE_LIBBPF_SUPPORT is not defined, fixing the build in systems without
      binutils devel files installed.
      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: Jiri Olsa <jolsa@kernel.org>
      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-16-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      d56354dc
    • S
      perf annotate: Enable annotation of BPF programs · 6987561c
      Song Liu 提交于
      In symbol__disassemble(), DSO_BINARY_TYPE__BPF_PROG_INFO dso calls into
      a new function symbol__disassemble_bpf(), where annotation line
      information is filled based on the bpf_prog_info and btf data saved in
      given perf_env.
      
      symbol__disassemble_bpf() uses binutils's libopcodes to disassemble bpf
      programs.
      
      Committer testing:
      
      After fixing this:
      
        -               u64 *addrs = (u64 *)(info_linear->info.jited_ksyms);
        +               u64 *addrs = (u64 *)(uintptr_t)(info_linear->info.jited_ksyms);
      
      Detected when crossbuilding to a 32-bit arch.
      
      And making all this dependent on HAVE_LIBBFD_SUPPORT and
      HAVE_LIBBPF_SUPPORT:
      
      1) Have a BPF program running, one that has BTF info, etc, I used
         the tools/perf/examples/bpf/augmented_raw_syscalls.c put in place
         by 'perf trace'.
      
        # grep -B1 augmented_raw ~/.perfconfig
        [trace]
      	add_events = /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c
        #
        # perf trace -e *mmsg
        dnf/6245 sendmmsg(20, 0x7f5485a88030, 2, MSG_NOSIGNAL) = 2
        NetworkManager/10055 sendmmsg(22<socket:[1056822]>, 0x7f8126ad1bb0, 2, MSG_NOSIGNAL) = 2
      
      2) Then do a 'perf record' system wide for a while:
      
        # perf record -a
        ^C[ perf record: Woken up 68 times to write data ]
        [ perf record: Captured and wrote 19.427 MB perf.data (366891 samples) ]
        #
      
      3) Check that we captured BPF and BTF info in the perf.data file:
      
        # perf report --header-only | grep 'b[pt]f'
        # event : name = cycles:ppp, , id = { 294789, 294790, 294791, 294792, 294793, 294794, 294795, 294796 }, size = 112, { sample_period, sample_freq } = 4000, sample_type = IP|TID|TIME|CPU|PERIOD, read_format = ID, disabled = 1, inherit = 1, mmap = 1, comm = 1, freq = 1, task = 1, precise_ip = 3, sample_id_all = 1, exclude_guest = 1, mmap2 = 1, comm_exec = 1, ksymbol = 1, bpf_event = 1
        # bpf_prog_info of id 13
        # bpf_prog_info of id 14
        # bpf_prog_info of id 15
        # bpf_prog_info of id 16
        # bpf_prog_info of id 17
        # bpf_prog_info of id 18
        # bpf_prog_info of id 21
        # bpf_prog_info of id 22
        # bpf_prog_info of id 41
        # bpf_prog_info of id 42
        # btf info of id 2
        #
      
      4) Check which programs got recorded:
      
         # perf report | grep bpf_prog | head
           0.16%  exe              bpf_prog_819967866022f1e1_sys_enter      [k] bpf_prog_819967866022f1e1_sys_enter
           0.14%  exe              bpf_prog_c1bd85c092d6e4aa_sys_exit       [k] bpf_prog_c1bd85c092d6e4aa_sys_exit
           0.08%  fuse-overlayfs   bpf_prog_819967866022f1e1_sys_enter      [k] bpf_prog_819967866022f1e1_sys_enter
           0.07%  fuse-overlayfs   bpf_prog_c1bd85c092d6e4aa_sys_exit       [k] bpf_prog_c1bd85c092d6e4aa_sys_exit
           0.01%  clang-4.0        bpf_prog_c1bd85c092d6e4aa_sys_exit       [k] bpf_prog_c1bd85c092d6e4aa_sys_exit
           0.01%  clang-4.0        bpf_prog_819967866022f1e1_sys_enter      [k] bpf_prog_819967866022f1e1_sys_enter
           0.00%  clang            bpf_prog_c1bd85c092d6e4aa_sys_exit       [k] bpf_prog_c1bd85c092d6e4aa_sys_exit
           0.00%  runc             bpf_prog_819967866022f1e1_sys_enter      [k] bpf_prog_819967866022f1e1_sys_enter
           0.00%  clang            bpf_prog_819967866022f1e1_sys_enter      [k] bpf_prog_819967866022f1e1_sys_enter
           0.00%  sh               bpf_prog_c1bd85c092d6e4aa_sys_exit       [k] bpf_prog_c1bd85c092d6e4aa_sys_exit
        #
      
        This was with the default --sort order for 'perf report', which is:
      
          --sort comm,dso,symbol
      
        If we just look for the symbol, for instance:
      
         # perf report --sort symbol | grep bpf_prog | head
           0.26%  [k] bpf_prog_819967866022f1e1_sys_enter                -      -
           0.24%  [k] bpf_prog_c1bd85c092d6e4aa_sys_exit                 -      -
         #
      
        or the DSO:
      
         # perf report --sort dso | grep bpf_prog | head
           0.26%  bpf_prog_819967866022f1e1_sys_enter
           0.24%  bpf_prog_c1bd85c092d6e4aa_sys_exit
        #
      
      We'll see the two BPF programs that augmented_raw_syscalls.o puts in
      place,  one attached to the raw_syscalls:sys_enter and another to the
      raw_syscalls:sys_exit tracepoints, as expected.
      
      Now we can finally do, from the command line, annotation for one of
      those two symbols, with the original BPF program source coude intermixed
      with the disassembled JITed code:
      
        # perf annotate --stdio2 bpf_prog_819967866022f1e1_sys_enter
      
        Samples: 950  of event 'cycles:ppp', 4000 Hz, Event count (approx.): 553756947, [percent: local period]
        bpf_prog_819967866022f1e1_sys_enter() bpf_prog_819967866022f1e1_sys_enter
        Percent      int sys_enter(struct syscall_enter_args *args)
         53.41         push   %rbp
      
          0.63         mov    %rsp,%rbp
          0.31         sub    $0x170,%rsp
          1.93         sub    $0x28,%rbp
          7.02         mov    %rbx,0x0(%rbp)
          3.20         mov    %r13,0x8(%rbp)
          1.07         mov    %r14,0x10(%rbp)
          0.61         mov    %r15,0x18(%rbp)
          0.11         xor    %eax,%eax
          1.29         mov    %rax,0x20(%rbp)
          0.11         mov    %rdi,%rbx
                     	return bpf_get_current_pid_tgid();
          2.02       → callq  *ffffffffda6776d9
          2.76         mov    %eax,-0x148(%rbp)
                       mov    %rbp,%rsi
                     int sys_enter(struct syscall_enter_args *args)
                       add    $0xfffffffffffffeb8,%rsi
                     	return bpf_map_lookup_elem(pids, &pid) != NULL;
                       movabs $0xffff975ac2607800,%rdi
      
          1.26       → callq  *ffffffffda6789e9
                       cmp    $0x0,%rax
          2.43       → je     0
                       add    $0x38,%rax
          0.21         xor    %r13d,%r13d
                     	if (pid_filter__has(&pids_filtered, getpid()))
          0.81         cmp    $0x0,%rax
                     → jne    0
                       mov    %rbp,%rdi
                     	probe_read(&augmented_args.args, sizeof(augmented_args.args), args);
          2.22         add    $0xfffffffffffffeb8,%rdi
          0.11         mov    $0x40,%esi
          0.32         mov    %rbx,%rdx
          2.74       → callq  *ffffffffda658409
                     	syscall = bpf_map_lookup_elem(&syscalls, &augmented_args.args.syscall_nr);
          0.22         mov    %rbp,%rsi
          1.69         add    $0xfffffffffffffec0,%rsi
                     	syscall = bpf_map_lookup_elem(&syscalls, &augmented_args.args.syscall_nr);
                       movabs $0xffff975bfcd36000,%rdi
      
                       add    $0xd0,%rdi
          0.21         mov    0x0(%rsi),%eax
          0.93         cmp    $0x200,%rax
                     → jae    0
          0.10         shl    $0x3,%rax
      
          0.11         add    %rdi,%rax
          0.11       → jmp    0
                       xor    %eax,%eax
                     	if (syscall == NULL || !syscall->enabled)
          1.07         cmp    $0x0,%rax
                     → je     0
                     	if (syscall == NULL || !syscall->enabled)
          6.57         movzbq 0x0(%rax),%rdi
      
                     	if (syscall == NULL || !syscall->enabled)
                       cmp    $0x0,%rdi
          0.95       → je     0
                       mov    $0x40,%r8d
                     	switch (augmented_args.args.syscall_nr) {
                       mov    -0x140(%rbp),%rdi
                     	switch (augmented_args.args.syscall_nr) {
                       cmp    $0x2,%rdi
                     → je     0
                       cmp    $0x101,%rdi
                     → je     0
                       cmp    $0x15,%rdi
                     → jne    0
                     	case SYS_OPEN:	 filename_arg = (const void *)args->args[0];
                       mov    0x10(%rbx),%rdx
                     → jmp    0
                     	case SYS_OPENAT: filename_arg = (const void *)args->args[1];
                       mov    0x18(%rbx),%rdx
                     	if (filename_arg != NULL) {
                       cmp    $0x0,%rdx
                     → je     0
                       xor    %edi,%edi
                     		augmented_args.filename.reserved = 0;
                       mov    %edi,-0x104(%rbp)
                     		augmented_args.filename.size = probe_read_str(&augmented_args.filename.value,
                       mov    %rbp,%rdi
                       add    $0xffffffffffffff00,%rdi
                     		augmented_args.filename.size = probe_read_str(&augmented_args.filename.value,
                       mov    $0x100,%esi
                     → callq  *ffffffffda658499
                       mov    $0x148,%r8d
                     		augmented_args.filename.size = probe_read_str(&augmented_args.filename.value,
                       mov    %eax,-0x108(%rbp)
                     		augmented_args.filename.size = probe_read_str(&augmented_args.filename.value,
                       mov    %rax,%rdi
                       shl    $0x20,%rdi
      
                       shr    $0x20,%rdi
      
                     		if (augmented_args.filename.size < sizeof(augmented_args.filename.value)) {
                       cmp    $0xff,%rdi
                     → ja     0
                     			len -= sizeof(augmented_args.filename.value) - augmented_args.filename.size;
                       add    $0x48,%rax
                     			len &= sizeof(augmented_args.filename.value) - 1;
                       and    $0xff,%rax
                       mov    %rax,%r8
                       mov    %rbp,%rcx
                     	return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, &augmented_args, len);
                       add    $0xfffffffffffffeb8,%rcx
                       mov    %rbx,%rdi
                       movabs $0xffff975fbd72d800,%rsi
      
                       mov    $0xffffffff,%edx
                     → callq  *ffffffffda658ad9
                       mov    %rax,%r13
                     }
                       mov    %r13,%rax
          0.72         mov    0x0(%rbp),%rbx
                       mov    0x8(%rbp),%r13
          1.16         mov    0x10(%rbp),%r14
          0.10         mov    0x18(%rbp),%r15
          0.42         add    $0x28,%rbp
          0.54         leaveq
          0.54       ← retq
        #
      
      Please see 'man perf-config' to see how to control what should be seen,
      via ~/.perfconfig [annotate] section, for instance, one can suppress the
      source code and see just the disassembly, etc.
      
      Alternatively, use the TUI bu just using 'perf annotate', press
      '/bpf_prog' to see the bpf symbols, press enter and do the interactive
      annotation, which allows for dumping to a file after selecting the
      the various output tunables, for instance, the above without source code
      intermixed, plus showing all the instruction offsets:
      
        # perf annotate bpf_prog_819967866022f1e1_sys_enter
      
      Then press: 's' to hide the source code + 'O' twice to show all
      instruction offsets, then 'P' to print to the
      bpf_prog_819967866022f1e1_sys_enter.annotation file, which will have:
      
        # cat bpf_prog_819967866022f1e1_sys_enter.annotation
        bpf_prog_819967866022f1e1_sys_enter() bpf_prog_819967866022f1e1_sys_enter
        Event: cycles:ppp
      
         53.41    0:   push   %rbp
      
          0.63    1:   mov    %rsp,%rbp
          0.31    4:   sub    $0x170,%rsp
          1.93    b:   sub    $0x28,%rbp
          7.02    f:   mov    %rbx,0x0(%rbp)
          3.20   13:   mov    %r13,0x8(%rbp)
          1.07   17:   mov    %r14,0x10(%rbp)
          0.61   1b:   mov    %r15,0x18(%rbp)
          0.11   1f:   xor    %eax,%eax
          1.29   21:   mov    %rax,0x20(%rbp)
          0.11   25:   mov    %rdi,%rbx
          2.02   28: → callq  *ffffffffda6776d9
          2.76   2d:   mov    %eax,-0x148(%rbp)
                 33:   mov    %rbp,%rsi
                 36:   add    $0xfffffffffffffeb8,%rsi
                 3d:   movabs $0xffff975ac2607800,%rdi
      
          1.26   47: → callq  *ffffffffda6789e9
                 4c:   cmp    $0x0,%rax
          2.43   50: → je     0
                 52:   add    $0x38,%rax
          0.21   56:   xor    %r13d,%r13d
          0.81   59:   cmp    $0x0,%rax
                 5d: → jne    0
                 63:   mov    %rbp,%rdi
          2.22   66:   add    $0xfffffffffffffeb8,%rdi
          0.11   6d:   mov    $0x40,%esi
          0.32   72:   mov    %rbx,%rdx
          2.74   75: → callq  *ffffffffda658409
          0.22   7a:   mov    %rbp,%rsi
          1.69   7d:   add    $0xfffffffffffffec0,%rsi
                 84:   movabs $0xffff975bfcd36000,%rdi
      
                 8e:   add    $0xd0,%rdi
          0.21   95:   mov    0x0(%rsi),%eax
          0.93   98:   cmp    $0x200,%rax
                 9f: → jae    0
          0.10   a1:   shl    $0x3,%rax
      
          0.11   a5:   add    %rdi,%rax
          0.11   a8: → jmp    0
                 aa:   xor    %eax,%eax
          1.07   ac:   cmp    $0x0,%rax
                 b0: → je     0
          6.57   b6:   movzbq 0x0(%rax),%rdi
      
                 bb:   cmp    $0x0,%rdi
          0.95   bf: → je     0
                 c5:   mov    $0x40,%r8d
                 cb:   mov    -0x140(%rbp),%rdi
                 d2:   cmp    $0x2,%rdi
                 d6: → je     0
                 d8:   cmp    $0x101,%rdi
                 df: → je     0
                 e1:   cmp    $0x15,%rdi
                 e5: → jne    0
                 e7:   mov    0x10(%rbx),%rdx
                 eb: → jmp    0
                 ed:   mov    0x18(%rbx),%rdx
                 f1:   cmp    $0x0,%rdx
                 f5: → je     0
                 f7:   xor    %edi,%edi
                 f9:   mov    %edi,-0x104(%rbp)
                 ff:   mov    %rbp,%rdi
                102:   add    $0xffffffffffffff00,%rdi
                109:   mov    $0x100,%esi
                10e: → callq  *ffffffffda658499
                113:   mov    $0x148,%r8d
                119:   mov    %eax,-0x108(%rbp)
                11f:   mov    %rax,%rdi
                122:   shl    $0x20,%rdi
      
                126:   shr    $0x20,%rdi
      
                12a:   cmp    $0xff,%rdi
                131: → ja     0
                133:   add    $0x48,%rax
                137:   and    $0xff,%rax
                13d:   mov    %rax,%r8
                140:   mov    %rbp,%rcx
                143:   add    $0xfffffffffffffeb8,%rcx
                14a:   mov    %rbx,%rdi
                14d:   movabs $0xffff975fbd72d800,%rsi
      
                157:   mov    $0xffffffff,%edx
                15c: → callq  *ffffffffda658ad9
                161:   mov    %rax,%r13
                164:   mov    %r13,%rax
          0.72  167:   mov    0x0(%rbp),%rbx
                16b:   mov    0x8(%rbp),%r13
          1.16  16f:   mov    0x10(%rbp),%r14
          0.10  173:   mov    0x18(%rbp),%r15
          0.42  177:   add    $0x28,%rbp
          0.54  17b:   leaveq
          0.54  17c: ← retq
      
      Another cool way to test all this is to symple use 'perf top' look for
      those symbols, go there and press enter, annotate it live :-)
      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-13-songliubraving@fb.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
      6987561c
  24. 20 3月, 2019 6 次提交
  25. 21 2月, 2019 1 次提交
  26. 15 2月, 2019 1 次提交