uvm__barrier介绍
- 在SV模块中,多个线程的同步除了可以通过semaphore和mailbox来进行,也可以通过fork-join的结构控制语句块来控制整体的运行节奏。
- 然而对于UVM环境中的多个独立组件,SV的这些方法都受到了作用域的局限。. UVM提供了一个新的类uvm_barrier来对
多个组件进行同步协调,同时为了解决组件独立运作的封闭性需要,也定义了新的类uvm_barrier pool来全局管理这uvm_barrier对象。 - uvm_barrier_pool同之前的uvm_event _pool—样,也是基于通用参数类uvm_object_string pool来定义的。
typedef uvm_object_string_pool #(uvm_barrier) uvm_barrier_pool;
typedef uvm_object_string _pool # (uvm_event# (uvm_object)) uvm_event _pool; - uvm_barrier可以设置一定的等待阈值(threshold),当有不少于该阈值的进程在等待该对象时,才会触发该事件,同时激活所有正在等待的进程,使其可以继续进行。
class env1 extends uvm_env;
compl c1;
comp2 c2;
uvm_barrier b1;
'uvm_component_utils (env1)...
function void build_phase (uvm_phase phase) ;
super.build_phase(phase);
c1 = compl : :type_id: :create ( "c1", this );
c2 = comp2: :type_id: :create ( "c2", this ) ;
b1 = uvm_barrier_pool : : get_global ( "bl");
endfunction: build_phase
task run_phase (uvm_phase phase) ;
b1.set_threshold (3) ;
'uvm_info ("BSYNC",$sformatf ("env set bl threshold %d at %0t ps", bl.get_threshold ( ) , $time), UVM_LOW)
#50ns;
b1.set_threshold (2) ; //当有2个目标正在等待的时候,触发
'uvm_info("BSYNC",$sformatf ("env set b1 threshold %d at $0t ps", b1.get_threshold ( ) , $time) , UVM_LOW)
endtask
endclass
class comp1 extends uvm_component;
uvm_barrier b1;
`uvm_component_utils (comp1)...
function void build_phase (uvm_phase phase) ;
super.build_phase (phase) ;
b1 = uvm_barrier_pool: :get_global ( "b1" );
endfunction
task run_phase (uvm_phase phase) ;#10ns;
'uvm_info("BSYNC",$sformatf ( "cl wait for b1 at %0t ps", $time),UVM_LOW)
b1.wait_for ( );
'uvm_info ("BSYNC",$sformatf("cl is activated at %0t ps" ,$time),UVM_LOW)
endtask
endclass
class comp2 extends uvm_component;
uvm_barrier b1;
`uvm_component_utils (comp2)
...
function void build_phase (uvm_phase phase) ;
super.build_phase(phase);
b1 = uvm_barrier_pool: :get_global ( "b1") ;
endfunction
task run_phase (uvm_phase phase) ;
#20ns;
'uvm_info("BSYNC",$sformatf ("c2 wait for b1 at 80t ps" , $time),UVM_LOW)
b1.wait_for () ;
'uvm_info("BSYNC",$sformatf("c2 is activated at $0t ps", $time),UVM_LOW)
endtask
endclass