Vous êtes sur la page 1sur 31

Creating Stimulus and

Stimulating Creativity:
Using the VMM Scenario Generator
Jonathan Bromley
Doulos Ltd, Ringwood, UK
jonathan.bromley@doulos.com

Outline
Introduction: motivation for scenarios
The VMM Standard Library scenario generator
Motivation for hierarchical scenarios
Prototype VMM-compatible hierarchical scenarios
Further opportunities and future work
Summary

VMM testbench architecture


...
test_env env = new;
env.run();
...

Constraints;
directed tests

Focus of our attention:


the stimulus generator

Generator

Self Check

High level
transactions
Atomic
transactions

Checker

Monitor

Transactor

Driver

Properties

DUT

Checker

Monitor

Functional
Coverage

Motivation for scenarios


VMM transactions can be randomized
custom constraints

Realistic DUTs need structured sequences of


stimulus
Stream of independently randomized transactions will not
exercise interesting DUT behaviors

Scenarios provide this


and offer a natural way to express complex stimulus

Outline
Introduction: motivation for scenarios
The VMM Standard Library scenario generator
Motivation for hierarchical scenarios
Prototype VMM-compatible hierarchical scenarios
Further opportunities and future work
Summary

The VMM Scenario Generator


Part of VMM Standard Library
Most of the work is done for you automatically
by macro `vmm_scenario_gen()

Multiple levels of customization are possible


Simple example on the next few slides
Fuller description in section 3 of the printed paper

Scenario Generator Macro


class
class XYZ_data
XYZ_data extends
extends vmm_data;
vmm_data;
...
...
endclass
endclass :: XYZ_data
XYZ_data
`vmm_channel(XYZ_data)
`vmm_channel(XYZ_data)
`vmm_atomic_gen(XYZ_data,
`vmm_atomic_gen(XYZ_data, "XYZ
"XYZ atomic")
atomic")
`vmm_scenario_gen(XYZ_data,
`vmm_scenario_gen(XYZ_data, "XYZ
"XYZ scenario")
scenario")
base for your scenarios
predefined simple scenario
scenario chooser
generator (transactor)

Creates...

class
class XYZ_data_scenario
XYZ_data_scenario
class
class XYZ_data_atomic_scenario
XYZ_data_atomic_scenario
class
class XYZ_data_scenario_election
XYZ_data_scenario_election
class
class XYZ_data_scenario_gen
XYZ_data_scenario_gen

Scenario Generator Operation


Verification
Verification environment
environment
Scenario generator
scenario_set
[0] atomic
select_scenario
select

burst
items

[1] burst
[2] RMW

copies of items
generator's output channel

Downstream transactor

The Scenario Set


within scenario-generator class

Set of scenarios available for selection


data_class_scenario
data_class_scenario scenario_set[$];
scenario_set[$];

SystemVerilog queue

By default, contains just one atomic scenario object


Create instances of your own scenarios, add them to this queue
It's an array of factory objects

By default, scenario selector class chooses scenarios in cyclic order


Make the choice random:
gen.select_scenario.round_robin.constraint_mode(0);
gen.select_scenario.round_robin.constraint_mode(0);
your scenario generator instance

10

What's in a Scenario?
rand
rand data_class
data_class items[$];
items[$];

Array of transaction objects

You apply constraints to the items[] array (in a derived class):


class
class apb_RMW_scenario
apb_RMW_scenario extends
extends apb_data_scenario;
apb_data_scenario;
...
...
constraint
constraint read_modify_write
read_modify_write {{
desired number of entries in items[]
length
length ==
== 2;
2;
items[0].kind
items[0].kind ==
== apb_data::READ;
apb_data::READ;
items[1].kind
items[1].kind ==
== apb_data::WRITE;
apb_data::WRITE;
items[0].address
items[0].address ==
== items[1].address;
items[1].address;
}}

Generator chooses a scenario from scenario_set, then randomizes it

11

Multiple Scenarios in One Subclass


rand
rand int
int unsigned
unsigned scenario_kind;
scenario_kind;

choice within any subclass

scenario kind identifiers


int
int APB_RMW,
APB_RMW, APB_BURST;
APB_BURST;
constraint
constraint read_modify_write
read_modify_write {{
if
if (scenario_kind
(scenario_kind ==
== APB_RMW)
APB_RMW) {{
length
length ==
== 2;
2;
...
...
}}
randomized property of base class
}}
constraint
constraint burst
burst {{
if
if (scenario_kind
(scenario_kind ==
== APB_BURST)
APB_BURST) {{
length
length inside
inside {{ 2,
2, 4,
4, 8,
8, 16
16 };
};
...
...
}}
How do we set up the kind-identifiers?
}}

12

Creating Scenario Identifiers


Identifier values created by scenario's constructor
function
function new();
new();
super.new();
super.new();
APB_RMW
APB_RMW == define_scenario("APB
define_scenario("APB R-M-W",
R-M-W", 2);
2);
APB_BURST
APB_BURST == define_scenario("APB
define_scenario("APB burst",
burst", 16);
16);
endfunction
endfunction
Establishes set of possible
values for scenario_kind

Largest length each


scenario can take

Unique named values automatically maintained,


even if there are intermediate derived classes
Low cost - scenario is constructed only once per generator
You MUST define at least one scenario kind

13

The apply Method


After the scenario has been randomized, its items are
ready for delivery to the output channel
Generator calls scenario's apply method to do this
Default implementation (paraphrase):
virtual
virtual task
task apply
apply ((
apb_data_channel
apb_data_channel channel,
channel,
ref
ref int
int unsigned
unsigned n_insts);
n_insts);
foreach
foreach (items[i])
(items[i])
channel.put(items[i].copy());
channel.put(items[i].copy());
n_insts
n_insts == items[i].size();
items[i].size();
endtask
endtask

reference to generator's
output channel
allows generator to
count transactions

Override apply to create procedural scenarios

14

Outline
Introduction: motivation for scenarios
The VMM Standard Library scenario generator
Motivation for hierarchical scenarios
Prototype VMM-compatible hierarchical scenarios
Further opportunities and future work
Summary

15

Motivation for hierarchical scenarios


Compose scenarios from existing scenarios
Saves coding effort
Facilitates re-use

Naturally express nested activities:


layered protocols
instruction streams
high-level usage patterns

16

Outline
Introduction: motivation for scenarios
The VMM Standard Library scenario generator
Motivation for hierarchical scenarios
Prototype VMM-compatible hierarchical scenarios
Further opportunities and future work
Summary

17

Scenario Generator Operation


(review)
Verification
Verification environment
environment
Scenario generator
scenario_set
[0] atomic
select_scenario
select

burst
items

[1] burst
[2] RMW

copies of items
generator's output channel

Downstream transactor

18

Hierarchical Scenario
Verification
Verification environment
environment
Scenario generator
scenario_set

burst
items

[0] atomic
select_scenario
select

[1] burst
[2] RMW
[3]

burst8RMW0

burst8-RMW0
child

RMW
items
9
10

Downstream transactor

19

Problems to solve
Hierarchical scenario must do most things that
the generator currently does...
choose a scenario
randomize it
deliver its items to the output channel

Randomization may need additional constraints


Awkward to write additional derived classes
Need inline constraints like randomize...with {...}

Allow for multiple levels of scenario hierarchy

20

Structuring a solution
Hierarchical scenario must do most things that
the generator currently does...
choose a scenario

use the generator's scenario selector

randomize it
deliver its items to the output channel

this.randomize
this.apply

perform method of hierarchical scenario


base class
apply method may choose/perform child scenario(s)

Outline apply Method of


Hierarchical Scenario
For each sub-scenario:
ask generator to choose from its scenario_set
ask the chosen sub-scenario to perform itself
class
class apb_multi_scenario
apb_multi_scenario extends
extends apb_data_HS;
apb_data_HS;
...
...
randomized property
virtual
virtual task
task apply
apply (...);
(...);
of this scenario?
apb_data_HS
apb_data_HS child;
child;
repeat
repeat (number_of_scenarios)
(number_of_scenarios) begin
begin
customize choice
child
child == parent_generator.choose(...);
parent_generator.choose(...);
child.perform(...);
child.perform(...);
customize randomization
n_insts++;
n_insts++;
end
end
class
class apb_data_HS
apb_data_HS extends
extends apb_data_scenario;
apb_data_scenario;
endtask
endtask
apb_data_HS_gen
apb_data_HS_gen parent_generator;
parent_generator;
...
function
...
function new
new (apb_data_HS_gen
(apb_data_HS_gen pg);
pg);
super.new();
endclass
super.new();
endclass

parent_generator
parent_generator == pg;
pg;
endfunction
endfunction
scenario has reference to its generator
...
...

21

22

The perform Method


With no constrainer, mimics generator's behavior
With a constrainer, custom randomization is easy to achieve
class
class apb_data_HS
apb_data_HS extends
extends apb_data_scenario;
apb_data_scenario;
...
...
users don't need to override this
virtual
virtual task
task perform
perform (( method in a derived scenario
apb_data_channel
apb_data_channel channel,
channel,
ref
ref int
int unsigned
unsigned n_insts,
n_insts,
apb_data_HS_constrainer
apb_data_HS_constrainer cc == null
null );
);
if
if (c
(c ==
== null)
null)
strategy class to customize
this.randomize();
this.randomize();
randomization
else
else
c.do_randomize(
c.do_randomize( this
this );
);
this.apply(
this.apply( channel,
channel, n_insts
n_insts );
);
endtask
endtask

23

Custom constrainer
Provides a convenient way to do randomize() with {...}
class
class apb_burst8
apb_burst8 extends
extends apb_data_HS_constrainer;
apb_data_HS_constrainer;
virtual
virtual function
function void
void do_randomize(
do_randomize( apb_data_scenario
apb_data_scenario it
it );
);
apb_RMW_burst_scenario
apb_RMW_burst_scenario s;
s;
assert
assert (( $cast(s,
$cast(s, it)
it) )) else
else $error("Bad
$error("Bad constrainer");
constrainer");
s.randomize()
s.randomize() with
with {{
Only one function to override!
scenario_kind
scenario_kind ==
== APB_BURST;
APB_BURST;
length
length ==
== 8;
8;
virtual
virtual task
task perform
perform ((
);
);
apb_data_channel
apb_data_channel channel,
channel,
endfunction
endfunction
ref
ref int
int unsigned
unsigned n_insts,
n_insts,
endclass
endclass
apb_data_HS_constrainer
apb_data_HS_constrainer cc == null
null );
);
if
if (c
(c ==
== null)
null)
this.randomize();
this.randomize();
scenario
else
else
c.do_randomize(
c.do_randomize( this
this );
);
this.apply(
this.apply( channel,
channel, n_insts
n_insts );
);
endtask
endtask

24

Choosing a Scenario
Expose generator's choice mechanism
scenario calls this to choose a child scenario
class
class apb_data_HS_gen
apb_data_HS_gen extends
extends apb_data_scenario_gen;
apb_data_scenario_gen;
virtual
virtual function
function apb_data_scenario
apb_data_scenario choose
choose allows user control of
(( apb_data_HS_chooser
choice strategy
apb_data_HS_chooser cc == null
null );
);
if
if (c
(c ==
== null)
null)
default: same as
this.select_scenario.randomize();
this.select_scenario.randomize(); standard generator
else
else
chooser class
c.choose(this.select_scenario);
c.choose(this.select_scenario);
customizes choice
return
return this.scenario_set[this.select_scenario.select];
this.scenario_set[this.select_scenario.select];
endfunction
endfunction
return a reference to chosen
member of scenario set
...
...
endclass
endclass

25

A Simple User-written Scenario


An 8-word burst write followed by a read-modify-write to address 0
virtual
virtual task
task apply
apply ((
apb_data_channel
apb_data_channel channel
channel ,,
ref
ref int
int unsigned
unsigned n_insts
n_insts );
);
choose a suitable scenario
special_chooser
special_chooser ch
ch == new;
new;
apb_burst_W8_constrainer
apb_burst_W8_constrainer c_w8
c_w8 == new;
new;
apb_RMW_addr0_constrainer
apb_RMW_addr0_constrainer c_rmw0
c_rmw0 == new;
new;
apb_data_HS
apb_data_HS child
child == parent_generator.choose(ch);
parent_generator.choose(ch);
child.perform(channel,
child.perform(channel, n_insts,
n_insts, c_w8);
c_w8);
randomize and apply
child.perform(channel,
child.perform(channel, n_insts,
n_insts, c_rmw0);
c_rmw0); randomize and apply
endtask
endtask

custom constraints

26

Outline
Introduction: motivation for scenarios
The VMM Standard Library scenario generator
Motivation for hierarchical scenarios
Prototype VMM-compatible hierarchical scenarios
Further opportunities and future work
Summary

27

Future work
Better integration with existing VMM infrastructure
Notifications, callbacks, logging

Macros for convenience


low overhead on top of existing VMM scenarios

Re-entrancy
define scenarios in terms of themselves with different
constraints

Debug and visibility

28

Further possibilities
Co-ordinated parallel scenarios
Each scenario can now choose to which channel
it sends its sub-scenarios (argument to perform)
A scenario can generate multiple scenarios in parallel
virtual
virtual task
task apply
apply (...);
(...);
...
...
apb_data_HS
apb_data_HS s_main
s_main == parent_generator.choose(...);
parent_generator.choose(...);
apb_data_HS
apb_data_HS s_intrpt
s_intrpt == parent_generator.choose(...);
parent_generator.choose(...);
fork
fork
s_main.perform(main_gen.out_chan,
s_main.perform(main_gen.out_chan, ...);
...);
s_intrpt.perform(irq_gen.out_chan,
s_intrpt.perform(irq_gen.out_chan, ...);
...);
join
join
endtask
endtask

29

Outline
Introduction: motivation for scenarios
The VMM Standard Library scenario generator
Motivation for hierarchical scenarios
Prototype VMM-compatible hierarchical scenarios
Further opportunities and future work
Summary

30

Summary
Standard VMM scenarios are easy to use
but customization can be laborious

Hierarchical scenario generator is possible


useful results from our prototype
more work required to integrate fully with VMM
some known limitations (not re-entrant)

Planning for extensibility and re-use is challenging


but inescapable

Thanks for your attention!


Questions?
Jonathan Bromley
Doulos Ltd, Ringwood, UK
jonathan.bromley@doulos.com

Vous aimerez peut-être aussi