H5.7 Per-ID Response Ordering Oracle

HardFixVerilator · serverReview the topic

Fix a write-response checker that accepts a B response before its write has all its data.

Hardware context: AXI4 burst engine using an explicitly limited protocol subset. Verify same-ID response ordering while permitting declared cross-ID reordering.

A checker passed a response scheduler that answered each write right after its address, before any data arrived. The early response even retired the write, so its real response later looked unsolicited.

The class response_order watches a write engine and a separate response scheduler. Each edge it sees the AW and W handshakes and the B offer. W data always follows AW order. A write may get its response only after its address and all its beats were accepted.

The tests call sample() once per edge for 64 edges, then finish(). They run two correct schedulers and seven faulty ones.

Find the bug and fix it.

Signals in the Timeline

SignalWidthRole
fault4input of each check
naddresses3input of each check
nbeats5input of each check
descriptors128input of each check
beats0256input of each check
beats1256input of each check
beats2128input of each check
address_release32input of each check
data_release128input of each check
ready_calendar64input of each check
reset_cycle8input of each check
restart_aw3input of each check
restart_w5input of each check
Full specification
The classes (keep these names and types)
class write_order_request;
  function new(input bit [1:0] id, input bit [15:0] address, input bit [1:0] length);
endclass
class response_order;
  function new();
  function void sample(input int cycle, input bit aw_take, input bit [1:0] awid, input bit [15:0] awaddr,
    input bit [1:0] awlen, input bit w_take, wlast, bvalid, bready, input bit [1:0] bid, bresp);
  function bit [79:0] finish();  // {error_cycles[63:0], error_kinds[7:0], pending_requests[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.
RuleMeaning
AssemblyBeats belong to writes in AW order, whatever their IDs. A beat that comes before its address waits.
CompleteA write is complete when its address and all AWLEN + 1 beats were accepted.
StatusDECERR for an address of 0x2000 or more. Otherwise SLVERR if any beat had a wrong WLAST. Otherwise OKAY.
Per-ID orderKeep one queue of writes per ID, oldest first. A B offer belongs to the oldest write of its BID.
TimingA response may come any time after the write is complete. No latency or global order is required.
Step in sample()What it does
HoldIf the last edge had BVALID = 1 and BREADY = 0, this edge must show the same BID and BRESP with BVALID = 1.
OfferFor BVALID = 1, take the oldest write of BID. None: bit 0. Not complete: bit 1. Wrong BRESP: bit 2.
RetireOn a B handshake, pop that write if it is complete, even when its status was wrong. An early response pops nothing.
AppendLast, add this edge's AW and W handshakes and update the assembly.
error_kinds bitRaised when
0A response has a BID with no outstanding write.
1A response comes before its write is complete.
2BRESP differs from the expected status.
3A stalled offer changed or vanished.
4finish() finds writes, unmatched beats or unfinished assembly left.

B carries no data. Two same-ID writes with the same status look the same on the wires. So the tests give same-ID writes different statuses, and a wrong order shows as a wrong BRESP.

SchedulerBehaviour
Correct, round-robinMay answer a later ID first.
Correct, global orderAnswers the oldest complete write first.
FaultyAnswers the newest same-ID write first. Answers right after AW. Repeats a response. Changes BID. Changes BRESP. Drops BVALID in a stall. Loses a response.

error_cycles has bit i set when edge i failed, counting edges from 0. finish() also sets bit 63 when work is left. pending_requests counts the writes still waiting.

Examples

Example 1

Different IDs May Finish in Another Order
Input
Round-robin scheduler. AW: ID 0 at 0x20 (2 beats), ID 3 at 0x8000 (1), ID 1 at 0x40 (1), ID 0 at 0x80 (1). BREADY is 0 until edge 24.
Output
error_cycles = {}, error_kinds = {}, pending_requests = 0

All data joins in AW order. The scheduler may answer ID 1 before the older ID 3. The two ID 0 responses keep their order, so nothing is reported.

Example 2

Different Statuses Show a Wrong Order
Input
Newest-first scheduler. AW: ID 0 at 0x10, then three ID 1 writes: 0x20 with a wrong WLAST, 0x8000, and 0x40.
Output
error_cycles = {26, 30}, error_kinds = {2}, pending_requests = 0

The ID 1 writes expect SLVERR, DECERR and OKAY, in that order. The scheduler answers OKAY, DECERR, SLVERR. The first and last offers fail with bit 2, on edges 26 and 30.

Example 3

An Address Alone Cannot Earn a Response
Input
Scheduler that answers right after AW. ID 2, INCR, 4 beats at 0x20. AW on edge 0, W from edge 12. BREADY is 1.
Output
error_cycles = {1}, error_kinds = {1}, pending_requests = 0

A response appears on edge 1, before any data. The oldest ID 2 write is not complete, so edge 1 fails with bit 1. The write stays expected, and its real response later clears it.

Example 4

Global Order Is Legal Too
Input
The first traffic on the global-order scheduler
Output
error_cycles = {}, error_kinds = {}, pending_requests = 0

Reordering across IDs is allowed, not required. The checker must stay silent on this schedule too.

Constraints and Contract

  • Do not reorder the expected responses to fit what you see.
  • A write is complete because of accepted AW and W handshakes, not because a response appeared.
  • Keep the class names, the method names and the argument types.

Hints

Hint 1

A write is complete only when its address and all AWLEN + 1 beats were accepted. A response before that is an error.

Hint 2

Trace the third example. On edge 1 the ID 2 write has no data yet. Which bit should fire, and should the write stay expected?

Hint 3

Look at how sample() handles a B offer. It never tests request.complete. Raise bit 1 for an incomplete write, and pop only a complete one.

What the grader checks: A real write engine feeds a separate response scheduler, correct or faulty. The checker never reads the scheduler's state. Same-ID writes with different statuses make order errors visible on B.

76 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

Different IDs May Finish in Another Order

Input
Round-robin scheduler. AW: ID 0 at 0x20 (2 beats), ID 3 at 0x8000 (1), ID 1 at 0x40 (1), ID 0 at 0x80 (1). BREADY is 0 until edge 24.
Expected output
error_cycles = {}, error_kinds = {}, pending_requests = 0

All data joins in AW order. The scheduler may answer ID 1 before the older ID 3. The two ID 0 responses keep their order, so nothing is reported.

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

Verilator · server