perf tool_pmu: Allow num_cpus(_online) to be specific to a cpumask
authorIan Rogers <irogers@google.com>
Sat, 19 Jul 2025 03:05:07 +0000 (20:05 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 24 Jul 2025 20:41:35 +0000 (13:41 -0700)
commit175c852325a1f566426e2470e5d5d67efc7621dd
treedce45d5597579302daf7ef0dd8bf2c64d9d7c513
parentbd741d80dc65922c7d6e5fd855a934f5d2cf2309
perf tool_pmu: Allow num_cpus(_online) to be specific to a cpumask

For hybrid metrics it is useful to know the number of p-core or e-core
CPUs. If a cpumask is specified for the num_cpus or num_cpus_online
tool events, compute the value relative to the given mask rather than
for the full system.

```
$ sudo /tmp/perf/perf stat -e 'tool/num_cpus/,tool/num_cpus,cpu=cpu_core/,
  tool/num_cpus,cpu=cpu_atom/,tool/num_cpus_online/,tool/num_cpus_online,
  cpu=cpu_core/,tool/num_cpus_online,cpu=cpu_atom/' true

 Performance counter stats for 'true':

                28      tool/num_cpus/
                16      tool/num_cpus,cpu=cpu_core/
                12      tool/num_cpus,cpu=cpu_atom/
                28      tool/num_cpus_online/
                16      tool/num_cpus_online,cpu=cpu_core/
                12      tool/num_cpus_online,cpu=cpu_atom/

       0.000767205 seconds time elapsed

       0.000938000 seconds user
       0.000000000 seconds sys
```

Reviewed-by: Thomas Falcon <thomas.falcon@intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250719030517.1990983-6-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/expr.c
tools/perf/util/tool_pmu.c
tools/perf/util/tool_pmu.h