Q216FreeSystemVerilog
Predict weighted round-robin grants
Interview prompt
Question
Extend the arbiter so port i has configurable weight W[i] and may receive up to that many consecutive grants before priority moves to the next active requester.
Starting point
Question code
class WRRPredictor #(int N = 8);
function void set_weights(int values[N]);
function int predict_next(bit [N-1:0] reqs);
function void update_state(int grant_idx, bit [N-1:0] reqs);
function void reset();
endclassReviewed example
Trace one case
Input
weights=[2,1,3]; all three requesters remain asserted for six accepted grantsExpected output
grant sequence=[0,0,1,2,2,2]Each port consumes its complete positive epoch before service rotates, exactly matching the configured weights.
What to cover
Requirements
- Require a positive effective weight for every port.
- Track the current priority port and its remaining grants in the current epoch.
- Skip inactive requesters and return -1 when all requests are inactive.
- Begin a fresh weight epoch when service moves to another port.
- Consume one unit only after an accepted grant.
- Define weight reconfiguration as starting a fresh epoch at the current priority.

