Skip to content

Commit 3257314

Browse files
Merge patch series "drivers: perf: fix crash with the legacy riscv driver"
Vadim Shakirov <vadim.shakirov@syntacore.com> says: This series fix crash with the legacy riscv driver when configs: CONFIG_RISCV_PMU_LEGACY=y and CONFIG_RISCV_PMU_SBI=n and you try to perf record * b4-shazam-lts: drivers: perf: ctr_get_width function for legacy is not defined drivers: perf: added capabilities for legacy PMU Link: https://lore.kernel.org/r/20240227170002.188671-1-vadim.shakirov@syntacore.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2 parents d82f322 + 682dc13 commit 3257314

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

drivers/perf/riscv_pmu.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,11 @@ u64 riscv_pmu_ctr_get_width_mask(struct perf_event *event)
150150
struct riscv_pmu *rvpmu = to_riscv_pmu(event->pmu);
151151
struct hw_perf_event *hwc = &event->hw;
152152

153-
if (!rvpmu->ctr_get_width)
154-
/**
155-
* If the pmu driver doesn't support counter width, set it to default
156-
* maximum allowed by the specification.
157-
*/
158-
cwidth = 63;
159-
else {
160-
if (hwc->idx == -1)
161-
/* Handle init case where idx is not initialized yet */
162-
cwidth = rvpmu->ctr_get_width(0);
163-
else
164-
cwidth = rvpmu->ctr_get_width(hwc->idx);
165-
}
153+
if (hwc->idx == -1)
154+
/* Handle init case where idx is not initialized yet */
155+
cwidth = rvpmu->ctr_get_width(0);
156+
else
157+
cwidth = rvpmu->ctr_get_width(hwc->idx);
166158

167159
return GENMASK_ULL(cwidth, 0);
168160
}

drivers/perf/riscv_pmu_legacy.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ static int pmu_legacy_event_map(struct perf_event *event, u64 *config)
3737
return pmu_legacy_ctr_get_idx(event);
3838
}
3939

40+
/* cycle & instret are always 64 bit, one bit less according to SBI spec */
41+
static int pmu_legacy_ctr_get_width(int idx)
42+
{
43+
return 63;
44+
}
45+
4046
static u64 pmu_legacy_read_ctr(struct perf_event *event)
4147
{
4248
struct hw_perf_event *hwc = &event->hw;
@@ -111,12 +117,14 @@ static void pmu_legacy_init(struct riscv_pmu *pmu)
111117
pmu->ctr_stop = NULL;
112118
pmu->event_map = pmu_legacy_event_map;
113119
pmu->ctr_get_idx = pmu_legacy_ctr_get_idx;
114-
pmu->ctr_get_width = NULL;
120+
pmu->ctr_get_width = pmu_legacy_ctr_get_width;
115121
pmu->ctr_clear_idx = NULL;
116122
pmu->ctr_read = pmu_legacy_read_ctr;
117123
pmu->event_mapped = pmu_legacy_event_mapped;
118124
pmu->event_unmapped = pmu_legacy_event_unmapped;
119125
pmu->csr_index = pmu_legacy_csr_index;
126+
pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
127+
pmu->pmu.capabilities |= PERF_PMU_CAP_NO_EXCLUDE;
120128

121129
perf_pmu_register(&pmu->pmu, "cpu", PERF_TYPE_RAW);
122130
}

0 commit comments

Comments
 (0)