Be A Sequence Pro To Avoid Bad Con Sequences
Be A Sequence Pro To Avoid Bad Con Sequences
Be A Sequence Pro To Avoid Bad Con Sequences
1
Introduction
UVM sequences are vital for verification success
Need Control Manage Complexity Need Reuse
• Reach scenarios • Debug constraint failures • Within a sequence library
• Find and isolate bugs • Reduce mistakes • With derivative projects
• Close coverage • Transfer knowledge • For generic VIP
2
Outline
• Introduction to sequences
• Sequence guidelines – improve control, complexity, & reuse
• Sequence execution – masters, reactive slaves, streaming data
• Verification productivity – strategies to manage features
• Portable Stimulus Considerations – how PSS impacts sequences
• Conclusion & references
3
What are UVM sequences and why do we care?
INTRODUCTION TO SEQUENCES
4
What is a Sequence?
A sequence encapsulates a scenario
5
Why Bother Using Sequences?
class access_seq extends base_seq;
rand master_enum source;
rand cmd_enum cmd;
rand bit[31:0] addr;
rand bit[31:0] data[]; Both sequences and tasks
encapsulate a scenario
Both provide
constraint legal_c{ ...}
options
task body();
... Both have procedural body
6
Why Bother Using Sequences?
class read_test extends uvm_test; class access_seq extends base_seq;
task run_phase(uvm_phase phase); rand master_enum source;
rand cmd_enum cmd;
`uvm_do_with(access_seq, rand bit[31:0] addr;
{source == PORT_A; rand bit[31:0] data[];
cmd == WRITE; start
addr == 'hA0; sequence constraint legal_c{ ...}
data == 'h55;})
... task body();
...
Adding args breaks existing code Adding options has minimal impact
8
test
configuration
constraints
virtual
sequencer
driver
vbus driver
vbus driver
i2c
agent#1 agent#2 agent
10
Sequence Layer Roles
LAYER CONSTRAINTS PRIMARY PURPOSE
Reduce complexity
TEST Test scenario Highest-level sequence
at each layer
User DUT use cases/scenarios API for test writer
TOP
Lower System requirements Scenario building blocks
Control with
User Protocol use cases Encapsulates sequencer(s) intuitive APIs
Middle Protocol operations Encapsulates basic operations
UVC
Low Low-level requirements Data formatting Sequences decoupled
and reusable
Item Enforce legality Support all possible scenarios
11
How to maximize the benefits of using sequences
SEQUENCE GUIDELINES
12
Legality Guideline
Produce legal stimulus by default
start sequence
14
Legality Guideline Without this guideline, we risk
wasting significant time!
start sequence
16
Control Knob Debug Guideline
Constrain control knobs with class constraints,
then pass results with inline constraints.
start sequence
17
Control Knob Debug Guideline
class ahb_write_burst_seq extends ahb_base_seq;
rand hburst_t hburst; Use class constraint
constraint c_hburst {
hburst inside {HBURST_SINGLE, HBURST_INCR};
}
task body(); Pass result to sequence
`uvm_do_with(ahb_seq,
ahb_seq.hwrite == HWRITE_WRITE;
ahb_seq.hburst inside {HBURST_SINGLE, HBURST_INCR};
ahb_seq.hburst == local::hburst;
start sequence
Two-Step Randomization:
class ahb_burst_seq extends ahb_base_seq;
rand hwrite_t hwrite; 1. Randomize class variables
rand hburst_t hburst;
2. Run body() to randomize
Debug randomization in isolated steps lower sequences 18
API Guideline
Minimize the number of control knobs
class ahb_master_write_seq extends ahb_base_seq;
rand int slave_num;
… Exposed control knob
protected rand int slave_id;
Hidden control knob
constraint id_c {
slave_id == p_sequencer.cfg.get_slave_id(slave_num);
}
Keep fixed and derived
virtual task body();
ahb_seq_item req;
variables in body()
`uvm_do_with(req,{req.hwrite == HWRITE_WRITE;
req.hprot3 == p_sequencer.cfg.get_hprot3();
req.haddr[31:24] == local::slave_num;
req.id == local::slave_id})
Users can’t control these
Users can’t misuse sequence
Sequences are easier to use and cause unexpected errors 19
Reuse Guideline
Make tests independent of testbench architecture
class ahb_fabric_write_seq extends base_seq;
task body();
ahb_fabric_master_write_seq master_write_seq;
`uvm_do(master_write_seq)
endtask: body Test-level sequence decoupled
from testbench architecture
start mid-level sequence
class ahb_fabric_master_write_seq extends ahb_base_seq;
...
task body();
ahb_master_write_seq ahb_master_write_seqs[string];
...
`uvm_do_on_with(ahb_master_write_seqs[b], Only mid-level sequences
p_sequencer.agent_sequencer[b], reference sequencers
{…})
24
SEQUENCE EXECUTION
25
Sequence Execution Overview
HANDLE TLM HANDLE CONNECT
VIF
I/F
SEQ ITEM
DUT
SEQ
26
Proactive Masters & Reactive Slaves
• Proactive Masters: REQ
EXPLICIT 1 PROACTIVE 2
TEST STIMULUS MASTER
DUT
3
RESP
– Test controls when sequences are executed on the UVC and timing of requests to DUT
– Stimulus blocks test flow waiting for DUT response
27
Proactive Master Operation
test or higher-level: generate sequence item drive request signals
start / do sequence & pass to driver via TLM according to protocol
on sequencer (& wait for response)
UVC ENVIRONMENT
MASTER AGENT
SVA
SEQUENCER DRIVER
1 REQ REQ
ITEM 3
VIF
INTERFACE
2
DUT
MONITOR 4 (SLAVE)
RESP
5 • coverage
VIF
• checks
TRANSACTION
SVA
SEQUENCER DRIVER
0 RESP RESP
ITEM 3
VIF
INTERFACE
2
TLM FIFO
DUT
1 REQ MONITOR (MASTER)
REQ
• coverage
VIF
4 • checks
TRANSACTION
• Key characteristics
– full control over all child sequences
– may be blocked by time-consuming sequences
– multiple virtual sequences may run at same time
(nested or parallel) on same virtual sequencer
Must target different resources
(not possible for physical sequencers) 30
Virtual Sequence VS
ENV
31
Normal Sequences
• Normal sequences use a sequence item to:
– Generate stimulus via a driver • bus transactions
• data packet
– Describe required transaction-level stimulus
• power on/reset
– Define a single finite transaction
• Key characteristics:
– Driver is not autonomous
– Fully controllable from sequences (& config) Return after complete
transaction (& response)
– Sequence handshake is blocking
– Sequence items handled consecutively
32
Proactive Master Sequence UVC ENV
class my_master_request_seq extends MASTER AGENT
uvm_sequence #(my_master_seq_item);
rand cmd_enum cmd; S D
rand bit[31:0] addr; DUT
rand bit[31:0] data[]; M
...
my_master_seq_item m_item;
...
task body();
`uvm_do_with(m_item,{
m_item.m_cmd == cmd; generate request item
m_item.m_addr == addr; based on sequence knobs
foreach (data[i]) m_item.m_data[i] == data[i];
...
})
...
33
Proactive Master Driver UVC ENV
MASTER AGENT
class my_master_driver extends uvm_driver #(my_master_seq_item);
my_master_seq_item m_item; S D
... DUT
task run_phase(...); M
...
forever begin
seq_item_port.get_next_item(m_item);
drive_item(m_item);
seq_item_port.item_done();
end standard driver-sequencer interaction
endtask
34
Reactive Slave Sequence UVC ENV
class my_slave_response_seq extends SLAVE AGENT
uvm_sequence #(my_slave_seq_item);
my_slave_seq_item m_item; S D
my_transaction m_request; call forever loop inside sequence DUT
... (sequence runs throughout phase: M
task body(); ...do not raise and drop objections!)
forever begin
p_sequencer.request_fifo.get(m_request); wait for a transaction request
case (m_request.m_direction)
(fifo.get is blocking)
READ :
`uvm_do_with(m_item,{
m_item.m_resp_kind == READ_RESPONSE;
m_item.m_delay <= get_max_delay();
m_item.m_data == get_data(m_request.m_addr);
...
}) generate response item
... based on observed request
35
Reactive Slave Driver UVC ENV
SLAVE AGENT
class my_slave_driver extends uvm_driver #(my_slave_seq_item);
my_slave_seq_item m_item; S D
... DUT
task run_phase(...); M
...
forever begin
seq_item_port.get_next_item(m_item);
drive_item(m_item);
seq_item_port.item_done();
end standard driver-sequencer interaction
endtask
37
Streaming Sequence UVC ENV
class my_ramp_seq extends uvm_sequence #(my_analog_seq_item); STREAM AGENT
rand real start;
rand real step; S D
rand time rate; random real and time control knobs DUT
... M
my_analog_seq_item m_item;
...
// constraint start inside {[0.0:0.75]};
// constraint rate inside {[1ps:100ns]};
... real and time constraints
task body();
`uvm_do_with(m_item,{ totally normal physical
m_item.m_start == start; sequence structure
m_item.m_step == step;
m_item.m_rate == rate; generate normal sequence item
}) constrained by sequence knobs
...
38
Streaming Driver UVC ENV
ANALOG
class my_analog_driver extends uvm_driver #(my_analog_seq_item); AGENT
my_analog_seq_item m_item; S D
... call item_done before drive_item DUT
task run_phase(...); to pass control back to sequencer M
...
forever begin
seq_item_port.get_next_item(m_item); blocking peek waits for new item
seq_item_port.item_done();
fork task drive_item(my_analog_seq_item item);
seq_item_port.peek(m_item); real value = item.start;
drive_item(m_item); forever begin // ramp generation
join_any vif.data = value;
disable fork; #(item.rate);
end value += item.step;
endtask ... // saturation & looping
... end
kill drive_item task when new item
endclass ... drive request pattern forever
endtask (unless new item received)
39
Constraint Strategies
Constraint Strategy Ideal Purpose
class constraints legal requirements
inline constraints scenarios
configuration objects configuration register dependencies
descriptor objects bundle sets of control knobs
policy classes [3] dynamically redefine constraints or impose
constraints that bypass many layers
40
Strategies to apply sequence API to reach project goals
VERIFICATION PRODUCTIVITY
41
How do we use our Sequence API?
• Problem: How can sequences help us reach project goals?
– Prioritize tasks and meet milestone deadlines
– Maximize chance of finding bugs
– Report status to stakeholders
Can stress any feature in isolation per test We can’t isolate every feature.
Choose strategically!
Can control mix of features per test 43
Step 2: Manage Feature Relationships
Feature Mode Description Example
FIXED Hardcode value for test (never changes) mode, number of enabled channels
DEFAULT Default design value reset values of registers
RAND Randomly changes with each simulation design configuration registers
DYNAMIC Randomly changes dynamically within a delays between transactions
simulation
MAX / MIN Absolute max or min option max/min timing, max/min input value,
max enabled channels
TYPICAL A typical setting used for common use-cases Nominal FIFO behavior
Stress FIXED, RAND FIXED, RAND illegal scenarios Easy to target corner-cases
(check DUT doesn’t hang) and use-cases
PORTABLE STIMULUS
46
What is Portable Stimulus?
• Portable Test and Stimulus Standard (PSS) [5]
“[PSS] defines a specification for creating a single representation of stimulus
and test scenarios ... enabling the generation of different implementations of a
scenario that run on a variety of execution platforms...”
seq lib
MANY HIGH-LEVEL
SCENARIO SEQUENCES
environment ”top environment DELEGATED TO PSS
sequencer env sequences”
seq lib
SOME LOW-LEVEL
UVC env UVC env SCENARIO SEQUENCES
UVC env DUPLICATED IN PSS
sequencer uvc_env ”UVC sequences”
seq lib
NO LOW-LEVEL
sequencers
driver
vbus driver
vbus driver
i2c
agent#1 agent#2 agent ALL REMAINING
SEQUENCES
USED BY PSS
51
CONCLUSION
52
Conclusion
• Apply guidelines to avoid common verification problems
– Retain control to reach scenarios
– Minimize complexity for improved efficiency and communication
– Improve reuse for future projects
• Apply sequence techniques for each situation
– Proactive masters, reactive slaves
– Streaming data sequences
• Design your sequence API to maximize project efficiency
– Risk management and prioritization of features
– Transparent status reporting
• PSS requires quality sequence APIs
53
References
1 Use the Sequence, Luke – Verilab, SNUG 2018
2 Mastering Reactive Slaves in UVM – Verilab, SNUG 2016
3 SystemVerilog Constraint Layering via
Reusable Randomization Policy Classes, John Dickol, DVCon 2015
4 Advanced UVM Tutorial – Verilab, DVCon 2014
5 Portable Test and Stimulus Standard, Version 1.0, Accellera
54
Q&A
55
The following images are licensed under CC BY 2.0
• Verdi_Requiem 008 by Penn State
• Sheet music by Trey Jones
• Flutist by operaficionado
• Cello Orchestra by Malvern St James
• Folk_am_Neckar_4915 by Ralf Schulze
• Flute by Bmeje
• Cello by Lori Griffin
56