Q190FreeSystemVerilog
Detect a starving arbiter requester
Interview prompt
Question
Add a watchdog that flags any port that remains continuously asserted but ungranted for more than K sampled cycles.
Candidate starting point
Implementation scaffold
class StarvationWatchdog #(int N = 8);
local longint unsigned wait_count[N];
local bit starving[N];
local bit starvation_alert;
local int threshold;
function new(int threshold);
if (N <= 0 || threshold < 0) $fatal(1, "invalid watchdog");
this.threshold = threshold;
foreach (wait_count[i]) begin
wait_count[i] = 0;
starving[i] = 0;
end
starvation_alert = 0;
endfunction
function void sample(int grant_idx, bit [N-1:0] reqs);
// Implement here: sample.
endfunction
function bit port_starving(int port);
// Implement here: port_starving.
endfunction
function bit any_starving();
// Implement here: any_starving.
endfunction
endclassReviewed example
Trace one case
Input
K=2; port 1 requests without a grant on sampled cycles 0, 1 and 2, then wins on cycle 3Expected output
wait counts = 1, 2, 3 with starvation asserted after cycle 2; cycle 3 clears count and flagContinuous ungranted assertion increments through cycles with no winner, and an accepted grant resets that port's watchdog state.
What to cover
Requirements
- Maintain a wait count and starvation flag per port.
- Increment a port only while it requests and does not receive the accepted grant.
- Clear a port's state when it wins or stops requesting.
- Set a global alert when any per-port count exceeds K.
- Count asserted requesters during cycles in which there is no grant.
- Expose both per-port status and the global alert.
