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