Re: [PATCH v1] perf arm: Workaround ARM PMUs cpu maps having offline cpus

From: Leo Yan
Date: Mon Jun 10 2024 - 09:30:27 EST



Hi Ian,

On 6/7/24 07:53, Ian Rogers wrote:

[...]

diff --git a/tools/perf/arch/arm/util/pmu.c b/tools/perf/arch/arm/util/pmu.c
index 8b7cb68ba1a8..6b544edbd3f6 100644
--- a/tools/perf/arch/arm/util/pmu.c
+++ b/tools/perf/arch/arm/util/pmu.c
@@ -11,12 +11,15 @@

#include "arm-spe.h"
#include "hisi-ptt.h"
+#include "../../../util/cpumap.h"
#include "../../../util/pmu.h"
#include "../../../util/cs-etm.h"
#include "../../arm64/util/mem-events.h"

-void perf_pmu__arch_init(struct perf_pmu *pmu __maybe_unused)
+void perf_pmu__arch_init(struct perf_pmu *pmu)
{
+ struct perf_cpu_map *intersect;
+
#ifdef HAVE_AUXTRACE_SUPPORT
if (!strcmp(pmu->name, CORESIGHT_ETM_PMU_NAME)) {
/* add ETM default config here */
@@ -33,6 +36,9 @@ void perf_pmu__arch_init(struct perf_pmu *pmu __maybe_unused)
pmu->selectable = true;
#endif
}
-
#endif
+ /* Workaround some ARM PMU's failing to correctly set CPU maps for online processors. */
+ intersect = perf_cpu_map__intersect(cpu_map__online(), pmu->cpus);
+ perf_cpu_map__put(pmu->cpus);
+ pmu->cpus = intersect;

I did a test for this patch, it works well for me.

Tested-by: Leo Yan <leo.yan@xxxxxxx>

Just a nitpick and I think it is not an issue caused by this patch.
After hotplug off one CPU and then if specify the CPU with option '-C',
the 'perf stat' command still continues to run. This is inconsistent
with the 'perf record' which exits with failures immediately.

Maybe consider to send an extra patch to address this issue?

The test steps are:

# echo 0 > /sys/devices/system/cpu0/online
# perf stat -C 0 -e armv9_cortex_a520/cycles/ -- sleep 1
WARNING: A requested CPU in '0' is not supported by PMU 'armv9_cortex_a520' (CPUs 5) for event 'armv9_cortex_a520/cycles/'

Performance counter stats for 'CPU(s) 0':

<not supported> armv9_cortex_a520/cycles/

1.001223060 seconds time elapsed

Thanks,
Leo

}
--
2.45.2.505.gda0bf45e8d-goog