【UVM】 uvm_barrier

UVM提供uvm_barrier对多个组件进行同步协调,同时为了解决组件独立运作的封闭性需要,定义了新的类uvm_barrier_pool来全局管理uvm_barrier对象。

 

uvm_barrier 可以设置一定的等待阈值,仅在有不少于该阈值的进程在等待该对象时才会触发该事件,同时激活所有正在等待的进程,使其基础进行。 


wait_forWaits for enough processes to reach the barrier before continuing.
resetResets the barrier.
set_auto_resetDetermines if the barrier should reset itself after the threshold is reached.
set_thresholdSets the process threshold.
get_thresholdGets the current threshold setting for the barrier.
get_num_waitersReturns the number of processes currently waiting at the barrier.
cancelDecrements the waiter count 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.

 


直接上栗子~~~

//----------------------------------------------------------------------
//component1
//----------------------------------------------------------------------

class comp1 extends uvm_component;
  uvm_barrier b1;
  ...
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    b1 = uvm_barrier_pool::get_global("b1");
  endfunction

  task run_phase(phase);
    #5ns;
    b1.wait_for();
  endtask
endclass

//----------------------------------------------------------------------
//component2
//----------------------------------------------------------------------

class comp2 extends uvm_component;
  uvm_barrier b1;
  ...
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    b1 = uvm_barrier_pool::get_global("b1");
  endfunction

  task run_phase(phase);
    #10ns;
    b1.wait_for();
  endtask
endclass
//----------------------------------------------------------------------
//env
//----------------------------------------------------------------------

class env extends uvm_env;
  comp1 c1;
  comp2 c2;
  uvm_barrier b1;
  ...
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    c1 = comp1::type_id::create("c1",this);
    c2 = comp1::type_id::create("c2",this);
    b1 = uvm_barrier_pool::get_global("b1");
  endfunction

  task run_phase(phase);
    b1.set_threshold(3);
    #20ns;
    b1.set_threshold(2);
    `uvm_info("BAR",$sformatf("set b1 thrd %0d at %0t fs",b1.get_threshold(),$time),UVM_NONE)
  endtask
endclass

为了同步c1和c2而定义了b1,b1为c1,c2和env共享。c1和c2通过wait_for()来等待激活,env通过设置阈值来调控“开闸”的时间。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值