Skip to content

Commit 81e15ca

Browse files
robherringwilldeacon
authored andcommitted
perf: arm_pmuv3: Avoid assigning fixed cycle counter with threshold
If the user has requested a counting threshold for the CPU cycles event, then the fixed cycle counter can't be assigned as it lacks threshold support. Currently, the thresholds will work or not randomly depending on which counter the event is assigned. While using thresholds for CPU cycles doesn't make much sense, it can be useful for testing purposes. Fixes: 816c267 ("arm64: perf: Add support for event counting threshold") Signed-off-by: Rob Herring (Arm) <[email protected]> Acked-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent d0d7c66 commit 81e15ca

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/perf/arm_pmuv3.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ static bool armv8pmu_event_want_user_access(struct perf_event *event)
338338
return ATTR_CFG_GET_FLD(&event->attr, rdpmc);
339339
}
340340

341+
static u32 armv8pmu_event_get_threshold(struct perf_event_attr *attr)
342+
{
343+
return ATTR_CFG_GET_FLD(attr, threshold);
344+
}
345+
341346
static u8 armv8pmu_event_threshold_control(struct perf_event_attr *attr)
342347
{
343348
u8 th_compare = ATTR_CFG_GET_FLD(attr, threshold_compare);
@@ -941,7 +946,8 @@ static int armv8pmu_get_event_idx(struct pmu_hw_events *cpuc,
941946
unsigned long evtype = hwc->config_base & ARMV8_PMU_EVTYPE_EVENT;
942947

943948
/* Always prefer to place a cycle counter into the cycle counter. */
944-
if (evtype == ARMV8_PMUV3_PERFCTR_CPU_CYCLES) {
949+
if ((evtype == ARMV8_PMUV3_PERFCTR_CPU_CYCLES) &&
950+
!armv8pmu_event_get_threshold(&event->attr)) {
945951
if (!test_and_set_bit(ARMV8_IDX_CYCLE_COUNTER, cpuc->used_mask))
946952
return ARMV8_IDX_CYCLE_COUNTER;
947953
else if (armv8pmu_event_is_64bit(event) &&
@@ -1033,7 +1039,7 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event,
10331039
* If FEAT_PMUv3_TH isn't implemented, then THWIDTH (threshold_max) will
10341040
* be 0 and will also trigger this check, preventing it from being used.
10351041
*/
1036-
th = ATTR_CFG_GET_FLD(attr, threshold);
1042+
th = armv8pmu_event_get_threshold(attr);
10371043
if (th > threshold_max(cpu_pmu)) {
10381044
pr_debug("PMU event threshold exceeds max value\n");
10391045
return -EINVAL;

0 commit comments

Comments
 (0)