Virtual Sequencers
Build a clean coordination layer that gives virtual sequences controlled access to multiple protocol sequencers.
Learning objectives
- Explain the architectural purpose of a virtual sequencer.
- Distinguish a virtual sequencer from a protocol sequencer and a virtual sequence.
- Declare typed handles to multiple agent sequencers.
- Connect agent sequencers to a virtual sequencer in
connect_phase. - Use
uvm_declare_p_sequencerto access the virtual sequencer from a virtual sequence. - Recognize why a virtual sequencer normally does not generate protocol transactions itself.
- Validate the complete virtual-sequencer path before adding complex synchronization.
Step 1: Understand the architectural problem
A virtual sequence can coordinate several interfaces, but it needs references to the real sequencers that control those interfaces.
Consider a DUT with three agents:
DUT
|
+----------+----------+
| | |
v v v
Control DMA Interrupt
Agent Agent Agent
| | |
v v v
bus_seqr dma_seqr irq_seqr
A system-level scenario might need all three:
virtual sequence
/ | \
v v v
bus_seqr dma_seqr irq_seqr
The virtual sequence therefore needs a clean way to access those sequencers. A virtual sequencer provides that coordination point.
Step 2: Three concepts that must not be confused
These three objects have different responsibilities.
| Object | Main responsibility |
|---|---|
| Protocol sequencer | Arbitrates sequences that generate transaction items for one protocol. |
| Virtual sequence | Defines a higher-level scenario and coordinates child sequences. |
| Virtual sequencer | Provides organized handles to multiple protocol sequencers. |
Think of the architecture as:
Virtual Sequence
|
v
Virtual Sequencer
/ |
v v v
bus_seqr dma_seqr irq_seqr
| | |
v v v
bus_drv dma_drv irq_drv
The virtual sequencer is infrastructure. The virtual sequence contains the scenario intent.
Step 3: Why not put the sequencer handles directly in the test?
A small testbench can technically pass several sequencer handles directly to a virtual sequence. However, as the environment grows, this quickly becomes difficult to manage.
Without a virtual sequencer:
test
|
+---- bus_seqr
|
+---- dma_seqr
|
+---- irq_seqr
|
+---- spi_seqr
|
+---- memory_seqr
The test increasingly becomes responsible for understanding the internal structure of the environment.
With a virtual sequencer:
test
|
v
virtual_seq
|
v
virtual_seqr
/ | |
v v v v
bus dma irq spi
The test starts a high-level sequence. The virtual sequence accesses the coordination infrastructure. The environment remains responsible for wiring its agents together.
Step 4: Declare the virtual sequencer
A virtual sequencer can be implemented as a UVM sequencer that contains handles to the real protocol sequencers.
class system_virtual_sequencer extends uvm_sequencer;
`uvm_component_utils(system_virtual_sequencer)
bus_sequencer bus_seqr;
dma_sequencer dma_seqr;
irq_sequencer irq_seqr;
function new(
string name,
uvm_component parent
);
super.new(name, parent);
endfunction
endclass
Notice that the virtual sequencer does not contain a driver and does not contain a protocol interface.
Its important state is the collection of sequencer handles:
bus_seqr
dma_seqr
irq_seqr Step 5: Understand the type of each handle
The handles should normally use the actual sequencer types:
bus_sequencer bus_seqr;
dma_sequencer dma_seqr;
irq_sequencer irq_seqr;
This is preferable to using only generic handles when the virtual sequence needs protocol-specific access or when strong type checking improves clarity.
The type relationship is:
bus_agent
|
+--> bus_sequencer
^
|
handle stored in
|
v
system_virtual_sequencer
The virtual sequencer does not instantiate another bus sequencer. It stores a handle to the sequencer already owned by the bus agent.
Step 6: Instantiate the virtual sequencer
The environment creates the virtual sequencer during build_phase.
class system_env extends uvm_env;
`uvm_component_utils(system_env)
bus_agent bus_agent;
dma_agent dma_agent;
irq_agent irq_agent;
system_virtual_sequencer virtual_seqr;
function new(
string name,
uvm_component parent
);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
bus_agent = bus_agent::type_id::create(
"bus_agent", this
);
dma_agent = dma_agent::type_id::create(
"dma_agent", this
);
irq_agent = irq_agent::type_id::create(
"irq_agent", this
);
virtual_seqr = system_virtual_sequencer::type_id::create(
"virtual_seqr", this
);
endfunction
endclass
At the end of build_phase, the components exist, but the virtual
sequencer's handles have not necessarily been connected yet.
Step 7: Connect the real sequencers
The actual agent sequencers are connected to the virtual sequencer in
connect_phase.
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
virtual_seqr.bus_seqr =
bus_agent.sequencer;
virtual_seqr.dma_seqr =
dma_agent.sequencer;
virtual_seqr.irq_seqr =
irq_agent.sequencer;
endfunction
This creates the handle relationships:
virtual_seqr.bus_seqr ---> bus_agent.sequencer
virtual_seqr.dma_seqr ---> dma_agent.sequencer
virtual_seqr.irq_seqr ---> irq_agent.sequencer
connect_phase?
The agent components and their sequencers are constructed during the build
phase. The connection phase is the natural place to connect handles between
already-created components.
Step 8: Give the virtual sequence typed access
The virtual sequence can declare the expected sequencer type with
uvm_declare_p_sequencer.
class system_virtual_seq extends uvm_sequence;
`uvm_object_utils(system_virtual_seq)
`uvm_declare_p_sequencer(system_virtual_sequencer)
function new(string name = "system_virtual_seq");
super.new(name);
endfunction
task body();
// Virtual-sequencer handles are available
// through p_sequencer.
endtask
endclass
The important relationship is:
system_virtual_seq
|
| p_sequencer
v
system_virtual_sequencer
|
+---- bus_seqr
+---- dma_seqr
+---- irq_seqr
This gives the virtual sequence a clean path to the protocol sequencers it needs.
Step 9: Start child sequences through the virtual sequencer
Now the virtual sequence can start reusable child sequences on the appropriate protocol sequencers.
task body();
configure_seq cfg_seq;
dma_traffic_seq dma_seq;
cfg_seq = configure_seq::type_id::create("cfg_seq");
dma_seq = dma_traffic_seq::type_id::create("dma_seq");
cfg_seq.start(p_sequencer.bus_seqr);
dma_seq.start(p_sequencer.dma_seqr);
endtask
Trace the complete path:
system_virtual_seq
|
| cfg_seq.start(...)
v
virtual_seqr.bus_seqr
|
v
bus_agent.sequencer
|
v
bus_driver
|
v
DUT
The virtual sequencer is therefore a routing point for sequence access, not a new protocol execution layer.
Step 10: Understand the complete hierarchy
A typical multi-agent environment now looks like this:
uvm_test
|
v
system_env
|
+-------------------+
| |
v v
agents virtual_seqr
| |
+-- bus_agent +--> bus_seqr
| +--> dma_seqr
+-- dma_agent +--> irq_seqr
| |
+-- irq_agent |
^
|
virtual sequence
Each object has a distinct responsibility:
- Test: selects the verification scenario.
- Environment: owns and connects the verification components.
- Agent: encapsulates one protocol interface.
- Protocol sequencer: arbitrates protocol sequences.
- Virtual sequencer: stores handles to protocol sequencers.
- Virtual sequence: coordinates the system-level scenario.
Step 11: Virtual sequencer versus virtual sequence
This distinction is one of the most important concepts in this lesson.
| Virtual sequencer | Virtual sequence |
|---|---|
| UVM component. | UVM object/sequence. |
| Lives in the component hierarchy. | Runs as stimulus. |
| Created by the environment. | Usually created/started by a test or another sequence. |
| Stores sequencer handles. | Uses those handles to start child sequences. |
| Does not normally define the scenario. | Defines the scenario. |
Step 12: Do not create a virtual sequencer for every test
The virtual sequencer belongs to the reusable environment architecture. It should not normally be recreated for every individual test scenario.
Instead:
system_env
|
+--> virtual_seqr
|
+--> bus_seqr
+--> dma_seqr
+--> irq_seqr
^
|
many virtual
sequences
Multiple tests can use different virtual sequences against the same environment.
smoke_virtual_seq
stress_virtual_seq
error_virtual_seq
reset_virtual_seq
performance_virtual_seq
|
v
same virtual_seqr
This is a major reuse advantage: the environment topology remains stable while the stimulus scenario changes.
Step 13: Handle optional agents carefully
Not every environment configuration necessarily contains every agent. If an agent can be disabled, the virtual-sequencer connection must account for that configuration.
if (dma_agent != null) begin
virtual_seqr.dma_seqr = dma_agent.sequencer;
end
More importantly, the virtual sequence should not blindly assume a handle is valid.
if (p_sequencer.dma_seqr == null)
`uvm_fatal("VSEQ",
"DMA sequencer is not connected")
Fail early with a useful message rather than allowing a null-handle failure much later in the scenario.
Step 14: Validate the connection before debugging the scenario
A surprisingly common debugging problem is starting with a complex virtual sequence before proving that the sequencer handles are connected.
Add a simple connectivity check:
function void end_of_elaboration_phase(uvm_phase phase);
super.end_of_elaboration_phase(phase);
if (virtual_seqr.bus_seqr == null)
`uvm_fatal("VSEQ_CONN",
"bus_seqr is not connected")
if (virtual_seqr.dma_seqr == null)
`uvm_fatal("VSEQ_CONN",
"dma_seqr is not connected")
if (virtual_seqr.irq_seqr == null)
`uvm_fatal("VSEQ_CONN",
"irq_seqr is not connected")
endfunction
This converts an obscure runtime failure into an immediate architectural diagnosis.
Step 15: A complete minimal implementation
Put the pieces together.
Virtual sequencer
class system_virtual_sequencer extends uvm_sequencer;
`uvm_component_utils(system_virtual_sequencer)
bus_sequencer bus_seqr;
dma_sequencer dma_seqr;
function new(
string name,
uvm_component parent
);
super.new(name, parent);
endfunction
endclass
Environment construction and connection
function void build_phase(uvm_phase phase);
super.build_phase(phase);
bus_agent = bus_agent::type_id::create("bus_agent", this);
dma_agent = dma_agent::type_id::create("dma_agent", this);
virtual_seqr =
system_virtual_sequencer::type_id::create(
"virtual_seqr", this
);
endfunction
function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
virtual_seqr.bus_seqr =
bus_agent.sequencer;
virtual_seqr.dma_seqr =
dma_agent.sequencer;
endfunction
Virtual sequence
class system_virtual_seq extends uvm_sequence;
`uvm_object_utils(system_virtual_seq)
`uvm_declare_p_sequencer(system_virtual_sequencer)
function new(string name = "system_virtual_seq");
super.new(name);
endfunction
task body();
configure_seq cfg_seq;
dma_traffic_seq dma_seq;
cfg_seq =
configure_seq::type_id::create("cfg_seq");
dma_seq =
dma_traffic_seq::type_id::create("dma_seq");
cfg_seq.start(p_sequencer.bus_seqr);
dma_seq.start(p_sequencer.dma_seqr);
endtask
endclass
This is the basic virtual-sequencer architecture you should be comfortable reading before moving into more advanced synchronization.
Step 16: Understand what the virtual sequencer does not do
It is useful to define the boundaries explicitly.
The virtual sequencer does not normally:
- drive DUT signals,
- sample DUT interfaces,
- implement a protocol,
- replace an agent sequencer,
- contain the scoreboard,
- decide what constitutes a passing transaction.
It does:
- provide access to multiple protocol sequencers,
- centralize the handles needed by virtual sequences,
- represent part of the environment's stimulus topology,
- help decouple system-level sequences from the environment's internal wiring.
Step 17: Common virtual-sequencer mistakes
connect_phase.
Creating the virtual sequencer does not automatically populate its handles.
Step 18: Debugging checklist
If a virtual sequence fails, inspect the architecture in this order:
- Was the virtual sequencer created?
- Was the required agent created?
- Was the agent's protocol sequencer created?
- Was the handle assigned in
connect_phase? - Is
p_sequencerpointing to the expected virtual sequencer? - Is the child sequence compatible with the target sequencer?
- Does the child sequence run correctly by itself?
- Only then investigate scenario ordering or synchronization.
Virtual sequence
|
| p_sequencer
v
Virtual sequencer
|
| handle
v
Real sequencer
|
v
Driver
|
v
DUT
Debugging becomes much easier when you trace this path one layer at a time.
Try it yourself
Build a virtual-sequencer architecture for a DUT with:
- an AXI-like control agent,
- a DMA agent, and
- an interrupt agent.
Create:
system_virtual_sequencerwith three typed sequencer handles.- A system environment that creates the virtual sequencer.
- A
connect_phasethat connects all three handles. - A virtual sequence using
uvm_declare_p_sequencer. - A configuration child sequence running on the control sequencer.
- A DMA child sequence running on the DMA sequencer.
- An interrupt child sequence running on the interrupt sequencer.
First run the child sequences independently. Then run them through the virtual sequence.
Challenge: Intentionally break one sequencer connection. Add a connectivity check that reports exactly which handle is missing.
Architecture challenge: Explain why the virtual sequencer should contain handles to the agent sequencers instead of creating new sequencers of its own.
Verification checkpoint
Before moving to synchronization, you should be able to answer these questions without looking at the code:
- What problem does a virtual sequencer solve?
- What is the difference between a virtual sequence and a virtual sequencer?
- Who owns the real protocol sequencer?
- Why are sequencer handles connected in
connect_phase? - What does
uvm_declare_p_sequencerprovide? - Why should a virtual sequencer normally not contain protocol-generation logic?
- How can you prove that the virtual-sequencer infrastructure is correctly connected?
- Why is infrastructure validation useful before debugging sequence synchronization?
p_sequencer, through the virtual sequencer and real
sequencer, to the driver—you are not ready to debug a multi-agent virtual
sequence.
Key takeaways
- A virtual sequencer is primarily a coordination structure that holds handles to multiple protocol sequencers.
- The virtual sequence contains system-level stimulus intent; the virtual sequencer provides the infrastructure needed to execute that intent.
- Real protocol sequencers remain owned by their respective agents.
- The environment creates the virtual sequencer and connects its handles to the agent sequencers.
-
uvm_declare_p_sequencergives a virtual sequence convenient, typed access to the virtual sequencer. - A virtual sequencer should not become a second driver, protocol engine, or scenario container.
- Validate sequencer connectivity before debugging complex multi-agent synchronization.
- A clean virtual-sequencer architecture creates the foundation for the next step: deterministic synchronization between independently running sequences.