Virtual Sequences
Coordinate reusable sequences across multiple sequencers to model realistic system-level scenarios without coupling protocol details into the test.
Learning objectives
- Explain why virtual sequences are needed in multi-agent UVM environments.
- Distinguish a virtual sequence from a normal protocol sequence.
- Understand how a virtual sequence accesses multiple sequencers.
- Start child sequences on different sequencers from a virtual sequence.
- Coordinate sequential and parallel stimulus using
fork...join. - Recognize when a virtual sequencer is useful and when it is unnecessary.
- Validate cross-interface behavior using observable verification evidence.
Step 1: Understand the problem virtual sequences solve
In the previous lessons, sequences were primarily responsible for generating transactions for one protocol interface.
Real systems rarely have only one interface. A verification scenario may need to coordinate:
- CPU or control-bus traffic
- DMA traffic
- interrupt activity
- memory traffic
- configuration transactions
- reset or power-management activity
Each interface can have its own agent and sequencer:
Test
|
v
Virtual Sequence
/ | \
/ | \
v v v
bus_seqr dma_seqr irq_seqr
| | |
v v v
bus drv dma drv irq drv
| | |
+---------+---------+
|
DUT
The virtual sequence provides the coordination layer. It decides when each interface should act, while the child sequences decide how each protocol operation is performed.
Step 2: Virtual sequence versus normal sequence
A normal sequence usually targets one sequencer and produces sequence items for one protocol.
bus_write_seq
|
v
bus_sequencer
|
v
bus_driver
|
v
bus interface
A virtual sequence instead coordinates other sequences:
virtual_seq
|
+----> bus_write_seq -> bus_sequencer
|
+----> dma_seq -> dma_sequencer
|
+----> irq_seq -> irq_sequencer
The virtual sequence therefore operates at a higher level of abstraction.
| Normal sequence | Virtual sequence |
|---|---|
| Generates protocol-specific stimulus. | Coordinates multiple stimulus streams. |
| Usually targets one sequencer. | May control multiple sequencers. |
| Understands protocol details. | Should mainly understand scenario relationships. |
| Produces sequence items. | Usually starts child sequences that produce sequence items. |
Step 3: Build a simple virtual sequence
Assume the environment contains two independent sequencers:
bus_seqr
dma_seqr
We want a scenario that first configures the DUT and then starts DMA traffic.
The reusable protocol sequences already exist:
configure_seq
dma_traffic_seq
The virtual sequence can coordinate them:
class system_virtual_seq extends uvm_sequence;
`uvm_object_utils(system_virtual_seq)
uvm_sequencer_base bus_seqr;
uvm_sequencer_base dma_seqr;
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");
cfg_seq.start(bus_seqr);
dma_seq = dma_traffic_seq::type_id::create("dma_seq");
dma_seq.start(dma_seqr);
endtask
endclass
Notice the architecture:
system_virtual_seq
|
+--> configure_seq.start(bus_seqr)
|
+--> dma_traffic_seq.start(dma_seqr)
The virtual sequence does not manually create bus or DMA sequence items. It delegates that work to reusable child sequences.
Step 4: Understand sequencer handles
The virtual sequence needs references to the sequencers on which its child sequences will run.
Conceptually:
virtual sequence
|
+---- bus_seqr
|
+---- dma_seqr
|
+---- irq_seqr
These are handles, not copies of the sequencers. The virtual sequence is telling each child sequence which existing sequencer should arbitrate its sequence items.
Step 5: Use a virtual sequencer to organize access
As the number of interfaces increases, passing individual sequencer handles everywhere becomes difficult. A virtual sequencer can provide a central collection of handles.
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
The architecture becomes:
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 does not itself drive protocol signals. Its primary purpose is to provide organized access to the real sequencers.
Step 6: Connect the virtual sequencer
The environment should connect the virtual sequencer's handles to the actual agent sequencers.
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
The ownership relationship is important:
- The agent owns its protocol sequencer.
- The virtual sequencer stores handles to those sequencers.
- The virtual sequence accesses those handles.
- The child sequences generate the protocol-specific transactions.
Step 7: Use p_sequencer
UVM provides a convenient mechanism for a sequence to access a specific sequencer type.
class system_virtual_seq
extends uvm_sequence;
`uvm_object_utils(system_virtual_seq)
`uvm_declare_p_sequencer(system_virtual_sequencer)
task body();
configure_seq cfg_seq;
dma_traffic_seq dma_seq;
cfg_seq = configure_seq::type_id::create("cfg_seq");
cfg_seq.start(p_sequencer.bus_seqr);
dma_seq = dma_traffic_seq::type_id::create("dma_seq");
dma_seq.start(p_sequencer.dma_seqr);
endtask
endclass
Now the virtual sequence has a strongly typed reference to the virtual sequencer.
Step 8: Coordinate parallel stimulus
One of the main reasons to use a virtual sequence is to create realistic concurrent activity.
Suppose DMA traffic and interrupt activity should occur at the same time:
task body();
dma_traffic_seq dma_seq;
irq_seq irq_seq;
dma_seq = dma_traffic_seq::type_id::create("dma_seq");
irq_seq = irq_seq::type_id::create("irq_seq");
fork
dma_seq.start(p_sequencer.dma_seqr);
irq_seq.start(p_sequencer.irq_seqr);
join
endtask
The fork...join causes both child sequences to execute concurrently
from the virtual sequence's point of view.
The parent virtual sequence continues after both child sequences complete.
virtual sequence
|
fork
/ \
v v
DMA IRQ
\ /
\ /
join
|
v
continue scenario
Step 9: Understand ordered versus parallel coordination
A virtual sequence should explicitly express the relationship between activities.
Ordered:
configure
|
v
start DMA
|
v
wait for DMA
|
v
check status
SystemVerilog implementation:
cfg_seq.start(p_sequencer.bus_seqr);
dma_seq.start(p_sequencer.dma_seqr);
status_seq.start(p_sequencer.bus_seqr);
Parallel:
+--> DMA traffic --+
| |
start -------+ +----> continue
| |
+--> IRQ traffic --+
SystemVerilog implementation:
fork
dma_seq.start(p_sequencer.dma_seqr);
irq_seq.start(p_sequencer.irq_seqr);
join
Choosing between these structures is a verification requirement, not merely a coding preference.
Step 10: Do not put protocol logic in the virtual sequence
A common beginner mistake is to make the virtual sequence perform low-level protocol work itself.
Avoid code such as:
// Poor abstraction
task body();
bus_item req;
req = bus_item::type_id::create("req");
start_item(req);
req.addr = 'h100;
req.data = 'h55;
finish_item(req);
// More protocol-specific implementation...
endtask
Instead, delegate protocol behavior:
// Better abstraction
task body();
configure_seq cfg_seq;
dma_traffic_seq dma_seq;
cfg_seq.start(p_sequencer.bus_seqr);
dma_seq.start(p_sequencer.dma_seqr);
endtask
This keeps the virtual sequence focused on system-level intent.
Step 11: A realistic multi-agent scenario
Imagine a DUT with a control bus, DMA interface, and interrupt interface. The verification requirement is:
- Configure the DUT.
- Start DMA traffic.
- Generate an interrupt while DMA is active.
- Wait until both activities complete.
- Read status registers.
The virtual sequence expresses the scenario:
task body();
configure_seq cfg_seq;
dma_traffic_seq dma_seq;
irq_seq irq_seq;
read_status_seq status_seq;
cfg_seq = configure_seq::type_id::create("cfg_seq");
dma_seq = dma_traffic_seq::type_id::create("dma_seq");
irq_seq = irq_seq::type_id::create("irq_seq");
status_seq = read_status_seq::type_id::create("status_seq");
// 1. Configure first.
cfg_seq.start(p_sequencer.bus_seqr);
// 2-3. DMA and interrupt activity overlap.
fork
dma_seq.start(p_sequencer.dma_seqr);
irq_seq.start(p_sequencer.irq_seqr);
join
// 4-5. Both completed; inspect status.
status_seq.start(p_sequencer.bus_seqr);
endtask
This is the central value of a virtual sequence: it describes the relationship between independent stimulus streams.
Step 12: Sequence synchronization is a separate concern
Starting two sequences in parallel does not automatically mean that they interact at the exact cycle you intended.
For example:
fork
dma_seq.start(p_sequencer.dma_seqr);
irq_seq.start(p_sequencer.irq_seqr);
join
means the sequences are launched concurrently, but their internal timing still depends on the child sequences and their drivers.
If the verification requirement says:
Start DMA
|
v
wait until DMA reaches a defined point
|
v
trigger interrupt
then the virtual sequence needs an explicit synchronization mechanism.
The detailed synchronization techniques—events, barriers, objections, callbacks, and protocol-specific completion conditions—will be developed in the following lessons.
fork...join gives concurrency; it does not by itself define
protocol-level synchronization.
Step 13: Know when a virtual sequence is appropriate
Use a virtual sequence when a scenario must coordinate multiple independent stimulus sources.
| Scenario | Virtual sequence? |
|---|---|
| One bus generates a register write. | Usually no. |
| One bus generates a burst. | Usually no. |
| CPU traffic must overlap DMA traffic. | Yes. |
| DMA must run while interrupts are generated. | Yes. |
| Several interfaces must follow a defined scenario order. | Yes. |
| A single reusable protocol sequence needs different data values. | No; use configuration. |
Step 14: Common virtual-sequence mistakes
fork...join provides synchronization.
It provides concurrency and waits for the forked processes to complete.
It does not define meaningful DUT-level synchronization points.
Step 15: Build virtual sequences incrementally
- Verify each protocol agent independently.
- Verify the reusable child sequences on their individual sequencers.
- Create the virtual sequencer and connect its sequencer handles.
- Create a virtual sequence that runs one child sequence at a time.
- Add ordered multi-agent coordination.
- Add parallel activity with
fork...join. - Add explicit synchronization only where the scenario requires it.
- Use monitors and scoreboards to prove that cross-interface behavior is correct.
This progression makes failures much easier to localize. If the child sequence works independently but the system scenario fails, the problem is likely in coordination rather than basic transaction generation.
Try it yourself
Build a virtual sequence for a DUT containing a control-bus agent and a DMA agent.
- Create a
configure_seqfor the control bus. - Create a
dma_traffic_seqfor the DMA interface. - Create a virtual sequencer containing handles to both sequencers.
- Connect those handles in the environment's
connect_phase. - Create a virtual sequence using
uvm_declare_p_sequencer. - Run configuration first.
- Then start DMA traffic.
- Extend the scenario so DMA traffic and interrupt activity execute concurrently.
Challenge: Modify the scenario so that status-register reads occur only after both the DMA and interrupt sequences have completed.
Architecture challenge: Identify which code belongs in the child sequences and which code belongs in the virtual sequence. Your virtual sequence should describe what the system scenario does, not the low-level mechanics of each protocol.
Verification checkpoint
Before moving to the next lesson, make sure you can explain:
- Why can't a normal single-interface sequence solve every system-level stimulus problem?
- What is the responsibility of a virtual sequence?
- What is the responsibility of a virtual sequencer?
- Why should virtual sequences delegate protocol generation to child sequences?
- What does
fork...joinprovide when coordinating child sequences? - Why does parallel execution not automatically guarantee deterministic synchronization?
- When is a virtual sequence unnecessary?
- How can monitor and scoreboard results prove that multi-agent coordination worked?
Key takeaways
- Virtual sequences coordinate multiple independent stimulus streams at the system-scenario level.
- A virtual sequence should coordinate child sequences rather than implement low-level protocol behavior itself.
- A virtual sequencer provides organized access to the real protocol sequencers used by the child sequences.
-
p_sequencerprovides convenient, strongly typed access to the virtual sequencer. -
Sequential calls express ordering, while
fork...joincan express concurrent stimulus. - Concurrency is not the same as synchronization. Meaningful DUT-level synchronization requires explicit mechanisms and well-defined completion conditions.
- Virtual sequences are most valuable when multiple agents must participate in one verification scenario.
- Well-designed virtual sequences depend on reusable lower-level sequences, which is why the sequence-reuse patterns from the previous lesson matter.