Q182FreeSystemVerilog
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.
Starting point
Question code
class StarvationWatchdog #(int N = 8);
function void sample(int grant_idx, bit [N-1:0] reqs);
function bit port_starving(int port);
function bit any_starving();
endclassReviewed example
Trace one case
Input
K=2; port1 requests without a grant on sampled cycles0,1,2, then wins on cycle3Expected output
wait counts=1,2,3 with starvation asserted after cycle2; cycle3 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.

