1. 03 Feb, 2023 16 commits
    • Kan Liang's avatar
      perf report: Support Retire Latency · d7d213e0
      Kan Liang authored
      The Retire Latency field is added in the var3_w of the
      PERF_SAMPLE_WEIGHT_STRUCT. The Retire Latency reports pipeline stall of
      this instruction compared to the previous instruction in cycles.  That's
      quite useful to display the information with perf mem report.
      
      The p_stage_cyc for Power is also from the var3_w. Union the p_stage_cyc
      and retire_lat to share the code.
      
      Implement X86 specific codes to display the X86 specific header.
      
      Add a new sort key retire_lat for the Retire Latency.
      Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
      Signed-off-by: default avatarKan Liang <kan.liang@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Stephane Eranian <eranian@google.com>
      Link: http://lore.kernel.org/lkml/20230104201349.1451191-8-kan.liang@linux.intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d7d213e0
    • Namhyung Kim's avatar
      perf lock contention: Support filters for different aggregation · ebab2916
      Namhyung Kim authored
      It'd be useful to filter other than the current aggregation mode.  For
      example, users may want to see callstacks for specific locks only.  Or
      they may want tasks from a certain callstack.
      
      The tracepoints already collected the information but it needs to check
      the condition again when processing the event.  And it needs to change
      BPF to allow the key combinations.
      
      The lock contentions on 'rcu_state' spinlock can be monitored:
      
        $ sudo perf lock con -abv -L rcu_state sleep 1
        ...
         contended   total wait     max wait     avg wait         type   caller
      
                 4    151.39 us     62.57 us     37.85 us     spinlock   rcu_core+0xcb
                                0xffffffff81fd1666  _raw_spin_lock_irqsave+0x46
                                0xffffffff8172d76b  rcu_core+0xcb
                                0xffffffff822000eb  __softirqentry_text_start+0xeb
                                0xffffffff816a0ba9  __irq_exit_rcu+0xc9
                                0xffffffff81fc0112  sysvec_apic_timer_interrupt+0xa2
                                0xffffffff82000e46  asm_sysvec_apic_timer_interrupt+0x16
                                0xffffffff81d49f78  cpuidle_enter_state+0xd8
                                0xffffffff81d4a259  cpuidle_enter+0x29
                 1     30.21 us     30.21 us     30.21 us     spinlock   rcu_core+0xcb
                                0xffffffff81fd1666  _raw_spin_lock_irqsave+0x46
                                0xffffffff8172d76b  rcu_core+0xcb
                                0xffffffff822000eb  __softirqentry_text_start+0xeb
                                0xffffffff816a0ba9  __irq_exit_rcu+0xc9
                                0xffffffff81fc00c4  sysvec_apic_timer_interrupt+0x54
                                0xffffffff82000e46  asm_sysvec_apic_timer_interrupt+0x16
                 1     28.84 us     28.84 us     28.84 us     spinlock   rcu_accelerate_cbs_unlocked+0x40
                                0xffffffff81fd1c60  _raw_spin_lock+0x30
                                0xffffffff81728cf0  rcu_accelerate_cbs_unlocked+0x40
                                0xffffffff8172da82  rcu_core+0x3e2
                                0xffffffff822000eb  __softirqentry_text_start+0xeb
                                0xffffffff816a0ba9  __irq_exit_rcu+0xc9
                                0xffffffff81fc0112  sysvec_apic_timer_interrupt+0xa2
                                0xffffffff82000e46  asm_sysvec_apic_timer_interrupt+0x16
                                0xffffffff81d49f78  cpuidle_enter_state+0xd8
        ...
      
      To see tasks calling 'rcu_core' function:
      
        $ sudo perf lock con -abt -S rcu_core sleep 1
         contended   total wait     max wait     avg wait          pid   comm
      
                19     23.46 us      2.21 us      1.23 us            0   swapper
                 2     18.37 us     17.01 us      9.19 us      2061859   ThreadPoolForeg
                 3      5.76 us      1.97 us      1.92 us         3909   pipewire-pulse
                 1      2.26 us      2.26 us      2.26 us      1809271   MediaSu~isor #2
                 1      1.97 us      1.97 us      1.97 us      1514882   Chrome_ChildIOT
                 1       987 ns       987 ns       987 ns         3740   pipewire-pulse
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Hao Luo <haoluo@google.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Juri Lelli <juri.lelli@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230203021324.143540-4-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ebab2916
    • Namhyung Kim's avatar
      perf lock contention: Use lock_stat_find{,new} · 16cad1d3
      Namhyung Kim authored
      This is a preparation work to support complex keys of BPF maps.  Now it
      has single value key according to the aggregation mode like stack_id or
      pid.  But we want to use a combination of those keys.
      
      Then lock_contention_read() should still aggregate the result based on
      the key that was requested by user.  The other key info will be used for
      filtering.
      
      So instead of creating a lock_stat entry always, Check if it's already
      there using lock_stat_find() first.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Hao Luo <haoluo@google.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Juri Lelli <juri.lelli@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230203021324.143540-3-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      16cad1d3
    • Namhyung Kim's avatar
      perf lock contention: Factor out lock_contention_get_name() · 492fef21
      Namhyung Kim authored
      The lock_contention_get_name() returns a name for the lock stat entry
      based on the current aggregation mode.  As it's called sequentially in a
      single thread, it can return the address of a static buffer for symbol
      and offset of the caller.
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Hao Luo <haoluo@google.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Juri Lelli <juri.lelli@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Song Liu <song@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230203021324.143540-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      492fef21
    • Rob Herring's avatar
      perf arm-spe: Add raw decoding for SPEv1.2 previous branch address · 7105311c
      Rob Herring authored
      Arm SPEv1.2 adds a new optional address packet type: previous branch
      target. The recorded address is the target virtual address of the most
      recently taken branch in program order.
      
      Add support for decoding the address packet in raw dumps.
      Reviewed-by: default avatarLeo Yan <leo.yan@linaro.org>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20230203162401.132931-1-robh@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7105311c
    • Ian Rogers's avatar
      perf jevents: Run metric_test.py at compile-time · b777b3d2
      Ian Rogers authored
      Add a target that generates a log file for running metric_test.py and
      make this a dependency on generating pmu-events.c. The log output is
      displayed if the test fails like (the test was modified to make it
      fail):
      
      ```
        TEST    /tmp/perf/pmu-events/metric_test.log
      F......
      ======================================================================
      FAIL: test_Brackets (__main__.TestMetricExpressions)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "tools/perf/pmu-events/metric_test.py", line 33, in test_Brackets
          self.assertEqual((a * b + c).ToPerfJson(), 'a * b + d')
      AssertionError: 'a * b + c' != 'a * b + d'
      - a * b + c
      ?         ^
      + a * b + d
      ?         ^
      
      ----------------------------------------------------------------------
      Ran 7 tests in 0.004s
      
      FAILED (failures=1)
      make[3]: *** [pmu-events/Build:32: /tmp/perf/pmu-events/metric_test.log] Error 1
      ```
      
      However, normal execution will just show the TEST line.
      
      This is roughly modeled on fortify testing in the kernel lib directory.
      
      Modify metric_test.py so that it is executable. This is necessary when
      PYTHON isn't specified in the build, the normal case.
      
      Use variables to make the paths to files clearer and more consistent.
      
      Committer notes:
      
      Add pmu-events/metric_test.log to tools/perf/.gitignore and to the
      'clean' target on tools/perf/Makefile.perf.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-16-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      b777b3d2
    • Ian Rogers's avatar
      tools build: Add test echo-cmd · e30f3405
      Ian Rogers authored
      Add quiet_cmd_test so that:
      $(Q)$(call echo-cmd,test)
      
      will print:
      TEST   <path>
      
      This is useful for executing compile-time tests similar to what
      happens for fortify tests in the kernel's lib directory.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-15-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      e30f3405
    • Ian Rogers's avatar
      perf jevents: Correct bad character encoding · d2e3dc82
      Ian Rogers authored
      A character encoding issue added a "3D" character that breaks the
      metrics test.
      
      Fixes: 40769665 ("perf jevents: Parse metrics during conversion")
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-14-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d2e3dc82
    • Ian Rogers's avatar
      perf pmu-events: Fix testing with JEVENTS_ARCH=all · 3340a083
      Ian Rogers authored
      The #slots literal will return NAN when not on ARM64 which causes a
      perf test failure when not on an ARM64 for a JEVENTS_ARCH=all build:
      ..
       10.4: Parsing of PMU event table metrics with fake PMUs             : FAILED!
      ..
      Add an is_test boolean so that the failure can be avoided when running
      as a test.
      
      Fixes: acef233b ("perf pmu: Add #slots literal support for arm64")
      Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-13-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3340a083
    • Ian Rogers's avatar
      perf jevents: Add model list option · 5a09b1fd
      Ian Rogers authored
      This allows the set of generated jevents events and metrics be limited
      to a subset of the model names. Appropriate if trying to minimize the
      binary size where only a set of models are possible.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-12-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      5a09b1fd
    • Ian Rogers's avatar
      perf jevents: Generate metrics and events as separate tables · 62774db2
      Ian Rogers authored
      Turn a perf json event into an event, metric or both. This reduces the
      number of events needed to scan to find an event or metric. As events
      no longer need the relatively seldom used metric fields, 4 bytes is
      saved per event. This reduces the big C string's size by 335kb (14.8%)
      on x86.
      
      Note, for the test PMU architecture pme_test_soc_cpu is renamed
      pmu_events__test_soc_cpu for consistency with the event vs metric
      naming convention.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-11-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      62774db2
    • Ian Rogers's avatar
      perf pmu-events: Introduce pmu_metrics_table · f8ea2c15
      Ian Rogers authored
      Add a metrics table that is just a cast from pmu_events_table. This
      changes the APIs so that event and metric usage of the underlying
      table is different. For the no jevents case the tables are already
      separate, later changes will separate the tables for the jevents case.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-10-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      f8ea2c15
    • Ian Rogers's avatar
      perf jevents: Combine table prefix and suffix writing · 9f587cc9
      Ian Rogers authored
      Combine into a single function to simplify, in a later change, writing
      metrics separately.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-9-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      9f587cc9
    • Ian Rogers's avatar
      perf stat: Remove evsel metric_name/expr · 6f8f98ab
      Ian Rogers authored
      Metrics are their own unit and these variables held broken metrics
      previously and now just hold the value NULL. Remove code that used
      these variables.
      Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-8-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6f8f98ab
    • Ian Rogers's avatar
      perf pmu-events: Remove now unused event and metric variables · d9dc8874
      Ian Rogers authored
      Previous changes separated the uses of pmu_event and pmu_metric,
      however, both structures contained all the variables of event and
      metric. This change removes the event variables from metric and the
      metric variables from event.
      
      Note, this change removes the setting of evsel's metric_name/expr as
      these fields are no longer part of struct pmu_event. The metric
      remains but is no longer implicitly requested when the event is. This
      impacts a few Intel uncore events, however, as the ScaleUnit is shared
      by the event and the metric this utility is questionable. Also the
      MetricNames look broken (contain spaces) in some cases and when trying
      to use the functionality with '-e' the metrics fail but regular
      metrics with '-M' work. For example, on SkylakeX '-M' works:
      
      ```
      $ perf stat -M LLC_MISSES.PCIE_WRITE -a sleep 1
      
       Performance counter stats for 'system wide':
      
                       0      UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 #  57896.0 Bytes  LLC_MISSES.PCIE_WRITE  (49.84%)
                   7,174      UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1                                        (49.85%)
                       0      UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3                                        (50.16%)
                      63      UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0                                        (50.15%)
      
             1.004576381 seconds time elapsed
      ```
      
      whilst the event '-e' version is broken even with --group/-g (fwiw, we should also remove -g [1]):
      
      ```
      $ perf stat -g -e LLC_MISSES.PCIE_WRITE -g -a sleep 1
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART2 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART1 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART3 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      Add UNC_IIO_DATA_REQ_OF_CPU.MEM_WRITE.PART0 event to groups to get metric expression for LLC_MISSES.PCIE_WRITE
      
       Performance counter stats for 'system wide':
      
                  27,316 Bytes LLC_MISSES.PCIE_WRITE
      
             1.004505469 seconds time elapsed
      ```
      
      The code also carries warnings where the user is supposed to select
      events for metrics [2] but given the lack of use of such a feature,
      let's clean the code and just remove.
      
      [1] https://lore.kernel.org/lkml/20220707195610.303254-1-irogers@google.com/
      [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/stat-shadow.c?id=01b8957b738f42f96a130079bc951b3cc78c5b8a#n425Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      d9dc8874
    • Ian Rogers's avatar
      perf pmu-events: Separate the metrics from events for no jevents · 96d2a746
      Ian Rogers authored
      Separate the event and metric table when building without jevents. Add
      find_core_metrics_table and perf_pmu__find_metrics_table while
      renaming existing utilities to be event specific, so that users can
      find the right table for their need.
      
      Committer notes:
      
      Fix the build on aarch64 with:
      
        tools/perf/arch/arm64/util/pmu.c
        @@ -32,7 +32,7 @@ const struct pmu_events_table *pmu_events_table__find(void)
        -               return perf_pmu__find_table(pmu);
        +               return perf_pmu__find_events_table(pmu);
      Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-6-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      96d2a746
  2. 02 Feb, 2023 24 commits
    • Ian Rogers's avatar
      perf pmu-events: Add separate metric from pmu_event · db95818e
      Ian Rogers authored
      Create a new pmu_metric for the metric related variables from pmu_event
      but that is initially just a clone of pmu_event. Add iterators for
      pmu_metric and use in places that metrics are desired rather than
      events. Make the event iterator skip metric only events, and the metric
      iterator skip event only events.
      Reviewed-by: default avatarJohn Garry <john.g.garry@oracle.com>
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-5-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      db95818e
    • Ian Rogers's avatar
      perf jevents: Rewrite metrics in the same file with each other · df5499dd
      Ian Rogers authored
      Rewrite metrics within the same file in terms of each other. For example, on Power8
      other_stall_cpi is rewritten from:
      
      "PM_CMPLU_STALL / PM_RUN_INST_CMPL - PM_CMPLU_STALL_BRU_CRU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_FXU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_VSU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_LSU / PM_RUN_INST_CMPL - PM_CMPLU_STALL_NTCG_FLUSH / PM_RUN_INST_CMPL - PM_CMPLU_STALL_NO_NTF / PM_RUN_INST_CMPL"
      
      to:
      
      "stall_cpi - bru_cru_stall_cpi - fxu_stall_cpi - vsu_stall_cpi - lsu_stall_cpi - ntcg_flush_cpi - no_ntf_stall_cpi"
      Which more closely matches the definition on Power9.
      
      To avoid recomputation decorate the function with a cache.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-4-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      df5499dd
    • Ian Rogers's avatar
      perf jevents metric: Add ability to rewrite metrics in terms of others · 2efbb73d
      Ian Rogers authored
      Add RewriteMetricsInTermsOfOthers that iterates over pairs of names and
      expressions trying to replace an expression, within the current
      expression, with its name.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      2efbb73d
    • Ian Rogers's avatar
      perf jevents metric: Correct Function equality · 3241cd11
      Ian Rogers authored
      rhs may not be defined, say for source_count, so add a guard.
      Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
      Signed-off-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Caleb Biggers <caleb.biggers@intel.com>
      Cc: Florian Fischer <florian.fischer@muhq.space>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: John Garry <john.g.garry@oracle.com>
      Cc: Kan Liang <kan.liang@linux.intel.com>
      Cc: Kang Minchul <tegongkang@gmail.com>
      Cc: Kim Phillips <kim.phillips@amd.com>
      Cc: Leo Yan <leo.yan@linaro.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mike Leach <mike.leach@linaro.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Perry Taylor <perry.taylor@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Sandipan Das <sandipan.das@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230126233645.200509-2-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3241cd11
    • Sandipan Das's avatar
      perf session: Show branch speculation info in raw dump · 8eaf8ec3
      Sandipan Das authored
      Show the branch speculation info if provided by the branch recording
      hardware feature. This can be useful for purposes of code optimization.
      
      E.g.
      
        $ perf record -j any,u ./test_branch
        $ perf report --dump-raw-trace
      
      Before:
      
        [...]
        8380958377610 0x40b178 [0x1b0]: PERF_RECORD_SAMPLE(IP, 0x2): 7952/7952: 0x4f851a period: 48973 addr: 0
        ... branch stack: nr:16
        .....  0: 00000000004b52fd -> 00000000004f82c0 0 cycles  P   0
        .....  1: ffffffff8220137c -> 00000000004b52f0 0 cycles M    0
        .....  2: 000000000041d1c4 -> 00000000004b52f0 0 cycles  P   0
        .....  3: 00000000004e7ead -> 000000000041d1b0 0 cycles M    0
        .....  4: 00000000004e7f91 -> 00000000004e7ead 0 cycles  P   0
        .....  5: 00000000004e7ea8 -> 00000000004e7f70 0 cycles  P   0
        .....  6: 00000000004e7e52 -> 00000000004e7e98 0 cycles M    0
        .....  7: 00000000004e7e1f -> 00000000004e7e40 0 cycles M    0
        .....  8: 00000000004e7f60 -> 00000000004e7df0 0 cycles  P   0
        .....  9: 00000000004e7f58 -> 00000000004e7f60 0 cycles M    0
        ..... 10: 000000000041d85d -> 00000000004e7f50 0 cycles  P   0
        ..... 11: 000000000043306a -> 000000000041d840 0 cycles  P   0
        ..... 12: ffffffff8220137c -> 0000000000433040 0 cycles M    0
        ..... 13: 000000000041e4a1 -> 0000000000433040 0 cycles  P   0
        ..... 14: ffffffff8220137c -> 000000000041e490 0 cycles M    0
        ..... 15: 000000000041d89b -> 000000000041e487 0 cycles  P   0
         ... thread: test_branch:7952
         ...... dso: /data/sandipan/test_branch
        [...]
      
      After:
      
        [...]
        8380958377610 0x40b178 [0x1b0]: PERF_RECORD_SAMPLE(IP, 0x2): 7952/7952: 0x4f851a period: 48973 addr: 0
        ... branch stack: nr:16
        .....  0: 00000000004b52fd -> 00000000004f82c0 0 cycles  P   0  NON_SPEC_CORRECT_PATH
        .....  1: ffffffff8220137c -> 00000000004b52f0 0 cycles M    0  NON_SPEC_CORRECT_PATH
        .....  2: 000000000041d1c4 -> 00000000004b52f0 0 cycles  P   0  NON_SPEC_CORRECT_PATH
        .....  3: 00000000004e7ead -> 000000000041d1b0 0 cycles M    0  NON_SPEC_CORRECT_PATH
        .....  4: 00000000004e7f91 -> 00000000004e7ead 0 cycles  P   0  NON_SPEC_CORRECT_PATH
        .....  5: 00000000004e7ea8 -> 00000000004e7f70 0 cycles  P   0  NON_SPEC_CORRECT_PATH
        .....  6: 00000000004e7e52 -> 00000000004e7e98 0 cycles M    0  SPEC_CORRECT_PATH
        .....  7: 00000000004e7e1f -> 00000000004e7e40 0 cycles M    0  NON_SPEC_CORRECT_PATH
        .....  8: 00000000004e7f60 -> 00000000004e7df0 0 cycles  P   0  NON_SPEC_CORRECT_PATH
        .....  9: 00000000004e7f58 -> 00000000004e7f60 0 cycles M    0  NON_SPEC_CORRECT_PATH
        ..... 10: 000000000041d85d -> 00000000004e7f50 0 cycles  P   0  NON_SPEC_CORRECT_PATH
        ..... 11: 000000000043306a -> 000000000041d840 0 cycles  P   0  NON_SPEC_CORRECT_PATH
        ..... 12: ffffffff8220137c -> 0000000000433040 0 cycles M    0  NON_SPEC_CORRECT_PATH
        ..... 13: 000000000041e4a1 -> 0000000000433040 0 cycles  P   0  NON_SPEC_CORRECT_PATH
        ..... 14: ffffffff8220137c -> 000000000041e490 0 cycles M    0  NON_SPEC_CORRECT_PATH
        ..... 15: 000000000041d89b -> 000000000041e487 0 cycles  P   0  NON_SPEC_CORRECT_PATH
         ... thread: test_branch:7952
         ...... dso: /data/sandipan/test_branch
        [...]
      
      With the addition of new branch flags, the "brstacksym" fields in perf
      script output now shows speculation information after the branch type.
      Change the regular expressions accordingly for the test to pass. Since
      branch speculation information may vary across platforms, the test does
      not look for specific values.
      
      E.g.
      
        $ perf test -v 110
      
      Before:
      
        110: Check branch stack sampling                                     :
        --- start ---
        test child forked, pid 54154
        Testing user branch stack sampling
        + grep -E -m1 ^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL$ /tmp/__perf_test.program.AfhUI/perf.script
        + cleanup
        + rm -rf /tmp/__perf_test.program.AfhUI
        test child finished with -1
        ---- end ----
        Check branch stack sampling: FAILED!
      
      After:
      
        110: Check branch stack sampling                                     :
        --- start ---
        test child forked, pid 43716
        Testing user branch stack sampling
        + grep -E -m1 ^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL/.*$ /tmp/__perf_test.program.xgzAi/perf.script
        brstack_bench+0x66/brstack_foo+0x0/P/-/-/0/IND_CALL/NON_SPEC_CORRECT_PATH
        + grep -E -m1 ^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$ /tmp/__perf_test.program.xgzAi/perf.script
        brstack_foo+0x1b/brstack_bar+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
        + grep -E -m1 ^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL/.*$ /tmp/__perf_test.program.xgzAi/perf.script
        brstack_bench+0x58/brstack_foo+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
        + grep -E -m1 ^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$ /tmp/__perf_test.program.xgzAi/perf.script
        brstack_bench+0x5d/brstack_bar+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
        + grep -E -m1 ^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET/.*$ /tmp/__perf_test.program.xgzAi/perf.script
        brstack_bar+0x31/brstack_foo+0x20/P/-/-/0/RET/NON_SPEC_CORRECT_PATH
        + grep -E -m1 ^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET/.*$ /tmp/__perf_test.program.xgzAi/perf.script
        brstack_foo+0x36/brstack_bench+0x5d/P/-/-/0/RET/NON_SPEC_CORRECT_PATH
        + grep -E -m1 ^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND/.*$ /tmp/__perf_test.program.xgzAi/perf.script
        brstack_bench+0x76/brstack_bench+0x7d/P/-/-/0/COND/NON_SPEC_CORRECT_PATH
        + grep -E -m1 ^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND/.*$ /tmp/__perf_test.program.xgzAi/perf.script
        brstack+0x5a/brstack+0x41/P/-/-/0/UNCOND/NON_SPEC_CORRECT_PATH
        + set +x
        Testing branch stack filtering permutation (any_call,CALL|IND_CALL|COND_CALL|SYSCALL|IRQ)
        Testing branch stack filtering permutation (call,CALL|SYSCALL)
        Testing branch stack filtering permutation (cond,COND)
        Testing branch stack filtering permutation (any_ret,RET|COND_RET|SYSRET|ERET)
        Testing branch stack filtering permutation (call,cond,CALL|SYSCALL|COND)
        Testing branch stack filtering permutation (any_call,cond,CALL|IND_CALL|COND_CALL|IRQ|SYSCALL|COND)
        Testing branch stack filtering permutation (cond,any_call,any_ret,COND|CALL|IND_CALL|COND_CALL|SYSCALL|IRQ|RET|COND_RET|SYSRET|ERET)
        test child finished with 0
        ---- end ----
        Check branch stack sampling: Ok
      Signed-off-by: default avatarSandipan Das <sandipan.das@amd.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ananth Narayan <ananth.narayan@amd.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Santosh Shukla <santosh.shukla@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Cc: x86@kernel.org
      Link: https://lore.kernel.org/r/048d67c9de3cc8e3dbf19aaa7ff718dec91364c5.1675333809.git.sandipan.das@amd.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      8eaf8ec3
    • Sandipan Das's avatar
      perf script: Show branch speculation info · 6ade6c64
      Sandipan Das authored
      Show the branch speculation info if provided by the branch recording
      hardware feature. This can be useful for optimizing code further.
      
      The speculation info is appended to the end of the list of fields so any
      existing tools that use "/" as a delimiter for access fields via an index
      remain unaffected. Also show "-" instead of "N/A" when speculation info
      is unavailable because "/" is used as the field separator.
      
      E.g.
      
        $ perf record -j any,u,save_type ./test_branch
        $ perf script --fields brstacksym
      
      Before:
      
        [...]
        check_match+0x60/strcmp+0x0/P/-/-/0/CALL
        do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL
        [...]
      
      After:
      
        [...]
        check_match+0x60/strcmp+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
        do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
        [...]
      
      The bitfield swapping scheme used duing sample parsing has changed
      because of the addition of new branch flags, namely "spec", "new_type"
      and "priv". Earlier, these were all part of the "reserved" field but
      now, each of these fields get swapped separately. Change the expected
      flag values accordingly for the test to pass.
      
      E.g.
      
        $ perf test -v 27
      
      Before:
      
         27: Sample parsing                                                  :
        --- start ---
        test child forked, pid 61979
        parsing failed for sample_type 0x800
        test child finished with -1
        ---- end ----
        Sample parsing: FAILED!
      
      After:
      
         27: Sample parsing                                                  :
        --- start ---
        test child forked, pid 63293
        test child finished with 0
        ---- end ----
        Sample parsing: Ok
      Signed-off-by: default avatarSandipan Das <sandipan.das@amd.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ananth Narayan <ananth.narayan@amd.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ravi Bangoria <ravi.bangoria@amd.com>
      Cc: Santosh Shukla <santosh.shukla@amd.com>
      Cc: Stephane Eranian <eranian@google.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thomas Richter <tmricht@linux.ibm.com>
      Cc: x86@kernel.org
      Link: https://lore.kernel.org/r/56e272583552526e999ba0b536ac009ae3613966.1675333809.git.sandipan.das@amd.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6ade6c64
    • Namhyung Kim's avatar
      perf test: Add more test cases for perf lock contention · 79b7ca78
      Namhyung Kim authored
      Check callstack filter with two different aggregation mode.
      
        $ sudo ./perf test -v contention
         88: kernel lock contention analysis test                            :
        --- start ---
        test child forked, pid 83416
        Testing perf lock record and perf lock contention
        Testing perf lock contention --use-bpf
        Testing perf lock record and perf lock contention at the same time
        Testing perf lock contention --threads
        Testing perf lock contention --lock-addr
        Testing perf lock contention --type-filter (w/ spinlock)
        Testing perf lock contention --lock-filter (w/ tasklist_lock)
        Testing perf lock contention --callstack-filter (w/ unix_stream)
        Testing perf lock contention --callstack-filter with task aggregation
        test child finished with 0
        ---- end ----
        kernel lock contention analysis test: Ok
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Hao Luo <haoluo@google.com>
      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: Song Liu <song@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230202050455.2187592-5-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      79b7ca78
    • Tiezhu Yang's avatar
      perf bench syscall: Add execve syscall benchmark · 540f8b56
      Tiezhu Yang authored
      This commit adds the execve syscall benchmark, more syscall benchmarks
      can be added in the future.
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/1668052208-14047-5-git-send-email-yangtiezhu@loongson.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      540f8b56
    • Tiezhu Yang's avatar
      perf bench syscall: Add getpgid syscall benchmark · 391f84e5
      Tiezhu Yang authored
      This commit adds a simple getpgid syscall benchmark, more syscall
      benchmarks can be added in the future.
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/1668052208-14047-4-git-send-email-yangtiezhu@loongson.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      391f84e5
    • Tiezhu Yang's avatar
      perf bench syscall: Introduce bench_syscall_common() · 3fe91f32
      Tiezhu Yang authored
      In the current code, there is only a basic syscall benchmark via
      getppid, this is not enough. Introduce bench_syscall_common() so that we
      can add more syscalls to benchmark.
      
      This is preparation for later patch, no functionality change.
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/1668052208-14047-3-git-send-email-yangtiezhu@loongson.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3fe91f32
    • Tiezhu Yang's avatar
      tools x86: Keep list sorted by number in unistd_{32,64}.h · 1bad5027
      Tiezhu Yang authored
      It is better to keep list sorted by number in unistd_{32,64}.h,
      so that we can add more syscall number to a proper position.
      
      This is preparation for later patch, no functionality change.
      Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
      Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/1668052208-14047-2-git-send-email-yangtiezhu@loongson.cnSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1bad5027
    • Diederik de Haas's avatar
      perf test: Replace legacy `...` with $(...) · a912f597
      Diederik de Haas authored
      As detailed in https://www.shellcheck.net/wiki/SC2006:
      
      The use of `...` is legacy syntax with several issues:
      1. It has a series of undefined behaviors related to quoting in POSIX.
      2. It imposes a custom escaping mode with surprising results.
      3. It's exceptionally hard to nest.
      
      $(...) command substitution has none of these problems,
      and is therefore strongly encouraged.
      Signed-off-by: default avatarDiederik de Haas <didi.debian@cknow.org>
      Acked-by: default avatarCarsten Haitzler <carsten.haitzler@arm.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20230201214945.127474-3-didi.debian@cknow.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      a912f597
    • Diederik de Haas's avatar
      perf test: Replace 'grep | wc -l' with 'grep -c' · 5b420cf0
      Diederik de Haas authored
      To count the number of results from grep, use the '-c' parameter
      instead of piping it to 'wc'.
      
      See also https://www.shellcheck.net/wiki/SC2126Signed-off-by: default avatarDiederik de Haas <didi.debian@cknow.org>
      Acked-by: default avatarCarsten Haitzler <carsten.haitzler@arm.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20230201214945.127474-2-didi.debian@cknow.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      5b420cf0
    • Namhyung Kim's avatar
      perf stat: Hide invalid uncore event output for aggr mode · dd15480a
      Namhyung Kim authored
      The current display code for perf stat iterates given cpus and build the
      aggr map to collect the event data for the aggregation mode.
      
      But uncore events have their own cpu maps and it won't guarantee that
      it'd match to the aggr map.  For example, per-package uncore events
      would generate a single value for each socket.  When user asks per-core
      aggregation mode, the output would contain 0 values for other cores.
      
      Thus it needs to check the uncore PMU's cpumask and if it matches to the
      current aggregation id.
      
      Before:
        $ sudo ./perf stat -a --per-core -e power/energy-pkg/ sleep 1
      
         Performance counter stats for 'system wide':
      
        S0-D0-C0              1               3.73 Joules power/energy-pkg/
        S0-D0-C1              0      <not counted> Joules power/energy-pkg/
        S0-D0-C2              0      <not counted> Joules power/energy-pkg/
        S0-D0-C3              0      <not counted> Joules power/energy-pkg/
      
               1.001404046 seconds time elapsed
      
        Some events weren't counted. Try disabling the NMI watchdog:
        	echo 0 > /proc/sys/kernel/nmi_watchdog
        	perf stat ...
        	echo 1 > /proc/sys/kernel/nmi_watchdog
      
      The core 1, 2 and 3 should not be printed because the event is handled
      in a cpu in the core 0 only.  With this change, the output becomes like
      below.
      
      After:
        $ sudo ./perf stat -a --per-core -e power/energy-pkg/ sleep 1
      
         Performance counter stats for 'system wide':
      
        S0-D0-C0              1               2.09 Joules power/energy-pkg/
      
      Fixes: b8976135 ("perf stat: Update event skip condition for system-wide per-thread mode and merged uncore and hybrid events")
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Tested-by: default avatarIan Rogers <irogers@google.com>
      Acked-by: default avatarIan Rogers <irogers@google.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Michael Petlan <mpetlan@redhat.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20230125192431.2929677-1-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      dd15480a
    • Namhyung Kim's avatar
      perf lock contention: Add -S/--callstack-filter option · 7b204399
      Namhyung Kim authored
      The -S/--callstack-filter is to limit display entries having the given
      string in the callstack (not only in the caller in the output).
      
      The following example shows lock contention results if the callstack
      has 'net' substring somewhere.  Note that the caller '__dev_queue_xmit'
      does not match to it, but it has 'inet6_csk_xmit' in the callstack.
      
      This applies even if you don't use -v option to show the full callstack.
      
        $ sudo ./perf lock con -abv -S net sleep 1
        ...
         contended   total wait     max wait     avg wait         type   caller
      
                 5     70.20 us     16.13 us     14.04 us     spinlock   __dev_queue_xmit+0xb6d
                                0xffffffffa5dd1c60  _raw_spin_lock+0x30
                                0xffffffffa5b8f6ed  __dev_queue_xmit+0xb6d
                                0xffffffffa5cd8267  ip6_finish_output2+0x2c7
                                0xffffffffa5cdac14  ip6_finish_output+0x1d4
                                0xffffffffa5cdb477  ip6_xmit+0x457
                                0xffffffffa5d1fd17  inet6_csk_xmit+0xd7
                                0xffffffffa5c5f4aa  __tcp_transmit_skb+0x54a
                                0xffffffffa5c6467d  tcp_keepalive_timer+0x2fd
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      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: Song Liu <song@kernel.org>
      Cc: bpf@vger.kernel.org
      Link: https://lore.kernel.org/r/20230126000936.3017683-1-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      7b204399
    • Namhyung Kim's avatar
      perf script: Add 'cgroup' field for output · 3fd7a168
      Namhyung Kim authored
      There's no field for the cgroup, let's add one.  To do that, users need to
      specify --all-cgroup option for perf record to capture the cgroup info.
      
        $ perf record --all-cgroups -- true
      
        $ perf script -F comm,pid,cgroup
                  true 337112  /user.slice/user-657345.slice/user@657345.service/...
                  true 337112  /user.slice/user-657345.slice/user@657345.service/...
                  true 337112  /user.slice/user-657345.slice/user@657345.service/...
                  true 337112  /user.slice/user-657345.slice/user@657345.service/...
      
      If it's recorded without the --all-cgroups, it'd complain.
      
        $ perf script -F comm,pid,cgroup
        Samples for 'cycles:u' event do not have CGROUP attribute set. Cannot print 'cgroup' field.
        Hint: run 'perf record --all-cgroups ...'
      Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      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>
      Link: https://lore.kernel.org/r/20230126213610.3381147-1-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3fd7a168
    • Ross Zwisler's avatar
      perf tools docs: Use canonical ftrace path · 1df49ef9
      Ross Zwisler authored
      The canonical location for the tracefs filesystem is at /sys/kernel/tracing.
      
      But, from Documentation/trace/ftrace.rst:
      
        Before 4.1, all ftrace tracing control files were within the debugfs
        file system, which is typically located at /sys/kernel/debug/tracing.
        For backward compatibility, when mounting the debugfs file system,
        the tracefs file system will be automatically mounted at:
      
        /sys/kernel/debug/tracing
      
      A few spots in the perf docs still refer to this older debugfs path, so
      let's update them to avoid confusion.
      Signed-off-by: default avatarRoss Zwisler <zwisler@google.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: linux-trace-kernel@vger.kernel.org
      Link: http://lore.kernel.org/lkml/20230130181915.1113313-5-zwisler@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1df49ef9
    • Rob Herring's avatar
      perf arm-spe: Only warn once for each unsupported address packet · 28899594
      Rob Herring authored
      Unknown address packet indexes are not an error as the Arm architecture
      can (and has with SPEv1.2) define new ones and implementation defined
      ones are also allowed. The error message for every occurrence of the
      packet is needlessly noisy as well. Change the message to print just
      once for each unknown index.
      Reviewed-by: default avatarLeo Yan <leo.yan@linaro.org>
      Signed-off-by: default avatarRob Herring <robh@kernel.org>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Will Deacon <will@kernel.org>
      Link: https://lore.kernel.org/r/20230127205546.667740-1-robh@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      28899594
    • Krister Johansen's avatar
      perf symbols: Symbol lookup with kcore can fail if multiple segments match stext · 1c249565
      Krister Johansen authored
      This problem was encountered on an arm64 system with a lot of memory.
      Without kernel debug symbols installed, and with both kcore and kallsyms
      available, perf managed to get confused and returned "unknown" for all
      of the kernel symbols that it tried to look up.
      
      On this system, stext fell within the vmalloc segment.  The kcore symbol
      matching code tries to find the first segment that contains stext and
      uses that to replace the segment generated from just the kallsyms
      information.  In this case, however, there were two: a very large
      vmalloc segment, and the text segment.  This caused perf to get confused
      because multiple overlapping segments were inserted into the RB tree
      that holds the discovered segments.  However, that alone wasn't
      sufficient to cause the problem. Even when we could find the segment,
      the offsets were adjusted in such a way that the newly generated symbols
      didn't line up with the instruction addresses in the trace.  The most
      obvious solution would be to consult which segment type is text from
      kcore, but this information is not exposed to users.
      
      Instead, select the smallest matching segment that contains stext
      instead of the first matching segment.  This allows us to match the text
      segment instead of vmalloc, if one is contained within the other.
      Reviewed-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Signed-off-by: default avatarKrister Johansen <kjlx@templeofstupid.com>
      Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
      Cc: David Reaver <me@davidreaver.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      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/20230125183418.GD1963@templeofstupid.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      1c249565
    • Athira Rajeev's avatar
      perf probe: Fix usage when libtraceevent is missing · 3980ee9a
      Athira Rajeev authored
      While parsing the tracepoint events in parse_events_add_tracepoint()
      function, code checks for HAVE_LIBTRACEEVENT support. This is needed
      since libtraceevent is necessary for tracepoint. But while adding probe
      points, check for LIBTRACEEVENT is not done in case of perf probe.
      Hence, in environment with missing libtraceevent-devel, it is observed
      that adding a probe point shows below message though it can't be used
      via perf record.
      
      Example:
      
      Adding probe point:
      	./perf probe 'vfs_getname=getname_flags:72 pathname=result->name:string'
      	Added new event:
      	  probe:vfs_getname    (on getname_flags:72 with pathname=result->name:string)
      
      	You can now use it in all perf tools, such as:
      
      		perf record -e probe:vfs_getname -aR sleep 1
      
      But trying perf record:
      	./perf  record -e probe:vfs_getname -aR sleep 1
      	event syntax error: 'probe:vfs_getname'
      				\___ unsupported tracepoint
      	libtraceevent is necessary for tracepoint support
      	Run 'perf list' for a list of valid events
      
      The builtin tool like perf record needs libtraceevent to
      parse tracefs. But still the probe can be used by enabling
      via tracefs. Patch fixes the probe usage message to the user
      based on presence of libtraceevent. With the fix,
      
       # ./perf probe 'pmu:myprobe=schedule'
       Added new event:
         pmu:myprobe          (on schedule)
      
       perf is not linked with libtraceevent, to use the new probe you can use tracefs:
      
      	cd /sys/kernel/tracing/
      	echo 1 > events/pmu/myprobe/enable
      	echo 1 > tracing_on
      	cat trace_pipe
      	Before removing the probe, echo 0 > events/pmu/myprobe/enable
      Signed-off-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Disha Goel <disgoel@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nageswara R Sastry <rnsastry@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: linuxppc-dev@lists.ozlabs.org
      Link: https://lore.kernel.org/r/20230131134748.54567-1-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      3980ee9a
    • Adrian Hunter's avatar
      perf symbols: Get symbols for .plt.got for x86-64 · ce4c8e79
      Adrian Hunter authored
      For x86_64, determine a symbol for .plt.got entries. That requires
      computing the target offset and finding that in .rela.dyn, which in
      turn means .rela.dyn needs to be sorted by offset.
      
      Example:
      
        In this example, the GNU C Library is using .plt.got for malloc and
        free.
      
        Before:
      
          $ gcc --version
          gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
          Copyright (C) 2021 Free Software Foundation, Inc.
          This is free software; see the source for copying conditions.  There is NO
          warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
          $ perf record -e intel_pt//u uname
          Linux
          [ perf record: Woken up 1 times to write data ]
          [ perf record: Captured and wrote 0.027 MB perf.data ]
          $ perf script --itrace=be --ns -F-event,+addr,-period,-comm,-tid,-cpu > /tmp/cmp1.txt
      
        After:
      
          $ perf script --itrace=be --ns -F-event,+addr,-period,-comm,-tid,-cpu > /tmp/cmp2.txt
          $ diff /tmp/cmp1.txt /tmp/cmp2.txt | head -12
          15509,15510c15509,15510
          < 27046.755390907:      7f0b2943e3ab _nl_normalize_codeset+0x5b (/usr/lib/x86_64-linux-gnu/libc.so.6) =>     7f0b29428380 offset_0x28380@plt+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6)
          < 27046.755390907:      7f0b29428384 offset_0x28380@plt+0x4 (/usr/lib/x86_64-linux-gnu/libc.so.6) =>     7f0b294a5120 malloc+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6)
          ---
          > 27046.755390907:      7f0b2943e3ab _nl_normalize_codeset+0x5b (/usr/lib/x86_64-linux-gnu/libc.so.6) =>     7f0b29428380 malloc@plt+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6)
          > 27046.755390907:      7f0b29428384 malloc@plt+0x4 (/usr/lib/x86_64-linux-gnu/libc.so.6) =>     7f0b294a5120 malloc+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6)
          15821,15822c15821,15822
          < 27046.755394865:      7f0b2943850c _nl_load_locale_from_archive+0x5bc (/usr/lib/x86_64-linux-gnu/libc.so.6) =>     7f0b29428370 offset_0x28370@plt+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6)
          < 27046.755394865:      7f0b29428374 offset_0x28370@plt+0x4 (/usr/lib/x86_64-linux-gnu/libc.so.6) =>     7f0b294a5460 cfree@GLIBC_2.2.5+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6)
          ---
          > 27046.755394865:      7f0b2943850c _nl_load_locale_from_archive+0x5bc (/usr/lib/x86_64-linux-gnu/libc.so.6) =>     7f0b29428370 free@plt+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6)
          > 27046.755394865:      7f0b29428374 free@plt+0x4 (/usr/lib/x86_64-linux-gnu/libc.so.6) =>     7f0b294a5460 cfree@GLIBC_2.2.5+0x0 (/usr/lib/x86_64-linux-gnu/libc.so.6)
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Link: https://lore.kernel.org/r/20230131131625.6964-10-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      ce4c8e79
    • Adrian Hunter's avatar
      perf symbols: Start adding support for .plt.got for x86 · 51a188ad
      Adrian Hunter authored
      For x86, .plt.got is used, for example, when the address is taken of a
      dynamically linked function. Start adding support by synthesizing a
      symbol for each entry. A subsequent patch will attempt to get a better
      name for the symbol.
      
      Example:
      
        Before:
      
          $ cat tstpltlib.c
          void fn1(void) {}
          void fn2(void) {}
          void fn3(void) {}
          void fn4(void) {}
          $ cat tstpltgot.c
          void fn1(void);
          void fn2(void);
          void fn3(void);
          void fn4(void);
      
          void callfn(void (*fn)(void))
          {
                  fn();
          }
      
          int main()
          {
                  fn4();
                  fn1();
                  callfn(fn3);
                  fn2();
                  fn3();
                  return 0;
          }
          $ gcc --version
          gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
          Copyright (C) 2021 Free Software Foundation, Inc.
          This is free software; see the source for copying conditions.  There is NO
          warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
          $ gcc -Wall -Wextra -shared -o libtstpltlib.so tstpltlib.c
          $ gcc -Wall -Wextra -o tstpltgot tstpltgot.c -L . -ltstpltlib -Wl,-rpath="$(pwd)"
          $ readelf -SW tstpltgot | grep 'Name\|plt\|dyn'
            [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
            [ 6] .dynsym           DYNSYM          00000000000003d8 0003d8 0000f0 18   A  7   1  8
            [ 7] .dynstr           STRTAB          00000000000004c8 0004c8 0000c6 00   A  0   0  1
            [10] .rela.dyn         RELA            00000000000005d8 0005d8 0000d8 18   A  6   0  8
            [11] .rela.plt         RELA            00000000000006b0 0006b0 000048 18  AI  6  24  8
            [13] .plt              PROGBITS        0000000000001020 001020 000040 10  AX  0   0 16
            [14] .plt.got          PROGBITS        0000000000001060 001060 000020 10  AX  0   0 16
            [15] .plt.sec          PROGBITS        0000000000001080 001080 000030 10  AX  0   0 16
            [23] .dynamic          DYNAMIC         0000000000003d90 002d90 000210 10  WA  7   0  8
          $ perf record -e intel_pt//u --filter 'filter main @ ./tstpltgot , filter callfn @ ./tstpltgot' ./tstpltgot
          [ perf record: Woken up 1 times to write data ]
          [ perf record: Captured and wrote 0.011 MB perf.data ]
          $ perf script --itrace=be --ns -F+flags,-event,+addr,-period,-comm,-tid,-cpu,-dso
          28393.810326915:   tr strt                               0 [unknown] =>     562350baa1b2 main+0x0
          28393.810326915:   tr end  call               562350baa1ba main+0x8 =>     562350baa090 fn4@plt+0x0
          28393.810326917:   tr strt                               0 [unknown] =>     562350baa1bf main+0xd
          28393.810326917:   tr end  call               562350baa1bf main+0xd =>     562350baa080 fn1@plt+0x0
          28393.810326917:   tr strt                               0 [unknown] =>     562350baa1c4 main+0x12
          28393.810326917:   call                       562350baa1ce main+0x1c =>     562350baa199 callfn+0x0
          28393.810326917:   tr end  call               562350baa1ad callfn+0x14 =>     7f607d36110f fn3+0x0
          28393.810326922:   tr strt                               0 [unknown] =>     562350baa1af callfn+0x16
          28393.810326922:   return                     562350baa1b1 callfn+0x18 =>     562350baa1d3 main+0x21
          28393.810326922:   tr end  call               562350baa1d3 main+0x21 =>     562350baa0a0 fn2@plt+0x0
          28393.810326924:   tr strt                               0 [unknown] =>     562350baa1d8 main+0x26
          28393.810326924:   tr end  call               562350baa1d8 main+0x26 =>     562350baa060 [unknown]  <- call to fn3 via .plt.got
          28393.810326925:   tr strt                               0 [unknown] =>     562350baa1dd main+0x2b
          28393.810326925:   tr end  return             562350baa1e3 main+0x31 =>     7f607d029d90 __libc_start_call_main+0x80
      
        After:
      
          $ perf script --itrace=be --ns -F+flags,-event,+addr,-period,-comm,-tid,-cpu,-dso
          28393.810326915:   tr strt                               0 [unknown] =>     562350baa1b2 main+0x0
          28393.810326915:   tr end  call               562350baa1ba main+0x8 =>     562350baa090 fn4@plt+0x0
          28393.810326917:   tr strt                               0 [unknown] =>     562350baa1bf main+0xd
          28393.810326917:   tr end  call               562350baa1bf main+0xd =>     562350baa080 fn1@plt+0x0
          28393.810326917:   tr strt                               0 [unknown] =>     562350baa1c4 main+0x12
          28393.810326917:   call                       562350baa1ce main+0x1c =>     562350baa199 callfn+0x0
          28393.810326917:   tr end  call               562350baa1ad callfn+0x14 =>     7f607d36110f fn3+0x0
          28393.810326922:   tr strt                               0 [unknown] =>     562350baa1af callfn+0x16
          28393.810326922:   return                     562350baa1b1 callfn+0x18 =>     562350baa1d3 main+0x21
          28393.810326922:   tr end  call               562350baa1d3 main+0x21 =>     562350baa0a0 fn2@plt+0x0
          28393.810326924:   tr strt                               0 [unknown] =>     562350baa1d8 main+0x26
          28393.810326924:   tr end  call               562350baa1d8 main+0x26 =>     562350baa060 offset_0x1060@plt+0x0
          28393.810326925:   tr strt                               0 [unknown] =>     562350baa1dd main+0x2b
          28393.810326925:   tr end  return             562350baa1e3 main+0x31 =>     7f607d029d90 __libc_start_call_main+0x80
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Link: https://lore.kernel.org/r/20230131131625.6964-9-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      51a188ad
    • Adrian Hunter's avatar
      perf symbols: Allow for static executables with .plt · a1ab1285
      Adrian Hunter authored
      A statically linked executable can have a .plt due to IFUNCs, in which
      case .symtab is used not .dynsym. Check the section header link to see
      if that is the case, and then use symtab instead.
      
      Example:
      
        Before:
      
          $ cat tstifunc.c
          #include <stdio.h>
      
          void thing1(void)
          {
                  printf("thing1\n");
          }
      
          void thing2(void)
          {
                  printf("thing2\n");
          }
      
          typedef void (*thing_fn_t)(void);
      
          thing_fn_t thing_ifunc(void)
          {
                  int x;
      
                  if (x & 1)
                          return thing2;
                  return thing1;
          }
      
          void thing(void) __attribute__ ((ifunc ("thing_ifunc")));
      
          int main()
          {
                  thing();
                  return 0;
          }
          $ gcc --version
          gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
          Copyright (C) 2021 Free Software Foundation, Inc.
          This is free software; see the source for copying conditions.  There is NO
          warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
          $ gcc -static -Wall -Wextra -Wno-uninitialized -o tstifuncstatic tstifunc.c
          $ readelf -SW tstifuncstatic | grep 'Name\|plt\|dyn'
            [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
            [ 4] .rela.plt         RELA            00000000004002e8 0002e8 000258 18  AI 29  20  8
            [ 6] .plt              PROGBITS        0000000000401020 001020 000190 00  AX  0   0 16
            [20] .got.plt          PROGBITS        00000000004c5000 0c4000 0000e0 08  WA  0   0  8
          $ perf record -e intel_pt//u --filter 'filter main @ ./tstifuncstatic' ./tstifuncstatic
          thing1
          [ perf record: Woken up 1 times to write data ]
          [ perf record: Captured and wrote 0.008 MB perf.data ]
          $ perf script --itrace=be --ns -F+flags,-event,+addr,-period,-comm,-tid,-cpu,-dso
          15786.690189535:   tr strt                               0 [unknown] =>           4017cd main+0x0
          15786.690189535:   tr end  call                     4017d5 main+0x8 =>           401170 [unknown]
          15786.690197660:   tr strt                               0 [unknown] =>           4017da main+0xd
          15786.690197660:   tr end  return                   4017e0 main+0x13 =>           401c1a __libc_start_call_main+0x6a
      
        After:
      
          $ perf script --itrace=be --ns -F+flags,-event,+addr,-period,-comm,-tid,-cpu,-dso
          15786.690189535:   tr strt                               0 [unknown] =>           4017cd main+0x0
          15786.690189535:   tr end  call                     4017d5 main+0x8 =>           401170 thing_ifunc@plt+0x0
          15786.690197660:   tr strt                               0 [unknown] =>           4017da main+0xd
          15786.690197660:   tr end  return                   4017e0 main+0x13 =>           401c1a __libc_start_call_main+0x6a
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Link: https://lore.kernel.org/r/20230131131625.6964-8-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      a1ab1285
    • Adrian Hunter's avatar
      perf symbols: Allow for .plt without header · 60fbb3e4
      Adrian Hunter authored
      A static executable can have a .plt due to the presence of IFUNCs.  In
      that case the .plt does not have a header. Check for whether there is a
      header by comparing the number of entries to the number of relocation
      entries.
      Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Link: https://lore.kernel.org/r/20230131131625.6964-7-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      60fbb3e4