H5.4 Concurrent read/write Scoreboard

HardFixVerilator · serverReview the topic

Fix a memory scoreboard that checks late read data against current memory instead of the snapshot taken at AR.

Hardware context: AXI4 burst engine using an explicitly limited protocol subset. Check concurrent reads/writes against the declared memory visibility rule.

A read may be answered many edges after its address was accepted, and a write can land in between. In this design, a read returns memory as it was when AR was accepted. The scoreboard compared it with memory as it is now, and blamed a correct engine.

The class memory_read_checker checks a read engine that shares memory with a write engine. It keeps its own copy of the memory. write_edge() applies each predicted write to that copy, using a trusted write observer. sample() checks the AR and R channels with one queue of expected bursts per ID.

The tests run real engines, correct and faulty, on one memory. They compare the reports of the write observer and your checker with the expected reports.

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
read_fault2input of each check
Full specification
The classes (keep these names and types)
class memory_read_expectation;
  function new(input bit [1:0] id, input bit [15:0] address, input bit [1:0] length, burst,
               input bit [127:0] words);   // word j of the burst in bits 32*j+31 : 32*j
endclass
class memory_read_checker;
  bit [7:0] memory_bytes[8192];
  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 void write_edge(input write_observer writer);
  function bit [79:0] finish();  // {error_cycles[63:0], error_kinds[7:0], pending_reads[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 ruleMeaning
Start8192 bytes. The byte at address a starts as ((17 × a) XOR 0x5a) & 0xff.
WriteA commit with OKAY changes only its enabled byte lanes, after the edge. SLVERR and DECERR commits change nothing.
Partial burstEarlier OKAY beats of a burst stay written even when a later beat fails.
ReadThe edge that accepts AR takes a snapshot of every beat of the burst, from memory before that edge.
Same edgeAn AR and a write commit on the same edge: the read sees the old bytes.
Late beatsR beats may come much later. They still carry the snapshot, not the current memory.
ResetReset cancels every read, write and response in flight. Bytes already written stay.
Each edgeWhat happens
1The tests call sample() with the AR and R channels before the edge.
2They call write_edge(writer). It applies the next predicted write to memory_bytes, from the write observer's queues before the edge.
3The clock rises. The real engines move, and real OKAY commits change the real memory.
4The write observer samples the write channels.
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.

write_edge() must predict from the observer's queues. It must not copy the real commit data, address or strobes.

All bursts here are fully mapped or fully unmapped. An unmapped read returns zero data and DECERR.

EnginesBehaviour
Write engineCorrect, or one of seven faults. Data faults: zeroed data, a flipped data bit, or all strobes on.
Other write faults: a wrong BID, a BID that moves in a stall, an early burst end, or the newest address first.
Read engineCorrect, or one fault: a flipped data bit, or a wrong RRESP with correct data.
TestsEach test runs 64 edges. One test keeps BREADY at 0, so a write response is still owed at the end.

The tests build the text write_report|read_report, each 20 hex digits. write_report is finish() of the write observer: {error_cycles, accepted_aw, accepted_w}. read_report is finish() of memory_read_checker.

They compare it with the expected text, character by character. reports_match = yes means both reports are exactly right. report_chars and expected_chars are the two lengths, normally 41.

Examples

Example 1

A Read Before the Write Keeps the Old Bytes
Input
Correct engines. Write: ID 1, INCR, 2 beats at 0x20, strobes 0x5 then 0xa; W on edges 0 and 1, AW on edge 6. Reads: ID 0 at 0x20 on edge 0, ID 1 at 0x30 on 6, ID 0 at 0x20 on 18, ID 2 at 0x80 on 32. RREADY from edge 10.
Output
report_chars = 41, expected_chars = 41, reports_match = yes

The first read of 0x20 is accepted before the write, so its beats carry the old bytes. They retire only after the commits on edges 7 and 8. The read on edge 18 sees the new lanes. Both reports are clean. Expected text: 00000000000000000102|00000000000000000000.

Example 2

All Strobes On
Input
Write: ID 2, WRAP, 4 beats at 0x3c, W on edges 4 to 10. The engine commits every beat with all four strobes on. Same reads.
Output
report_chars = 41, expected_chars = 41, reports_match = yes

The write observer flags the commits of the two partial-strobe beats, on edges 5 and 7. These reads do not touch the changed bytes, so the read report stays clean. Expected text: 00000000000000a00104|00000000000000000000.

Example 3

Reset Keeps Written Bytes
Input
Write: ID 1, 4 beats at 0x20 from edge 0, reset on edges 12 and 13, then ID 1, 2 beats at 0x80. BREADY is 0 until edge 30. Reads restart after the reset.
Output
report_chars = 41, expected_chars = 41, reports_match = yes

The first burst commits all four beats before the reset. Its response is still waiting, and reset cancels it. The bytes stay, so the read of 0x20 accepted on edge 21 must see them. Expected text: 00000000000000000206|00000000000000000000.

Example 4

Bad Write Data Shows up in a Later Read
Input
The first traffic on a write engine that stores zeros instead of the W data
Output
report_chars = 41, expected_chars = 41, reports_match = yes

The write observer flags the commits on edges 7 and 8. Real memory now holds zeros in the enabled lanes. The read on edge 18 expects the predicted bytes, so its two beats fail on edges 20 and 22. Expected text: 00000000000001800102|00000000005000000200.

Constraints and Contract

  • Take the read snapshot before this edge's write is applied.
  • Keep the class names, the method names and the argument types.

Hints

Hint 1

A read beat must carry the memory value from the edge that accepted its AR. Writes that land later do not change it.

Hint 2

Look at what memory_read_expectation stores when it is created. Is that value used when a beat is checked?

Hint 3

In sample(), expected_data is read from memory_bytes through rom_word(). Use the captured word for the current position instead.

What the grader checks: Real write and read engines share one byte memory. Faulty engines change real data, strobes, IDs and responses, and some tests reset in the middle. Both reports are compared exactly. This is the teaching subset of AXI, not full AXI.

147 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

A Read Before the Write Keeps the Old Bytes

Input
Correct engines. Write: ID 1, INCR, 2 beats at 0x20, strobes 0x5 then 0xa; W on edges 0 and 1, AW on edge 6. Reads: ID 0 at 0x20 on edge 0, ID 1 at 0x30 on 6, ID 0 at 0x20 on 18, ID 2 at 0x80 on 32. RREADY from edge 10.
Expected output
report_chars = 41, expected_chars = 41, reports_match = yes

The first read of 0x20 is accepted before the write, so its beats carry the old bytes. They retire only after the commits on edges 7 and 8. The read on edge 18 sees the new lanes. Both reports are clean. Expected text: 00000000000000000102|00000000000000000000.

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

Verilator · server