Fix an arbiter checker that forgets the retained client, so it flags a correct arbiter during stalls.
Hardware context: Round-robin arbiter with accepted-grant priority updates. Retain an offered arbitration winner through downstream backpressure.
An arbiter checker flagged a correct design. Every false error came during a stall, just after another client raised its request. The arbiter was right to keep its offer. The checker was wrong.
The class grant_retention_checker watches one round-robin arbiter that keeps a stalled offer. After each edge, sample() gets the requests, the offer, the receipts, and the arbiter state on both sides. The checker predicts every value from its own model and records each mismatch. report() returns a one-line summary.
The tests run it on a correct arbiter and on eight faulty ones. It must stay silent on the correct one and report the exact mismatches on the others. The tests check report() after every edge.
Find the bug in the checker and fix it. The rules in brief: a stalled offer is kept until it transfers, is withdrawn or is reset. The full rules are in the specification.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
clients | 4 | input of each check |
initial_priority | 4 | input of each check |
hardware_fault | 4 | input of each check |
Full specification
class grant_retention_checker;
function new(input int clients, initial_priority);
function void sample(input int cycle, input bit reset, ready, input bit [7:0] requests,
input int pre_pointer, input bit pre_locked, input bit [7:0] pre_owner,
input bit valid, input bit [7:0] grant, winner,
input bit accepted, input bit [7:0] accepted_client, input bit canceled,
input int post_pointer, input bit post_locked, input bit [7:0] post_owner);
function string report();
endclass
| Rule | What the arbiter does |
|---|---|
| Clients | N is the number of clients. Clients are 0 to N - 1. Request bits at N and above are ignored. |
| Fresh choice | With no retained client, scan the clients in circular order, starting at priority_state. The first one that requests is offered. |
| Offer | valid = 1, winner = the client and grant = its one-hot bit. With no offer, valid = 0, winner = 0xff and grant = 0. |
| Transfer | A transfer happens at an edge with reset = 0, valid = 1 and ready = 1. priority_state then becomes winner + 1, wrapping to 0 after N - 1. |
| Stall | At an edge with valid = 1 and ready = 0, the offered client becomes the retained client. priority_state does not move. |
| Retained offer | While the retained client keeps requesting, it stays offered. Requests from other clients cannot take its place. |
| Withdrawal | If the retained client drops its request, the offer is idle for that whole cycle. This holds even when others request and ready = 1. |
| After a withdrawal | At that edge canceled = 1 and the retained client is released. priority_state does not move. A fresh choice starts in the next cycle. |
| Reset | reset is synchronous and active high. While it is 1 the offer is idle. Its edge accepts nothing, sets priority_state to 0 and releases the retained client. |
| Receipts | accepted and accepted_client describe the transfer at the last edge. accepted_client is 0xff when there was none. Reset clears both, and canceled stays 0. |
| Lock registers | locked and locked_client show the retained client. With none, locked = 0 and locked_client = 0xff. |
Each sample() call describes one edge. Check the old state against your model first. Then predict the edge, check the offer and receipts, and update your model. Check the new state last.
| Bit | Field | Compares |
|---|---|---|
| 0 | PREP | priority_state before the edge |
| 1 | PRELOCK | locked before the edge |
| 2 | PREOWNER | locked_client before the edge |
| 3 | VALID | valid of the offer |
| 4 | GRANT | the whole grant bitmap |
| 5 | WINNER | winner of the offer |
| 6 | ACCEPT | accepted after the edge |
| 7 | CLIENT | accepted_client after the edge |
| 8 | CANCEL | canceled after the edge |
| 9 | POSTP | priority_state after the edge |
| 10 | POSTLOCK | locked after the edge |
| 11 | POSTOWNER | locked_client after the edge |
Your model follows the rules, never the hardware. It must not copy the pointer or the lock from the pins, even after a mismatch. Keep checking after errors and through resets.
| Report item | Meaning |
|---|---|
| FIRST | The first mismatch, as FIELD@cycle:expected>actual with both values in 8 hex digits. Within one edge, the lowest bit wins. OK when there is none. |
| MASK | All field bits that ever failed, in 3 hex digits. |
| BAD | The number of edges with at least one mismatch. |
| A | Transfers your model predicts. |
| SEEN | Edges where the accepted pin was 1. |
| MATCH | Predicted transfers where the pin was 1 and accepted_client was right. |
| OPEN | Retained clients started: the first stalled edge of a fresh offer. A transfer with no stall opens nothing. |
| RET | Retained clients that ended in a transfer. |
| WITHDRAW | Retained clients that ended by withdrawal. |
| RESET_CANCEL | Retained clients that ended by reset. |
| RESETS | Reset edges. |
| P | Your predicted priority_state after the last edge. |
| OWNER | Your predicted retained client in 2 hex digits, or ff. |
The report joins the items with |, as FIRST=OK|MASK=000|... in the order above. Every retained client ends exactly once, so OPEN = RET + WITHDRAW + RESET_CANCEL, plus 1 if one is still retained.
| Faulty arbiter | What is wrong |
|---|---|
| 1 | It makes a fresh choice even while a client is retained. |
| 2 | The pointer moves on a stalled offer. |
| 3 | It keeps offering a retained client that has withdrawn. |
| 4 | It never retains a stalled offer. |
| 5 | The pointer wraps to 1 instead of 0, so client 0 is skipped. With N = 1 it behaves correctly. |
| 6 | The retained client survives reset. |
| 7 | grant also has a bit for every other client that asks. |
| 8 | The old receipt survives reset. |
Inputs are steady 1 ns before each rising edge. The tests read the offer and the old state just before the edge. They read the receipts and the new state 1 ns after it.
N is 1, 2, 3, 5 or 8. The tests do not tell the checker which arbiter it is watching.
PREFIX=<edges where report() was wrong>|<your final report>|TRACE=<the arbiter trace>
The result compares this line with the expected text, character by character. It shows both lengths and whether the two lines match. On a mismatch the log prints your line.
Examples
Example 1
A New Request Cannot Steal the Offer- Input
N = 3, priority 0, correct arbiter. Edge 0: client 2 stalls. Edge 1: clients 0 and 2 ask. Edge 2: only client 0 asks. Then transfers, stalls and two resets.
- Output
your_line_length = 1613, expected_line_length = 1613, lines_match = yes
Client 2 stays offered when client 0 arrives. When client 2 withdraws, edge 2 is idle and canceled = 1. Client 0 transfers on edge 3. The report is clean: OPEN=3, RET=1, WITHDRAW=1, RESET_CANCEL=1.
Example 2
A Stolen Offer Shows Before Any Count Changes- Input
The same traffic with faulty arbiter 1, which makes a fresh choice while a client is retained
- Output
your_line_length = 1636, expected_line_length = 1636, lines_match = yes
On edge 1 the arbiter offers client 0 instead of client 2. The first mismatch is GRANT@1:00000004>00000001, because VALID agrees. Later edges add WINNER and lock mismatches.
Example 3
A Withdrawn Client Is Still Offered- Input
The same traffic with faulty arbiter 3, which keeps offering a withdrawn client
- Output
your_line_length = 1636, expected_line_length = 1636, lines_match = yes
On edge 2 client 2 has withdrawn, so no offer is expected. The arbiter still shows valid = 1. The first mismatch is VALID@2:00000000>00000001.
Constraints and Contract
- Predict from your own model. Use the pointer and lock pins only for comparison.
- A reset ends a retained client before any transfer or withdrawal is counted.
- Keep the class name, the method names and the argument types.
Hints
Hint 1
Keep the retained client in your own model. It is set on the first stalled edge and cleared by a transfer, a withdrawal or a reset.
Hint 2
When a client is retained, the expected offer is that client if it still asks, and no offer if it has withdrawn. Only an empty model makes a fresh choice.
Hint 3
Look at how sample() picks the expected winner. It always scans the requests and never checks owner first.
What the grader checks: The checker watches real retained-offer arbiters with N = 1, 2, 3, 5 and 8: one correct and eight with distinct faults. Every report after every edge is compared. The traces are 32 edges long, so this is strong evidence but not a proof.
93 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