course advanced uvm session5 the proper care and feeding of sequences tfitzpatrick

27
[email protected] | www.verificationacademy.com Advanced UVM The Proper Care and Feeding of Sequences Tom Fitzpatrick Verification Evangelist

Upload: srigovindaduttadas

Post on 10-Jul-2016

232 views

Category:

Documents


8 download

DESCRIPTION

Advanced Uvm Session5

TRANSCRIPT

Page 1: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

[email protected] | www.verificationacademy.com

Advanced UVM The Proper Care and Feeding of Sequences

Tom Fitzpatrick

Verification Evangelist

Page 2: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Separating Stimulus from the Testbench • A key to reusability is to separate Behavior from Structure

VIP Testbench

DUT

Configuration & Factory

Behavior Structure

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 3: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Review: Sequences • Decouple stimulus specification from

structural hierarchy • Add/remove/modify stimulus scenarios independent of testbench • Simplify test writer API

• Sequences define transaction streams • May start on any sequencer

• Sequences can call children • Sequences & transactions customizable

via the factory

u1 u1

u1

s5

s1

s4

s3 s2

s1

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 4: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Create request Initiate Driver Handshake

Send transaction

Late Randomization

Note: begin-end around `uvm_<msg>

Transaction type

Review: Sequence Basics

© 2013 Mentor Graphics Corporation, all rights reserved.

class my_seq extends uvm_sequence #(req_t); `uvm_object_utils(uvm_seq) req_t req; int num = 10;

function new(string name = “my_seq”); super.new(name); endfunction

task body(); uvm_config_db#(int)::get(this, “”, “num”, num); req = req_t::type_id::create(“req”); for_int i = 0; i < num; i++) begin start_item(req); if(!req.randomize()) begin `uvm_error(“body”, “rand failure”) end finish_item(req); end endtask endclass

Default name in constructor

Page 5: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Review: Sequence/r/Driver Parameterization

© 2013 Mentor Graphics Corporation, all rights reserved.

class my_seq extends uvm_sequence #(type REQ=req_t, RSP=rsp_t); `uvm_object_utils(my_seq) … endclass class my_driver extends uvm_driver #(type REQ=req_t, RSP=rsp_t); `uvm_component_utils(my_driver) … endclass typedef uvm_sequencer #(type REQ=req_t, RSP=rsp_t) my_sequencer;

By default, RSP=REQ

Parameterization must match sequence

Don’t need to declare a new sequencer type

Page 6: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Review: Sequence/Driver Handshake

© 2013 Mentor Graphics Corporation, all rights reserved.

task body(); req = req_t::type_id::create(“req”); for_int i = 0; i < num; i++) begin start_item(req); if(!req.randomize()) begin `uvm_error(“body”, “rand failure”) end finish_item(req); `uvm_info(“my_seq1”,req.convert2string()); end endtask

my_seq1 driver get_next_item(req); start_item(req);

finish_item(req); item_done();

task run_phase(uvm_phase phase); forever begin seq_item_port.get_next_item(req); drive_item2bus(req); seq_item_port.item_done(); end endtask

If driver updates req with response information

Page 7: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Review: Sequence/Driver Handshake

© 2013 Mentor Graphics Corporation, all rights reserved.

task body(); req = req_t::type_id::create(“req”); for_int i = 0; i < num; i++) begin start_item(req); if(!req.randomize()) begin `uvm_error(“body”, “rand failure”) end finish_item(req); get_response(rsp); end endtask

my_seq1 driver get_next_item(req); start_item(req);

finish_item(req); item_done();

task run_phase(uvm_phase phase); forever begin seq_item_port.get_next_item(req); drive_item2bus(req,rsp); seq_item_port.item_done(); rsp.set_id_info(req); seq_item_port.put_response(rsp); end endtask

get_response(rsp); put_response(rsp);

If driver provides separate response object

Page 8: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Arbitration and Responses in the Sequencer

© 2013 Mentor Graphics Corporation, all rights reserved.

Sequencer

class myseq…; virtual task body(); … finish_item(req) get_response(rsp); endtask endclass

class myseq…; virtual task body(); … finish_item(req) get_response(rsp,id); endtask endclass

Driver

s1

s2

arbitrate requests

route responses

class req; seq_id = trans_id =

class req; seq_id = 1; trans_id = 1;

2,1

class req; seq_id = trans_id =

class req; seq_id = 2; trans_id = 1;

class driver…; task run(); … rsp.set_id_info(req); seq_item_port.put_response(rsp); endtask endclass

1,1 rsp seq_id = trans_id =

1,1

rsp seq_id = 1; trans_id = 1;

rsp seq_id = 1; trans_id = 1;

Sequence-specific

Unique within sequence

Both sequences now waiting for responses

set_id_info() copies id fields from req to rsp

Sequencer uses sequence_id to route response to originating sequence

Page 9: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Arbitration and Responses in the Sequencer

© 2013 Mentor Graphics Corporation, all rights reserved.

class myseq…; virtual task body(); use_response_handler(1); finish_item(req) get_response(rsp,id); endtask virtual function void response_handler(uvm_sequence_item response); … endfunction endclass

Customize the response handler as necessary

sequencer.set_arbitration(SEQ_ARB_USER); class my_sequencer extends uvm_sequencer(REQ); ‘uvm_component_utils(my_sequencer) virtual function integer user_priority_arbitration(integer avail_sequences[$]); … endfunction endclass

SEQ_ARB_FIFO SEQ_ARB_WEIGHTED SEQ_ARB_RANDOM SEQ_ARB_STRICT_FIFO SEQ_ARB_STRICT_RANDOM SEQ_ARB_USER

Page 10: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Review: Starting a Sequence

class test1 extends uvm_test; `uvm_component_utils(test1) my_env my_env_h; ... task run_phase(uvm_phase phase); read_modify_write seq; seq = read_modify_write::type_id::create(“seq”);

Create sequence via factory

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 11: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Review: Starting a Sequence

class test1 extends uvm_test; `uvm_component_utils(test1) my_env my_env_h; ... task run_phase(uvm_phase phase); read_modify_write seq; seq = read_modify_write::type_id::create(“seq”); phase.raise_objection(this); seq.start( my_env_h.my_agent_h.my_sequencer_h );

Always use start() to execute a sequence

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 12: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Review: Starting a Sequence

class test1 extends uvm_test; `uvm_component_utils(test1) my_env my_env_h; ... task run_phase(uvm_phase phase); read_modify_write seq; seq = read_modify_write::type_id::create(“seq”); phase.raise_objection(this); seq.start( my_env_h.my_agent_h.my_sequencer_h );

Path to sequencer

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 13: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Can Start Sequence from Environment too

class my_env extends uvm_env; `uvm_component_utils(my_env) my_agent my_agent_h; ... task run_phase(uvm_phase phase); read_modify_write seq; seq = read_modify_write::type_id::create(“seq”); phase.raise_objection(this); seq.start( my_agent_h.my_sequencer_h ); phase.drop_objection(this); endtask

Factory enables test to choose what default

sequence to run

Path to sequencer

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 14: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class my_test extends uvm_test; … init_seq iseq; exec_seq eseq; ... task run_phase(uvm_phase phase); iseq = init_seq::type_id::create(“iseq”); eseq = exec_seq::type_id::create(“eseq”); phase.raise_objection(this); iseq.start( my_env_h.my_agent_h.my_sequencer_h ); eseq.start( my_env_h.my_agent_h.my_sequencer_h ); … phase.drop_objection(this); endtask endclass

Sequential Sequences

init_seq

exec_seq

start() is blocking

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 15: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class my_test extends uvm_test; … init_seq iseq; exec_seq eseq; ... task run_phase(uvm_phase phase); iseq = init_seq::type_id::create(“iseq”); eseq = exec_seq::type_id::create(“eseq”); phase.raise_objection(this); fork iseq.start( my_env_h.my_agent_h.my_sequencer_h ); eseq.start( my_env.h.my_agent_h.my_sequencer_h ); join … phase.drop_objection(this); endtask endclass

Parallel Sequences

init_seq exec_seq

Don’t use fork-join_none

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 16: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class my_test extends uvm_test; … init_seq iseq; exec_seq eseq; ... task run_phase(uvm_phase phase); iseq = init_seq::type_id::create(“iseq”); eseq = exec_seq::type_id::create(“eseq”); phase.raise_objection(this); fork iseq.start( my_agent_h.my_sequencer_h, this, HIGH ); eseq.start( my_agent_h.my_sequencer_h, this, LOW ); join … phase.drop_objection(this); endtask endclass

Parallel Sequences

init_seq exec_seq

Optional priority

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 17: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Hierarchical Sequences

init_seq

exec_seq

test_seq

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 18: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class test_seq extends uvm_sequence #(req,rsp); `uvm_object_utils(test_seq) init_seq iseq; exec_seq eseq; task body(); iseq = init_seq::type_id::create(“iseq”); … endtask endclass

Hierarchical Sequences

init_seq test_seq

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 19: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class test_seq extends uvm_sequence #(req,rsp); `uvm_object_utils(test_seq) init_seq iseq; exec_seq eseq; task body(); iseq = init_seq::type_id::create(“iseq”); iseq.start( m_sequencer, this ); … endtask endclass

Hierarchical Sequences

init_seq test_seq

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 20: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class test_seq extends uvm_sequence #(req,rsp); `uvm_object_utils(test_seq) init_seq iseq; exec_seq eseq; task body(); iseq = init_seq::type_id::create(“iseq”); iseq.start( m_sequencer, this ); … endtask endclass

Hierarchical Sequences

init_seq test_seq

Run on test_seq’s sequencer

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 21: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class test_seq extends uvm_sequence #(req,rsp); `uvm_object_utils(test_seq) init_seq iseq; exec_seq eseq; task body(); iseq = init_seq::type_id::create(“iseq”); iseq.start( m_sequencer, this ); … endtask endclass

Hierarchical Sequences

init_seq test_seq

Optional parent sequence specifier

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 22: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class test_seq extends uvm_sequence #(req,rsp); `uvm_object_utils(test_seq) init_seq iseq; exec_seq eseq; task body(); iseq = init_seq::type_id::create(“iseq”); eseq = exec_seq::type_id::create(“eseq”); iseq.start( m_sequencer, this ); … endtask endclass

Hierarchical Sequences

init_seq

exec_seq

test_seq

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 23: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

class test_seq extends uvm_sequence #(req,rsp); `uvm_object_utils(test_seq) init_seq iseq; exec_seq eseq; task body(); iseq = init_seq::type_id::create(“iseq”); eseq = exec_seq::type_id::create(“eseq”); iseq.start( m_sequencer, this ); eseq.start( m_sequencer, this ); … endtask endclass

Hierarchical Sequences

init_seq

exec_seq

test_seq

“top.env.agent.sequencer.test_seq.eseq”

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 24: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Pipelined Driver

© 2013 Mentor Graphics Corporation, all rights reserved.

class mbus_pipelined_driver extends uvm_driver #(mbus_seq_item); `uvm_component_utils(mbus_pipelined_driver) virtual mbus_if MBUS; function new(string name = "mbus_pipelined_driver", uvm_component parent = null); super.new(name, parent); endfunction task run_phase(uvm_phase phase); @(posedge MBUS.MRESETN); @(posedge MBUS.MCLK); fork do_pipelined_transfer; do_pipelined_transfer; join endtask task do_pipelined_transfer; endtask endclass

Page 25: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Pipelined Driver

© 2013 Mentor Graphics Corporation, all rights reserved.

class mbus_pipelined_driver extends uvm_driver #(mbus_seq_item); `uvm_component_utils(mbus_pipelined_driver) virtual mbus_if MBUS; task do_pipelined_transfer; mbus_seq_item req,rsp; forever begin pipeline_lock.get(); seq_item_port.get(req); do_command_phase(req); pipeline_lock.put(); do_data_phase(req,rsp); seq_item_port.put(rsp); end endtask endclass

Page 26: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

Summary: General Rules • Make sure to parameterize sequence/sequencer/driver with

the same request and response types • Start sequences using seq.start(sequencer) • Use seq_item_port.get_next_item/item_done in the driver

• Use try_next_item/item_done if driver must perform idle cycles • Use get/put for pipelined drivers

• Use uvm_config_db#()::get() to configure sequences • Sequence and Driver must agree on response path, if any

© 2013 Mentor Graphics Corporation, all rights reserved.

Page 27: Course Advanced Uvm Session5 the Proper Care and Feeding of Sequences Tfitzpatrick

[email protected] | www.verificationacademy.com

Advanced UVM The Proper Care and Feeding of Sequences

Tom Fitzpatrick

Verification Evangelist