Skip to content

Commit 6ae1af9

Browse files
perf: RISC-V: Add support for SBI PMU and Sscofpmf
This series improves perf support for RISC-V based system using SBI PMU and Sscofpmf extensions, by adding a new generic RISC-V perf framework along with a pair of drivers: one that usese the new performance-monitoring extensions and one that keeps support for the existing systems that only have the legacy counters. Tested-by: Nikita Shubin <[email protected]> * palmer/riscv-pmu: MAINTAINERS: Add entry for RISC-V PMU drivers Documentation: riscv: Remove the old documentation RISC-V: Add sscofpmf extension support RISC-V: Add perf platform driver based on SBI PMU extension RISC-V: Add RISC-V SBI PMU extension definitions RISC-V: Add a simple platform driver for RISC-V legacy perf RISC-V: Add a perf core library for pmu drivers RISC-V: Add CSR encodings for all HPMCOUNTERS RISC-V: Remove the current perf implementation
2 parents 6b57ac0 + 33363c3 commit 6ae1af9

File tree

18 files changed

+1538
-827
lines changed

18 files changed

+1538
-827
lines changed

Documentation/riscv/pmu.rst

Lines changed: 0 additions & 255 deletions
This file was deleted.

MAINTAINERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16561,6 +16561,15 @@ S: Maintained
1656116561
F: drivers/mtd/nand/raw/r852.c
1656216562
F: drivers/mtd/nand/raw/r852.h
1656316563

16564+
RISC-V PMU DRIVERS
16565+
M: Atish Patra <[email protected]>
16566+
R: Anup Patel <[email protected]>
16567+
16568+
S: Supported
16569+
F: drivers/perf/riscv_pmu.c
16570+
F: drivers/perf/riscv_pmu_legacy.c
16571+
F: drivers/perf/riscv_pmu_sbi.c
16572+
1656416573
RISC-V ARCHITECTURE
1656516574
M: Paul Walmsley <[email protected]>
1656616575
M: Palmer Dabbelt <[email protected]>

arch/riscv/Kconfig

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,6 @@ config RISCV_ISA_C
333333

334334
If you don't know what to do here, say Y.
335335

336-
menu "supported PMU type"
337-
depends on PERF_EVENTS
338-
339-
config RISCV_BASE_PMU
340-
bool "Base Performance Monitoring Unit"
341-
def_bool y
342-
help
343-
A base PMU that serves as a reference implementation and has limited
344-
feature of perf. It can run on any RISC-V machines so serves as the
345-
fallback, but this option can also be disable to reduce kernel size.
346-
347-
endmenu
348-
349336
config FPU
350337
bool "FPU support"
351338
default y

arch/riscv/include/asm/csr.h

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#define IRQ_S_EXT 9
6767
#define IRQ_VS_EXT 10
6868
#define IRQ_M_EXT 11
69+
#define IRQ_PMU_OVF 13
6970

7071
/* Exception causes */
7172
#define EXC_INST_MISALIGNED 0
@@ -151,9 +152,69 @@
151152
#define CSR_CYCLE 0xc00
152153
#define CSR_TIME 0xc01
153154
#define CSR_INSTRET 0xc02
155+
#define CSR_HPMCOUNTER3 0xc03
156+
#define CSR_HPMCOUNTER4 0xc04
157+
#define CSR_HPMCOUNTER5 0xc05
158+
#define CSR_HPMCOUNTER6 0xc06
159+
#define CSR_HPMCOUNTER7 0xc07
160+
#define CSR_HPMCOUNTER8 0xc08
161+
#define CSR_HPMCOUNTER9 0xc09
162+
#define CSR_HPMCOUNTER10 0xc0a
163+
#define CSR_HPMCOUNTER11 0xc0b
164+
#define CSR_HPMCOUNTER12 0xc0c
165+
#define CSR_HPMCOUNTER13 0xc0d
166+
#define CSR_HPMCOUNTER14 0xc0e
167+
#define CSR_HPMCOUNTER15 0xc0f
168+
#define CSR_HPMCOUNTER16 0xc10
169+
#define CSR_HPMCOUNTER17 0xc11
170+
#define CSR_HPMCOUNTER18 0xc12
171+
#define CSR_HPMCOUNTER19 0xc13
172+
#define CSR_HPMCOUNTER20 0xc14
173+
#define CSR_HPMCOUNTER21 0xc15
174+
#define CSR_HPMCOUNTER22 0xc16
175+
#define CSR_HPMCOUNTER23 0xc17
176+
#define CSR_HPMCOUNTER24 0xc18
177+
#define CSR_HPMCOUNTER25 0xc19
178+
#define CSR_HPMCOUNTER26 0xc1a
179+
#define CSR_HPMCOUNTER27 0xc1b
180+
#define CSR_HPMCOUNTER28 0xc1c
181+
#define CSR_HPMCOUNTER29 0xc1d
182+
#define CSR_HPMCOUNTER30 0xc1e
183+
#define CSR_HPMCOUNTER31 0xc1f
154184
#define CSR_CYCLEH 0xc80
155185
#define CSR_TIMEH 0xc81
156186
#define CSR_INSTRETH 0xc82
187+
#define CSR_HPMCOUNTER3H 0xc83
188+
#define CSR_HPMCOUNTER4H 0xc84
189+
#define CSR_HPMCOUNTER5H 0xc85
190+
#define CSR_HPMCOUNTER6H 0xc86
191+
#define CSR_HPMCOUNTER7H 0xc87
192+
#define CSR_HPMCOUNTER8H 0xc88
193+
#define CSR_HPMCOUNTER9H 0xc89
194+
#define CSR_HPMCOUNTER10H 0xc8a
195+
#define CSR_HPMCOUNTER11H 0xc8b
196+
#define CSR_HPMCOUNTER12H 0xc8c
197+
#define CSR_HPMCOUNTER13H 0xc8d
198+
#define CSR_HPMCOUNTER14H 0xc8e
199+
#define CSR_HPMCOUNTER15H 0xc8f
200+
#define CSR_HPMCOUNTER16H 0xc90
201+
#define CSR_HPMCOUNTER17H 0xc91
202+
#define CSR_HPMCOUNTER18H 0xc92
203+
#define CSR_HPMCOUNTER19H 0xc93
204+
#define CSR_HPMCOUNTER20H 0xc94
205+
#define CSR_HPMCOUNTER21H 0xc95
206+
#define CSR_HPMCOUNTER22H 0xc96
207+
#define CSR_HPMCOUNTER23H 0xc97
208+
#define CSR_HPMCOUNTER24H 0xc98
209+
#define CSR_HPMCOUNTER25H 0xc99
210+
#define CSR_HPMCOUNTER26H 0xc9a
211+
#define CSR_HPMCOUNTER27H 0xc9b
212+
#define CSR_HPMCOUNTER28H 0xc9c
213+
#define CSR_HPMCOUNTER29H 0xc9d
214+
#define CSR_HPMCOUNTER30H 0xc9e
215+
#define CSR_HPMCOUNTER31H 0xc9f
216+
217+
#define CSR_SSCOUNTOVF 0xda0
157218

158219
#define CSR_SSTATUS 0x100
159220
#define CSR_SIE 0x104
@@ -241,7 +302,10 @@
241302
# define RV_IRQ_SOFT IRQ_S_SOFT
242303
# define RV_IRQ_TIMER IRQ_S_TIMER
243304
# define RV_IRQ_EXT IRQ_S_EXT
244-
#endif /* CONFIG_RISCV_M_MODE */
305+
# define RV_IRQ_PMU IRQ_PMU_OVF
306+
# define SIP_LCOFIP (_AC(0x1, UL) << IRQ_PMU_OVF)
307+
308+
#endif /* !CONFIG_RISCV_M_MODE */
245309

246310
/* IE/IP (Supervisor/Machine Interrupt Enable/Pending) flags */
247311
#define IE_SIE (_AC(0x1, UL) << RV_IRQ_SOFT)

arch/riscv/include/asm/hwcap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern unsigned long elf_hwcap;
5151
* available logical extension id.
5252
*/
5353
enum riscv_isa_ext_id {
54+
RISCV_ISA_EXT_SSCOFPMF = RISCV_ISA_EXT_BASE,
5455
RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX,
5556
};
5657

0 commit comments

Comments
 (0)