UVM CallBacks Developer and User perspectives Sirajudheen Mubarak,WaferSpace,
[email protected]
What is CallBack ? In computer programming, a callback is a piece of executable code that is passed as an argument to to other code, which is expected to call back (execute (execute the argument at some con!enient time . "he en!ironment de!eloper must insert calls to specific callback methods#tasks at points where the user might need to take specific action. "he de!eloper should should think and come up with the user$s re%uirement so that the user can do some operation on the transactions which are in progress. "he callback users can then create their deri!ed callback class and attach to one or more desired objects."he use model of callbacks is broken into two parts, the developer side and the user's side .
$UVM_HOME says.. “The callback class defines an interface consisting of one or more function or task prototypes. The signatures of each method have no restrictions. The component developer knows best the intended semantic of multiple registered callbacks. Thus the algorithm for traversal the callback queue s hould reside in the callback class itself. We could provide convenience macros that implement the most common traversal methods, such such as sequential in-order execution. Developer "he de!eloper must make the space where the callback to be executed so that the user can come and modif& the transaction object which are in progress. "he 'allack function should ha!e the referance to the the transaction object and other re%uired details like is)drop(if the user need to drop the transaction* , insert(user can insert new packet before or after the ongoing transaction etc. +sing our example from -ierarch& Information unctions/ on page 01, we ma& want to add a callback to the cit& class which gets executed before it prints its parent#child information. "o "o do this we would do something like2
typedef class packet; virtual class link_layer_cbs extends uvm_callback; function new(string name="link_layer_cbs"); super.new(name); endfunction pure virtual function void on_enter_link_layer(ref packet pkt); pure virtual task exit_link_layer(ref packet pkt); endclass 3e!eloper should register the callback t&pe with the class t &pe which uses the call back here it is link)la&er. +4M will check the t&pe of the callback when the user adds it.Without registering callbacks, user will get a warning from +4M that the callback t&pe was not registered with the object t&pe the& are tr&ing to add it to.
class link_layer extends uvm_component; `uvm_register_cb(link_layer link_layer_cbs ) ... endclass 5ow the de!eloper need to add the !irtual functions for adding callack or directl& add the callback b& using the u!m macro 6u!m)do)callbacks( as below. "here are set of u!m macros a!ailabe for adding,registering,doing callbacks.
!"v#_do_callacks_e%it_on&'(CB(ME'HOD(V)*+ 'alls the gi!en M7"-83 of all callbacks of t&pe ' registered with the calling object (i.e. this object, which is or is based on t&pe ", returning upon the first callback retur ning the bit !alue gi!en b & 49:. "his macro executes all of the callbacks associated with the calling object (i.e. this object. "he macro takes three arguments2 ' is the class t&pe of the callback objects to execute. "he class t&pe must ha!e a function signature that matches the M7"-83 argument. " is the t&pe associated with the callback. "&picall&, an instance of t&pe " is passed as one the arguments in the M7"-83 call. M7"-83 is the method call to in!oke, with all re%uired ar guments as if the& were in!oked directl&. 49:, if ;, sa&s return upon the first callback in!ocation that returns ;. If <, sa&s return upon the first callback in!ocation that returns <. •
•
• •
!"v#_do_callacks&'(CB(ME'HOD+ 'alls the gi!en M7"-83 of all callbacks of t&pe ' registered with the calling object (i.e. this object, which is or is based on t&pe ". "his macro executes all of the callbacks associated with the calling object (i.e. this object. "he macro takes three arguments2 ' is the class t&pe of the callback objects to execute. "he class t&pe must ha!e a function signature that matches the M7"-83 argument. " is the t&pe associated with the callback. "&picall&, an instance of t&pe " is passed as one the arguments in the M7"-83 call. M7"-83 is the method call to in!oke, with all re%uired ar guments as if the& were in!oked directl&. •
•
•
!"v#_re,ister_c&'(CB+ =egisters the gi!en ' callback t&pe with the gi!en " object t&pe. If a t&pe>callback pair is not registered then a warning is issued if an attempt is made to use the pair (add, delete, etc.. "he registration will t&picall& occur in the component that executes the gi!en t&pe of callback
!lass link_layer extends uvm_component; `uvm_register_cb(link_layer link_layer_cbs) virtual function bit on_enter_link_layer(packet pkt); `uvm_do_callbacks_exit_on( link_layer link_layer_cbs on_enter_link_layer(t#istr) $ return after t#e ) endfunction
t#is type callback type callback call first invocation
virtual task on_exit_link_layer(ref packet pkt); `uvm_do_callbacks( bus_driver bus_driver_cb trans_executed(t#istr) ) endtask
virtual task main_p#ase(uvm_p#ase p#se);
protocol_layer_port.get(pkt); uvm_report_info(get_type_name()"%acket &ntered to 'ink 'ayer"*_'+,); if (-on_enter_link_layer(pkt))
begin uvm_report_info("pkt dropped" "user callback indicated /+%%&0n"); return; end drive_pkt_to_next_layer(pkt); user task on_exit_link_layer(pkt); uvm_report_info(get_type_name()"pkt is &xiting 'ink 'ayer"*_'+,);
endtask endclass
End-User Use Model "he end>user simpl& needs to extend the callback base class, o!erriding an& or all of the protot&pes pro!ided in the de!eloper>supplied callback interface. "hen, register an instance of the callback class with an& object designed to use the base callback t&pe.
class my_ll_cbs extends link_layer_cbs; override t#e callback met#odes #ere. &ndclass "o a!oid compilation issue due to the order of compilation, define the t&pe o f callback typedef uvm_callbacks 1(link_layerlink_layer_cbs) link_layer_cbs_t;
ADD/DELETE INTEFACE
uvm_callbacks methods
Registers the given callback object, cb, with the givenobj handle. add
&g2 uvm_callbacks1(my_comp)22add(comp_a cb);
add_by_name
Registers the given callback object, cb, with one or more uvm_components. Deletes the given callback object, cb, from the queue associated with the given obj handle.
delete
&g2 uvm_callbacks1(my_comp my_callback)22delete(comp_acb);
delete_by_name
Removes the given callback object, cb, associated with one or more uvm_component callback queues.
ITERATOR INTERFACE get_first get_last
get_ne"t get_prev DEBUG display
This set of functions provide an iterator interface for callback queues. Returns the first enabled callback of t ype ! which resides in the queue for obj. Returns the last enabled callback of t ype ! which resides in the queue for obj. Returns the ne"t enabled callback of t ype ! which resides in the queue for obj, using itr as the starting point. Returns the previous enabled callback of type ! which resides in the queue for obj, using itr as the starting point. This function displays callback information for obj.
)ttachin, the Callack "o register the callbacks with the link)la&er, we get the global callback pool that is t&ped to our specific link)la&er> callback combination. We associate (register the callback objects with link)la&er using the callback pool$s add( method 3est buils_p#ase virtual fucntion void build_p#ase(uvm_p#ase p#ase) !reate t#e environment components link_layer link = link_layer22type_id22create("link"t#is); !reate t#e callback my_ll_cbs ll_cb = new("cb$"); 4dd callback to t#e link_layer link_layer_cbs_t22add (linkll_cb); endfunction
?uidelines for +sing 'allbacks 3e!eloper ?uidelines 'reate an abstract (!irtual class for the callbacks with pure !irtual methods for the interface. Aass a reference of the object making the callback call. Make sure that the packet is not modified without the user$s or de!eloper$s knowledge as we use referance of the transaction packet between the callbacks and the normal flow of the en!. • • •
•
Aro!ide a t&pedef for the uvm!callbacks"#T,$%& class with the name ")cb.
+ser ?uidelines 'reate a callback implementation class which implements all of the pure !irtual methods in the callback class. 9llocate a new callback object for each callback &ou add. • •
Sirajudheen Mubarak.7
[email protected]