Commit 5101ef20 authored by Mark Rutland's avatar Mark Rutland Committed by Ingo Molnar

perf/arm: Special-case hetereogeneous CPUs


  26657848 ("perf/core: Verify we have a single perf_hw_context PMU")

forcefully prevents multiple PMUs from sharing perf_hw_context, as this
generally doesn't make sense. It is a common bug for uncore PMUs to
use perf_hw_context rather than perf_invalid_context, which this detects.

However, systems exist with heterogeneous CPUs (and hence heterogeneous
HW PMUs), for which sharing perf_hw_context is necessary, and possible
in some limited cases.

To make this work we have to perform some gymnastics, as we did in these

  66eb579e ("perf: allow for PMU-specific event filtering")
  c904e32a ("arm: perf: filter unschedulable events")

To allow those systems to work, we must allow PMUs for heterogeneous
CPUs to share perf_hw_context, though we must still disallow sharing
otherwise to detect the common misuse of perf_hw_context.

This patch adds a new PERF_PMU_CAP_HETEROGENEOUS_CPUS for this, updates
the core logic to account for this, and makes use of it in the arm_pmu
code that is used for systems with heterogeneous CPUs. Comments are
added to make the rationale clear and hopefully avoid accidental abuse.
Signed-off-by: default avatarMark Rutland <>
Signed-off-by: default avatarPeter Zijlstra (Intel) <>
Cc: Alexander Shishkin <>
Cc: Arnaldo Carvalho de Melo <>
Cc: Catalin Marinas <>
Cc: Jiri Olsa <>
Cc: Linus Torvalds <>
Cc: Peter Zijlstra <>
Cc: Stephane Eranian <>
Cc: Thomas Gleixner <>
Cc: Vince Weaver <>
Cc: Will Deacon <>
Link: default avatarIngo Molnar <>
parent 6e855cd4
......@@ -847,6 +847,14 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
if (!platform_get_irq(cpu_pmu->plat_device, 0))
cpu_pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
* This is a CPU PMU potentially in a heterogeneous configuration (e.g.
* big.LITTLE). This is not an uncore PMU, and we have taken ctx
* sharing into account (e.g. with our pmu::filter_match callback and
* pmu::event_init group validation).
cpu_pmu->pmu.capabilities |= PERF_PMU_CAP_HETEROGENEOUS_CPUS;
return 0;
......@@ -225,6 +225,7 @@ struct perf_event;
#define PERF_PMU_CAP_ITRACE 0x20
* struct pmu - generic performance monitoring unit
......@@ -8443,7 +8443,13 @@ skip_type:
if (pmu->task_ctx_nr == perf_hw_context) {
static int hw_context_taken = 0;
if (WARN_ON_ONCE(hw_context_taken))
* Other than systems with heterogeneous CPUs, it never makes
* sense for two PMUs to share perf_hw_context. PMUs which are
* uncore must use perf_invalid_context.
if (WARN_ON_ONCE(hw_context_taken &&
!(pmu->capabilities & PERF_PMU_CAP_HETEROGENEOUS_CPUS)))
pmu->task_ctx_nr = perf_invalid_context;
hw_context_taken = 1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment