H5.3 Read-Response Reorder Checker

HardFixVerilator · serverReview the topic

Fix a per-ID read checker that only looks at a read beat on the edge that takes it.

Hardware context: AXI4 burst engine using an explicitly limited protocol subset. Check read beats and last markers under legal cross-ID reordering.

A valid R beat must hold still until its handshake. A read checker missed a responder that dropped RVALID during a stall. It also missed beats that were wrong while stalled. It looked at a beat only on the edge that took it.

The classes read_expectation and read_checker watch the AR and R channels of a read engine with four credits. The checker keeps a queue of expected bursts for each ID. Each R beat must match the oldest burst of its own RID. Different IDs may interleave and finish in any order.

The tests call sample() once per edge for 64 edges, then finish(). They run two correct engines with different schedules and eight faulty ones.

The checker has two bugs, both about stalled beats. Find them and fix them.

Signals in the Timeline

SignalWidthRole
fault4input of each check
naddresses3input of each check
descriptors128input of each check
releases32input of each check
ready_calendar64input of each check
Full specification
The classes (keep these names and types)
class read_expectation;
  function new(input bit [1:0] id, input bit [15:0] address, input bit [1:0] length, burst);
endclass
class read_checker;
  function new();
  function void sample(input int cycle, input bit resetn,
    arvalid, arready, input bit [1:0] arid, input bit [15:0] araddr, input bit [1:0] arlen, arburst,
    rvalid, rready, input bit [1:0] rid, rresp, input bit [31:0] rdata, input bit rlast);
  function bit [79:0] finish();  // {error_cycles[63:0], error_kinds[7:0], pending_bursts[7:0]}
endclass
AXI ruleMeaning
HandshakeA transfer happens on a rising edge where VALID and READY are both 1.
StallA sender that is not yet taken keeps VALID and its payload unchanged.
Write data orderAW and W are separate channels. In AXI4, W beats follow the order of the addresses and carry no ID.
Response orderResponses with the same ID come back in request order. Different IDs may come back in any order.
This designChoice
Bus16-bit addresses, 32-bit data, four byte strobes and 2-bit IDs.
BurstsFull-word, aligned bursts. FIXED and INCR have 1 to 4 beats. WRAP has 2 or 4 beats. A burst stays inside one 4 KiB page.
MapAddresses 0x0000 to 0x1fff are memory. Any other address completes with DECERR (3).
ResponsesOKAY is 0, SLVERR is 2 and DECERR is 3. EXOKAY is not used.
Left outNarrow or unaligned transfers, longer bursts, exclusive access, cache, QoS, protection and user fields.
BurstAddress of beat i
FIXED (0)The start address on every beat.
INCR (1)start + 4 × i.
WRAP (2)The window is beats × 4 bytes, aligned to its own size. Add 4 per beat and wrap to the window start at its end.

Memory is read-only here. The byte at address a is ((17 × a) XOR 0x5a) & 0xff. A word read at a holds bytes a to a + 3, lowest address in the lowest lane. An unmapped burst (address 0x2000 or more) returns zero data and DECERR on every beat. Every burst still has its declared beat count and RLAST.

Step in sample()What it does
Reset edgeEmpty every queue and clear the stall record. ARREADY and RVALID must be 0.
AR creditARREADY must equal (fewer than 4 bursts outstanding before the edge).
HoldAfter an edge with RVALID = 1 and RREADY = 0, the beat must stay. RVALID stays 1, and RID, RDATA, RRESP and RLAST do not change.
OfferOn every edge with RVALID = 1, find the oldest burst of RID. Check its next beat: data, response and RLAST.
RetireOnly on RVALID and RREADY, move to the next beat. Pop the burst after its declared last beat, whatever RLAST said.
AppendLast, add a burst for an AR handshake on this edge. A new AR cannot explain a beat on the same edge.
error_kinds bitRaised when
0A beat has an RID with no outstanding burst.
1Wrong data or response for the oldest burst of the ID.
2Wrong RLAST.
3A stalled beat changed or vanished.
4finish() finds bursts still outstanding.
5ARREADY disagrees with the free credits.
6ARREADY or RVALID is 1 during reset.
EngineBehaviour
Correct, round-robinTakes turns between IDs, so beats of different IDs interleave.
Correct, global orderAlways serves the oldest read. This is legal too.
FaultyFlips data. Marks the first beat last. Changes RID. Skips a middle beat. Drops RVALID in a stall. Serves the newest burst of an ID. Replays a finished burst. Sends a wrong RRESP only.

error_cycles has bit i set when edge i failed, counting edges from 0. finish() also sets bit 63 when bursts are left. pending_bursts counts them. The tests always give RREADY enough to drain a correct engine.

Examples

Example 1

Legal Interleaving Across IDs
Input
Round-robin engine. AR: ID 0 at 0x20 (4 beats), ID 2 at 0x80 (2), ID 1 at 0xc0 (1), ID 0 at 0x100 (2). RREADY is 0 on edges 0 to 7.
Output
error_cycles = {}, error_kinds = {}, pending_bursts = 0

The engine may serve ID 2 and ID 1 between the two ID 0 bursts. Each beat matches the oldest burst of its own ID. All nine beats retire and nothing is reported.

Example 2

Newest First Breaks the ID Order
Input
Engine that serves the newest burst of an ID. AR: ID 0 at 0x10 (1 beat), then ID 1 at 0x20 (2), 0x80 (2) and 0xc0 (1).
Output
error_cycles = {10, 12, 14, 16, 18}, error_kinds = {1, 2}, pending_bursts = 0

After the ID 0 beat, the engine serves the ID 1 bursts newest first. The checker expects 0x20 first. Five beats fail with wrong data or a wrong RLAST (bits 1 and 2).

Example 3

A Stalled Beat Cannot Disappear
Input
The first traffic on the engine that drops RVALID while RREADY is 0
Output
error_cycles = {3, 5, 7}, error_kinds = {3}, pending_bursts = 0

During the stall the engine lowers RVALID on some edges. Edges 3, 5 and 7 fail with bit 3, even though every beat arrives in the end.

Example 4

Global Order Is Legal Too
Input
The first traffic on the engine that always serves the oldest read
Output
error_cycles = {}, error_kinds = {}, pending_bursts = 0

This engine never reorders across IDs. It still keeps every per-ID rule, so the checker must stay silent.

Constraints and Contract

  • Do not keep one global order for all IDs. A correct engine may answer a later ID first.
  • The hold check covers RID, data, response and RLAST together.
  • Keep the class names, the method names and the argument types.

Hints

Hint 1

RREADY decides only when a beat retires. The beat on the wires must be right on every edge where RVALID is 1.

Hint 2

Keep the last stalled beat (RVALID = 1, RREADY = 0). On the next edge, compare the whole beat with it, and require RVALID = 1.

Hint 3

Look at the R branch of sample(). It checks a beat only when rvalid && rready. Next to the held = ... line, nothing compares a stalled beat with this edge.

What the grader checks: A real read engine with four credits interleaves beats across IDs and holds them under stalls. Two legal schedules and eight faulty engines drive the checker. Every error mask is compared exactly.

134 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 8 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

Legal Interleaving Across IDs

Input
Round-robin engine. AR: ID 0 at 0x20 (4 beats), ID 2 at 0x80 (2), ID 1 at 0xc0 (1), ID 0 at 0x100 (2). RREADY is 0 on edges 0 to 7.
Expected output
error_cycles = {}, error_kinds = {}, pending_bursts = 0

The engine may serve ID 2 and ID 1 between the two ID 0 bursts. Each beat matches the oldest burst of its own ID. All nine beats retire and nothing is reported.

Run samples executes all 4 public checks. Check all tests runs 134 checks on the server.

Verilator · server