#UVM# useage 解析 之 uvm_barrier 和 uvm_barrier_pool (一)小白易懂

UVM提供uvm_barrier对多个组件进行同步协调,同时为了解决组件独立运作的封闭性需要,定义了新的类uvm_barrier_pool来全局管理uvm_barrier对象。uvm_barrier 可以设置一定的等待阈值,仅在有不少于该阈值的进程在等待该对象时才会触发该事件,同时激活所有正在等待的进程,使其基础进行。

 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通过设置阈值来调控“开闸”的时间。

感谢大佬分享!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值