mirror of
https://github.com/lowRISC/ibex.git
synced 2025-04-22 12:57:13 -04:00
Update documentation on CSRs and performance counters
This commit is contained in:
parent
d5a89b571f
commit
effa61c684
5 changed files with 219 additions and 227 deletions
|
@ -3,35 +3,62 @@
|
|||
Control and Status Registers
|
||||
============================
|
||||
|
||||
Ibex does not implement all control and status registers specified in the RISC-V privileged specifications, but is limited to the registers that were needed for the PULP system. The reason for this is that we wanted to keep the footprint of the core as low as possible and avoid any overhead that we do not explicitly need.
|
||||
Ibex implements all the Control and Status Registers (CSRs) listed in the following table according to the RISC-V Privileged Specification, draft version 1.11.
|
||||
|
||||
.. tabularcolumns:: |p{1cm}|p{.6cm}|p{.6cm}|p{1cm}|p{1cm}|p{1.5cm}|p{1.2cm}|p{6cm}|
|
||||
|
||||
+----------------------------+--------+---------+--------+-----------------------------------+
|
||||
| CSR Address | Hex | Name | Access | Description |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
| 11:10 | 9:8 | 7:6 | 5:0 | | | | |
|
||||
+=======+=====+=====+========+========+=========+========+===================================+
|
||||
| 00 | 11 | 00 | 000000 | 0x300 | MSTATUS | R/W | Machine Status |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
| 00 | 11 | 00 | 000101 | 0x305 | MTVEC | R | Machine Trap-Vector Base Address |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
| 00 | 11 | 01 | 000001 | 0x341 | MEPC | R/W | Machine Exception Program Counter |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
| 00 | 11 | 01 | 000010 | 0x342 | MCAUSE | R/W | Machine Trap Cause |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
| 01 | 11 | 00 | 0xxxxx | 0x780- | PCCRs | R/W | Performance Counter Counter |
|
||||
| | | | | 0x79F | | | Registers |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
| 01 | 11 | 10 | 100000 | 0x7A0 | PCER | R/W | Performance Counter Enable |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
| 01 | 11 | 10 | 100001 | 0x7A1 | PCMR | R/W | Performance Counter Mode |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
| 11 | 11 | 00 | 010100 | 0xF14 | MHARTID | R | Hardware Thread ID |
|
||||
+-------+-----+-----+--------+--------+---------+--------+-----------------------------------+
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| Address | Name | Access | Description |
|
||||
+=========+====================+========+===============================================+
|
||||
| 0x300 | ``mstatus`` | RW | Machine Status |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x301 | ``misa`` | WARL | Machine ISA and Extensions |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x305 | ``mtvec`` | WARL | Machine Trap-Handler Base Address |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x320 | ``mcountinhibit`` | RW | Machine Counter-Inhibit Register |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x323 | ``mhpmevent3`` | WARL | Machine Performance-Monitoring Event Selector |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| . . . . |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x33F | ``mhpmevent31`` | WARL | Machine performance-monitoring event selector |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x341 | ``mepc`` | RW | Machine Exception Program Counter |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x342 | ``mcause`` | RW | Machine Trap Cause |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x7B0 | ``dcsr`` | RW | Debug Control and Status Register |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x7B1 | ``dpc`` | RW | Debug PC |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x7B2 | ``dscratch0`` | RW | Debug Scratch Register 0 |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0x7B3 | ``dscratch1`` | RW | Debug Scratch Register 1 |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xB00 | ``mcycle`` | RW | Machine Cycle Counter |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xB02 | ``minstret`` | RW | Machine Instructions-Retired Counter |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xB03 | ``mhpmcounter3`` | WARL | Machine Performance-Monitoring Counter |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| . . . . |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xB1F | ``mhpmcounter31`` | WARL | Machine Performance-Monitoring Counter |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xB80 | ``mcycleh`` | RW | Upper 32 bits of ``mcycle`` |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xB82 | ``minstreth`` | RW | Upper 32 bits of ``minstret`` |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xB83 | ``mhpmcounter3h`` | WARL | Upper 32 bits of ``mhmpcounter3`` |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| . . . . |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xB9F | ``mhpmcounter31h`` | WARL | Upper 32 bits of ``mhmpcounter31`` |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
| 0xF14 | ``mhartid`` | R | Hardware Thread ID |
|
||||
+---------+--------------------+--------+-----------------------------------------------+
|
||||
|
||||
|
||||
Machine Status (MSTATUS)
|
||||
Machine Status (mstatus)
|
||||
------------------------
|
||||
|
||||
CSR Address: ``0x300``
|
||||
|
@ -43,35 +70,37 @@ Reset Value: ``0x0000_1800``
|
|||
+-------+-----+------------------------------------------------------------------+
|
||||
| 12:11 | R | **MPP:** Statically 2’b11 and cannot be altered (read-only). |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 7 | R/W | **Previous Interrupt Enable:** When an exception is encountered, |
|
||||
| 7 | RW | **Previous Interrupt Enable:** When an exception is encountered, |
|
||||
| | | MPIE will be set to IE. When the mret instruction is executed, |
|
||||
| | | the value of MPIE will be stored to IE. |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 3 | R/W | **Interrupt Enable:** If you want to enable interrupt handling |
|
||||
| 3 | RW | **Interrupt Enable:** If you want to enable interrupt handling |
|
||||
| | | in your exception handler, set the Interrupt Enable to 1’b1 |
|
||||
| | | inside your handler code. |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
|
||||
|
||||
Machine Trap-Vector Base Address (MTVEC)
|
||||
Machine Trap-Vector Base Address (mtvec)
|
||||
----------------------------------------
|
||||
|
||||
CSR Address: ``0x305``
|
||||
|
||||
When an exception is encountered, the core jumps to the corresponding handler using the content of the MTVEC as base address. It is a read-only register which contains the boot address.
|
||||
When an exception is encountered, the core jumps to the corresponding handler using the content of the ``mtvec`` as base address.
|
||||
It is a read-only register which contains the boot address.
|
||||
|
||||
|
||||
Machine Exception PC (MEPC)
|
||||
Machine Exception PC (mepc)
|
||||
---------------------------
|
||||
|
||||
CSR Address: ``0x341``
|
||||
|
||||
Reset Value: ``0x0000_0000``
|
||||
|
||||
When an exception is encountered, the current program counter is saved in MEPC, and the core jumps to the exception address. When an mret instruction is executed, the value from MEPC replaces the current program counter.
|
||||
When an exception is encountered, the current program counter is saved in ``mepc``, and the core jumps to the exception address.
|
||||
When an ``mret`` instruction is executed, the value from ``mepc`` replaces the current program counter.
|
||||
|
||||
|
||||
Machine Cause (MCAUSE)
|
||||
Machine Cause (mcause)
|
||||
----------------------
|
||||
|
||||
CSR Address: ``0x342``
|
||||
|
@ -90,8 +119,8 @@ Reset Value: ``0x0000_0000``
|
|||
|
||||
.. _csr-mhartid:
|
||||
|
||||
MHARTID
|
||||
-------
|
||||
Hardware Thread ID (mhartid)
|
||||
----------------------------
|
||||
|
||||
CSR Address: ``0xF14``
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 52 KiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 55 KiB |
|
@ -8,73 +8,73 @@ Instantiation Template
|
|||
|
||||
.. code-block:: verilog
|
||||
|
||||
ibex_core
|
||||
#(.N_EXT_PERF_COUNTERS (0),
|
||||
.RV32E (0),
|
||||
.RV32M (1),
|
||||
.DM_HALT_ADDRESS(32'h1A110800),
|
||||
.DM_EXCEPTION_ADDRESS(32'h1A110808))
|
||||
u_core
|
||||
(// Clock and reset
|
||||
.clk_i (),
|
||||
.rst_ni (),
|
||||
.test_en_i (),
|
||||
ibex_core #(
|
||||
.NumMHPMCounters (8),
|
||||
.WidthMHPMCounters (40),
|
||||
.RV32E (0),
|
||||
.RV32M (1),
|
||||
.DmHaltAddr (32'h1A110800),
|
||||
.DmExceptionAddr (32'h1A110808)
|
||||
) u_core (
|
||||
// Clock and reset
|
||||
.clk_i (),
|
||||
.rst_ni (),
|
||||
.test_en_i (),
|
||||
|
||||
// Configuration
|
||||
.core_id_i (),
|
||||
.cluster_id_i (),
|
||||
.boot_addr_i (),
|
||||
// Configuration
|
||||
.core_id_i (),
|
||||
.cluster_id_i (),
|
||||
.boot_addr_i (),
|
||||
|
||||
// Instruction memory interface
|
||||
.instr_req_o (),
|
||||
.instr_gnt_i (),
|
||||
.instr_rvalid_i (),
|
||||
.instr_addr_o (),
|
||||
.instr_rdata_i (),
|
||||
// Instruction memory interface
|
||||
.instr_req_o (),
|
||||
.instr_gnt_i (),
|
||||
.instr_rvalid_i (),
|
||||
.instr_addr_o (),
|
||||
.instr_rdata_i (),
|
||||
|
||||
// Data memory interface
|
||||
.data_req_o (),
|
||||
.data_gnt_i (),
|
||||
.data_rvalid_i (),
|
||||
.data_we_o (),
|
||||
.data_be_o (),
|
||||
.data_addr_o (),
|
||||
.data_wdata_o (),
|
||||
.data_rdata_i (),
|
||||
.data_err_i (),
|
||||
// Data memory interface
|
||||
.data_req_o (),
|
||||
.data_gnt_i (),
|
||||
.data_rvalid_i (),
|
||||
.data_we_o (),
|
||||
.data_be_o (),
|
||||
.data_addr_o (),
|
||||
.data_wdata_o (),
|
||||
.data_rdata_i (),
|
||||
.data_err_i (),
|
||||
|
||||
// Interrupt inputs
|
||||
.irq_i (),
|
||||
.irq_id_i (),
|
||||
.irq_ack_o (),
|
||||
.irq_id_o (),
|
||||
// Interrupt inputs
|
||||
.irq_i (),
|
||||
.irq_id_i (),
|
||||
.irq_ack_o (),
|
||||
.irq_id_o (),
|
||||
|
||||
// Debug Interface
|
||||
.debug_req_i (),
|
||||
// Debug Interface
|
||||
.debug_req_i (),
|
||||
|
||||
// Special control signal
|
||||
.fetch_enable_i (),
|
||||
|
||||
// External performance counters
|
||||
.ext_perf_counters_i ()
|
||||
);
|
||||
// Special control signal
|
||||
.fetch_enable_i ()
|
||||
);
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
+--------------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| Name | Type/Range | Default | Description |
|
||||
+==========================+=============+============+=================================================================+
|
||||
| ``N_EXT_PERF_COUNTERS`` | int (0..21) | 0 | Number of external performance counters |
|
||||
+--------------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| ``RV32E`` | bit | 0 | RV32E mode enable (16 integer registers only) |
|
||||
+--------------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| ``RV32M`` | bit | 1 | M(ultiply) extension enable |
|
||||
+-------------------------+--------------+------------+-----------------------------------------------------------------+
|
||||
| ``DM_HALT_ADDRESS`` | int | 0x1A110800 | Address to jump to when entering debug mode |
|
||||
+-------------------------+---------------------------------------------------------------------------------------------+
|
||||
| ``DM_EXCEPTION_ADDRESS`` | int | 0x1A110808 | Address to jump to when an exception occurs while in debug mode |
|
||||
+--------------------------+--------------------------------------------------------------------------------------------+
|
||||
+-----------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| Name | Type/Range | Default | Description |
|
||||
+=======================+=============+============+=================================================================+
|
||||
| ``NumMHPMCounters`` | int (0..29) | 8 | Number of performance monitor event counters |
|
||||
+-----------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| ``WidthMHPMCounters`` | int (64..32)| 40 | Bit width of performance monitor event counters |
|
||||
+-----------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| ``RV32E`` | bit | 0 | RV32E mode enable (16 integer registers only) |
|
||||
+-----------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| ``RV32M`` | bit | 1 | M(ultiply) extension enable |
|
||||
+-----------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| ``DmHaltAddr`` | int | 0x1A110800 | Address to jump to when entering debug mode |
|
||||
+-----------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
| ``DmExceptionAddr`` | int | 0x1A110808 | Address to jump to when an exception occurs while in debug mode |
|
||||
+-----------------------+-------------+------------+-----------------------------------------------------------------+
|
||||
|
||||
|
||||
Interfaces
|
||||
|
@ -90,7 +90,7 @@ Interfaces
|
|||
+-------------------------+-------------------------+-----+----------------------------------------+
|
||||
| ``test_en_i`` | 1 | in | Test input, enables clock |
|
||||
+-------------------------+-------------------------+-----+----------------------------------------+
|
||||
| ``core_id_i`` | 4 | in | Core id, usually static, can be read |
|
||||
| ``core_id_i`` | 4 | in | Core ID, usually static, can be read |
|
||||
| | | | from :ref:`csr-mhartid` |
|
||||
+-------------------------+-------------------------+-----+ +
|
||||
| ``cluster_id_i`` | 6 | in | |
|
||||
|
@ -107,5 +107,3 @@ Interfaces
|
|||
+-------------------------+-------------------------+-----+----------------------------------------+
|
||||
| ``fetch_enable_i`` | 1 | in | Enable the core, won't fetch when 0 |
|
||||
+-------------------------+-------------------------+-----+----------------------------------------+
|
||||
| ``ext_perf_counters_i`` | ``N_EXT_PERF_COUNTERS`` | in | External performance counter |
|
||||
+-------------------------+-------------------------+-----+----------------------------------------+
|
||||
|
|
|
@ -3,144 +3,114 @@
|
|||
Performance Counters
|
||||
====================
|
||||
|
||||
Performance Counters in Ibex are placed inside the Control and Status Registers and can be accessed with csrr and csrw instructions.
|
||||
Ibex implements performance counters according to the RISC-V Privileged Specification, draft version 1.11 (see Hardware Performance Monitor, Section 3.1.11).
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Performance Counter Mode Register (PCMR)
|
||||
----------------------------------------
|
||||
Event Selector
|
||||
--------------
|
||||
|
||||
CSR Address: ``0x7A1``
|
||||
The following events can be monitored using the performance counters of Ibex.
|
||||
|
||||
Reset Value: ``0x0000_0003``
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| Event ID/Bit | Event Name | Event Description |
|
||||
+==============+==================+=========================================================+
|
||||
| 0 | NumCycles | Number of cycles |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 2 | NumInstrRet | Number of instructions retired |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 3 | NumCyclesLSU | Number of cycles waiting for data memory |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 4 | NumCyclesIF | Cycles waiting for instruction fetches, i.e., number of |
|
||||
| | | instructions wasted due to non-ideal caching |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 5 | NumLoads | Number of data memory loads. Misaligned accesses are |
|
||||
| | | counted as two accesses |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 6 | NumStores | Number of data memory stores. Misaligned accesses are |
|
||||
| | | counted as two accesses |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 7 | NumJumps | Number of unconditional jumps (j, jal, jr, jalr) |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 8 | NumBranches | Number of branches (conditional) |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 9 | NumBranchesTaken | Number of taken branches (conditional) |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
| 10 | NumInstrRetC | Number of compressed instructions retired |
|
||||
+--------------+------------------+---------------------------------------------------------+
|
||||
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| Bit# | R/W | Description |
|
||||
+=======+=====+==================================================================+
|
||||
| 0 | R/W | **Global Enable:** Activate/deactivate all performance counters. |
|
||||
| | | If this bit is 0, all performance counters are disabled. After |
|
||||
| | | reset, this bit is set. |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 1 | R/W | **Saturation:** If this bit is set, saturating arithmetic is |
|
||||
| | | used in the performance counter counters. After reset, this bit |
|
||||
| | | is set. |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
The event selector CSRs ``mhpmevent3`` - ``mhpmevent31`` define which of these events are counted by the event counters ``mhpmcounter3(h)`` - ``mhpmcounter31(h)``.
|
||||
If a specific bit in an event selector CSR is set to 1, this means that events with this ID are being counted by the counter associated with that selector CSR.
|
||||
If an event selector CSR is 0, this means that the corresponding counter is not counting any event.
|
||||
|
||||
Counter Control
|
||||
---------------
|
||||
|
||||
Performance Counter Event Register (PCER)
|
||||
-----------------------------------------
|
||||
By default, all available counters are enabled after reset.
|
||||
They can be individually enabled/disabled by overwriting the corresponding bit in the ``mcountinhibit`` CSR at address ``0x320`` as described in the RISC-V Privileged Specification, draft version 1.11 (see Machine Counter-Inhibit CSR, Section 3.1.13).
|
||||
In particular, to enable/disable ``mcycle(h)``, bit 0 must be written. For ``minstret(h)``, it is bit 2. For event counter ``mhpmcounterX(h)``, it is bit X.
|
||||
|
||||
CSR Address: ``0x7A0``
|
||||
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.
|
||||
Reads to all these registers are non-destructive.
|
||||
|
||||
Reset Value: ``0x0000_0000``
|
||||
Counter Config
|
||||
--------------
|
||||
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| Bit# | R/W | Description |
|
||||
+=======+=====+==================================================================+
|
||||
| 16 | R/W | **TCDM_CONT** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 15 | R/W | **ST_EXT_CYC** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 14 | R/W | **LD_EXT_CYC** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 13 | R/W | **ST_EXT** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 12 | R/W | **LD_EXT** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 11 | R/W | **DELAY_SLOT** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 10 | R/W | **BRANCH** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 9 | R/W | **JUMP** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 8 | R/W | **ST** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 7 | R/W | **LD** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 6 | R/W | **WBRANCH_CYC** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 5 | R/W | **WBRANCH** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 4 | R/W | **IMISS** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 3 | R/W | **RESERVED** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 2 | R/W | **RESERVED** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 1 | R/W | **INSTR** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
| 0 | R/W | **CYCLES** |
|
||||
+-------+-----+------------------------------------------------------------------+
|
||||
The ``mcycle(h)`` and ``minstret(h)`` counters are 64 bit wide.
|
||||
The bit width of the event counters ``mhpmcounter3(h)`` - ``mhpmcounter31(h)`` can be controlled via the ``WidthMHPMCounters`` parameter.
|
||||
|
||||
Each bit in the PCER register controls one performance counter. If the bit is 1, the counter is enabled and starts counting events. If it is 0, the counter is disabled and its value won’t change.
|
||||
The effective number of available event counters ``mhpmcounterX(h)`` can be controlled via the ``NumMHPMCounters`` parameter.
|
||||
By default, only the first 8 counters ``mhpmcounter3(h)`` - ``mhpmcounter10(h)`` are available.
|
||||
The association of events with these counters is hardwired as listed in the following table.
|
||||
The remaining counters are disabled and tied to 0.
|
||||
|
||||
In the ASIC there is only one counter register, thus all counter events are masked by PCER and ORed together, i.e. if one of the enabled event happens, the counter will be increased. If multiple non-masked events happen at the same time, the counter will only be increased by one.
|
||||
In order to be able to count separate events on the ASIC, the program can be executed in a loop with different events configured.
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| Event Counter | CSR Address | Event ID/Bit | Event Name |
|
||||
+======================+================+==============+==================+
|
||||
| ``mcycle(h)`` | 0xB00 (0xB80) | 0 | NumCycles |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``minstret(h)`` | 0xB02 (0xB82) | 2 | NumInstrRet |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``mhpmcounter3(h)`` | 0xB03 (0xB83) | 3 | NumCyclesLSU |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``mhpmcounter4(h)`` | 0xB04 (0xB84) | 4 | NumCyclesIF |
|
||||
| | | | |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``mhpmcounter5(h)`` | 0xB05 (0xB85) | 5 | NumLoads |
|
||||
| | | | |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``mhpmcounter6(h)`` | 0xB06 (0xB86) | 6 | NumStores |
|
||||
| | | | |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``mhpmcounter7(h)`` | 0xB07 (0xB87) | 7 | NumJumps |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``mhpmcounter8(h)`` | 0xB08 (0xB88) | 8 | NumBranches |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``mhpmcounter9(h)`` | 0xB09 (0xB89) | 9 | NumBranchesTaken |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
| ``mhpmcounter10(h)`` | 0xB0A (0xB8A) | 10 | NumInstrRetC |
|
||||
+----------------------+----------------+--------------+------------------+
|
||||
|
||||
In the FPGA or RTL simulation version, each event has its own counter and can be accessed separately.
|
||||
Similarly, the event selector CSRs are hardwired as follows.
|
||||
The remaining event selector CSRs are tied to 0, i.e., no events are counted by the corresponding counters.
|
||||
|
||||
Performance Counter Counter Register (PCCR0-31)
|
||||
-----------------------------------------------
|
||||
|
||||
CSR Address: ``0x780`` - ``0x79F``
|
||||
|
||||
Reset Value: ``0x0000_0000``
|
||||
|
||||
PCCR registers support both saturating and wrap-around arithmetic. This is controlled by the saturation bit in PCMR.
|
||||
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| Register | Name | Description |
|
||||
+==========+================+================================================================+
|
||||
| PCCR0 | **CYCLES** | Counts the number of cycles the core was active (not sleeping) |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR1 | **INSTR** | Counts the number of instructions executed |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR2 | **-** | Reserved |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR3 | **-** | Reserved |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR4 | **IMISS** | Cycles waiting for instruction fetches, i.e. number of |
|
||||
| | | instructions wasted due to non-ideal caching |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR5 | **LD** | Number of data memory loads executed. Misaligned accesses are |
|
||||
| | | counted twice |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR6 | **ST** | Number of data memory stores executed. Misaligned accesses are |
|
||||
| | | counted twice |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR7 | **JUMP** | Number of unconditional jumps (j, jal, jr, jalr) |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR8 | **BRANCH** | Number of branches. Counts taken and not taken branches |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR9 | **BTAKEN** | Number of taken branches. |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR10 | **RVC** | Number of compressed instructions executed |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR11 | **LD_EXT** | Number of memory loads to EXT executed. Misaligned accesses |
|
||||
| | | are counted twice. Every non-TCDM access is considered |
|
||||
| | | external (PULP only) |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR12 | **ST_EXT** | Number of memory stores to EXT executed. Misaligned accesses |
|
||||
| | | are counted twice. Every non-TCDM access is considered |
|
||||
| | | external (PULP only) |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR13 | **LD_EXT_CYC** | Cycles used for memory loads to EXT. Every non-TCDM access is |
|
||||
| | | considered external (PULP only) |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR14 | **ST_EXT_CYC** | Cycles used for memory stores to EXT. Every non-TCDM access is |
|
||||
| | | considered external (PULP only) |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR15 | **TCDM_CONT** | Cycles wasted due to TCDM/log-interconnect contention |
|
||||
| | | (PULP only) |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
| PCCR31 | **ALL** | Special Register, a write to this register will set all |
|
||||
| | | counters to the supplied value |
|
||||
+----------+----------------+----------------------------------------------------------------+
|
||||
|
||||
In the FPGA, RTL simulation and Virtual-Platform there are individual counters for each event type, i.e. PCCR0-30 each represent a separate register. To save area in the ASIC, there is only one counter and one counter register. Accessing PCCR0-30 will access the same counter register in the ASIC. Reading/writing from/to PCCR31 in the ASIC will access the same register as PCCR0-30.
|
||||
|
||||
:numref:`pcer` shows how events are first masked with the PCER register and then ORed together to increase the one performance counter PCCR.
|
||||
|
||||
.. figure:: images/pcer.png
|
||||
:name: pcer
|
||||
|
||||
Events and PCCR, PCMR and PCER on the ASIC.
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
| Event Selector | CSR Address | Reset Value | Event ID/Bit |
|
||||
+======================+=============+=============+==============+
|
||||
| ``mhpmevent3(h)`` | 0x323 | 0x0000_0008 | 3 |
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
| ``mhpmevent4(h)`` | 0x324 | 0x0000_0010 | 4 |
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
| ``mhpmevent5(h)`` | 0x325 | 0x0000_0020 | 5 |
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
| ``mhpmevent6(h)`` | 0x326 | 0x0000_0040 | 6 |
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
| ``mhpmevent7(h)`` | 0x327 | 0x0000_0080 | 7 |
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
| ``mhpmevent8(h)`` | 0x328 | 0x0000_0100 | 8 |
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
| ``mhpmevent9(h)`` | 0x329 | 0x0000_0200 | 9 |
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
| ``mhpmevent10(h)`` | 0x32A | 0x0000_0400 | 10 |
|
||||
+----------------------+-------------+-------------+--------------+
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue