H3.2 Round-Robin Grant Sequence

MediumFixVerilator · serverReview the topic

Fix a round-robin arbiter whose priority pointer moves on a stalled offer, so a client loses its turn.

Hardware context: Round-robin arbiter with accepted-grant priority updates. Update priority only when a hardware grant is accepted.

A round-robin arbiter should give every client a turn. This one skipped clients whenever the bus stalled. Its pointer moved on at each offer, even when nothing was transferred.

The module rr_pointer_core offers one client at a time. It picks the first requesting client in circular order, starting at priority_state. The client transfers on a rising edge where ready = 1. The pointer must then move to the client after the winner.

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 pointer. After it they read the receipts and the new pointer. Every value is checked.

Find the bug and fix it.

Signals in the Timeline

SignalWidthRole
clients4input of each check
initial_priority4input of each check
Full specification
The ports (keep them)
module rr_pointer_core #(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 int       priority_state);
  // your arbiter
endmodule
RuleWhat the arbiter does
ClientsN is 1, 2, 3, 5 or 8. Clients are 0 to N - 1. Request bits at N and above are ignored.
OfferScan the clients in circular order from priority_state. The first one that requests is offered: valid = 1, winner = its number, grant = its one-hot bit.
No offerWith no request, and while reset or clear is 1, valid = 0, winner = 0xff and grant = 0.
TransferA transfer happens at an edge with valid = 1 and ready = 1. priority_state becomes winner + 1, wrapping to 0 after N - 1.
No transferpriority_state holds. This covers idle edges and stalls, where valid = 1 and ready = 0.
ReceiptsAfter each edge, accepted = 1 only if that edge transferred. accepted_client is the winner then, and 0xff otherwise.
clearA test-only input that wins over everything. It loads initial_priority and clears the receipts.
resetSynchronous and active high. It sets priority_state to 0 and clears the receipts. Nothing transfers on a reset edge.

This arbiter does not keep a stalled offer. If the requests change during a stall, the offer may change too. Only the pointer must not move.

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>|TRACE=<one record per edge>
record: cycle:<reset><ready>:<requests hex>:P<old pointer>:V<valid>:G<grant hex>:I<winner hex>:A<accepted>/<client hex>:P<new pointer>;

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

The Pointer Follows the Real Winner
Input
N = 3, initial_priority = 2. Edges 0 to 4: requests 0x05 stalled, 0x05, 0x05, none, 0x02. Then idle.
Output
your_line_length = 1028, expected_line_length = 1028, lines_match = yes

Client 2 is offered on edge 0 but stalled, so the pointer stays at 2. Client 2 transfers on edge 1 and the pointer goes to 0. Client 0 then moves it to 1. Client 1 moves it to 2. That is 3 transfers.

Example 2

A New Request During a Stall
Input
N = 5, initial_priority = 4. Edges 0 to 5: 0x02 stalled, 0x10 stalled, 0x03, 0x1f, reset, 0x1f. Then idle.
Output
your_line_length = 1028, expected_line_length = 1028, lines_match = yes

The two stalled offers are client 1, then client 4. The pointer stays at 4. Clients 0 and 1 transfer next. Reset sets the pointer to 0, and client 0 then transfers. That is 3 transfers, ending at 1.

Example 3

One Client Still Needs the Rules
Input
N = 1. Edges 0 to 5: 0xff, 0xfe, 0x01 stalled, 0x01, reset with 0x01, 0x01. Then idle.
Output
your_line_length = 1028, expected_line_length = 1028, lines_match = yes

Only client 0 exists. It transfers on edges 0, 3 and 5. Edge 1 has only unused bits set. Edge 2 is a stall, and edge 4 is a reset. The pointer always wraps to 0.

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

An offer is not a transfer. Which signal tells you that the client was really served?

Hint 2

Trace a stall by hand: N = 3, requests = 0b101, ready = 0. Client 2 is offered. Where should the pointer be after the edge?

Hint 3

Look at the condition on the priority_state update. It moves on valid alone, but it should also need ready.

What the grader checks: Five copies with N = 1, 2, 3, 5 and 8 run real 32-edge traces with stalls, gaps and resets. The offer, receipts and pointer are checked on every edge. This problem has no retained offer; Grant Changes Under Stall adds that.

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

The Pointer Follows the Real Winner

Input
N = 3, initial_priority = 2. Edges 0 to 4: requests 0x05 stalled, 0x05, 0x05, none, 0x02. Then idle.
Expected output
your_line_length = 1028, expected_line_length = 1028, lines_match = yes

Client 2 is offered on edge 0 but stalled, so the pointer stays at 2. Client 2 transfers on edge 1 and the pointer goes to 0. Client 0 then moves it to 1. Client 1 moves it to 2. That is 3 transfers.

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

Verilator · server