A counter lost a DMA engine's write although every core used exclusive accesses. Find the first wrong cycle in the target's monitor, name the cause from five real bugs, and fix it.
Hardware context: Three requesters sharing one target through an arbiter. Diagnose and fix exclusive monitors that a plain write fails to clear, so a DMA update is lost.
Lesson P1.9 cured the lost update with exclusive pairs: read exclusively, write exclusively, retry if the write fails. The cure only works if the target's monitors are right.
Core A increments a counter at address 4 with exclusive pairs. A DMA engine on the other port resets the counter to 40 with a plain write. The final value should be 41. The log says: the counter at address 4 is 0b, expected 41. The DMA's write vanished, and no core broke a rule.
Step 1: find the first cycle where a signal shows a value a correct target would not, and name the signal. Step 2: choose the cause from five real bugs. Step 3, optional: fix the target and run the tests.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
ops | 5 | input of each check |
Full specification
module excl_mem (
input logic clk, rst_n, op_valid, op_who,
input logic [1:0] op_kind, // 0 read, 1 exclusive read, 2 write, 3 exclusive write
input logic [3:0] op_addr, input logic [7:0] op_wdata,
output logic [7:0] rdata, output logic xok);
| Rule | Correct target |
|---|---|
| Exclusive read | Sets the monitor of its initiator to that address, moving it if it was set elsewhere. |
| Exclusive write | Succeeds (xok = 1) only while its initiator's monitor holds that address. A failed one writes nothing. |
| Any write that happens | Plain or exclusive, it clears every monitor on its address, whoever wrote. |
| Timing | An operation is offered for one cycle; rdata and xok show its result in the next. |
The failing program has four phases. A moves its monitor, A and B race, the DMA writes next door, and the DMA resets the counter. Cycle N is the stretch where the cycle counter shows N.
The tests run ten more programs and report every operation's xok and the data of the last five reads.
Diagnose the Failing Run
The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.
Log
Waveform
Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.
Step 3 is optional: fix the code in the editor, then run the tests.
Examples
Example 1
The Failing Program on a Fixed Target- Input
Bytes start as 05. Operations: A xread 8, A xread 4, A xwrite 4=A+1, A xread 4, B xread 4, A xwrite 4=A+1, B xwrite 4=B+1, B xread 4, B xwrite 4=B+1, A xread 4, B write 8=88, A xwrite 4=A+1, A xread 4, B write 4=40, A xwrite 4=A+1, A xread 4, A xwrite 4=A+1, A read 4
- Output
ops = 18, xok_fold = 0x2c, xok_bits = 0x10924, last_reads = 0x708094041
In phase 4 the DMA's plain write clears A's monitor, so A's exclusive write fails. A reads 40 again, writes 41 and succeeds.
Example 2
A Plain Write Breaks a Pair- Input
Bytes start as 05. Operations: A xread 2, B write 2=22, A xwrite 2=A+1, A read 2
- Output
ops = 4, xok_fold = 0x0, xok_bits = 0x0, last_reads = 0x522
Initiator 1 writes address 2 plainly between A's exclusive read and write. A's monitor must be cleared, so A's write fails and the last read shows 22.
Example 3
Writes Next Door Change Nothing- Input
Bytes start as 05. Operations: A xread 2, B write 3=33, B write 6=66, A xwrite 2=A+1, A read 2
- Output
ops = 5, xok_fold = 0x8, xok_bits = 0x8, last_reads = 0x506
Addresses 3 and 6 are not the monitored address 2, so A's exclusive write succeeds and stores 06.
Constraints and Contract
- Bytes start as 05. Initiator 0 is core A; initiator 1 is core B in phase 2 and the DMA engine after it.
- Keep the module name and its ports.
Hints
Hint 1
Find the first exclusive write whose xok differs from what the rules say. Which write before it should have cleared, or kept, the monitor?
Hint 2
Each bug breaks a different phase. A monitor that does not move breaks phase 1; a write that clears only its own monitor breaks phase 2.
Hint 3
In phase 4, the DMA's write is plain. Which monitors must it clear?
What the grader checks: The failing run is simulated live. The first bad cycle and each option's first wrong value come from simulating every target on the same bench. The optional fix is checked against an independent model on ten programs.
10 checks on Icarus · browser samples / server checks. 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 3 steps and the final capstone