Skip to content

Commit

Permalink
[hardware] Parametrize performance counters
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelRiedel committed Oct 9, 2023
1 parent 5b13586 commit 4dc86d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add Channel Estimation application and kernels
- Update Bender to version 0.27.3
- Update default Questasim version to 2022.3
- Parametrize the performance counters

### Fixed
- Fix type issue in `snitch_addr_demux`
- Properly disable the debugging CSRs in ASIC implementations

## 0.6.0 - 2023-01-09

Expand Down
1 change: 1 addition & 0 deletions hardware/deps/snitch/Bender.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
sources:
- defines:
SNITCH_ENABLE_PERF: 1
SNITCH_ENABLE_STALL_COUNTER: 1
files:
# packages
- src/riscv_instr.sv
Expand Down
19 changes: 15 additions & 4 deletions hardware/deps/snitch/src/snitch.sv
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
`include "common_cells/assertions.svh"

// `SNITCH_ENABLE_PERF Enables mcycle, minstret performance counters (read only)
// `SNITCH_ENABLE_STALL_COUNTER Enables stall_ins, stall_raw, stall_lsu performance counters (read only)

module snitch
import snitch_pkg::meta_id_t;
Expand Down Expand Up @@ -291,11 +292,14 @@ module snitch
`ifdef SNITCH_ENABLE_PERF
logic [63:0] cycle_q;
logic [63:0] instret_q;
`FFAR(cycle_q, cycle_q + 1, '0, clk_i, rst_i);
`FFLAR(instret_q, instret_q + 1, !stall, '0, clk_i, rst_i);
`endif

`ifdef SNITCH_ENABLE_STALL_COUNTER
logic [31:0] stall_ins_q;
logic [31:0] stall_raw_q;
logic [31:0] stall_lsu_q;
`FFAR(cycle_q, cycle_q + 1, '0, clk_i, rst_i);
`FFLAR(instret_q, instret_q + 1, !stall, '0, clk_i, rst_i);
`FFLAR(stall_ins_q, stall_ins_q + 1, stall && (!inst_ready_i) && inst_valid_o, '0, clk_i, rst_i)
`FFLAR(stall_raw_q, stall_raw_q + 1, (!operands_ready) || (!dst_ready), '0, clk_i, rst_i)
`FFLAR(stall_lsu_q, stall_lsu_q + 1, lsu_stall, '0, clk_i, rst_i)
Expand Down Expand Up @@ -1417,6 +1421,8 @@ module snitch
riscv_instr::CSR_MINSTRETH: begin
csr_rvalue = instret_q[63:32];
end
`endif
`ifdef SNITCH_ENABLE_STALL_COUNTER
riscv_instr::CSR_MHPMCOUNTER3: begin
csr_rvalue = stall_ins_q[31:0];
end
Expand All @@ -1436,8 +1442,13 @@ module snitch
end

// CSR registers
`FFLAR(csr_trace_q, alu_result, csr_trace_en, '0, clk_i, rst_i);
`FFLAR(csr_stack_limit_q, alu_result, csr_stack_limit_en, 32'hFFFF_FFFF, clk_i, rst_i);
`ifdef TARGET_ASIC
assign csr_trace_q = '0;
assign csr_stack_limit_q = '0;
`else
`FFLAR(csr_trace_q, alu_result, csr_trace_en, '0, clk_i, rst_i);
`FFLAR(csr_stack_limit_q, alu_result, csr_stack_limit_en, 32'hFFFF_FFFF, clk_i, rst_i);
`endif

// pragma translate_off
always_ff @(posedge clk_i or posedge rst_i) begin
Expand Down

0 comments on commit 4dc86d5

Please sign in to comment.