stats: Add string support to statistics collector

Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
Alex Forencich
2025-04-16 17:08:52 -07:00
parent e3fcf54466
commit 031d092513
4 changed files with 161 additions and 11 deletions

View File

@@ -33,6 +33,8 @@ export PARAM_CNT := 8
export PARAM_INC_W := 8
export PARAM_ID_BASE := 0
export PARAM_UPDATE_PERIOD := 128
export PARAM_STR_EN := 1
export PARAM_PREFIX_STR := "\"BLK\""
export PARAM_STAT_INC_W := 16
export PARAM_STAT_ID_W := $(shell python -c "print(($(PARAM_CNT)-1).bit_length())")

View File

@@ -25,6 +25,10 @@ from cocotb.regression import TestFactory
from cocotbext.axi import AxiStreamBus, AxiStreamSink
def str2int(s):
return int.from_bytes(s.encode('utf-8'), 'big')
class TB(object):
def __init__(self, dut):
self.dut = dut
@@ -39,6 +43,7 @@ class TB(object):
for k in range(len(dut.stat_inc)):
dut.stat_inc[k].setimmediatevalue(0)
dut.stat_valid[k].setimmediatevalue(0)
dut.stat_str[k].setimmediatevalue(str2int(f"STR_{k}"))
dut.gate.setimmediatevalue(1)
dut.update.setimmediatevalue(0)
@@ -86,9 +91,10 @@ async def run_test_acc(dut, backpressure_inserter=None):
while not tb.stat_sink.empty():
stat = await tb.stat_sink.recv()
assert stat.tdata[0] != 0
if not stat.tuser:
assert stat.tdata[0] != 0
data[stat.tid] += stat.tdata[0]
data[stat.tid] += stat.tdata[0]
print(data)
@@ -124,9 +130,10 @@ async def run_test_max(dut, backpressure_inserter=None):
while not tb.stat_sink.empty():
stat = await tb.stat_sink.recv()
assert stat.tdata[0] != 0
if not stat.tuser:
assert stat.tdata[0] != 0
data[stat.tid] += stat.tdata[0]
data[stat.tid] += stat.tdata[0]
print(data)
@@ -137,6 +144,54 @@ async def run_test_max(dut, backpressure_inserter=None):
await RisingEdge(dut.clk)
async def run_test_str(dut, backpressure_inserter=None):
tb = TB(dut)
stat_count = len(dut.stat_valid)
await tb.cycle_reset()
tb.set_backpressure_generator(backpressure_inserter)
strings = [bytearray() for x in range(stat_count)]
done_cnt = 0
while done_cnt < stat_count:
stat = await tb.stat_sink.recv()
print(stat)
val = stat.tdata[0]
index = stat.tid
ptr = (val & 0x7)*2
b = bytearray()
for k in range(2):
c = (val >> (k*6 + 4)) & 0x3f
if c & 0x20:
c = (c & 0x1f) | 0x40
else:
c = (c & 0x1f) | 0x20
b.append(c)
if len(strings[index]) == ptr:
strings[index].extend(b)
if ptr == 14:
done_cnt += 1
print(strings)
for i, s in enumerate(strings):
s = (s[0:8].strip() + b"." + s[8:].strip()).decode('ascii')
print(s)
assert s == f'BLK.STR_{i}'
await RisingEdge(dut.clk)
await RisingEdge(dut.clk)
async def run_stress_test(dut, backpressure_inserter=None):
tb = TB(dut)
@@ -203,9 +258,10 @@ async def run_stress_test(dut, backpressure_inserter=None):
while not tb.stat_sink.empty():
stat = await tb.stat_sink.recv()
assert stat.tdata[0] != 0
if not stat.tuser:
assert stat.tdata[0] != 0
data[stat.tid] += stat.tdata[0]
data[stat.tid] += stat.tdata[0]
print(data)
@@ -224,6 +280,7 @@ if cocotb.SIM_NAME:
for test in [
run_test_acc,
run_test_max,
run_test_str,
run_stress_test,
]:
@@ -270,6 +327,8 @@ def test_taxi_stats_collect(request):
parameters['INC_W'] = 8
parameters['ID_BASE'] = 0
parameters['UPDATE_PERIOD'] = 128
parameters['STR_EN'] = 1
parameters['PREFIX_STR'] = "\"BLK\""
parameters['STAT_INC_W'] = 16
parameters['STAT_ID_W'] = (parameters['CNT']-1).bit_length()

View File

@@ -22,6 +22,8 @@ module test_taxi_stats_collect #
parameter INC_W = 8,
parameter ID_BASE = 0,
parameter UPDATE_PERIOD = 128,
parameter logic STR_EN = 1'b1,
parameter logic [8*8-1:0] PREFIX_STR = "BLK",
parameter STAT_INC_W = 16,
parameter STAT_ID_W = $clog2(CNT)
/* verilator lint_on WIDTHTRUNC */
@@ -33,13 +35,16 @@ logic rst;
logic [INC_W-1:0] stat_inc[CNT];
logic [0:0] stat_valid[CNT];
logic [8*8-1:0] stat_str[CNT];
taxi_axis_if #(
.DATA_W(STAT_INC_W),
.KEEP_EN(0),
.KEEP_W(1),
.ID_EN(1),
.ID_W(STAT_ID_W)
.ID_W(STAT_ID_W),
.USER_EN(1),
.USER_W(1)
) m_axis_stat();
logic gate;
@@ -49,7 +54,9 @@ taxi_stats_collect #(
.CNT(CNT),
.INC_W(INC_W),
.ID_BASE(ID_BASE),
.UPDATE_PERIOD(UPDATE_PERIOD)
.UPDATE_PERIOD(UPDATE_PERIOD),
.STR_EN(STR_EN),
.PREFIX_STR(PREFIX_STR)
)
uut (
.clk(clk),
@@ -60,6 +67,7 @@ uut (
*/
.stat_inc(stat_inc),
.stat_valid(stat_valid),
.stat_str(stat_str),
/*
* Statistics increment output