Commit 32573148 authored by Palmer Dabbelt's avatar Palmer Dabbelt

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.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parents d82f3220 682dc133
...@@ -150,19 +150,11 @@ u64 riscv_pmu_ctr_get_width_mask(struct perf_event *event) ...@@ -150,19 +150,11 @@ u64 riscv_pmu_ctr_get_width_mask(struct perf_event *event)
struct riscv_pmu *rvpmu = to_riscv_pmu(event->pmu); struct riscv_pmu *rvpmu = to_riscv_pmu(event->pmu);
struct hw_perf_event *hwc = &event->hw; struct hw_perf_event *hwc = &event->hw;
if (!rvpmu->ctr_get_width) if (hwc->idx == -1)
/** /* Handle init case where idx is not initialized yet */
* If the pmu driver doesn't support counter width, set it to default cwidth = rvpmu->ctr_get_width(0);
* maximum allowed by the specification. else
*/ cwidth = rvpmu->ctr_get_width(hwc->idx);
cwidth = 63;
else {
if (hwc->idx == -1)
/* Handle init case where idx is not initialized yet */
cwidth = rvpmu->ctr_get_width(0);
else
cwidth = rvpmu->ctr_get_width(hwc->idx);
}
return GENMASK_ULL(cwidth, 0); return GENMASK_ULL(cwidth, 0);
} }
......
...@@ -37,6 +37,12 @@ static int pmu_legacy_event_map(struct perf_event *event, u64 *config) ...@@ -37,6 +37,12 @@ static int pmu_legacy_event_map(struct perf_event *event, u64 *config)
return pmu_legacy_ctr_get_idx(event); return pmu_legacy_ctr_get_idx(event);
} }
/* cycle & instret are always 64 bit, one bit less according to SBI spec */
static int pmu_legacy_ctr_get_width(int idx)
{
return 63;
}
static u64 pmu_legacy_read_ctr(struct perf_event *event) static u64 pmu_legacy_read_ctr(struct perf_event *event)
{ {
struct hw_perf_event *hwc = &event->hw; struct hw_perf_event *hwc = &event->hw;
...@@ -111,12 +117,14 @@ static void pmu_legacy_init(struct riscv_pmu *pmu) ...@@ -111,12 +117,14 @@ static void pmu_legacy_init(struct riscv_pmu *pmu)
pmu->ctr_stop = NULL; pmu->ctr_stop = NULL;
pmu->event_map = pmu_legacy_event_map; pmu->event_map = pmu_legacy_event_map;
pmu->ctr_get_idx = pmu_legacy_ctr_get_idx; pmu->ctr_get_idx = pmu_legacy_ctr_get_idx;
pmu->ctr_get_width = NULL; pmu->ctr_get_width = pmu_legacy_ctr_get_width;
pmu->ctr_clear_idx = NULL; pmu->ctr_clear_idx = NULL;
pmu->ctr_read = pmu_legacy_read_ctr; pmu->ctr_read = pmu_legacy_read_ctr;
pmu->event_mapped = pmu_legacy_event_mapped; pmu->event_mapped = pmu_legacy_event_mapped;
pmu->event_unmapped = pmu_legacy_event_unmapped; pmu->event_unmapped = pmu_legacy_event_unmapped;
pmu->csr_index = pmu_legacy_csr_index; pmu->csr_index = pmu_legacy_csr_index;
pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
pmu->pmu.capabilities |= PERF_PMU_CAP_NO_EXCLUDE;
perf_pmu_register(&pmu->pmu, "cpu", PERF_TYPE_RAW); perf_pmu_register(&pmu->pmu, "cpu", PERF_TYPE_RAW);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment