|
3 | 3 | Performance Counters |
4 | 4 | ==================== |
5 | 5 |
|
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. |
7 | 7 | 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. |
8 | 8 |
|
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 | + |
10 | 13 | ``mcycle(h)`` and ``minstret(h)`` are always available and 64 bit wide. |
11 | 14 | The ``mhpmcounter`` performance counters are optional (unavailable by default) and parametrizable in width. |
12 | 15 |
|
@@ -60,6 +63,19 @@ In particular, to enable/disable ``mcycle(h)``, bit 0 must be written. For ``min |
60 | 63 | 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. |
61 | 64 | Reads to all these registers are non-destructive. |
62 | 65 |
|
| 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 | + |
63 | 79 | Parametrization at synthesis time |
64 | 80 | --------------------------------- |
65 | 81 |
|
|
0 commit comments