UVM_OBJECTION

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

@shraddha_pawankar Date:31/03/2024

UVM OBJECTION

1) The objection mechanism is a powerful feature in UVM.


2) It provides proper synchronization and coordination among different components of
the testbench and object. And it is easier to manage complex verification
environment.
3) Used in Run phase(in components)
4) It remain in same phase till all the objection are dropped.

1) Uvm_objection class extends from uvm_report_object.


2) Objection deals with the concept of raise and drop objection
Which means internal counter is increment or decrement .
3) Raise and drop objection do asynchronously.
4) When all objection are dropped,the counter value will become zero.
5) Once the activities of run phase are completed the drop objection called.
6) When we start any process- raised objection
When process completed – dropped objection

1) Concept used by UVM based testbenches to figure out when specific components
functionality is completed.
2) Simulation is completed when all objections raised or dropped.
3) If a TB does not have any objections raised,simulation completed at 0 time.
4) A component raise_objection to indicate that component functionality has started.
Phase.raise_objection(this);
5) A component drops objection to indicate that functionality has completed
Phase.drop_objection(this);
6) Phase is coming from uvm_root,hence uvm_root keeps track of all objections raised
and dropped.
--------------------------------------------------------------------------------------------------------------------------
//OBJECTIONS
--------------------
1) IN COMPONENTS
 Phase.raise_objection(this);
This method tells the UVM that a test is running,UVM will stay in the
run_phase() until the test drops the objection

 Phase.drop_objection(this);
This method tells the UVM that the test has finished & that the run phase can
end

1|Page
@shraddha_pawankar Date:31/03/2024

2) IN OBJECT
 Starting_phase.raise_objection(this);
 Staring .phase.drop_objection(this);

Objection in the sequence


The objection can be raised and dropped in body task or pre_body or post_body task.

Drain time:

The amount of wait time between all objection has been dropped and calling all_dropped()
called drain time.
Set drain time :
Phase.phase_done.set_drain_time(100,1);
Even after all objections are dropped,we wait for 100 ns for simulation to finish.
Example:

If 3 components of TB raised objection,all those objections are dropped at 1200ns,if drain


time is 100ns,simulation will finish at 1300ns.

Drain time is set in the test run phase.

1) Objection can only be raised on a phase


Uvm_phase phase defined in uvm_root and passed to all components as specific
phase arguments
Phase.raise_objection(this);
Phase.drop_objection(this);

2) Components have phases


Build phase,connect phase,run_phase,main_phase,reset_phase
function void build_phase(uvm_phase phase);
function void run_phase(uvm_phase phase);

3) Objects don’t have phase,since only components can have phase.


How do we raise/drop objections?
Objects don’t have build_phase/connect_phase etc
Solution: starting_phase
Phase in which sequence will be started

How sequence will get the starting_phase value?


 It is decided by test

2|Page
@shraddha_pawankar Date:31/03/2024

 Objection gives smooth finish to the simulation.


 $finish will result in abrupt ending of the simulation,other phases will not run.

 Objections make sure that all the phases of UVM TB complete,only then
$finish get called,Hence user will see the extract ,check,report phase also
getting executed,even though drop objection is happening in run_phase.

Objection: few Scenarios

1) No objections are raised and dropped in TB?


 Simulation ends at time 0.

2) Some of the objections are never dropped in simulation?


 Simulation will hang.
 It will by default 9200sec unless user has passed UVM_TIMEOUT
argument.

3) $finish is called before all objections are dropped?


 Simulation will finish since user is manually asking to end simulation.

4) Why objections are never called in driver,monitor,scoreboard etc


 Driver has forever loop implemented.it will never complete,if any
objection raised it will never dropped.Hence it will result in simulation
hanging.

task run_phase(uvm_phase phase);


phase.raise_objection(this);
forever
begin
------
end
phase.drop_objection(this);//this line will never get executed
endtask

5) How sequence keeps track of phase.starting_phase


 calling objections in test and sequence.

3|Page
@shraddha_pawankar Date:31/03/2024

6) Where we can raise and drop objections?


 Objections are raised in components which does not have forever
functionality.
 Ex: objections cant be raised in driver,monitor,coverage,scoreboard etc
 Objections can be raised in test,sequence
 Objections raised and dropped in test run_phase
 Objections raised and dropped in sequence body task.

UVM_OBJECTION USAGE:

1. UVM phasing mechanism uses objections to coordinate with each other and
the phase should be ended when all objections are dropped. They can be
used in all UVM phases.

task run_phase(uvm_phase phase);


phase.raise_objection(this, "Raised Objection");
...
phase.drop_objection(this, "Dropped Objection");
endtask

Objections are generally used in components and sequences.

CALLBACK HOOKS:
The callback methods are defined in the uvm_objection_callback class which is derived from
the uvm_callback class.

Callback
Description
Hooks

Called when an objection is raised for this component or its derived


Raised
classes.

Called when an objection is dropped for this component or its derived


Dropped
classes.

Called when all objections are dropped for this component and its derived
all_dropped
classes.

4|Page
@shraddha_pawankar Date:31/03/2024

A OBJECTION IN THE SEQUENCE:


The objection can be raised and dropped either in body tasks or pre_body/ post_body tasks.

class base_seq extends uvm_sequence #(seq_item);


...
task pre_body();
if(starting_phase != null) starting_phase.raise_objection(this);
endtask

task body();
req = seq_item::type_id::create("req");
// send to the driver
#20;
...
endtask

task post_body();
if(starting_phase != null) starting_phase.drop_objection(this);
endtask
endclass

The objection mechanism in the sequence can be used with the below two approaches.
1. With set_starting_phase and get_starting_phase methods
2. With set_automatic_phase_objection method
With set_starting_phase and get_starting_phase methods

 As the name implies set_starting_phase and get_starting_phase are used to set and
retrieve the phase.
 Note: If get_starting_phase returns null, then the sequence will not raise and drop
objection.

Code:

class seq_item extends uvm_sequence_item;

5|Page
@shraddha_pawankar Date:31/03/2024

rand bit[15:0] addr;


rand bit[15:0] data;
`uvm_object_utils(seq_item)

function new(string name = "seq_item");


super.new(name);
endfunction

endclass

class base_seq extends uvm_sequence #(seq_item);


seq_item req;
uvm_phase phase;
`uvm_object_utils(base_seq)

function new (string name = "base_seq");


super.new(name);
endfunction

task pre_body();
`uvm_info(get_type_name(), "Inside pre_body", UVM_LOW);
phase = get_starting_phase; // Retrieve phase information
if (phase != null) phase.raise_objection(this);
endtask

task body();
`uvm_info(get_type_name(), "Base seq: Body started", UVM_LOW);
req = seq_item::type_id::create("req");
// send to the driver
#20;
`uvm_info(get_type_name(), "Base seq: Body completed", UVM_LOW);
endtask

task post_body();
`uvm_info(get_type_name(), "Inside post_body", UVM_LOW);
if (phase != null) phase.drop_objection(this);
endtask
endclass

class base_test extends uvm_test;


base_seq bseq;

`uvm_component_utils(base_test)

function new(string name = "base_test", uvm_component parent = null);


super.new(name, parent);

6|Page
@shraddha_pawankar Date:31/03/2024

endfunction

function void build_phase(uvm_phase phase);


super.build_phase(phase);
endfunction

task run_phase(uvm_phase phase);


super.run_phase(phase);
bseq = base_seq::type_id::create("bseq");
bseq.set_starting_phase(phase); // Set starting phase
bseq.start(null);
endtask
endclass

module tb_top;
initial begin
run_test("base_test");
end
endmodule

Output :
UVM_INFO testbench.sv(18) @ 0: reporter@@bseq [base_seq] Inside pre_body
UVM_INFO testbench.sv(24) @ 0: reporter@@bseq [base_seq] Base seq: Body started
UVM_INFO testbench.sv(28) @ 20: reporter@@bseq [base_seq] Base seq: Body completed
UVM_INFO testbench.sv(32) @ 20: reporter@@bseq [base_seq] Inside post_body

With set_automatic_phase_objection method


 The uvm1.2 also added the set_automatic_phase_objection method that
automatically raises and drops the objection for the current sequence. Alternatively,
there is no need to call raise_objection prior to executing the sequence
and drop_objection once execution is completed.
 Instead, make set_automatic_phase_objection(1) either in the new() method of the
sequence or before starting the sequence.
 Note: Do not make set_automatic_phase_objection(1) if the sequence runs with a
forever loop inside of the body, as the objection will never get dropped.

Que) if you have multiple objections and for one drop objection you left how will you
rectify the situation?

1) If we have multiple objection in the UVM and and multiple objection undropped.
It could lead synchronization problem,unintended simulation results.
2) We can handle this situation:

7|Page
@shraddha_pawankar Date:31/03/2024

a) Identify the undropped objection


b) Check the objection count
c) Locate the missing drop call
d) Determine appropriate location for drop
e) Fix the code
f) Rerun the simulation
Additionally we can use UVM built in -debug facilities to help us track objection
related issue
UVM provides `uvm_objection_checker.

-----------------------------------------------------------------------------------------------------------------
----------

Example : Phase and Drop objection

//two objection are raised @0 time unit and one drop objection @10 time unit another
drop objection @100 time unit
//simulator will remains in the run phase till the objections dropped

//hence,the objection mechanism helps the simulator to decide at what point of time it
can proceed to extract phase from run phase

// USE +UVM_OBJECTION_TRACE IN run option we get counter like mechanism

`include "uvm_macros.svh"
import uvm_pkg::*;

class Transmitter extends uvm_component;


`uvm_component_utils(Transmitter)

function new(string name="",uvm_component parent=null);


super.new(name,parent);
endfunction

8|Page
@shraddha_pawankar Date:31/03/2024

virtual task run_phase(uvm_phase phase);


phase.raise_objection(this);
#10;
`uvm_info(get_type_name(),"------------Run phase of transmitter-----------",UVM_NONE)
phase.drop_objection(this);
endtask

endclass

class Receiver extends uvm_component;


`uvm_component_utils(Receiver)

function new(string name="",uvm_component parent=null);


super.new(name,parent);
endfunction

virtual task run_phase(uvm_phase phase);


phase.raise_objection(this);
#100;
`uvm_info(get_type_name(),"------------Run phase of Receiver-----------",UVM_NONE)
phase.drop_objection(this);
endtask

endclass

class env extends uvm_env;


`uvm_component_utils(env)

Transmitter Tx;

9|Page
@shraddha_pawankar Date:31/03/2024

Receiver Rx;

function new(string name="",uvm_component parent);


super.new(name,parent);
Tx=Transmitter::type_id::create("Tx",this);
Rx=Receiver::type_id::create("Rx",this);
endfunction
endclass

class test extends uvm_test;


`uvm_component_utils(test)

env env_h;
function new(string name="",uvm_component parent);
super.new(name,parent);
endfunction

virtual function void build_phase(uvm_phase phase);


super.build_phase(phase);
env_h=env::type_id::create("env_h",this);
endfunction
endclass

module tb;
initial
begin
run_test("test");
end
endmodule

10 | P a g e
@shraddha_pawankar Date:31/03/2024

OUTPUT :

# KERNEL: UVM_INFO @ 0: reporter [RNTST] Running test test...


# KERNEL: UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top.env_h.Tx raised 1
objection(s): count=1 total=1
# KERNEL: UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top.env_h added 1
objection(s) to its total (raised from source object ): count=0 total=1
# KERNEL: UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top added 1 objection(s) to
its total (raised from source object uvm_test_top.env_h.Tx): count=0 total=1
# KERNEL: UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_top added 1 objection(s) to its
total (raised from source object uvm_test_top.env_h.Tx): count=0 total=1
# KERNEL: UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top.env_h.Rx raised 1
objection(s): count=1 total=1
# KERNEL: UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top.env_h added 1
objection(s) to its total (raised from source object ): count=0 total=2
# KERNEL: UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_test_top added 1 objection(s) to
its total (raised from source object uvm_test_top.env_h.Rx): count=0 total=2
# KERNEL: UVM_INFO @ 0: run [OBJTN_TRC] Object uvm_top added 1 objection(s) to its
total (raised from source object uvm_test_top.env_h.Rx): count=0 total=2
# KERNEL: UVM_INFO /home/runner/testbench.sv(19) @ 10: uvm_test_top.env_h.Tx
[Transmitter] ------------Run phase of transmitter-----------
# KERNEL: UVM_INFO @ 10: run [OBJTN_TRC] Object uvm_test_top.env_h.Tx dropped 1
objection(s): count=0 total=0
# KERNEL: UVM_INFO @ 10: run [OBJTN_TRC] Object uvm_test_top.env_h.Tx all_dropped 1
objection(s): count=0 total=0
# KERNEL: UVM_INFO @ 10: run [OBJTN_TRC] Object uvm_test_top.env_h subtracted 1
objection(s) from its total (dropped from source object ): count=0 total=1
# KERNEL: UVM_INFO @ 10: run [OBJTN_TRC] Object uvm_test_top subtracted 1
objection(s) from its total (dropped from source object uvm_test_top.env_h.Tx): count=0
total=1
# KERNEL: UVM_INFO @ 10: run [OBJTN_TRC] Object uvm_top subtracted 1 objection(s)
from its total (dropped from source object uvm_test_top.env_h.Tx): count=0 total=1
# KERNEL: UVM_INFO /home/runner/testbench.sv(35) @ 100: uvm_test_top.env_h.Rx
[Receiver] ------------Run phase of Receiver-----------
# KERNEL: UVM_INFO @ 100: run [OBJTN_TRC] Object uvm_test_top.env_h.Rx dropped 1
objection(s): count=0 total=0
# KERNEL: UVM_INFO @ 100: run [OBJTN_TRC] Object uvm_test_top.env_h.Rx all_dropped
1 objection(s): count=0 total=0
# KERNEL: UVM_INFO @ 100: run [OBJTN_TRC] Object uvm_test_top.env_h subtracted 1
objection(s) from its total (dropped from source object ): count=0 total=0
# KERNEL: UVM_INFO @ 100: run [OBJTN_TRC] Object uvm_test_top.env_h subtracted 1
objection(s) from its total (all_dropped from source object ): count=0 total=0
# KERNEL: UVM_INFO @ 100: run [OBJTN_TRC] Object uvm_test_top subtracted 1

11 | P a g e
@shraddha_pawankar Date:31/03/2024

objection(s) from its total (dropped from source object uvm_test_top.env_h.Rx): count=0
total=0
# KERNEL: UVM_INFO @ 100: run [OBJTN_TRC] Object uvm_test_top subtracted 1
objection(s) from its total (all_dropped from source object uvm_test_top.env_h.Rx):
count=0 total=0
# KERNEL: UVM_INFO @ 100: run [OBJTN_TRC] Object uvm_top subtracted 1 objection(s)
from its total (dropped from source object uvm_test_top.env_h.Rx): count=0 total=0
# KERNEL: UVM_INFO @ 100: run [OBJTN_TRC] Object uvm_top subtracted 1 objection(s)
from its total (all_dropped from source object uvm_test_top.env_h.Rx): count=0 total=0
# KERNEL: UVM_INFO /home/build/vlib1/vlib/uvm-1.2/src/base/uvm_objection.svh(1271)
@ 100: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
# KERNEL: UVM_INFO /home/build/vlib1/vlib/uvm-
1.2/src/base/uvm_report_server.svh(869) @ 100: reporter [UVM/REPORT/SERVER]

Output : https://www.edaplayground.com/x/JAFw

12 | P a g e

You might also like