Re: [PATCH 0/3] Perf avoid opening events on offline CPUs

From: Ian Rogers
Date: Mon Jun 03 2024 - 12:42:32 EST


On Mon, Jun 3, 2024 at 2:33 AM Yicong Yang <yangyicong@xxxxxxxxxx> wrote:
>
> From: Yicong Yang <yangyicong@xxxxxxxxxxxxx>
>
> If user doesn't specify the CPUs, perf will try to open events on CPUs
> of the PMU which is initialized from the PMU's "cpumask" or "cpus" sysfs
> attributes if provided. But we doesn't check whether the CPUs provided
> by the PMU are all online. So we may open events on offline CPUs if PMU
> driver provide offline CPUs and then we'll be rejected by the kernel:
>
> [root@localhost yang]# echo 0 > /sys/devices/system/cpu/cpu0/online

Generally Linux won't let you take CPU0 off line, I'm not able to
follow this step on x86 Linux. Fwiw, I routinely run perf with the
core hyperthread siblings offline.

Thanks,
Ian

> [root@localhost yang]# ./perf_static stat -e armv8_pmuv3_0/cycles/ --timeout 100
> Error:
> The sys_perf_event_open() syscall returned with 19 (No such device) for event (cpu-clock).
> /bin/dmesg | grep -i perf may provide additional information.
>
> This patchset tries to avoid this case by:
> - Double check the PMU's cpumask in the perf tool and only include online CPUs
> - Trying to make the PMU drivers only export online CPUs in its "cpus" or "cpumask"
> attributes
>
> Previously discussion can be found at [1]. Will suggested to do it in userspace.
> I think it makes sense to do a double check in the perf tool in case the driver
> doesn't do this. So PATCH 1/3 is added in this version.
>
> [1] https://lore.kernel.org/linux-arm-kernel/20240410095833.63934-1-yangyicong@xxxxxxxxxx/
>
> Yicong Yang (3):
> perf pmu: Limit PMU cpumask to online CPUs
> perf: arm_pmu: Only show online CPUs in device's "cpus" attribute
> perf: arm_spe: Only show online CPUs in device's "cpumask" attribute
>
> drivers/perf/arm_pmu.c | 24 +++++++++++++++++++++++-
> drivers/perf/arm_spe_pmu.c | 22 +++++++++++++++++++++-
> tools/perf/util/pmu.c | 13 +++++++++++--
> 3 files changed, 55 insertions(+), 4 deletions(-)
>
> --
> 2.24.0
>