Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0844f38

Browse files
committed
added stat in scoreboards and displaying verification result
1 parent 3af1268 commit 0844f38

File tree

6 files changed

+178
-11
lines changed

6 files changed

+178
-11
lines changed

rtl/head_table.sv

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ assign pdata_in_d1_ready = pdata_out_ready_i;
172172

173173

174174
// synthesis translate_off
175-
function void print( string msg );
176-
$display("%08t: %m: %s", $time, msg);
177-
endfunction
175+
`include "../tb/ht_dbg.vh"
178176

179177
function void print_wr_head_table( );
180178
string msg;

tb/ht_environment.sv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ class ht_environment;
4949
join
5050
endtask
5151

52+
function post_test( );
53+
bit passed = 1'b1;
54+
55+
scb.show_stat( );
56+
scb_inner.show_stat( );
57+
58+
passed &= scb.test_passed( );
59+
passed &= scb_inner.test_passed( );
60+
61+
$display( " " );
62+
$display( "%m: VERIFICATION: %s", passed ? ( "PASSSED" ) : ( "FAILED" ) );
63+
endfunction
64+
5265
// return 1 if all mailboxs is empty
5366
// otherwize 0
5467
function bit mailboxs_is_empty( );

tb/ht_inner_scoreboard.sv

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,52 @@ class ht_inner_scoreboard;
2525

2626
logic [TABLE_ADDR_CNT-1:0] empty_ptr_mask;
2727

28+
typedef enum int unsigned {
29+
HEAD_TABLE_WR,
30+
31+
DATA_TABLE_WR,
32+
DATA_TABLE_RD,
33+
34+
EMPTY_PTR_SRST,
35+
EMPTY_PTR_STORAGE_ADD,
36+
EMPTY_PTR_STORAGE_DEL,
37+
38+
// just calcing how much we execute this functions
39+
FUNC_CHECK_ONE_ADDR,
40+
FUNC_CHECK_HEAD_TABLE_EQUAL_PTR,
41+
FUNC_GO_THROUGH_ALL_DATA,
42+
43+
// it's "fake" constant
44+
STAT_CNT
45+
46+
} stat_t;
47+
48+
typedef enum int unsigned {
49+
HEAD_TABLE_BUCKET_LINKS,
50+
51+
DATA_TABLE_RD_FROM_EMPTY,
52+
53+
EMPTY_PTR_STORAGE_REEMPTY,
54+
EMPTY_PTR_STORAGE_NOTEMPTY,
55+
56+
MORE_THAN_ONE_LINK,
57+
PTR_VAL_TO_EMPTY_ADDR,
58+
KEY_BUCKET_MISMATCH,
59+
60+
// "fake" constant
61+
ERR_STAT_CNT
62+
} stat_err_t;
63+
64+
int stats [STAT_CNT-1:0];
65+
int stats_err [ERR_STAT_CNT-1:0];
66+
67+
`define INC_STATS( x ) stats [ x ] += 1;
68+
`define INC_ERR_STATS( x ) stats_err[ x ] += 1;
69+
2870
function new( input virtual head_table_if _head_table_if,
2971
virtual data_table_if _data_table_if,
3072
virtual empty_ptr_storage_if _eps_if
31-
);
73+
);
3274

3375
this._head_t_if = _head_table_if;
3476
this._data_t_if = _data_table_if;
@@ -43,14 +85,46 @@ class ht_inner_scoreboard;
4385
eps_thread( );
4486
join
4587
endtask
88+
89+
function void show_stat( );
90+
$display("%m:");
91+
92+
for( int i = 0; i < STAT_CNT; i++ )
93+
begin
94+
$display( "| %-35s | %10d |", stat_t'(i), stats[i] );
95+
end
96+
97+
$display(" ");
98+
99+
for( int i = 0; i < ERR_STAT_CNT; i++ )
100+
begin
101+
$display( "| ERR_%-31s | %10d |", stat_err_t'(i), stats_err[i] );
102+
end
103+
endfunction
104+
105+
// return 1, if no error happend
106+
function bit test_passed( );
107+
bit rez = 1'b1;
108+
109+
for( int i = 0; i < ERR_STAT_CNT; i++ )
110+
begin
111+
if( stats_err[i] > 0 )
112+
rez = 1'b0;
113+
end
114+
115+
return rez;
116+
endfunction
46117

47118
task head_table_thread( );
48119
forever
49120
begin
50121
@( _head_t_if.cb )
51122

52123
if( _head_t_if.cb.wr_en )
53-
head_table[ _head_t_if.wr_addr ] = _head_t_if.wr_data;
124+
begin
125+
`INC_STATS( HEAD_TABLE_WR )
126+
head_table[ _head_t_if.cb.wr_addr ] = _head_t_if.cb.wr_data;
127+
end
54128

55129
end
56130
endtask
@@ -63,15 +137,21 @@ class ht_inner_scoreboard;
63137

64138
if( _data_t_if.cb.wr_en )
65139
begin
140+
`INC_STATS( DATA_TABLE_WR )
141+
66142
data_table[ _data_t_if.cb.wr_addr ] = _data_t_if.cb.wr_data;
143+
67144
do_tables_check( );
68145
end
69146

70147
if( _data_t_if.cb.rd_en )
71148
begin
149+
`INC_STATS( DATA_TABLE_RD )
150+
72151
// checking that we don't read from addreses that we think is empty
73152
if( empty_ptr_mask[ _data_t_if.cb.rd_addr ] == 1'b1 )
74153
begin
154+
`INC_ERR_STATS( DATA_TABLE_RD_FROM_EMPTY )
75155
$error( "ERROR: reading from empty addr = 0x%x", _data_t_if.cb.rd_addr );
76156
end
77157

@@ -87,13 +167,19 @@ class ht_inner_scoreboard;
87167

88168
if( _eps_if.cb.srst )
89169
begin
170+
`INC_STATS( EMPTY_PTR_SRST )
171+
90172
empty_ptr_mask = '0;
91173
end
92174

93175
if( _eps_if.cb.add_empty_ptr_en )
94176
begin
177+
178+
`INC_STATS( EMPTY_PTR_STORAGE_ADD )
179+
95180
if( empty_ptr_mask[ _eps_if.cb.add_empty_ptr ] == 1'b1 )
96181
begin
182+
`INC_ERR_STATS( EMPTY_PTR_STORAGE_REEMPTY )
97183
$error( "ERROR: trying to empty addr = 0x%x, that is already empty!",
98184
_eps_if.cb.add_empty_ptr );
99185
end
@@ -103,8 +189,12 @@ class ht_inner_scoreboard;
103189

104190
if( _eps_if.cb.next_empty_ptr_rd_ack )
105191
begin
192+
`INC_STATS( EMPTY_PTR_STORAGE_DEL )
193+
106194
if( empty_ptr_mask[ _eps_if.cb.next_empty_ptr ] == 1'b0 )
107195
begin
196+
`INC_ERR_STATS( EMPTY_PTR_STORAGE_NOTEMPTY )
197+
108198
$error( "ERROR: trying to make not empty addr = 0x%x, that is already not empty!",
109199
_eps_if.cb.next_empty_ptr );
110200
end
@@ -122,7 +212,8 @@ class ht_inner_scoreboard;
122212

123213
function automatic void check_head_table_equal_ptr( );
124214
int ptr_cnt [BUCKETS_CNT-1:0];
125-
215+
216+
`INC_STATS( FUNC_CHECK_HEAD_TABLE_EQUAL_PTR )
126217

127218
// calculating how much ptr exists in head_table
128219
for( int i = 0; i < HEAD_TABLE_WORDS; i++ )
@@ -135,6 +226,7 @@ class ht_inner_scoreboard;
135226
begin
136227
if( ptr_cnt[i] > 1 )
137228
begin
229+
`INC_ERR_STATS( HEAD_TABLE_BUCKET_LINKS )
138230
$error("failed! bucket_num = %d ptr_cnt = %d", i, ptr_cnt[i] );
139231
end
140232
end
@@ -147,22 +239,32 @@ class ht_inner_scoreboard;
147239
int rez;
148240

149241
rez = 0;
242+
243+
`INC_STATS( FUNC_CHECK_ONE_ADDR )
150244

151245
if( data_addr_cnt[ _addr ] > 1 )
152246
begin
247+
`INC_ERR_STATS( MORE_THAN_ONE_LINK )
248+
153249
$error("ERROR: addr = 0x%x. More than one link to this addr.", _addr );
250+
154251
rez = -1;
155252
end
156253

157254
if( empty_ptr_mask[ _addr ] == 1'b1 )
158255
begin
256+
`INC_ERR_STATS( PTR_VAL_TO_EMPTY_ADDR )
257+
159258
$error("ERROR: addr = 0x%x. This addr is empty, but ptr is val", _addr );
160259

161260
rez = -1;
162261
end
163262

263+
// NOTE: only for dummy hashing
164264
if( data_table[ _addr ].key[KEY_WIDTH-1:KEY_WIDTH - BUCKET_WIDTH] != _bucket_num )
165265
begin
266+
`INC_ERR_STATS( KEY_BUCKET_MISMATCH )
267+
166268
$error("ERROR: addr = 0x%x key=0x%x don't match bucket_num = 0x%x",
167269
_addr, data_table[_addr].key, _bucket_num );
168270

@@ -174,6 +276,8 @@ class ht_inner_scoreboard;
174276

175277
function automatic void go_through_all_data( );
176278
bit [BUCKET_WIDTH-1:0] _bucket_num;
279+
280+
`INC_STATS( FUNC_GO_THROUGH_ALL_DATA )
177281

178282
foreach( data_addr_cnt[i] )
179283
data_addr_cnt[i] = 0;

tb/ht_scoreboard.sv

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,27 @@ class ht_scoreboard;
2020

2121
ref_hash_table ref_ht;
2222

23-
int stat_in_opcode [ OPCODE_CNT - 1 : 0 ];
24-
int stat_out_opcode [ OPCODE_CNT - 1 : 0 ];
25-
int stat_rescode [ RESCODE_CNT - 1 : 0 ];
23+
typedef enum int unsigned {
24+
COMMAND_LOST_REORDER,
25+
26+
// ref and dut results not match
27+
OP_INIT_NOT_MATCH,
28+
OP_SEARCH_NOT_MATCH,
29+
OP_INSERT_NOT_MATCH,
30+
OP_DELETE_NOT_MATCH,
31+
32+
UNKNOWN_OPCODE,
33+
34+
// "fake" constant
35+
ERR_STAT_CNT
36+
} stat_err_t;
37+
38+
int stat_in_opcode [ OPCODE_CNT - 1 : 0 ];
39+
int stat_out_opcode [ OPCODE_CNT - 1 : 0 ];
40+
int stat_rescode [ RESCODE_CNT - 1 : 0 ];
41+
int stats_err [ ERR_STAT_CNT - 1 : 0 ];
42+
43+
`define INC_ERR_STATS( x ) stats_err[ x ] += 1;
2644

2745
function new( input mailbox #( ht_command_t ) _drv2scb,
2846
mailbox #( ht_result_t ) _mon2scb );
@@ -56,6 +74,7 @@ class ht_scoreboard;
5674
endfunction
5775

5876
function void show_stat( );
77+
$display("%m:");
5978

6079
$display( "| %-35s | %10s | %10s |", "OPCODE", "IN", "OUT" );
6180

@@ -73,13 +92,33 @@ class ht_scoreboard;
7392
$display("| %-35s | %10d |", ht_rescode_t'(i), stat_rescode[i] );
7493
end
7594

95+
$display( " " );
96+
for( int i = 0; i < ERR_STAT_CNT; i++ )
97+
begin
98+
$display("| ERR_%-31s | %10d |", stat_err_t'(i), stats_err[i] );
99+
end
100+
76101
endfunction
77102

103+
// return 1, if no error happend
104+
function bit test_passed( );
105+
bit rez = 1'b1;
106+
107+
for( int i = 0; i < ERR_STAT_CNT; i++ )
108+
begin
109+
if( stats_err[i] > 0 )
110+
rez = 1'b0;
111+
end
112+
113+
return rez;
114+
endfunction
115+
78116
function void check( input ht_command_t c, ht_result_t r );
79117
ht_result_t ref_res;
80118

81119
if( r.cmd != c )
82120
begin
121+
`INC_ERR_STATS( COMMAND_LOST_REORDER )
83122
$error("DUT command in result don't match (maybe lost some command or reordering...?)");
84123
return;
85124
end
@@ -92,6 +131,7 @@ class ht_scoreboard;
92131
if( ( ref_res.rescode != r.rescode ) ||
93132
( ref_res.found_value != r.found_value ) )
94133
begin
134+
`INC_ERR_STATS( OP_SEARCH_NOT_MATCH )
95135
$error("Did not in %s: key = 0x%x REF: %s found = 0x%x, DUT: %s found = 0x%x", c.opcode, c.key, ref_res.rescode, ref_res.found_value, r.rescode, r.found_value );
96136
end
97137
end
@@ -100,9 +140,22 @@ class ht_scoreboard;
100140
begin
101141
if( ref_res.rescode != r.rescode )
102142
begin
143+
case( c.opcode )
144+
OP_INIT : `INC_ERR_STATS ( OP_INIT_NOT_MATCH )
145+
OP_INSERT : `INC_ERR_STATS ( OP_INSERT_NOT_MATCH )
146+
OP_DELETE : `INC_ERR_STATS ( OP_DELETE_NOT_MATCH )
147+
endcase
148+
103149
$error("Did not in %s REF: %s, DUT: %s", c.opcode, ref_res.rescode, r.rescode );
104150
end
105151
end
152+
153+
default:
154+
begin
155+
`INC_ERR_STATS( UNKNOWN_OPCODE )
156+
157+
$error( "Unknown opcode [%s]!", c.opcode );
158+
end
106159
endcase
107160

108161
endfunction

tb/make.tcl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ proc do_compile {} {
55
# compiling files
66
vlog -work work -coverall "../rtl/hash_table_pkg.sv"
77
vlog -work work -coverall "../tb/ht_tb_pkg.sv"
8-
vlog -work work -coverall "../tb/tables_monitor.sv"
98
vlog -work work -coverall "top_tb.sv"
109
vlog -work work -coverall "../rtl/*.sv"
1110
vlog -work work -coverall "../rtl/*.v"

tb/top_tb.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ initial
357357

358358
wait_end_of_tests( );
359359

360-
env.scb.show_stat( );
360+
env.post_test( );
361361

362362
$stop();
363363
end

0 commit comments

Comments
 (0)