|
| 1 | +/*! |
| 2 | + * \file axi4s_rq_stats.sv |
| 3 | + * \brief Get statistic from axi4s |
| 4 | + * \author Radek Iša <[email protected]> |
| 5 | + * \date 2018 |
| 6 | + * \copyright CESNET, z. s. p. o. |
| 7 | + */ |
| 8 | + |
| 9 | +/* SPDX-License-Identifier: BSD-3-Clause */ |
| 10 | + |
| 11 | +class Axi4S_RQ_meter #(DATA_WIDTH = 512, USER_WIDTH = 137, ITEM_WIDTH_IN = 8, ST_COUNT = 4) extends Monitor; |
| 12 | + |
| 13 | + localparam REGIONS = ST_COUNT; |
| 14 | + localparam REGION_SIZE = 1; |
| 15 | + localparam ITEM_WIDTH = 8; |
| 16 | + localparam BLOCK_SIZE = DATA_WIDTH/REGIONS/ITEM_WIDTH; |
| 17 | + |
| 18 | + protected int sof_pos[REGIONS]; |
| 19 | + protected int eof_pos[REGIONS]; |
| 20 | + |
| 21 | + localparam ITEMS = REGIONS * REGION_SIZE * BLOCK_SIZE; |
| 22 | + localparam REGION_ITEMS = REGION_SIZE * BLOCK_SIZE; |
| 23 | + localparam WORD_BLOCKS = REGIONS * REGION_SIZE; |
| 24 | + localparam SOF_POS_WIDTH = $clog2(REGION_SIZE); |
| 25 | + localparam EOF_POS_WIDTH = $clog2(REGION_SIZE * BLOCK_SIZE); |
| 26 | + |
| 27 | + protected virtual iAxi4STx#(DATA_WIDTH, USER_WIDTH, ITEM_WIDTH_IN) vif; |
| 28 | + protected sv_common_pkg::stats speed; |
| 29 | + protected int unsigned speed_curr; |
| 30 | + protected logic inframe; |
| 31 | + protected int old_inframe = 0; |
| 32 | + |
| 33 | + function new(string i, virtual iAxi4STx#(DATA_WIDTH, USER_WIDTH, ITEM_WIDTH_IN) v); |
| 34 | + super.new(i); |
| 35 | + speed = new(); |
| 36 | + vif = v; |
| 37 | + endfunction |
| 38 | + |
| 39 | + virtual task setEnabled(); |
| 40 | + enabled = 1; |
| 41 | + fork |
| 42 | + run(); |
| 43 | + join_none; |
| 44 | + endtask |
| 45 | + |
| 46 | + function int hasSOF(); |
| 47 | + if (USER_WIDTH==137) // ULTRASCALE |
| 48 | + return vif.cb.TUSER[21:20]; |
| 49 | + else begin // 7SERIES |
| 50 | + if (!inframe) |
| 51 | + return vif.cb.TVALID; |
| 52 | + else |
| 53 | + return 0; |
| 54 | + end |
| 55 | + endfunction |
| 56 | + |
| 57 | + function int hasEOF(); |
| 58 | + if (USER_WIDTH==137) // ULTRASCALE |
| 59 | + return vif.cb.TUSER[27:26]; |
| 60 | + else begin // 7SERIES |
| 61 | + return vif.cb.TLAST; |
| 62 | + end |
| 63 | + endfunction |
| 64 | + |
| 65 | + function logic [3:0] fbe(int unsigned index); |
| 66 | + if(USER_WIDTH== 137) begin |
| 67 | + return vif.cb.TUSER[(index+1)*4-1 -: 4]; |
| 68 | + end else if (USER_WIDTH == 60) begin |
| 69 | + return vif.cb.TUSER[3:0]; |
| 70 | + end else begin |
| 71 | + $write("NOT SUPPORTED AXI USER_WIDTH\n"); |
| 72 | + $stop(); |
| 73 | + end |
| 74 | + endfunction |
| 75 | + |
| 76 | + function logic [3:0] lbe(int unsigned index); |
| 77 | + if(USER_WIDTH== 137) begin |
| 78 | + return vif.cb.TUSER[(index+1)*4+7 -: 4]; |
| 79 | + end else if (USER_WIDTH == 60) begin |
| 80 | + return vif.cb.TUSER[7:4]; |
| 81 | + end else begin |
| 82 | + $write("NOT SUPPORTED AXI USER_WIDTH\n"); |
| 83 | + $stop(); |
| 84 | + end |
| 85 | + endfunction |
| 86 | + |
| 87 | + function int sofPos(int index); |
| 88 | + if(SOF_POS_WIDTH == 0) begin |
| 89 | + return 0; |
| 90 | + end |
| 91 | + |
| 92 | + if (USER_WIDTH==137) // ULTRASCALE |
| 93 | + return index; |
| 94 | + else begin // 7SERIES |
| 95 | + return 0; |
| 96 | + end |
| 97 | + endfunction |
| 98 | + |
| 99 | + function int eofPos(int index); |
| 100 | + int pos = 0; |
| 101 | + int j = 0; |
| 102 | + |
| 103 | + if (EOF_POS_WIDTH == 0) begin |
| 104 | + return 0; |
| 105 | + end |
| 106 | + |
| 107 | + if (USER_WIDTH==137) begin // ULTRASCALE |
| 108 | + if ((vif.cb.TUSER[26] && vif.cb.TUSER[31:31] == index)) |
| 109 | + return vif.cb.TUSER[30:28]; |
| 110 | + if ((vif.cb.TUSER[27] && vif.cb.TUSER[35:35] == index)) |
| 111 | + return vif.cb.TUSER[34:32]; |
| 112 | + end else begin // 7SERIES |
| 113 | + for (j = 0; j < REGION_ITEMS; j++) begin |
| 114 | + if (vif.cb.TKEEP[j]==1'b0) |
| 115 | + break; |
| 116 | + pos = j; |
| 117 | + end |
| 118 | + return pos; |
| 119 | + end |
| 120 | + return -1; |
| 121 | + endfunction |
| 122 | + |
| 123 | + function int isSOF(int index); |
| 124 | + if (USER_WIDTH==137) begin // ULTRASCALE |
| 125 | + if ((vif.cb.TUSER[20] && vif.cb.TUSER[23:23] == index) || |
| 126 | + (vif.cb.TUSER[21] && vif.cb.TUSER[25:25] == index)) |
| 127 | + return 1; |
| 128 | + end else begin // 7SERIES |
| 129 | + if (!old_inframe) |
| 130 | + return vif.cb.TVALID; |
| 131 | + end |
| 132 | + return 0; |
| 133 | + endfunction |
| 134 | + |
| 135 | + function int isEOF(int index); |
| 136 | + if (USER_WIDTH==137) begin // ULTRASCALE |
| 137 | + if ((vif.cb.TUSER[26] && vif.cb.TUSER[31:31] == index) || |
| 138 | + (vif.cb.TUSER[27] && vif.cb.TUSER[35:35] == index)) |
| 139 | + return 1; |
| 140 | + end else begin // 7SERIES |
| 141 | + return hasEOF(); // only 1 region |
| 142 | + end |
| 143 | + return 0; |
| 144 | + endfunction |
| 145 | + |
| 146 | + task run_meter(); |
| 147 | + speed_curr = 0; |
| 148 | + while (enabled) begin |
| 149 | + time speed_start_time; |
| 150 | + time speed_end_time; |
| 151 | + const int unsigned mesures = 100; |
| 152 | + string msg; |
| 153 | + |
| 154 | + speed_end_time = $time(); |
| 155 | + forever begin |
| 156 | + time step_speed_end_time = speed_end_time; |
| 157 | + time step_speed_start_time; |
| 158 | + |
| 159 | + for (int unsigned it = 0; it < mesures; it++) begin |
| 160 | + step_speed_start_time = step_speed_end_time; |
| 161 | + |
| 162 | + #(1us); |
| 163 | + step_speed_end_time = $time(); |
| 164 | + speed.next_val(real'(speed_curr)/((step_speed_end_time-step_speed_start_time)/1ns)); |
| 165 | + |
| 166 | + speed_curr = 0; |
| 167 | + end |
| 168 | + |
| 169 | + begin |
| 170 | + real min, max, avg, std_dev; |
| 171 | + |
| 172 | + speed_start_time = speed_end_time; |
| 173 | + speed_end_time = step_speed_end_time; |
| 174 | + speed.count(min, max, avg, std_dev); |
| 175 | + msg = $sformatf("\n\tSpeed [%0dns:%0dns]\n\t\tAverage : %0.2fGb/s std_dev %0.2fGb/s\n\t\tmin : %0.2fGb/s max %0.2fGb/s", |
| 176 | + speed_start_time/1ns, speed_end_time/1ns, avg*ITEM_WIDTH, std_dev*ITEM_WIDTH, min*ITEM_WIDTH, max*ITEM_WIDTH); |
| 177 | + $write({"\n", this.inst , "\n", msg, "\n"}); |
| 178 | + speed.reset(); |
| 179 | + end |
| 180 | + end |
| 181 | + end |
| 182 | + endtask |
| 183 | + |
| 184 | + |
| 185 | + virtual task run(); |
| 186 | + inframe = 0; |
| 187 | + |
| 188 | + fork |
| 189 | + run_meter(); |
| 190 | + join_none |
| 191 | + |
| 192 | + |
| 193 | + while (enabled) begin |
| 194 | + int unsigned data_frame_size = 0; |
| 195 | + |
| 196 | + do begin |
| 197 | + @(vif.monitor_cb); |
| 198 | + end while (enabled && !(vif.monitor_cb.TVALID && vif.monitor_cb.TREADY)); |
| 199 | + |
| 200 | + if (!enabled) |
| 201 | + break; |
| 202 | + |
| 203 | + for (int unsigned it = 0; it < REGIONS; it++) begin |
| 204 | + if (inframe == 1) begin |
| 205 | + if (isEOF(it)) begin |
| 206 | + data_frame_size += eofPos(it)+1; |
| 207 | + inframe = 0; |
| 208 | + if (isSOF(it)) begin |
| 209 | + data_frame_size += (REGION_SIZE - sofPos(it))*BLOCK_SIZE; |
| 210 | + inframe = 1; |
| 211 | + end |
| 212 | + old_inframe = inframe; |
| 213 | + end else begin |
| 214 | + data_frame_size += REGION_SIZE*BLOCK_SIZE; |
| 215 | + end |
| 216 | + end else begin |
| 217 | + if (isSOF(it)) begin |
| 218 | + if (isEOF(it)) begin |
| 219 | + data_frame_size += (eofPos(it)+1 - sofPos(it)*BLOCK_SIZE); |
| 220 | + inframe = 0; |
| 221 | + end else begin |
| 222 | + data_frame_size += (REGION_SIZE - sofPos(it))*BLOCK_SIZE; |
| 223 | + inframe = 1; |
| 224 | + end |
| 225 | + old_inframe = inframe; |
| 226 | + end else begin |
| 227 | + data_frame_size += 0; |
| 228 | + end |
| 229 | + end |
| 230 | + end |
| 231 | + speed_curr += data_frame_size; |
| 232 | + end |
| 233 | + endtask |
| 234 | + |
| 235 | +endclass |
0 commit comments