1. 01 Aug, 2022 9 commits
    • Jiri Olsa's avatar
      perf tools: Rework prologue generation code · 5f4e821c
      Jiri Olsa authored
      Some functions we use for bpf prologue generation are going to be
      deprecated. This change reworks current code not to use them.
      
      We need to replace following functions/struct:
         bpf_program__set_prep
         bpf_program__nth_fd
         struct bpf_prog_prep_result
      
      Currently we use bpf_program__set_prep to hook perf callback before
      program is loaded and provide new instructions with the prologue.
      
      We replace this function/ality by taking instructions for specific
      program, attaching prologue to them and load such new ebpf programs
      with prologue using separate bpf_prog_load calls (outside libbpf
      load machinery).
      
      Before we can take and use program instructions, we need libbpf to
      actually load it. This way we get the final shape of its instructions
      with all relocations and verifier adjustments).
      
      There's one glitch though.. perf kprobe program already assumes
      generated prologue code with proper values in argument registers,
      so loading such program directly will fail in the verifier.
      
      That's where the fallback pre-load handler fits in and prepends
      the initialization code to the program. Once such program is loaded
      we take its instructions, cut off the initialization code and prepend
      the prologue.
      
      I know.. sorry ;-)
      
      To have access to the program when loading this patch adds support to
      register 'fallback' section handler to take care of perf kprobe programs.
      The fallback means that it handles any section definition besides the
      ones that libbpf handles.
      
      The handler serves two purposes:
        - allows perf programs to have special arguments in section name
        - allows perf to use pre-load callback where we can attach init
          code (zeroing all argument registers) to each perf program
      Suggested-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Acked-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: John Fastabend <john.fastabend@gmail.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: Yonghong Song <yhs@fb.com>
      Cc: bpf@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Link: https://lore.kernel.org/r/20220616202214.70359-2-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      5f4e821c
    • Jiri Olsa's avatar
      perf bpf: Convert legacy map definition to BTF-defined · 8b1e1a03
      Jiri Olsa authored
      The libbpf is switching off support for legacy map definitions [1],
      which will break the perf llvm tests.
      
      Moving the base source map definition to BTF-defined, so we need
      to use -g compile option for to add debug/BTF info.
      
      [1] https://lore.kernel.org/bpf/20220627211527.2245459-1-andrii@kernel.org/Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20220704152721.352046-1-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8b1e1a03
    • Ian Rogers's avatar
      perf symbol: Fail to read phdr workaround · 6d518ac7
      Ian Rogers authored
      The perf jvmti agent doesn't create program headers, in this case
      fallback on section headers as happened previously.
      
      Committer notes:
      
      To test this, from a public post by Ian:
      
      1) download a Java workload dacapo-9.12-MR1-bach.jar from
      https://sourceforge.net/projects/dacapobench/
      
      2) build perf such as "make -C tools/perf O=/tmp/perf NO_LIBBFD=1" it
      should detect Java and create /tmp/perf/libperf-jvmti.so
      
      3) run perf with the jvmti agent:
      
        perf record -k 1 java -agentpath:/tmp/perf/libperf-jvmti.so -jar dacapo-9.12-MR1-bach.jar -n 10 fop
      
      4) run perf inject:
      
        perf inject -i perf.data -o perf-injected.data -j
      
      5) run perf report
      
        perf report -i perf-injected.data | grep org.apache.fop
      
      With this patch reverted I see lots of symbols like:
      
           0.00%  java             jitted-388040-4656.so  [.] org.apache.fop.fo.FObj.bind(org.apache.fop.fo.PropertyList)
      
      With the patch (2d86612a ("perf symbol: Correct address for bss
      symbols")) I see lots of:
      
        dso__load_sym_internal: failed to find program header for symbol:
        Lorg/apache/fop/fo/FObj;bind(Lorg/apache/fop/fo/PropertyList;)V
        st_value: 0x40
      
      Fixes: 2d86612a ("perf symbol: Correct address for bss symbols")
      Reviewed-by: default avatarLeo Yan <leo.yan@linaro.org>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarLeo Yan <leo.yan@linaro.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20220731164923.691193-1-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6d518ac7
    • Namhyung Kim's avatar
      perf lock: Implement cpu and task filters for BPF · 6fda2405
      Namhyung Kim authored
      Add -a/--all-cpus and -C/--cpu options for cpu filtering.  Also -p/--pid
      and --tid options are added for task filtering.  The short -t option is
      taken for --threads already.  Tracking the command line workload is
      possible as well.
      
        $ sudo perf lock contention -a -b sleep 1
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Blake Jones <blakejones@google.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20220729200756.666106-4-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6fda2405
    • Namhyung Kim's avatar
      perf lock: Use BPF for lock contention analysis · 407b36f6
      Namhyung Kim authored
      Add -b/--use-bpf option to use BPF to collect lock contention stats.
      For simplicity it now runs system-wide and requires C-c to stop.
      Upcoming changes will add the usual filtering.
      
        $ sudo perf lock con -b
        ^C
         contended   total wait     max wait     avg wait         type   caller
      
                42    192.67 us     13.64 us      4.59 us     spinlock   queue_work_on+0x20
                23     85.54 us     10.28 us      3.72 us     spinlock   worker_thread+0x14a
                 6     13.92 us      6.51 us      2.32 us        mutex   kernfs_iop_permission+0x30
                 3     11.59 us     10.04 us      3.86 us        mutex   kernfs_dop_revalidate+0x3c
                 1      7.52 us      7.52 us      7.52 us     spinlock   kthread+0x115
                 1      7.24 us      7.24 us      7.24 us     rwlock:W   sys_epoll_wait+0x148
                 2      7.08 us      3.99 us      3.54 us     spinlock   delayed_work_timer_fn+0x1b
                 1      6.41 us      6.41 us      6.41 us     spinlock   idle_balance+0xa06
                 2      2.50 us      1.83 us      1.25 us        mutex   kernfs_iop_lookup+0x2f
                 1      1.71 us      1.71 us      1.71 us        mutex   kernfs_iop_getattr+0x2c
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Blake Jones <blakejones@google.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20220729200756.666106-3-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      407b36f6
    • Namhyung Kim's avatar
      perf lock: Pass machine pointer to is_lock_function() · 77d54a2c
      Namhyung Kim authored
      This is a preparation for later change to expose the function externally
      so that it can be used without the implicit session data.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Blake Jones <blakejones@google.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Davidlohr Bueso <dave@stgolabs.net>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20220729200756.666106-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      77d54a2c
    • Ian Rogers's avatar
      perf test: Add user space counter reading tests · 9bd70218
      Ian Rogers authored
      These tests are based on test_stat_user_read in
      tools/lib/perf/tests/test-evsel.c.
      
      The tests are modified to skip if perf_event_open fails or rdpmc isn't
      supported.
      
      Committer testing:
      
        ⬢[acme@toolbox perf]$ perf test "mmap interface"
          4: mmap interface tests                         :
          4.1: Read samples using the mmap interface      : Skip (permissions)
        ⬢[acme@toolbox perf]$
      
        [root@five ~]# perf test "mmap interface"
          4: mmap interface tests                         :
          4.1: Read samples using the mmap interface      : Ok
        [root@five ~]#
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Anshuman Khandual <anshuman.khandual@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20220719223946.176299-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9bd70218
    • Ian Rogers's avatar
      perf test: Remove x86 rdpmc test · 481fadfb
      Ian Rogers authored
      This test has been superseded by test_stat_user_read in:
      
        tools/lib/perf/tests/test-evsel.c
      
      The updated test doesn't divide-by-0 when running time of a counter is
      0. It also supports ARM64.
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Acked-by: default avatarRob Herring <robh@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Anshuman Khandual <anshuman.khandual@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20220719223946.176299-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      481fadfb
    • Arnaldo Carvalho de Melo's avatar
      Merge remote-tracking branch 'torvalds/master' into perf/core · 18808564
      Arnaldo Carvalho de Melo authored
      To pick up the fixes that went upstream via acme/perf/urgent and to get
      to v5.19.
      Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      18808564
  2. 31 Jul, 2022 6 commits
  3. 30 Jul, 2022 2 commits
  4. 29 Jul, 2022 23 commits