-
Notifications
You must be signed in to change notification settings - Fork 18
/
axi_dma_perf_counters.sv
198 lines (173 loc) · 6.98 KB
/
axi_dma_perf_counters.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Copyright 2020 ETH Zurich and University of Bologna.
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
// SPDX-License-Identifier: SHL-0.51
// Thomas Benz <[email protected]>
`include "common_cells/registers.svh"
// Sample implementation of performance counters.
module axi_dma_perf_counters #(
parameter int unsigned TRANSFER_ID_WIDTH = -1,
parameter int unsigned DATA_WIDTH = -1,
parameter type axi_req_t = logic,
parameter type axi_res_t = logic,
parameter type dma_events_t = logic,
localparam bit EnablePerfCounters = 0
) (
input logic clk_i,
input logic rst_ni,
// AXI4 bus
input axi_req_t axi_dma_req_i,
input axi_res_t axi_dma_res_i,
// ID input
input logic [TRANSFER_ID_WIDTH-1:0] next_id_i,
input logic [TRANSFER_ID_WIDTH-1:0] completed_id_i,
// DMA busy
input logic dma_busy_i,
// performance bus
output axi_dma_pkg::dma_perf_t dma_perf_o,
output dma_events_t dma_events_o
);
localparam int unsigned StrbWidth = DATA_WIDTH / 8;
// internal state
axi_dma_pkg::dma_perf_t dma_perf_d, dma_perf_q;
// Event counter
dma_events_t dma_events;
// need popcount common cell to get the number of bytes active in the strobe signal
logic [$clog2(StrbWidth)+1-1:0] num_bytes_written;
popcount #(
.INPUT_WIDTH ( StrbWidth )
) i_popcount (
.data_i ( axi_dma_req_i.w.strb ),
.popcount_o ( num_bytes_written )
);
// see if counters should be increased
always_comb begin : proc_next_perf_state
// default: keep old value
dma_perf_d = dma_perf_q;
dma_events = '0;
// aw
if ( axi_dma_req_i.aw_valid) begin
dma_perf_d.aw_valid_cnt = dma_perf_q.aw_valid_cnt + 'h1;
dma_events.aw_valid = 1'b1;
end
if ( axi_dma_res_i.aw_ready) begin
dma_perf_d.aw_ready_cnt = dma_perf_q.aw_ready_cnt + 'h1;
dma_events.aw_ready = 1'b1;
end
if ( axi_dma_res_i.aw_ready && axi_dma_req_i.aw_valid) begin
dma_perf_d.aw_done_cnt = dma_perf_q.aw_done_cnt + 'h1;
dma_events.aw_done = 1'b1;
end
if ( axi_dma_res_i.aw_ready && axi_dma_req_i.aw_valid) begin
dma_perf_d.aw_bw =
dma_perf_q.aw_bw + ((axi_dma_req_i.aw.len + 1) << axi_dma_req_i.aw.size);
dma_events.aw_len = axi_dma_req_i.aw.len;
dma_events.aw_size = axi_dma_req_i.aw.size;
end
if (!axi_dma_res_i.aw_ready && axi_dma_req_i.aw_valid) begin
dma_perf_d.aw_stall_cnt = dma_perf_q.aw_stall_cnt + 'h1;
dma_events.aw_stall = 1'b1;
end
// ar
if (axi_dma_req_i.ar_valid) begin
dma_perf_d.ar_valid_cnt = dma_perf_q.ar_valid_cnt + 'h1;
dma_events.ar_valid = 1'b1;
end
if (axi_dma_res_i.ar_ready) begin
dma_perf_d.ar_ready_cnt = dma_perf_q.ar_ready_cnt + 'h1;
dma_events.ar_ready = 1'b1;
end
if (axi_dma_res_i.ar_ready && axi_dma_req_i.ar_valid) begin
dma_perf_d.ar_done_cnt = dma_perf_q.ar_done_cnt + 'h1;
dma_events.ar_done = 1'b1;
end
if (axi_dma_res_i.ar_ready && axi_dma_req_i.ar_valid) begin
dma_perf_d.ar_bw =
dma_perf_q.ar_bw + ((axi_dma_req_i.ar.len + 1) << axi_dma_req_i.ar.size);
dma_events.ar_len = axi_dma_req_i.ar.len;
dma_events.ar_size = axi_dma_req_i.ar.size;
end
if (!axi_dma_res_i.ar_ready && axi_dma_req_i.ar_valid) begin
dma_perf_d.ar_stall_cnt = dma_perf_q.ar_stall_cnt + 'h1;
dma_events.ar_stall = 1'b1;
end
// r
if (axi_dma_res_i.r_valid) begin
dma_perf_d.r_valid_cnt = dma_perf_q.r_valid_cnt + 'h1;
dma_events.r_valid = 1'b1;
end
if (axi_dma_req_i.r_ready) begin
dma_perf_d.r_ready_cnt = dma_perf_q.r_ready_cnt + 'h1;
dma_events.r_ready = 1'b1;
end
if (axi_dma_req_i.r_ready && axi_dma_res_i.r_valid) begin
dma_perf_d.r_done_cnt = dma_perf_q.r_done_cnt + 'h1;
dma_events.r_done = 1'b1;
end
if (axi_dma_req_i.r_ready && axi_dma_res_i.r_valid) begin
dma_perf_d.r_bw = dma_perf_q.r_bw + DATA_WIDTH / 8;
dma_events.r_bw = 1'b1;
end
if (axi_dma_req_i.r_ready && !axi_dma_res_i.r_valid) begin
dma_perf_d.r_stall_cnt = dma_perf_q.r_stall_cnt + 'h1;
dma_events.r_stall = 1'b1;
end
// w
if (axi_dma_req_i.w_valid) begin
dma_perf_d.w_valid_cnt = dma_perf_q.w_valid_cnt + 'h1;
dma_events.w_valid = 1'b1;
end
if (axi_dma_res_i.w_ready) begin
dma_perf_d.w_ready_cnt = dma_perf_q.w_ready_cnt + 'h1;
dma_events.w_ready = 1'b1;
end
if (axi_dma_res_i.w_ready && axi_dma_req_i.w_valid) begin
dma_perf_d.w_done_cnt = dma_perf_q.w_done_cnt + 'h1;
dma_events.w_done = 1'b1;
end
if (axi_dma_res_i.w_ready && axi_dma_req_i.w_valid) begin
dma_perf_d.w_bw = dma_perf_q.w_bw + num_bytes_written;
dma_events.num_bytes_written = num_bytes_written;
end
if (!axi_dma_res_i.w_ready && axi_dma_req_i.w_valid) begin
dma_perf_d.w_stall_cnt = dma_perf_q.w_stall_cnt + 'h1;
dma_events.w_stall = 1'b1;
end
// b
if (axi_dma_res_i.b_valid) begin
dma_perf_d.b_valid_cnt = dma_perf_q.b_valid_cnt + 'h1;
dma_events.b_valid = 1'b1;
end
if (axi_dma_req_i.b_ready) begin
dma_perf_d.b_ready_cnt = dma_perf_q.b_ready_cnt + 'h1;
dma_events.b_ready = 1'b1;
end
if (axi_dma_req_i.b_ready && axi_dma_res_i.b_valid) begin
dma_perf_d.b_done_cnt = dma_perf_q.b_done_cnt + 'h1;
dma_events.b_done = 1'b1;
end
// buffer
if ( axi_dma_res_i.w_ready && !axi_dma_req_i.w_valid) begin
dma_perf_d.buf_w_stall_cnt = dma_perf_q.buf_w_stall_cnt + 'h1;
dma_events.w_stall = 1'b1;
end
if (!axi_dma_req_i.r_ready && axi_dma_res_i.r_valid) begin
dma_perf_d.buf_r_stall_cnt = dma_perf_q.buf_r_stall_cnt + 'h1;
dma_events.r_stall = 1'b1;
end
// ids
dma_perf_d.next_id = 32'h0 + next_id_i;
dma_perf_d.completed_id = 32'h0 + completed_id_i;
// busy
if (dma_busy_i) begin
dma_perf_d.dma_busy_cnt = dma_perf_q.dma_busy_cnt + 'h1;
dma_events.dma_busy = 1'b1;
end
end
assign dma_events_o = dma_events;
assign dma_perf_o = dma_perf_q;
if (EnablePerfCounters) begin : gen_perf_counters
`FF(dma_perf_q, dma_perf_d, 0);
end else begin
assign dma_perf_q = '0;
end
endmodule