Q172FreeDesign Verification
MSI Cache-Coherence Directory Scoreboard
Interview prompt
Question
Track a sparse cache directory using the Modified, Shared, Invalid (MSI) protocol. Requests, snoops, invalidation acknowledgements, evictions, and data responses may appear on different interfaces. CPU_READ/WRITE start one serialized transaction per line. DATA_RSP names the receiving requester; writes provide a strictly increasing committed version and reads return the latest version (initially 0). EVICT removes a cached copy and writes back any Modified data, preserving memory version history. Transaction IDs are not reused while stale responses remain possible.
Candidate starting point
Implementation scaffold
typedef enum {CPU_READ, CPU_WRITE, SNOOP_INV, INV_ACK,
DATA_RSP, EVICT} coh_event_e;
class MsiDirectory #(int AGENTS = 8);
typedef enum { STABLE, READ_DATA, WRITE_INV } transient_e;
typedef struct {
bit [AGENTS-1:0] sharers;
int owner; // -1 means no Modified owner
int latest_version;
transient_e transient;
int txn_id;
int requester;
bit [AGENTS-1:0] pending_acks;
bit [AGENTS-1:0] snoops_seen;
bit response_seen;
int response_version;
} line_state_t;
line_state_t lines[longint unsigned];
int unsigned errors;
function void fail(string message);
errors++;
$error("MSI directory: %s", message);
endfunction
function void finish_write(ref line_state_t s);
// TODO: commit a write only after valid data and every required ack.
endfunction
function void observe(coh_event_e evt, int agent, longint line_addr,
int txn_id, int data_version);
// TODO: check the event and update the per-line directory state.
endfunction
function int error_count(); return errors; endfunction
endclass
Reviewed example
Trace one case
Input
line X initially I/I
core0 Read X
core1 Read X
core0 Write XExpected output
directory states: S/I -> S/S -> M/I, with an invalidation sent to core1 before core0 writesThe scoreboard tracks sharers and enforces the single-writer invariant during the S-to-M transition.
What to cover
Requirements
- At most one agent may own a line in Modified state.
- Modified ownership implies that no other agent remains a Shared holder.
- Represent transient states while invalidations or data transfers are outstanding.
- Count required acknowledgements and reject duplicate, stale, or unexpected responses.
- Track a data version so the next reader receives the most recent completed write.
