Protected Course Page
Enter the password to view Day 23 of the UVM 30-Day plan.
Day 23: Multi-Agent Environments — Composition, Coordination, Cross-Domain Scoreboards
A 30-day SystemVerilog/UVM verification series. Two agents is a testbench. Three agents is an environment. Four is a real DUT. Today is the layering that makes that scale.
Real DUTs do not have one interface. They have a bus, a clock, a reset, and usually more than one of those. A CPU sees an APB for its registers and an AXI-Lite for its memory. A sensor hub has a slow interface for configuration and a fast one for streaming. Every one of those interfaces has its own agent, and every agent has its own driver, monitor, and sequencer. The environment has to coordinate them.
This is where most testbenches fail to scale. Two agents work. Three agents expose a missing layer. Four agents fall apart. The fix is not "more code" — it is understanding what the env owns, what the agents own, and where the coordination boundaries are.
1. What Changes When You Add a Third Agent
With two agents (write and read of a FIFO), the coordination was easy: the virtual sequence started a write sequence on one agent, then a read sequence on the other. The env had one scoreboard that connected two analysis ports.
With three or four agents, the questions multiply:
- Which scoreboard compares against which agent? A cross-domain scoreboard compares transactions from different agents. A per-domain scoreboard compares within one agent.
- Does the virtual sequence need to coordinate all of them? Sometimes yes (a memory-mapped access that requires the address agent, the data agent, and the response agent to move in sequence). Sometimes no (each agent runs its own sequences independently).
- Do the agents share a reset? Usually yes. One agent asserting reset for itself while others keep running is a common source of "the test passes sometimes."
The env is where these questions get answered. The agents know only their own interface.
2. The Env Composition Pattern
A common structure for a DUT with an APB register bus and an AXI-Lite memory bus:
class dut_env extends uvm_env;
`uvm_component_utils(dut_env)
apb_agent apb_agent_inst;
axi_agent axi_agent_inst;
ref_model ref_model_inst;
register_scoreboard reg_sb;
memory_scoreboard mem_sb;
dut_vseqr vseqr;
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
apb_agent_inst = apb_agent::type_id::create("apb_agent_inst", this);
axi_agent_inst = axi_agent::type_id::create("axi_agent_inst", this);
ref_model_inst = ref_model::type_id::create("ref_model_inst", this);
reg_sb = register_scoreboard::type_id::create("reg_sb", this);
mem_sb = memory_scoreboard::type_id::create("mem_sb", this);
vseqr = dut_vseqr::type_id::create("vseqr", this);
endfunction
virtual function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
// Observation: each agent's monitor feeds its domain's consumers
apb_agent_inst.mon.ap.connect(reg_sb.apb_export);
apb_agent_inst.mon.ap.connect(ref_model_inst.apb_imp);
axi_agent_inst.mon.ap.connect(mem_sb.axi_export);
// Cross-domain: the reference model predicts AXI traffic from APB activity
ref_model_inst.axi_ap.connect(mem_sb.expected_export);
// Virtual sequencer handles
if (apb_agent_inst.get_is_active() == UVM_ACTIVE)
vseqr.apb_sqr = apb_agent_inst.sqr;
if (axi_agent_inst.get_is_active() == UVM_ACTIVE)
vseqr.axi_sqr = axi_agent_inst.sqr;
endfunction
endclass
Notice the two distinct scoreboards and the reference model between them:
- reg_sb — checks that APB register accesses behave correctly. It needs only the APB monitor.
- ref_model — watches APB register writes and predicts what AXI memory traffic they should produce (e.g., a config write triggers a memory fetch at a specific address).
- mem_sb — checks that AXI memory traffic matches what the reference model predicted.
This is modular decomposition. Each scoreboard has exactly one job and one source of expectations. It is the only structure that scales to a real DUT.
3. Cross-Domain Scoreboards
A cross-domain scoreboard compares transactions from two different agents. There are two ways to build one:
Pattern A: direct comparison
The scoreboard receives the transaction from each side and compares them in order or by transaction ID:
class cross_domain_scoreboard extends uvm_scoreboard;
`uvm_analysis_imp_decl(_src)
`uvm_analysis_imp_decl(_dst)
uvm_analysis_imp_src #(src_item, cross_domain_scoreboard) src_export;
uvm_analysis_imp_dst #(dst_item, cross_domain_scoreboard) dst_export;
src_item expected [$];
int mismatches;
function void write_src(src_item tr);
expected.push_back(tr); // the source produces expected
endfunction
function void write_dst(dst_item tr);
src_item e;
if (expected.size() == 0) begin
`uvm_error("XSB", "unexpected dst transaction")
return;
end
e = expected.pop_front();
if (tr.data !== e.expected_data) begin
mismatches++;
`uvm_error("XSB", $sformatf("mismatch: exp %0h got %0h",
e.expected_data, tr.data))
end
endfunction
endclass
This is what Day 9's advanced scoreboard was. It works when the two streams are strictly ordered.
Pattern B: reference model + comparator
Split the responsibility: a reference model produces the expected stream from one side, and the comparator compares the model's output to the other side. This is what the dut_env pattern above does.
Pattern B is almost always better. It is: - Testable — you can unit-test the reference model without a comparator. - Reusable — the reference model can feed a scoreboard, a coverage collector, or a second scoreboard. - Debuggable — when a mismatch occurs, you can inspect the model's expected stream separately from the comparator's output.
4. Virtual Sequencer with Three or More Agents
The virtual sequencer from Day 8 generalizes directly: add a handle per active agent.
class dut_vseqr extends uvm_sequencer;
`uvm_component_utils(dut_vseqr)
apb_sequencer apb_sqr;
axi_sequencer axi_sqr;
// ... more if needed ...
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
endclass
The virtual sequence coordinates them:
class dut_memory_access_seq extends uvm_sequence;
`uvm_object_utils(dut_memory_access_seq)
`uvm_declare_p_sequencer(dut_vseqr)
apb_write_seq apb_wr;
axi_read_seq axi_rd;
virtual task body();
// 1. Configure the memory controller via APB
apb_wr = apb_write_seq::type_id::create("apb_wr");
apb_wr.addr = 'h10;
apb_wr.data = 'h1000;
apb_wr.start(p_sequencer.apb_sqr);
// 2. Trigger a fetch via APB (write to a control register)
apb_wr = apb_write_seq::type_id::create("apb_wr");
apb_wr.addr = 'h00;
apb_wr.data = 'h01; // START bit
apb_wr.start(p_sequencer.apb_sqr);
// 3. Read the fetched data via AXI
axi_rd = axi_read_seq::type_id::create("axi_rd");
axi_rd.addr = 'h1000;
axi_rd.start(p_sequencer.axi_sqr);
endtask
endclass
Three things worth highlighting:
- Each sub-sequence starts on its agent's sequencer. The virtual sequence never drives pins directly.
- Null checks are still required. If the AXI agent is passive,
axi_sqris null and the read must be skipped (or the whole sequence must be skipped). - The order matters. APB configure, then APB trigger, then AXI read. A virtual sequence is what guarantees that order.
5. Reset Coordination
When the DUT resets, every agent must reset — drivers must release their pins, monitors must flush their in-flight transactions, sequencers must stop delivering items, and scoreboards must clear their expected queues. If any one of those misses, the testbench's view of the DUT diverges and every subsequent comparison fails.
The mechanism is a shared uvm_event (Day 11) or a reset sequence in the virtual sequencer. The event is the cleaner of the two:
// In the env's build_phase:
uvm_event#() reset_event = new("reset_event");
uvm_config_db#(uvm_event#())::set(this, "*", "reset_event", reset_event);
// In each driver's run_phase, at the top:
uvm_event#() reset_ev;
if (!uvm_config_db#(uvm_event#())::get(this, "", "reset_event", reset_ev))
`uvm_fatal("NOEV", "no reset_event")
forever begin
fork
// Normal driver work
begin
seq_item_port.get_next_item(req);
// ... drive pins ...
seq_item_port.item_done();
end
// Reset watcher
begin
reset_ev.wait_trigger();
// Abort the current transaction
`uvm_info("DRV", "reset seen — aborting transaction", UVM_LOW)
disable fork;
end
join_any
disable fork;
end
Every driver that shares the reset waits on the same event. When the reset fires, all of them abort in the same delta cycle, and every monitor / scoreboard / predictor flushes on the same event. This is the only pattern that produces a deterministic reset behaviour across a multi-agent environment.
6. What Day 24 Will Add
Tomorrow: Regression and Automation. You have a multi-agent environment. Now you have to run it hundreds of times per night, parse the results, and know whether the DUT got better or worse since yesterday. Tomorrow covers Makefiles, plusarg-driven test selection, log parsing, and the pass/fail infrastructure that lets you sleep through a regression.
7. Quiz
Ten questions on multi-agent composition, cross-domain scoreboards, and reset coordination.
Coming Up Next: Day 24 — Regression and Automation
- Makefile structure — test selection, seed control, coverage merging, log parsing.
- Plusargs —
+UVM_TESTNAME,+ntb_random_seed, and custom plusargs for test knobs. - Log parsing — the UVM report summary and how to make it the pass/fail criterion.
- Regression dashboard — the numbers that tell you whether today was better than yesterday.
Series: 30 days of SystemVerilog/UVM verification. Day 23's multi-agent patterns.
No comments:
Post a Comment