[PATCH v1 0/7] Refactor cpuid and metric table lookup code

Ian Rogers posted 7 patches 2 weeks, 2 days ago
There is a newer version of this series
tools/perf/arch/arm64/util/arm-spe.c     | 14 +---
tools/perf/arch/arm64/util/header.c      | 73 ++++++++++-----------
tools/perf/arch/arm64/util/pmu.c         | 20 ------
tools/perf/arch/loongarch/util/header.c  |  4 +-
tools/perf/arch/powerpc/util/header.c    |  4 +-
tools/perf/arch/riscv/util/header.c      |  4 +-
tools/perf/arch/s390/util/header.c       |  6 +-
tools/perf/arch/x86/util/auxtrace.c      |  3 +-
tools/perf/arch/x86/util/header.c        |  5 +-
tools/perf/bench/numa.c                  | 51 +++++++++++++++
tools/perf/builtin-kvm.c                 |  4 +-
tools/perf/pmu-events/empty-pmu-events.c | 39 ++++++-----
tools/perf/pmu-events/jevents.py         | 39 ++++++-----
tools/perf/pmu-events/pmu-events.h       |  2 +-
tools/perf/tests/expr.c                  |  5 +-
tools/perf/util/env.c                    |  4 +-
tools/perf/util/expr.c                   |  6 +-
tools/perf/util/header.c                 | 82 ++++++++----------------
tools/perf/util/header.h                 | 23 +++----
tools/perf/util/pmu.c                    | 25 --------
tools/perf/util/pmu.h                    |  2 -
tools/perf/util/probe-event.c            |  1 +
22 files changed, 187 insertions(+), 229 deletions(-)
[PATCH v1 0/7] Refactor cpuid and metric table lookup code
Posted by Ian Rogers 2 weeks, 2 days ago
Xu Yang <xu.yang_2@nxp.com> reported issues with the system metric
lookup:
https://lore.kernel.org/linux-perf-users/20241106085441.3945502-1-xu.yang_2@nxp.com/
These patches remove a lot of the logic relating CPUIDs to PMUs so
that the PMU isn't part of the question when finding a metric table.
For time reasons, it doesn't go as far as allowing system metrics
without a metric table as a metric table is needed for metrics to
refer to other metrics, and the refactoring of that resolution is a
hassle.

Ian Rogers (7):
  perf header: Move is_cpu_online to numa bench
  perf header: Refactor get_cpuid to take a CPU for ARM
  perf arm64 header: Use cpu argument in get_cpuid
  perf header: Avoid transitive PMU includes
  perf header: Pass a perf_cpu rather than a PMU to get_cpuid_str
  perf jevents: Add map_for_cpu
  perf pmu: Move pmu_metrics_table__find and remove ARM override

 tools/perf/arch/arm64/util/arm-spe.c     | 14 +---
 tools/perf/arch/arm64/util/header.c      | 73 ++++++++++-----------
 tools/perf/arch/arm64/util/pmu.c         | 20 ------
 tools/perf/arch/loongarch/util/header.c  |  4 +-
 tools/perf/arch/powerpc/util/header.c    |  4 +-
 tools/perf/arch/riscv/util/header.c      |  4 +-
 tools/perf/arch/s390/util/header.c       |  6 +-
 tools/perf/arch/x86/util/auxtrace.c      |  3 +-
 tools/perf/arch/x86/util/header.c        |  5 +-
 tools/perf/bench/numa.c                  | 51 +++++++++++++++
 tools/perf/builtin-kvm.c                 |  4 +-
 tools/perf/pmu-events/empty-pmu-events.c | 39 ++++++-----
 tools/perf/pmu-events/jevents.py         | 39 ++++++-----
 tools/perf/pmu-events/pmu-events.h       |  2 +-
 tools/perf/tests/expr.c                  |  5 +-
 tools/perf/util/env.c                    |  4 +-
 tools/perf/util/expr.c                   |  6 +-
 tools/perf/util/header.c                 | 82 ++++++++----------------
 tools/perf/util/header.h                 | 23 +++----
 tools/perf/util/pmu.c                    | 25 --------
 tools/perf/util/pmu.h                    |  2 -
 tools/perf/util/probe-event.c            |  1 +
 22 files changed, 187 insertions(+), 229 deletions(-)

-- 
2.47.0.199.ga7371fff76-goog
Re: [PATCH v1 0/7] Refactor cpuid and metric table lookup code
Posted by Xu Yang 2 weeks, 2 days ago
Hi Ian Rogers,

On Wed, Nov 06, 2024 at 11:15:53PM -0800, Ian Rogers wrote:
> Xu Yang <xu.yang_2@nxp.com> reported issues with the system metric
> lookup:
> https://lore.kernel.org/linux-perf-users/20241106085441.3945502-1-xu.yang_2@nxp.com/
> These patches remove a lot of the logic relating CPUIDs to PMUs so
> that the PMU isn't part of the question when finding a metric table.
> For time reasons, it doesn't go as far as allowing system metrics
> without a metric table as a metric table is needed for metrics to
> refer to other metrics, and the refactoring of that resolution is a
> hassle.
> 
> Ian Rogers (7):
>   perf header: Move is_cpu_online to numa bench
>   perf header: Refactor get_cpuid to take a CPU for ARM
>   perf arm64 header: Use cpu argument in get_cpuid
>   perf header: Avoid transitive PMU includes
>   perf header: Pass a perf_cpu rather than a PMU to get_cpuid_str
>   perf jevents: Add map_for_cpu
>   perf pmu: Move pmu_metrics_table__find and remove ARM override
> 
>  tools/perf/arch/arm64/util/arm-spe.c     | 14 +---
>  tools/perf/arch/arm64/util/header.c      | 73 ++++++++++-----------
>  tools/perf/arch/arm64/util/pmu.c         | 20 ------
>  tools/perf/arch/loongarch/util/header.c  |  4 +-
>  tools/perf/arch/powerpc/util/header.c    |  4 +-
>  tools/perf/arch/riscv/util/header.c      |  4 +-
>  tools/perf/arch/s390/util/header.c       |  6 +-
>  tools/perf/arch/x86/util/auxtrace.c      |  3 +-
>  tools/perf/arch/x86/util/header.c        |  5 +-
>  tools/perf/bench/numa.c                  | 51 +++++++++++++++

Meet error when build perf tool:

  CC      util/levenshtein.o
  CC      tests/mem.o
  CC      util/mmap.o
bench/numa.c: In function ‘is_cpu_online’:
bench/numa.c:550:21: error: storage size of ‘statbuf’ isn’t known
  550 |         struct stat statbuf;
      |                     ^~~~~~~
bench/numa.c:554:13: error: implicit declaration of function ‘stat’; did you mean ‘strcat’? [-Werror=implicit-function-declaration]
  554 |         if (stat(buf, &statbuf) != 0)
      |             ^~~~
      |             strcat
bench/numa.c:578:13: error: implicit declaration of function ‘sysfs__read_str’ [-Werror=implicit-function-declaration]
  578 |         if (sysfs__read_str(buf, &str, &strlen) < 0)
      |             ^~~~~~~~~~~~~~~
bench/numa.c:550:21: error: unused variable ‘statbuf’ [-Werror=unused-variable]
  550 |         struct stat statbuf;
      |                     ^~~~~~~
  CC      tests/cpumap.o
  CC      tests/stat.o

After remove these errors, my issue is disappeared.

Thanks,
Xu Yang

>  tools/perf/builtin-kvm.c                 |  4 +-
>  tools/perf/pmu-events/empty-pmu-events.c | 39 ++++++-----
>  tools/perf/pmu-events/jevents.py         | 39 ++++++-----
>  tools/perf/pmu-events/pmu-events.h       |  2 +-
>  tools/perf/tests/expr.c                  |  5 +-
>  tools/perf/util/env.c                    |  4 +-
>  tools/perf/util/expr.c                   |  6 +-
>  tools/perf/util/header.c                 | 82 ++++++++----------------
>  tools/perf/util/header.h                 | 23 +++----
>  tools/perf/util/pmu.c                    | 25 --------
>  tools/perf/util/pmu.h                    |  2 -
>  tools/perf/util/probe-event.c            |  1 +
>  22 files changed, 187 insertions(+), 229 deletions(-)
> 
> -- 
> 2.47.0.199.ga7371fff76-goog
> 
Re: [PATCH v1 0/7] Refactor cpuid and metric table lookup code
Posted by Ian Rogers 2 weeks, 2 days ago
On Thu, Nov 7, 2024 at 1:05 AM Xu Yang <xu.yang_2@nxp.com> wrote:
>
> Hi Ian Rogers,
>
> On Wed, Nov 06, 2024 at 11:15:53PM -0800, Ian Rogers wrote:
> > Xu Yang <xu.yang_2@nxp.com> reported issues with the system metric
> > lookup:
> > https://lore.kernel.org/linux-perf-users/20241106085441.3945502-1-xu.yang_2@nxp.com/
> > These patches remove a lot of the logic relating CPUIDs to PMUs so
> > that the PMU isn't part of the question when finding a metric table.
> > For time reasons, it doesn't go as far as allowing system metrics
> > without a metric table as a metric table is needed for metrics to
> > refer to other metrics, and the refactoring of that resolution is a
> > hassle.
> >
> > Ian Rogers (7):
> >   perf header: Move is_cpu_online to numa bench
> >   perf header: Refactor get_cpuid to take a CPU for ARM
> >   perf arm64 header: Use cpu argument in get_cpuid
> >   perf header: Avoid transitive PMU includes
> >   perf header: Pass a perf_cpu rather than a PMU to get_cpuid_str
> >   perf jevents: Add map_for_cpu
> >   perf pmu: Move pmu_metrics_table__find and remove ARM override
> >
> >  tools/perf/arch/arm64/util/arm-spe.c     | 14 +---
> >  tools/perf/arch/arm64/util/header.c      | 73 ++++++++++-----------
> >  tools/perf/arch/arm64/util/pmu.c         | 20 ------
> >  tools/perf/arch/loongarch/util/header.c  |  4 +-
> >  tools/perf/arch/powerpc/util/header.c    |  4 +-
> >  tools/perf/arch/riscv/util/header.c      |  4 +-
> >  tools/perf/arch/s390/util/header.c       |  6 +-
> >  tools/perf/arch/x86/util/auxtrace.c      |  3 +-
> >  tools/perf/arch/x86/util/header.c        |  5 +-
> >  tools/perf/bench/numa.c                  | 51 +++++++++++++++
>
> Meet error when build perf tool:
>
>   CC      util/levenshtein.o
>   CC      tests/mem.o
>   CC      util/mmap.o
> bench/numa.c: In function ‘is_cpu_online’:
> bench/numa.c:550:21: error: storage size of ‘statbuf’ isn’t known
>   550 |         struct stat statbuf;
>       |                     ^~~~~~~
> bench/numa.c:554:13: error: implicit declaration of function ‘stat’; did you mean ‘strcat’? [-Werror=implicit-function-declaration]
>   554 |         if (stat(buf, &statbuf) != 0)
>       |             ^~~~
>       |             strcat
> bench/numa.c:578:13: error: implicit declaration of function ‘sysfs__read_str’ [-Werror=implicit-function-declaration]
>   578 |         if (sysfs__read_str(buf, &str, &strlen) < 0)
>       |             ^~~~~~~~~~~~~~~
> bench/numa.c:550:21: error: unused variable ‘statbuf’ [-Werror=unused-variable]
>   550 |         struct stat statbuf;
>       |                     ^~~~~~~
>   CC      tests/cpumap.o
>   CC      tests/stat.o
>
> After remove these errors, my issue is disappeared.

Thanks, I'll fix this in v2. I'll also add your patch to the front for
the sake of backport fixing. If you could provide tags for my changes
it would be appreciated.

Thanks,
Ian