Skip to content

Commit 5363a07

Browse files
robherringopsiff
authored andcommitted
perf: arm_pmuv3: Avoid assigning fixed cycle counter with threshold
[Upstream commit 81e15ca] 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) <robh@kernel.org> Acked-by: Mark Rutland <mark.rutland@arm.com> Link: https://lore.kernel.org/r/20240626-arm-pmu-3-9-icntr-v2-1-c9784b4f4065@kernel.org Signed-off-by: Will Deacon <will@kernel.org> Signed-off-by: yeyiyang <850219375@qq.com> Signed-off-by: WangYuli <wangyl5933@chinaunicom.cn>
1 parent b58e56e commit 5363a07

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

drivers/perf/arm_pmuv3.c

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

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

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

0 commit comments

Comments
 (0)