rdcycle from userland with RISCV_PMU_SBI=y

Jan Wassenberg janwas at google.com
Sun Sep 4 22:40:45 PDT 2022


> Currently, only "time" CSR is available to user-space and all other performance
> counters should be enabled (or accessed) using Linux perf syscalls.
Unfortunately that would seem to prevent precisely measuring very small code
regions (order of 10 cycles). What is the corresponding advantage/benefit?
As mentioned, there is no security gain from merely disabling rdcycle.

> In the future, someone can always propose a RISC-V ISA extension to obfuscate
> "time" CSR values visible to user-space but the "cycle" counter is
> purely a performance counter and accurately reflects cycles taken by the CPU.
Yes, this is why we use it. I'm curious why we think rdcycle is being
used to measure wall time?

About consistency: I understand there will be a time when rdcycle may
or may not be available on Linux depending on PMU.
But there is also bare metal, and other OSes. Is there a way for
userland to detect whether rdcycle will fault?



More information about the linux-riscv mailing list