1*cb7aa33aSEmmanuel Vadot# SPDX-License-Identifier: BSD-2-Clause 2*cb7aa33aSEmmanuel Vadot%YAML 1.2 3*cb7aa33aSEmmanuel Vadot--- 4*cb7aa33aSEmmanuel Vadot$id: http://devicetree.org/schemas/perf/riscv,pmu.yaml# 5*cb7aa33aSEmmanuel Vadot$schema: http://devicetree.org/meta-schemas/core.yaml# 6*cb7aa33aSEmmanuel Vadot 7*cb7aa33aSEmmanuel Vadottitle: RISC-V SBI PMU events 8*cb7aa33aSEmmanuel Vadot 9*cb7aa33aSEmmanuel Vadotmaintainers: 10*cb7aa33aSEmmanuel Vadot - Atish Patra <atishp@rivosinc.com> 11*cb7aa33aSEmmanuel Vadot 12*cb7aa33aSEmmanuel Vadotdescription: | 13*cb7aa33aSEmmanuel Vadot The SBI PMU extension allows supervisor software to configure, start and 14*cb7aa33aSEmmanuel Vadot stop any performance counter at anytime. Thus, a user can leverage all 15*cb7aa33aSEmmanuel Vadot capabilities of performance analysis tools, such as perf, if the SBI PMU 16*cb7aa33aSEmmanuel Vadot extension is enabled. The following constraints apply: 17*cb7aa33aSEmmanuel Vadot 18*cb7aa33aSEmmanuel Vadot The platform must provide information about PMU event to counter mappings 19*cb7aa33aSEmmanuel Vadot either via device tree or another way, specific to the platform. 20*cb7aa33aSEmmanuel Vadot Without the event to counter mappings, the SBI PMU extension cannot be used. 21*cb7aa33aSEmmanuel Vadot 22*cb7aa33aSEmmanuel Vadot Platforms should provide information about the PMU event selector values 23*cb7aa33aSEmmanuel Vadot that should be encoded in the expected value of MHPMEVENTx while configuring 24*cb7aa33aSEmmanuel Vadot MHPMCOUNTERx for that specific event. The can either be done via device tree 25*cb7aa33aSEmmanuel Vadot or another way, specific to the platform. 26*cb7aa33aSEmmanuel Vadot The exact value to be written to MHPMEVENTx is completely dependent on the 27*cb7aa33aSEmmanuel Vadot platform. 28*cb7aa33aSEmmanuel Vadot 29*cb7aa33aSEmmanuel Vadot For information on the SBI specification see the section "Performance 30*cb7aa33aSEmmanuel Vadot Monitoring Unit Extension" of: 31*cb7aa33aSEmmanuel Vadot https://github.com/riscv-non-isa/riscv-sbi-doc/blob/master/riscv-sbi.adoc 32*cb7aa33aSEmmanuel Vadot 33*cb7aa33aSEmmanuel Vadotproperties: 34*cb7aa33aSEmmanuel Vadot compatible: 35*cb7aa33aSEmmanuel Vadot const: riscv,pmu 36*cb7aa33aSEmmanuel Vadot 37*cb7aa33aSEmmanuel Vadot riscv,event-to-mhpmevent: 38*cb7aa33aSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/uint32-matrix 39*cb7aa33aSEmmanuel Vadot description: 40*cb7aa33aSEmmanuel Vadot Represents an ONE-to-ONE mapping between a PMU event and the event 41*cb7aa33aSEmmanuel Vadot selector value that the platform expects to be written to the MHPMEVENTx 42*cb7aa33aSEmmanuel Vadot CSR for that event. 43*cb7aa33aSEmmanuel Vadot The mapping is encoded in an matrix format where each element represents 44*cb7aa33aSEmmanuel Vadot an event. 45*cb7aa33aSEmmanuel Vadot This property shouldn't encode any raw hardware event. 46*cb7aa33aSEmmanuel Vadot items: 47*cb7aa33aSEmmanuel Vadot items: 48*cb7aa33aSEmmanuel Vadot - description: event_idx, a 20-bit wide encoding of the event type and 49*cb7aa33aSEmmanuel Vadot code. Refer to the SBI specification for a complete description of 50*cb7aa33aSEmmanuel Vadot the event types and codes. 51*cb7aa33aSEmmanuel Vadot - description: upper 32 bits of the event selector value for MHPMEVENTx 52*cb7aa33aSEmmanuel Vadot - description: lower 32 bits of the event selector value for MHPMEVENTx 53*cb7aa33aSEmmanuel Vadot 54*cb7aa33aSEmmanuel Vadot riscv,event-to-mhpmcounters: 55*cb7aa33aSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/uint32-matrix 56*cb7aa33aSEmmanuel Vadot description: 57*cb7aa33aSEmmanuel Vadot Represents a MANY-to-MANY mapping between a range of events and all the 58*cb7aa33aSEmmanuel Vadot MHPMCOUNTERx in a bitmap format that can be used to monitor these range 59*cb7aa33aSEmmanuel Vadot of events. The information is encoded in an matrix format where each 60*cb7aa33aSEmmanuel Vadot element represents a certain range of events and corresponding counters. 61*cb7aa33aSEmmanuel Vadot This property shouldn't encode any raw event. 62*cb7aa33aSEmmanuel Vadot items: 63*cb7aa33aSEmmanuel Vadot items: 64*cb7aa33aSEmmanuel Vadot - description: first event_idx of the range of events 65*cb7aa33aSEmmanuel Vadot - description: last event_idx of the range of events 66*cb7aa33aSEmmanuel Vadot - description: bitmap of MHPMCOUNTERx for this event 67*cb7aa33aSEmmanuel Vadot 68*cb7aa33aSEmmanuel Vadot riscv,raw-event-to-mhpmcounters: 69*cb7aa33aSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/uint32-matrix 70*cb7aa33aSEmmanuel Vadot description: 71*cb7aa33aSEmmanuel Vadot Represents an ONE-to-MANY or MANY-to-MANY mapping between the rawevent(s) 72*cb7aa33aSEmmanuel Vadot and all the MHPMCOUNTERx in a bitmap format that can be used to monitor 73*cb7aa33aSEmmanuel Vadot that raw event. 74*cb7aa33aSEmmanuel Vadot The encoding of the raw events are platform specific. The information is 75*cb7aa33aSEmmanuel Vadot encoded in a matrix format where each element represents the specific raw 76*cb7aa33aSEmmanuel Vadot event(s). 77*cb7aa33aSEmmanuel Vadot If a platform directly encodes each raw PMU event as a unique ID, the 78*cb7aa33aSEmmanuel Vadot value of variant must be 0xffffffff_ffffffff. 79*cb7aa33aSEmmanuel Vadot items: 80*cb7aa33aSEmmanuel Vadot items: 81*cb7aa33aSEmmanuel Vadot - description: 82*cb7aa33aSEmmanuel Vadot upper 32 invariant bits for the range of events 83*cb7aa33aSEmmanuel Vadot - description: 84*cb7aa33aSEmmanuel Vadot lower 32 invariant bits for the range of events 85*cb7aa33aSEmmanuel Vadot - description: 86*cb7aa33aSEmmanuel Vadot upper 32 bits of the variant bit mask for the range of events 87*cb7aa33aSEmmanuel Vadot - description: 88*cb7aa33aSEmmanuel Vadot lower 32 bits of the variant bit mask for the range of events 89*cb7aa33aSEmmanuel Vadot - description: 90*cb7aa33aSEmmanuel Vadot bitmap of all MHPMCOUNTERx that can monitor the range of events 91*cb7aa33aSEmmanuel Vadot 92*cb7aa33aSEmmanuel Vadotdependencies: 93*cb7aa33aSEmmanuel Vadot "riscv,event-to-mhpmevent": [ "riscv,event-to-mhpmcounters" ] 94*cb7aa33aSEmmanuel Vadot "riscv,event-to-mhpmcounters": [ "riscv,event-to-mhpmevent" ] 95*cb7aa33aSEmmanuel Vadot 96*cb7aa33aSEmmanuel Vadotrequired: 97*cb7aa33aSEmmanuel Vadot - compatible 98*cb7aa33aSEmmanuel Vadot 99*cb7aa33aSEmmanuel VadotadditionalProperties: false 100*cb7aa33aSEmmanuel Vadot 101*cb7aa33aSEmmanuel Vadotexamples: 102*cb7aa33aSEmmanuel Vadot - | 103*cb7aa33aSEmmanuel Vadot pmu { 104*cb7aa33aSEmmanuel Vadot compatible = "riscv,pmu"; 105*cb7aa33aSEmmanuel Vadot riscv,event-to-mhpmevent = <0x0000B 0x0000 0x0001>; 106*cb7aa33aSEmmanuel Vadot riscv,event-to-mhpmcounters = <0x00001 0x00001 0x00000001>, 107*cb7aa33aSEmmanuel Vadot <0x00002 0x00002 0x00000004>, 108*cb7aa33aSEmmanuel Vadot <0x00003 0x0000A 0x00000ff8>, 109*cb7aa33aSEmmanuel Vadot <0x10000 0x10033 0x000ff000>; 110*cb7aa33aSEmmanuel Vadot riscv,raw-event-to-mhpmcounters = 111*cb7aa33aSEmmanuel Vadot /* For event ID 0x0002 */ 112*cb7aa33aSEmmanuel Vadot <0x0000 0x0002 0xffffffff 0xffffffff 0x00000f8>, 113*cb7aa33aSEmmanuel Vadot /* For event ID 0-4 */ 114*cb7aa33aSEmmanuel Vadot <0x0 0x0 0xffffffff 0xfffffff0 0x00000ff0>, 115*cb7aa33aSEmmanuel Vadot /* For event ID 0xffffffff0000000f - 0xffffffff000000ff */ 116*cb7aa33aSEmmanuel Vadot <0xffffffff 0x0 0xffffffff 0xffffff0f 0x00000ff0>; 117*cb7aa33aSEmmanuel Vadot }; 118*cb7aa33aSEmmanuel Vadot 119*cb7aa33aSEmmanuel Vadot - | 120*cb7aa33aSEmmanuel Vadot /* 121*cb7aa33aSEmmanuel Vadot * For HiFive Unmatched board the encodings can be found here 122*cb7aa33aSEmmanuel Vadot * https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf 123*cb7aa33aSEmmanuel Vadot * 124*cb7aa33aSEmmanuel Vadot * This example also binds standard SBI PMU hardware IDs to U74 PMU event 125*cb7aa33aSEmmanuel Vadot * codes, U74 uses a bitfield for events encoding, so several U74 events 126*cb7aa33aSEmmanuel Vadot * can be bound to a single perf ID. 127*cb7aa33aSEmmanuel Vadot * See SBI PMU hardware IDs in arch/riscv/include/asm/sbi.h 128*cb7aa33aSEmmanuel Vadot */ 129*cb7aa33aSEmmanuel Vadot pmu { 130*cb7aa33aSEmmanuel Vadot compatible = "riscv,pmu"; 131*cb7aa33aSEmmanuel Vadot riscv,event-to-mhpmevent = 132*cb7aa33aSEmmanuel Vadot /* SBI_PMU_HW_CACHE_REFERENCES -> Instruction or Data cache/ITIM busy */ 133*cb7aa33aSEmmanuel Vadot <0x00003 0x00000000 0x1801>, 134*cb7aa33aSEmmanuel Vadot /* SBI_PMU_HW_CACHE_MISSES -> Instruction or Data cache miss or MMIO access */ 135*cb7aa33aSEmmanuel Vadot <0x00004 0x00000000 0x0302>, 136*cb7aa33aSEmmanuel Vadot /* SBI_PMU_HW_BRANCH_INSTRUCTIONS -> Conditional branch retired */ 137*cb7aa33aSEmmanuel Vadot <0x00005 0x00000000 0x4000>, 138*cb7aa33aSEmmanuel Vadot /* SBI_PMU_HW_BRANCH_MISSES -> Branch or jump misprediction */ 139*cb7aa33aSEmmanuel Vadot <0x00006 0x00000000 0x6001>, 140*cb7aa33aSEmmanuel Vadot /* L1D_READ_MISS -> Data cache miss or MMIO access */ 141*cb7aa33aSEmmanuel Vadot <0x10001 0x00000000 0x0202>, 142*cb7aa33aSEmmanuel Vadot /* L1D_WRITE_ACCESS -> Data cache write-back */ 143*cb7aa33aSEmmanuel Vadot <0x10002 0x00000000 0x0402>, 144*cb7aa33aSEmmanuel Vadot /* L1I_READ_ACCESS -> Instruction cache miss */ 145*cb7aa33aSEmmanuel Vadot <0x10009 0x00000000 0x0102>, 146*cb7aa33aSEmmanuel Vadot /* LL_READ_MISS -> UTLB miss */ 147*cb7aa33aSEmmanuel Vadot <0x10011 0x00000000 0x2002>, 148*cb7aa33aSEmmanuel Vadot /* DTLB_READ_MISS -> Data TLB miss */ 149*cb7aa33aSEmmanuel Vadot <0x10019 0x00000000 0x1002>, 150*cb7aa33aSEmmanuel Vadot /* ITLB_READ_MISS-> Instruction TLB miss */ 151*cb7aa33aSEmmanuel Vadot <0x10021 0x00000000 0x0802>; 152*cb7aa33aSEmmanuel Vadot riscv,event-to-mhpmcounters = <0x00003 0x00006 0x18>, 153*cb7aa33aSEmmanuel Vadot <0x10001 0x10002 0x18>, 154*cb7aa33aSEmmanuel Vadot <0x10009 0x10009 0x18>, 155*cb7aa33aSEmmanuel Vadot <0x10011 0x10011 0x18>, 156*cb7aa33aSEmmanuel Vadot <0x10019 0x10019 0x18>, 157*cb7aa33aSEmmanuel Vadot <0x10021 0x10021 0x18>; 158*cb7aa33aSEmmanuel Vadot riscv,raw-event-to-mhpmcounters = <0x0 0x0 0xffffffff 0xfc0000ff 0x18>, 159*cb7aa33aSEmmanuel Vadot <0x0 0x1 0xffffffff 0xfff800ff 0x18>, 160*cb7aa33aSEmmanuel Vadot <0x0 0x2 0xffffffff 0xffffe0ff 0x18>; 161*cb7aa33aSEmmanuel Vadot }; 162