Skip to content

Commit a862521

Browse files
atishp04avpatel
authored andcommitted
drivers/perf: riscv: Implement SBI PMU snapshot function
SBI v2.0 SBI introduced PMU snapshot feature which adds the following features. 1. Read counter values directly from the shared memory instead of csr read. 2. Start multiple counters with initial values with one SBI call. These functionalities optimizes the number of traps to the higher privilege mode. If the kernel is in VS mode while the hypervisor deploy trap & emulate method, this would minimize all the hpmcounter CSR read traps. If the kernel is running in S-mode, the benefits reduced to CSR latency vs DRAM/cache latency as there is no trap involved while accessing the hpmcounter CSRs. In both modes, it does saves the number of ecalls while starting multiple counter together with an initial values. This is a likely scenario if multiple counters overflow at the same time. Acked-by: Palmer Dabbelt <palmer@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Link: https://lore.kernel.org/r/20240420151741.962500-10-atishp@rivosinc.com Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent b994cdf commit a862521

3 files changed

Lines changed: 264 additions & 21 deletions

File tree

drivers/perf/riscv_pmu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ void riscv_pmu_stop(struct perf_event *event, int flags)
191191
struct hw_perf_event *hwc = &event->hw;
192192
struct riscv_pmu *rvpmu = to_riscv_pmu(event->pmu);
193193

194-
WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED);
195-
196194
if (!(hwc->state & PERF_HES_STOPPED)) {
197195
if (rvpmu->ctr_stop) {
198196
rvpmu->ctr_stop(event, 0);
@@ -408,6 +406,7 @@ struct riscv_pmu *riscv_pmu_alloc(void)
408406
cpuc->n_events = 0;
409407
for (i = 0; i < RISCV_MAX_COUNTERS; i++)
410408
cpuc->events[i] = NULL;
409+
cpuc->snapshot_addr = NULL;
411410
}
412411
pmu->pmu = (struct pmu) {
413412
.event_init = riscv_pmu_event_init,

0 commit comments

Comments
 (0)