[PATCH 0/4] perf: Fix the ctx->pmu for a hybrid system

From: kan . liang
Date: Wed Jun 16 2021 - 15:10:25 EST

From: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>

The patchset is to fix the below WARNING triggered on an ADL machine
when a user enables per-task monitoring with all available
perf_hw_context PMUs.

WARNING: CPU: 8 PID: 37107 at arch/x86/events/core.c:1505
Call Trace:
? x86_pmu_del+0x42/0x190
? free_inode_nonrcu+0x18/0x20

Here is the line of the WARNING.
if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)))

To fix the issue, the generic perf codes have to understand the
supported CPU mask of a specific hybrid PMU. So it can update the
ctx->pmu accordingly, when a task is scheduled on a CPU which has
a different type of PMU from the previous CPU. The supported_cpus
has to be moved to the struct pmu.

Besides, the moving can bring another improvement. All hybrid
architectures including x86 and arm check whether an event is
schedulable on the current CPU via the filter_match callback. Since the
supported_cpus is moved to struct pmu, the check can be done in the
generic code. The filter_match callback may be avoided. The patchset
only implements the improvement for x86. Arm may implement a similar
improvement later separately.

Kan Liang (4):
perf: Update the ctx->pmu for a hybrid system
perf/x86: Fix the x86_pmu_start WARNING on a hybrid system
perf: Check the supported CPU of an event
perf/x86: Remove filter_match callback

arch/x86/events/core.c | 22 ++++------------------
arch/x86/events/intel/core.c | 19 ++++---------------
arch/x86/events/perf_event.h | 2 --
include/linux/perf_event.h | 7 +++++++
kernel/events/core.c | 39 ++++++++++++++++++++++++++++++++++++++-
5 files changed, 53 insertions(+), 36 deletions(-)