UVM提供uvm_barrier对多个组件进行同步协调,同时为了解决组件独立运作的封闭性需要,定义了新的类uvm_barrier_pool来全局管理uvm_barrier对象。
uvm_barrier 可以设置一定的等待阈值,仅在有不少于该阈值的进程在等待该对象时才会触发该事件,同时激活所有正在等待的进程,使其基础进行。
wait_for | Waits for enough processes to reach the barrier before continuing. |
reset | Resets the barrier. |
set_auto_reset | Determines if the barrier should reset itself after the threshold is reached. |
set_thresh_hold | Sets the process threshold. |
get_thresh_hold | Gets the current threshold setting for the barrier. |
get_num_waiters | Returns the number of processes currently waiting at the barrier. |
cancel | Decrements the waiter counter by one. |
virtual function void reset (bit wakeup = 1)
Resets the barrier. This sets the waiter count back to zero.
The threshold is unchanged. After reset, the barrier will force processes to wait for the threshold again.
If the wakeup bit is set, any currently waiting processes will be activated.
virtual function void set_auto_reset (bit value = 1)
The default is on, so when a barrier hits its threshold it will reset, and new processes will block until the threshold is reached again.
If auto reset is off, then once the threshold is achieved, new processes pass through without being blocked until the barrier is reset.
virtual function void set_threshold (int threshold)
This determines how many processes must be waiting on the barrier before the processes may proceed.
Once the threshold is reached, all waiting processes are activated.
If threshold is set to a value less than the number of currently waiting processes, then the barrier is reset and waiting processes are activated.
1 //---------------------------------------------------------------------- 2 //component1 3 //---------------------------------------------------------------------- 4 5 class comp1 extends uvm_component; 6 uvm_barrier b1; 7 ... 8 function void build_phase(uvm_phase phase); 9 super.build_phase(phase); 10 b1 = uvm_barrier_pool::get_global("b1"); 11 endfunction 12 task run_phase(phase); 13 #5ns; 14 b1.wait_for(); 15 endtask 16 endclass 17 18 //---------------------------------------------------------------------- 19 //component2 20 //---------------------------------------------------------------------- 21 22 class comp2 extends uvm_component; 23 uvm_barrier b1; 24 ... 25 function void build_phase(uvm_phase phase); 26 super.build_phase(phase); 27 b1 = uvm_barrier_pool::get_global("b1"); 28 endfunction 29 task run_phase(phase); 30 #10ns; 31 b1.wait_for(); 32 endtask 33 endclass 34 //---------------------------------------------------------------------- 35 //env 36 //---------------------------------------------------------------------- 37 38 class env extends uvm_env; 39 comp1 c1; 40 comp2 c2; 41 uvm_barrier b1; 42 ... 43 function void build_phase(uvm_phase phase); 44 super.build_phase(phase); 45 c1 = comp1::type_id::create("c1",this); 46 c2 = comp1::type_id::create("c2",this); 47 b1 = uvm_barrier_pool::get_global("b1"); 48 endfunction 49 50 task run_phase(phase); 51 b1.set_threshold(3); 52 #20ns; 53 b1.set_threshold(2); 54 `uvm_info("BAR",$sformatf("set b1 thrd %0d at %0t fs",b1.get_threshold(),$time),UVM_NONE) 55 endtask 56 endclass
为了同步c1和c2而定义了b1,b1为c1,c2和env共享。c1和c2通过wait_for()来等待激活,env通过设置阈值来调控“开闸”的时间。
————————————————
版权声明:本文为CSDN博主「lbt_dvshare」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lbt_dvshare/article/details/82713831