]> www.infradead.org Git - users/jedix/linux-maple.git/commit
perf: arm_pmu: Don't disable counter in armpmu_add()
authorMark Rutland <mark.rutland@arm.com>
Tue, 18 Feb 2025 20:39:57 +0000 (14:39 -0600)
committerWill Deacon <will@kernel.org>
Sat, 1 Mar 2025 05:08:10 +0000 (05:08 +0000)
commitdcca27bc1eccb9abc2552aab950b18a9742fb8e7
tree08fde77f3b1f83691eee2c36d38366ea4298b1ae
parent04bd15c4cbc3f7bd2399d1baab958c5e738dbfc9
perf: arm_pmu: Don't disable counter in armpmu_add()

Currently armpmu_add() tries to handle a newly-allocated counter having
a stale associated event, but this should not be possible, and if this
were to happen the current mitigation is insufficient and potentially
expensive. It would be better to warn if we encounter the impossible
case.

Calls to pmu::add() and pmu::del() are serialized by the core perf code,
and armpmu_del() clears the relevant slot in pmu_hw_events::events[]
before clearing the bit in pmu_hw_events::used_mask such that the
counter can be reallocated. Thus when armpmu_add() allocates a counter
index from pmu_hw_events::used_mask, it should not be possible to observe
a stale even in pmu_hw_events::events[] unless either
pmu_hw_events::used_mask or pmu_hw_events::events[] have been corrupted.

If this were to happen, we'd end up with two events with the same
event->hw.idx, which would clash with each other during reprogramming,
deletion, etc, and produce bogus results. Add a WARN_ON_ONCE() for this
case so that we can detect if this ever occurs in practice.

That possiblity aside, there's no need to call arm_pmu::disable(event)
for the new event. The PMU reset code initialises the counter in a
disabled state, and armpmu_del() will disable the counter before it can
be reused. Remove the redundant disable.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Tested-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250218-arm-brbe-v19-v20-2-4e9922fc2e8e@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
drivers/perf/arm_pmu.c