Skip to content

Commit 8d4fc8f

Browse files
committed
[doc] Document the newly added performance counters
1 parent 2ea303d commit 8d4fc8f

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

doc/01_overview/compliance.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ In addition, the following instruction set extensions are available.
4343
- 2.0
4444
- always enabled
4545

46+
* - **"Zicntr" and "Zihpm": Extensions for Counters and Performance Monitoring**
47+
- 2.0
48+
- always enabled
49+
4650
* - **Zifencei**: Instruction-Fetch Fence
4751
- 2.0
4852
- always enabled

doc/03_reference/performance_counters.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
Performance Counters
44
====================
55

6-
Ibex implements performance counters according to the RISC-V Privileged Specification, version 1.11 (see Hardware Performance Monitor, Section 3.1.11).
6+
Ibex implements performance counters according to the RISC-V Privileged Specification, version 1.11 (see Hardware Performance Monitor, Section 3.1.11) and supports the **Zihpm** (Hardware Performance Counters) extension.
77
The performance counters are placed inside the Control and Status Registers (CSRs) and can be accessed with the ``CSRRW(I)`` and ``CSRRS/C(I)`` instructions.
88

9-
Ibex implements the clock cycle counter ``mcycle(h)``, the retired instruction counter ``minstret(h)``, as well as the 29 event counters ``mhpmcounter3(h)`` - ``mhpmcounter31(h)`` and the corresponding event selector CSRs ``mhpmevent3`` - ``mhpmevent31``, and the ``mcountinhibit`` CSR to individually enable/disable the counters.
9+
Ibex implements the machine-mode clock cycle counter ``mcycle(h)``, the retired instruction counter ``minstret(h)``, as well as the 29 event counters ``mhpmcounter3(h)`` - ``mhpmcounter31(h)`` and the corresponding event selector CSRs ``mhpmevent3`` - ``mhpmevent31``, and the ``mcountinhibit`` CSR to individually enable/disable the counters.
10+
11+
Additionally, Ibex implements the Zicntr and Zihpm extensions which provide User-mode (U-mode) aliases for these performance counters: ``cycle(h)``, ``instret(h)``, and ``hpmcounter3(h)`` - ``hpmcounter31(h)``. These aliases provide read-only access to the exact same underlying hardware counters configured in M-mode.
12+
1013
``mcycle(h)`` and ``minstret(h)`` are always available and 64 bit wide.
1114
The ``mhpmcounter`` performance counters are optional (unavailable by default) and parametrizable in width.
1215

@@ -60,6 +63,19 @@ In particular, to enable/disable ``mcycle(h)``, bit 0 must be written. For ``min
6063
The lower 32 bits of all counters can be accessed through the base register, whereas the upper 32 bits are accessed through the ``h``-register.
6164
Reads to all these registers are non-destructive.
6265

66+
User-Mode Counter Access (mcounteren)
67+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68+
69+
Access to the U-mode counter aliases (``cycle(h)``, ``instret(h)``, and ``hpmcounterX(h)``) is controlled via the Machine Counter-Enable CSR (``mcounteren``). This register can gate access to the counters from less privileged modes to prevent benchmarking the core if desired.
70+
71+
* **Bit 0** controls access to ``cycle(h)``.
72+
* **Bit 2** controls access to ``instret(h)``.
73+
* **Bit X** controls access to ``hpmcounterX(h)``.
74+
75+
When a bit in ``mcounteren`` is clear (0), any attempt to read the corresponding counter alias from U-mode will trigger an illegal instruction exception.
76+
77+
To secure this mechanism, the ``mcounteren`` register can be locked against software modifications using a MUBI input signal called ``mcounteren_writeable``. When this signal disables writes, any attempt by software to modify the contents of ``mcounteren`` is ignored.
78+
6379
Parametrization at synthesis time
6480
---------------------------------
6581

0 commit comments

Comments
 (0)