Skip to content

Commit 2e2cbe5

Browse files
mrutland-armjfvogel
authored andcommitted
perf: arm_pmu: Don't disable counter in armpmu_add()
[ Upstream commit dcca27bc1eccb9abc2552aab950b18a9742fb8e7 ] 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 <[email protected]> Signed-off-by: Rob Herring (Arm) <[email protected]> Reviewed-by: Anshuman Khandual <[email protected]> Tested-by: James Clark <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 1b3ebfb15dc0bb14d3ac202446919acd4b4e9408) Signed-off-by: Jack Vogel <[email protected]>
1 parent 6401235 commit 2e2cbe5

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

drivers/perf/arm_pmu.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,10 @@ armpmu_add(struct perf_event *event, int flags)
342342
if (idx < 0)
343343
return idx;
344344

345-
/*
346-
* If there is an event in the counter we are going to use then make
347-
* sure it is disabled.
348-
*/
345+
/* The newly-allocated counter should be empty */
346+
WARN_ON_ONCE(hw_events->events[idx]);
347+
349348
event->hw.idx = idx;
350-
armpmu->disable(event);
351349
hw_events->events[idx] = event;
352350

353351
hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;

0 commit comments

Comments
 (0)