在SV中用来做线程间同步的几种方法,它们分别是semaphore、event和mailbox。
而在UVM中event进化成uvm_event,不仅仅拥有达成不同组件进程之间同步的功能,还能像TLM通信一样传递数据,并且作用范围更广(TLM通信只能在uvm_component之间,而uvm_event不限于此)。

常见的uvm_event使用方法
首先从常见的uvm_event达成同步的方式讲起:

 module testimport uvm_pkg::*;initial begin// get a reference to the global singleton object by // calling a static methoduvm_event_pool ev_pool = uvm_event_pool::get_global_pool();  //// either create a uvm_event or return a reference to it// (which depends on the order of execution of the two//  initial blocks - the first call creates the event,//  the second and subsequent calls return a reference to//  an existing event.)uvm_event ev = ev_pool.get("ev");                            //// wait (an arbitrary) 10 and then trigger the event#10 ev.trigger();                                            //trigger event$display("%t: event ev triggered", $time);endinitial begin// get a reference to the global singleton object by // calling a static methoduvm_event_pool ev_pool = uvm_event_pool::get_global_pool();  //// either create a uvm_event or return a reference to ituvm_event ev = ev_pool.get("ev");                            //// wait for the triggerev.wait_trigger();                                           //wait event$display("%t: event ev trigger received", $time);end
endmodule

(两个initial 块可以想象成两个不同UVM组件的不同进程)
通过上面的注释已经基本可以理解uvm_event的达成同步的方法,下面看看背后的原理:

  1. 得到一个全局的单例的uvm_event_pool类型对象的句柄
    uvm_event_pool ev_pool = uvm_event_pool::get_global_pool();

要知道上面的的语句干了什么是就得知道uvm_event_pool的源代码:
https://verificationacademy.com/verification-methodology-reference/uvm/src/base/uvm_pool.svh

class uvm_object_string_pool #(type T=uvm_object) extends uvm_pool #(string,T);typedef uvm_object_string_pool #(T) this_type;static protected this_type m_global_pool;// Function: new// Creates a new pool with the given ~name~.function new (string name="");super.new(name);endfunctionconst static string type_name = {"uvm_obj_str_pool"};// Function: get_type_name// Returns the type name of this object.virtual function string get_type_name();return type_name;endfunction// Function: get_global_pool// Returns the singleton global pool for the item type, T. // This allows items to be shared amongst components throughout the// verification environment.static function this_type get_global_pool ();if (m_global_pool==null)m_global_pool = new("global_pool");return m_global_pool;endfunction// Function: get_global// Returns the specified item instance from the global item pool. static function T get_global (string key);this_type gpool;gpool = get_global_pool(); return gpool.get(key);endfunction// Function: get// Returns the object item at the given string ~key~.// If no item exists by the given ~key~, a new item is created for that key// and returned.virtual function T get (string key);if (!pool.exists(key))pool[key] = new (key);return pool[key];endfunction// Function: delete// Removes the item with the given string ~key~ from the pool....// Function- do_print...
endclass
typedef class uvm_barrier;
typedef class uvm_event;
typedef uvm_object_string_pool #(uvm_barrier) uvm_barrier_pool;
typedef uvm_object_string_pool #(uvm_event) uvm_event_pool;

uvm_event_pool是一个参数为uvm_event类型的uvm_object_string_pool,而uvm_object_string_pool又是继承于uvm_pool。

  typedef uvm_object_string_pool #(T) this_type;static protected this_type m_global_pool;protected T pool[KEY];  // type KEY = string
.........static function this_type get_global_pool ();if (m_global_pool==null)m_global_pool = new("global_pool");return m_global_pool;endfunction

get_global_pool()的源代码如上,结合uvm_event_pool的成员pool和m_global_pool——其中pool是从uvm_pool中继承过来的,而KEY和T正是传递的类型参数,string和uvm_event——可以知道, 调用get_global_pool()会返回一个类型为uvm_event_pool的句柄,句柄指向的对象是全局并且单例的。也就是说两个initial块中两次调用get_global_pool都是返回同一个uvm_event_pool类型对象的句柄,只是先调用的那个get_global_pool函数会创建这个对象。

  1. 通过这个uvm_event_pool句柄调用get()方法得到一个uvm_event对象的的句柄
    uvm_event ev = ev_pool.get("ev");

get ()函数如下:

virtual function T get (string key);if (!pool.exists(key))pool[key] = new (key);return pool[key];
endfunction

根据之前的源代码知道,**在这里pool是一个关联数组,类型为uvm_event,索引类型为string(这也是为什么get()的参数为字符串)。两个initial块两次调用get(),是为了获得同一个pool[string]对象的句柄,先调用的那个get()会创建这个pool[string],而后调用的那个只是获得这个pool[string]对象的句柄。**这个过程和systemverilog中event的传递是一样的,是在两个进程中完成同步的基础。

  1. 通过uvm_event对象的方法trigget () 和wait_trigger ()达成同步
    #10 ev.trigger();ev.wait_trigger();

**前两部的目的本质上是为了让两个Initial块中两个uvm_event句柄指向同一个对象,**这种作法相对于conifg_db或者层次化引用的方式显然方便得多,并且使用get_global()而非get()会更简单。接下来和systemverlog中event达成同步的操作一样了,在一个进程中触发->,另外一个进程中等待触发wait (event.triggered) or @event。
在uvm_event中,触发的方式是uvm_event.trigger();而等待出发的方式是wait_ptrigger()电平触发)or wait_trigger()上升沿触发(与event的两种等待方式对应)。

uvm_event 相较于event的功能扩展
uvm_event的源代码如下,去掉了一些不常用的方法,这里只看关键的方法。

class uvm_event extends uvm_object;const static string type_name = "uvm_event";local event      m_event;local int        num_waiters;local bit        on;local time       trigger_time=0;local uvm_object trigger_data;local uvm_event_callback  callbacks[$];// Function: newfunction new (string name="");super.new(name);endfunction  // Task: wait_onvirtual task wait_on (bit delta=0);if (on) beginif (delta)#0;return;endnum_waiters++;@on;endtask// Task: wait_offvirtual task wait_off (bit delta=0);if (!on) beginif (delta)#0;return;endnum_waiters++;@on;endtask// Task: wait_triggervirtual task wait_trigger ();num_waiters++;@m_event;endtask// Task: wait_ptriggervirtual task wait_ptrigger ();if (m_event.triggered)return;num_waiters++;@m_event;endtask// Task: wait_trigger_datavirtual task wait_trigger_data (output uvm_object data);wait_trigger();data = get_trigger_data();endtask// Task: wait_ptrigger_datavirtual task wait_ptrigger_data (output uvm_object data);wait_ptrigger();data = get_trigger_data();endtask// Function: triggervirtual function void trigger (uvm_object data=null);int skip;skip=0;if (callbacks.size()) beginfor (int i=0;i<callbacks.size();i++) beginuvm_event_callback tmp;tmp=callbacks[i];skip = skip + tmp.pre_trigger(this,data);endendif (skip==0) begin->m_event;if (callbacks.size()) beginfor (int i=0;i<callbacks.size();i++) beginuvm_event_callback tmp;tmp=callbacks[i];tmp.post_trigger(this,data);endendnum_waiters = 0;on = 1;trigger_time = $realtime;trigger_data = data;endendfunction// Function: get_trigger_datavirtual function uvm_object get_trigger_data ();return trigger_data;endfunction// Function: get_trigger_timevirtual function time get_trigger_time ();return trigger_time;endfunction// Function: is_on// Function: is_off// Function: resetvirtual function void reset (bit wakeup=0);event e;if (wakeup)->m_event;m_event = e;num_waiters = 0;on = 0;trigger_time = 0;trigger_data = null;endfunction// Function: add_callback// Function: delete_callback// Function: cancelvirtual function void cancel ();if (num_waiters > 0)num_waiters--;endfunction// Function: get_num_waitersvirtual function int get_num_waiters ();return num_waiters;endfunctionvirtual function uvm_object create(string name=""); uvm_event v;v=new(name);return v;endfunctionvirtual function string get_type_name();return type_name;endfunctionvirtual function void do_print (uvm_printer printer);endfunctionvirtual function void do_copy (uvm_object rhs);endfunction
endclass : uvm_event

可以发现uvm_event的基础其实还是event,只不过event的触发和等待两个动作进行了很多扩展, 主要区别如下:
http://www.sohu.com/a/140684109_778637
1.event被->触发之后,会触发使用@等待该事件的对象;uvm_event通过trigger()来触发,会触发使用wait_trigger()等待的对象。如果要再次等待事件触发,event只需要再次用->来触发,而uvm_event需要先通过reset()方法重置初始状态,再使用trigger()来触发。
2.event无法携带更多的信息,而uvm_event可以通过trigger(uvm_event data = null)的可选参数,将所要伴随触发的数据信息都写入到该触发事件中,而等待该事件的对象可以通过方法wait_trigger_data(output uvm_object data)来获取事件触发时写入的数据对象。这实际上是一个句柄的传递,句柄的类型是uvm_object,也就是说传递的对象句柄得是uvm_object类型的。那如何传递非uvm_object类型的对象呢,首先这个对象必须是uvm_object的子类或者子类的子类,然后才能将其句柄作为trigger()方法的参数,然后wait_trigger ()的参数必须是uvm_object类型的,可以用一个uvm_object类型的tmp作为参数传递句柄,然后使用$cast赋值给目标类型句柄。可以参考:http://www.sohu.com/a/140684109_778637
3.event触发时无法直接触发回调函数,而uvm_event可以通过add_callback(uvm_event_callback cb, bit append = 1)函数来添加回调函数。
4.event无法直接获取等待它的进程数目,而uvm_event不但可以通过get_num_waiters()来获取等待它的进程数目。
5.uvm_event 能够使用callback机制(这里就不讨论uvm_event_callback了,也不复杂),uvm_event能够获取目前事件的等待获触发状态。两者最大的区别还是uvm_event能够传递数据,而event不行。

不使用get()而使用get_global()
由于m_global_pool是一个静态全局的单例,没有必要专门创建一个uvm_event_pool的句柄来指向它;

  static function T get_global (string key);this_type gpool;gpool = get_global_pool(); return gpool.get(key);endfunction

get_global (string key)中集合了get_global_pool()和 get()方法,于是下面两部可以合成一句话

    uvm_event_pool ev_pool = uvm_event_pool::get_global_pool();  //合并前语句1uvm_event ev = ev_pool.get("ev");                            //合并前语句2                //合并后uvm_event ev = uvm_event_pool::get_global ("ev");            //合并后的语句

其实这两种做法的结果都是一样的,都是在uvm_event_pool::m_global_pool这个静态全局单例中的创建了一个uvm_event对象,并存放在关联数组uvm_event_pool::m_global_pool.pool[string]中,索引就是get or get_global ()的参数, 如果这个字符串索引已经存在,那么就返回这个pool[string]句柄。
https://www.chipverify.com/uvm/uvm-pool
https://www.edaplayground.com/x/2Jyj
https://www.cnblogs.com/lybinger/p/8057653.html
https://verificationacademy.com/verification-methodology-reference/uvm/docs_1.1c/html/files/base/uvm_event-svh.html#uvm_event.wait_on

uvm中uvm_event, uvm_event_pool的用法相关推荐

  1. UVM实战 卷I学习笔记10——UVM中的寄存器模型(3)

    目录 后门访问与前门访问 *UVM中前门访问的实现 后门访问操作的定义 *使用interface进行后门访问操作 UVM中后门访问操作的实现:DPI+VPI *UVM中后门访问操作接口 后门访问与前门 ...

  2. UVM中SVA使用指南

    UVM中SVA使用指南 文章目录 UVM中SVA使用指南 前言 一.SVA是什么,什么时候使用SVA 二.SVA块 三.SVA块嵌入UVM平台 3.1 绑定方法 3.2 例化方法 四.SVA语法浅讲 ...

  3. UVM中set/get_config_int/string/object与uvm_cofig_int/string/object的使用

    set_config与get_config get_config_int这种写法最初来自OVM中,UVM继承了这种写法,并在此基础上发展出了config_db.set_config与get_confi ...

  4. PHP中魔术方法的用法

    PHP中魔术方法的用法 /** PHP把所有以__(两个下划线)开头的类方法当成魔术方法.所以你定义自己的类方法时,不要以 __为前缀. * */// __toString.__set.__get__ ...

  5. 简单介绍SQLserver中的declare变量用法

    这篇文章主要介绍了SQLserver中的declare变量用法,sql中declare是声明的意思,就是声明变量的,这个一般是用在函数和存储过程中的.感兴趣的可以来了解一下 平时写SQL查询.存储过程 ...

  6. python的继承用法_【后端开发】python中继承有什么用法?python继承的用法详解

    本篇文章给大家带来的内容是关于python中继承有什么用法?python继承的用法详解,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 面向对象三大特征 1.封装:根据职责将属性和方法 ...

  7. 关于sql中case when的用法

    Oracle CASE WHEN 用法介绍 1. CASE WHEN 表达式有两种形式 --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ...

  8. 【node】express中mysql的基本用法、连接池的使用、事务的回滚

    [node]express中mysql的基本用法.连接池的使用 安装mysql包 mysql的配置信息 mysql基本操作 查询mysql并渲染数据 mysql插入操作 首先在html页面写上< ...

  9. git 只merge部分_[Skill]俩小时掌握多人开发中git的主要用法

    前言 几个月前看完了git文档,但是在实际开发中对很多git命令的具体影响仍有疑惑,比方说pull.fetch和rebase三个命令和检出位置拎不清. Git - Book​git-scm.com 安 ...

  10. python的for语句用法_python中list循环语句用法实例

    本文实例讲述了python中list循环语句用法.分享给大家供大家参考.具体用法分析如下: Python 的强大特性之一就是其对 list 的解析,它提供一种紧凑的方法,可以通过对 list 中的每个 ...

最新文章

  1. java调用权报表的代码_ireport5.6使用table组件,如何用table显示javaBean数据源
  2. 【upc 9541 矩阵乘法】非正解
  3. 分析性能瓶颈 — 调试OutOfMemoryException
  4. 关于KVM的几篇细节文档
  5. junit白盒测试 案例_JUnit通过失败测试案例
  6. dataframe 一列的不同值_python数据分析包|Pandas-02之缺失值(NA)处理
  7. 子div用了float浮动之后,如何撑开父元素,让父元素div自动适应高度的问题
  8. 读书笔记2014第10本:《设计心理学》
  9. 图片随意移动,可以拖动图片计算
  10. TypeScript:变量和数据类型
  11. MacBook安装telnet工具和使用
  12. 15b万用表怎么测电容_怎么判断启动电容好坏_启动电容怎么测量好坏_数字万用表测电容好坏...
  13. 反客为主:巧妙用grldr冒名顶替ntldr引导XP/Ubuntu
  14. 昆仑ONLINE外挂脚本--基于Seraph
  15. 【C语言】数据表现形式及基本数据类型
  16. Android root环境下设置ro.debuggable = 1
  17. 零基础开发WIFI设备(esp8266)
  18. gulp仿移动端网易云音乐播放界面
  19. java毕业设计—— 基于java+javaEE+jsp的项目管理系统设计与实现(毕业论文+程序源码)——项目管理系统
  20. pip install下载一些包很慢,可-i 从豆瓣源下载

热门文章

  1. Typora安装 Pandoc实现导出功能
  2. Unity 利用Skybox Panoramic着色器制作全景图预览有条缝隙问题解决办法
  3. VS与VS Code的区别
  4. python绘制人物关系图_文本分析之制作网络关系图——Python
  5. OpenCV 5种图像滤波辨析:方框、均值、高斯、中值、双边
  6. 间断点怎么求?——6个例子来详细解析较难的间断点的求法
  7. idea中编译DataSphereStudio编译方法及问题排查
  8. 网站首页导航栏移入移出动画(一)slideDown、slideUp
  9. 三国志2017服务器维护时间,《三国志2017》版本更新公告
  10. 给手机安装sqlite3