H1.6 Registered-Read Response Tracker

MediumFixVerilator · serverReview the topic

Fix a FIFO checker that forgets the response to the read that empties the FIFO.

Hardware context: Clocked FIFO plus ready/valid output adapter. Track each accepted FIFO read until its registered response becomes available.

A FIFO checker reported a false error at the end of every drain. The last read empties the FIFO, and the checker stopped expecting its response. The response is registered, so it is still due after that edge.

The class response_tracker checks one FIFO of 8-bit entries with DEPTH 1, 3 or 5. For each of 32 edges the tests call offer() just before the rising edge and retire() just after it. offer() predicts the edge from the requests. retire() checks what the FIFO shows after the edge. finish() returns a report.

The tests run it on a correct FIFO and on five faulty ones. The tracker must stay silent on the correct FIFO. On a faulty one it must flag every edge that breaks a rule. Find the bug in the tracker and fix it.

Signals in the Timeline

SignalWidthRole
profile3input of each check
controls96input of each check
values0256input of each check
values1256input of each check
values2256input of each check
values3256input of each check
fault3input of each check
Full specification
The class (keep these names and types)
class response_tracker;
  function new(input int depth);
  function void offer(input bit reset, write_en, read_en, input bit [7:0] write_data,
                      input bit pre_full, pre_empty);
  function void retire(input int cycle, input bit reset, post_full, post_empty, read_valid,
                       input bit [7:0] read_data);
  function bit [79:0] finish();
endclass
RuleWhat a correct FIFO does
WriteAccepted when reset = 0, write_en = 1 and fewer than DEPTH entries are stored before the edge. write_data joins the back.
ReadAccepted when reset = 0, read_en = 1 and at least one entry is stored before the edge. The oldest entry leaves.
Both on one edgeBoth decisions use the count before the edge. When empty, only the write is accepted. When full, only the read is accepted. Otherwise the read takes the oldest entry and the write joins the back.
ResponseThe edge that accepts a read loads the response registers. Right after that edge, read_valid = 1 and read_data holds the entry. This is true even when the read leaves the FIFO empty.
No readAfter an edge that accepts no read, read_valid = 0. read_data may then hold any old value.
Resetreset is synchronous, active high, and wins over both requests. It empties the FIFO and clears read_valid and read_data to 0.
Flagsfull = 1 exactly when DEPTH entries are stored. empty = 1 exactly when none are. Both follow the count with no delay.
CallWhat it does
offer()Check pre_full and pre_empty against your own queue. Decide both requests from the queue before the edge. For an accepted read, pop the oldest entry into a pending response. Push an accepted write. Reset empties the queue and creates no response.
retire()Check post_full and post_empty against the queue. read_valid must be 1 exactly when this edge accepted a read. When a response is due, check read_data. On a reset edge, read_data must be 0. Then clear the pending response.
finish()Return the report described below.

A failing edge sets bit cycle of error_edges once; cycle counts from 0. first_bad is the first failing cycle plus 1, or 0 when nothing failed.

accepted_writes and accepted_reads come from your queue model. observed_valid_edges counts the edges where the read_valid pin was 1. All counts run across resets, and reset_discarded counts entries thrown away by reset.

A missing or late response is an error. Moving the expectation one edge later is not a fix.

Faulty FIFOWhat is wrong
1Bit 0 of read data is flipped.
2read_valid stays high on idle edges.
3read_valid never rises.
4The whole response is one edge late.
5A read and a write on one edge return the new value, not the oldest.

Examples

Example 1

The Last Read Still Has a Response
Input
Depth 1, correct FIFO: write+read 0x21, read, idle, then 29 idle edges
Output
error_edges = {}, accepted_writes = 1, accepted_reads = 1, observed_valid_edges = 1, first_bad = 0, final_queued = 0, reset_discarded = 0

Edge 0 finds the FIFO empty, so only the write is accepted. Edge 1 reads 0x21 and leaves the FIFO empty. read_valid must still be 1 after that edge. No error is recorded.

Example 2

A Response One Edge Late
Input
Depth 3, response one edge late: write 0x31, read, idle, then 29 idle edges
Output
error_edges = {1, 2}, accepted_writes = 1, accepted_reads = 1, observed_valid_edges = 1, first_bad = 2, final_queued = 0, reset_discarded = 0

The read on edge 1 has no response after edge 1, so edge 1 fails. A response then appears after edge 2, when none is due, so edge 2 fails too. The counts match, but the timing is wrong.

Example 3

read_valid Stays High
Input
Depth 3, read_valid stays high: write 0x41, read, idle, reset with write+read 0x99, then 28 idle edges
Output
error_edges = {2}, accepted_writes = 1, accepted_reads = 1, observed_valid_edges = 2, first_bad = 3, final_queued = 0, reset_discarded = 0

After the idle edge 2, read_valid is still 1, so edge 2 fails and first_bad is 3. Reset clears the stale response and refuses both offers. One read was accepted, but read_valid was high on two edges.

Constraints and Contract

  • The last accepted read still needs read_valid = 1, even when post_empty = 1.
  • A write and a read on an empty FIFO accept only the write, so no response is due.
  • Keep the class name, the method names and the argument types.

Hints

Hint 1

Keep the pending response, a due bit and the expected byte, apart from the queue. The queue says what is stored. The pending response says what the pins must show now.

Hint 2

Compare read_valid on every edge, including idle and reset edges. It must equal the due bit exactly.

Hint 3

Look at the read_valid check in retire(). Does it depend on the queue size after the edge? It should not, because the read that empties the FIFO still returns data.

What the grader checks: The tracker sees the pins of six real FIFOs: one correct and five with a planted fault each. The error masks and counts are checked exactly. Passing shows that it catches these faults on these traces.

75 checks on Verilator · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 9 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

The Last Read Still Has a Response

Input
Depth 1, correct FIFO: write+read 0x21, read, idle, then 29 idle edges
Expected output
error_edges = {}, accepted_writes = 1, accepted_reads = 1, observed_valid_edges = 1, first_bad = 0, final_queued = 0, reset_discarded = 0

Edge 0 finds the FIFO empty, so only the write is accepted. Edge 1 reads 0x21 and leaves the FIFO empty. read_valid must still be 1 after that edge. No error is recorded.

Run samples executes all 3 public checks. Check all tests runs 75 checks on the server.

Verilator · server