H3.3 Grant Changes Under Stall

MediumFixVerilator · serverReview the topic

Fix an arbiter whose grant jumps to a new client while the bus is stalled.

Hardware context: Round-robin arbiter with accepted-grant priority updates. Repair a stalled grant that switches requesters before acceptance.

An arbiter feeds a bus that sometimes stalls. During a stall a higher-priority client raised its request, and the grant jumped to it. The bus saw the offer change before the first client was served.

The module retained_arbiter is a round-robin arbiter that must keep a stalled offer. Its clocked logic already records the retained client in locked and locked_client. Its offer logic has one bug. Find it and fix it.

The tests run copies with N = 1, 2, 3, 5 and 8 for 32 edges each. Before each edge they read the offer and the old state. After it they read the receipts and the new state. Every value is checked.

The rules in brief: a stalled offer is kept until it transfers, is withdrawn or is reset. Only a transfer moves the pointer. The full rules are in the specification.

Signals in the Timeline

SignalWidthRole
clients4input of each check
initial_priority4input of each check
hardware_fault4input of each check
Full specification
The ports (keep them)
module retained_arbiter #(parameter int N = 3) (
  input  bit       clk, clear, reset, ready,
  input  bit [7:0] requests,
  input  int       initial_priority,
  output bit       valid,
  output bit [7:0] grant, winner,
  output bit       accepted,
  output bit [7:0] accepted_client,
  output bit       canceled,
  output int       priority_state,
  output bit       locked,
  output bit [7:0] locked_client);
  // your arbiter
endmodule
RuleWhat the arbiter does
ClientsN is the number of clients. Clients are 0 to N - 1. Request bits at N and above are ignored.
Fresh choiceWith no retained client, scan the clients in circular order, starting at priority_state. The first one that requests is offered.
Offervalid = 1, winner = the client and grant = its one-hot bit. With no offer, valid = 0, winner = 0xff and grant = 0.
TransferA 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.
StallAt an edge with valid = 1 and ready = 0, the offered client becomes the retained client. priority_state does not move.
Retained offerWhile the retained client keeps requesting, it stays offered. Requests from other clients cannot take its place.
WithdrawalIf 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 withdrawalAt that edge canceled = 1 and the retained client is released. priority_state does not move. A fresh choice starts in the next cycle.
Resetreset 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.
Receiptsaccepted 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 registerslocked and locked_client show the retained client. With none, locked = 0 and locked_client = 0xff.

clear is a test-only input that wins over reset. It loads initial_priority, releases the retained client and clears every receipt.

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.

The line the tests compare
A=<transfers>|P=<final priority_state>|OWNER=<final locked_client hex>|TRACE=<one record per edge>
record: cycle:<reset><ready>:<requests hex>:P<old pointer>:L<old locked>/<old owner hex>:V<valid>:G<grant hex>:I<winner hex>:A<accepted>/<client hex>:C<canceled>:P<new pointer>:L<new locked>/<new owner hex>;

The result compares this line, built from your module's pins 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

Keep the Offer Through a New Arrival
Input
N = 3, priority 0. Edge 0: client 2 stalls. Edge 1: clients 0 and 2 ask, stalled. Edge 2: only client 0 asks. Edge 3: client 0, ready. Then more traffic.
Output
your_line_length = 1517, expected_line_length = 1517, lines_match = yes

The offers on edges 0 to 2 are client 2, client 2, then none. Edge 2 is the withdrawal, with canceled = 1 after it. Client 0 transfers on edge 3 and the pointer moves to 1.

Example 2

Wrap and Reset
Input
N = 5, priority 4. The same pattern, with client 4 as the first stalled client
Output
your_line_length = 1517, expected_line_length = 1517, lines_match = yes

Client 4 stays offered when client 0 arrives. Its withdrawal does not move the pointer. Later transfers move it by the normal rule, and a reset sets it to 0 and releases the retained client.

Example 3

One Client Still Stalls
Input
N = 1, priority 0. Client 0 asks on edges 0 to 10, with stalls, transfers and two resets. Then idle.
Output
your_line_length = 1517, expected_line_length = 1517, lines_match = yes

There is no rival client, but a stall still sets locked = 1. A transfer or the reset releases it. The pointer stays 0, and an idle owner is 0xff, never client 1.

Constraints and Contract

  • Use clocked state with nonblocking updates. The offer is combinational.
  • The receipt after an edge describes the offer before that edge, not the new offer after it.
  • Keep the module name, the parameter and the ports.

Hints

Hint 1

Watch edge 1 of the first example. Client 2 is retained, and client 0 starts asking. Which client does your offer show?

Hint 2

The offer logic must check the lock first. A retained client is offered if it still asks; if it has withdrawn, there is no offer at all.

Hint 3

Look at the always_comb block. It scans the requests every cycle and never reads locked or locked_client.

What the grader checks: Five copies with N = 1, 2, 3, 5 and 8 run real 32-edge traces with new arrivals, withdrawals, stalls and resets. The offer, receipts, pointer and lock are checked on every edge. Finite traces are strong evidence, not a proof.

63 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

Keep the Offer Through a New Arrival

Input
N = 3, priority 0. Edge 0: client 2 stalls. Edge 1: clients 0 and 2 ask, stalled. Edge 2: only client 0 asks. Edge 3: client 0, ready. Then more traffic.
Expected output
your_line_length = 1517, expected_line_length = 1517, lines_match = yes

The offers on edges 0 to 2 are client 2, client 2, then none. Edge 2 is the withdrawal, with canceled = 1 after it. Client 0 transfers on edge 3 and the pointer moves to 1.

Run samples executes all 3 public checks. Check all tests runs 63 checks on the server.

Verilator · server