UVM中的配置机制uvm_config_db,uvm_config_db机制用于在UVM平台间传递参数。它们通常是成对出现的,set 寄信,而get函数是收信。config 机制大大提高了UVM的验证灵活性。例如module 和 class 连接通过config_db virtual interace.
 
module tb_top

    initial begin
uvm_config_db #(virtual spi_if)::set(null, "", "vif", vif)
end
endmodule classs spi_drv extend uvm_driver; virtual spi_if vif; uvm_config_db #(virtual spi_if)::get(this, "", "vif", vif);
endclass
  对于config 机制只需要掌握两个原则:一是不同层次进行set,以最高层为准(test比env级要高,env比agent要高);二是同一层进行set,以最后一次set为准。对于环境变量中有大量参数需要设置时,用聚合config 变量,将所有的需要配置的变量放在一个专门的类(my_config extends uvm_object)中实现。
  config_db 机制是UVM中用于在不同component之间共享资源的一种机制,它满足了资源共享的要求,同时避免全局变量的弊端。uvm_config_db 是uvm_resource_db 的外壳。资源共享,有三个问题:
1 资源是存放在什么地方?( uvm_resource_pool )
2 资源以什么样的方式共享(存放)(uvm_resource#(type T) )
3 资源是如何共享的(存取的)(uvm_resource_db #(type T) )
 
下面然我们先看看uvm_config_db的源代码:
文件:src/base/uvm_config_db.svh
类:uvm_config_db,m_uvm_waiter
The uvm_config_db parameterized class provides a convenience interface on top of uvm_resource_db to simplify the basic interface that is used for reading and writing into the resource database.UVM's configuration facility provides an alternative to using the factory to configure a verification environment.
 
//----------------------------------------------------------------------
// class: uvm_config_db
//
// All of the functions in uvm_config_db#(T) are static, so they
// must be called using the :: operator. For example:
//
//| uvm_config_db#(int)::set(this, "*", "A");
//
// The parameter value "int" identifies the configuration type as
// an int property.
//
// The <set> and <get> methods provide the same API and
// semantics as the set/get_config_* functions in <uvm_component>.
//----------------------------------------------------------------------
class uvm_config_db#(type T=int) extends uvm_resource_db#(T); // Internal lookup of config settings so they can be reused
// The context has a pool that is keyed by the inst/field name.
static uvm_pool#(string,uvm_resource#(T)) m_rsc[uvm_component]; // Internal waiter list for wait_modified
static local uvm_queue#(m_uvm_waiter) m_waiters[string]; // function: get
//
// Get the value for ~field_name~ in ~inst_name~, using component ~cntxt~ as
// the starting search point. ~inst_name~ is an explicit instance name
// relative to ~cntxt~ and may be an empty string if the ~cntxt~ is the
// instance that the configuration object applies to. ~field_name~
// is the specific field in the scope that is being searched for.
//
// The basic ~get_config_*~ methods from <uvm_component> are mapped to
// this function as:
//
//| get_config_int(...) => uvm_config_db#(uvm_bitstream_t)::get(cntxt,...)
//| get_config_string(...) => uvm_config_db#(string)::get(cntxt,...)
//| get_config_object(...) => uvm_config_db#(uvm_object)::get(cntxt,...) static function bit get(uvm_component cntxt,
string inst_name,
string field_name,
inout T value);
//TBD: add file/line
int unsigned p;
uvm_resource#(T) r, rt;
uvm_resource_pool rp = uvm_resource_pool::get();
uvm_resource_types::rsrc_q_t rq;
uvm_coreservice_t cs = uvm_coreservice_t::get(); if(cntxt == null)
cntxt = cs.get_root();
if(inst_name == "")
inst_name = cntxt.get_full_name();
else if(cntxt.get_full_name() != "")
inst_name = {cntxt.get_full_name(), ".", inst_name}; rq = rp.lookup_regex_names(inst_name, field_name, uvm_resource#(T)::get_type());
r = uvm_resource#(T)::get_highest_precedence(rq); if(uvm_config_db_options::is_tracing())
m_show_msg("CFGDB/GET", "Configuration","read", inst_name, field_name, cntxt, r); if(r == null)
return ; value = r.read(cntxt); return ;
endfunction // function: set
//
// Create a new or update an existing configuration setting for
// ~field_name~ in ~inst_name~ from ~cntxt~.
// The setting is made at ~cntxt~, with the full scope of the set
// being {~cntxt~,".",~inst_name~}. If ~cntxt~ is ~null~ then ~inst_name~
// provides the complete scope information of the setting.
// ~field_name~ is the target field. Both ~inst_name~ and ~field_name~
// may be glob style or regular expression style expressions.
//
// If a setting is made at build time, the ~cntxt~ hierarchy is
// used to determine the setting's precedence in the database.
// Settings from hierarchically higher levels have higher
// precedence. Settings from the same level of hierarchy have
// a last setting wins semantic. A precedence setting of
// <uvm_resource_base::default_precedence> is used for uvm_top, and
// each hierarchical level below the top is decremented by 1.
//
// After build time, all settings use the default precedence and thus
// have a last wins semantic. So, if at run time, a low level
// component makes a runtime setting of some field, that setting
// will have precedence over a setting from the test level that was
// made earlier in the simulation.
//
// The basic ~set_config_*~ methods from <uvm_component> are mapped to
// this function as:
//
//| set_config_int(...) => uvm_config_db#(uvm_bitstream_t)::set(cntxt,...)
//| set_config_string(...) => uvm_config_db#(string)::set(cntxt,...)
//| set_config_object(...) => uvm_config_db#(uvm_object)::set(cntxt,...) static function void set(uvm_component cntxt,
string inst_name,
string field_name,
T value); uvm_root top;
uvm_phase curr_phase;
uvm_resource#(T) r;
bit exists;
string lookup;
uvm_pool#(string,uvm_resource#(T)) pool;
string rstate;
uvm_coreservice_t cs = uvm_coreservice_t::get(); //take care of random stability during allocation
process p = process::self();
if(p != null)
rstate = p.get_randstate(); top = cs.get_root(); curr_phase = top.m_current_phase; if(cntxt == null)
cntxt = top;
if(inst_name == "")
inst_name = cntxt.get_full_name();
else if(cntxt.get_full_name() != "")
inst_name = {cntxt.get_full_name(), ".", inst_name}; if(!m_rsc.exists(cntxt)) begin
m_rsc[cntxt] = new;
end
pool = m_rsc[cntxt]; // Insert the token in the middle to prevent cache
// oddities like i=foobar,f=xyz and i=foo,f=barxyz.
// Can't just use '.', because '.' isn't illegal
// in field names
lookup = {inst_name, "__M_UVM__", field_name}; if(!pool.exists(lookup)) begin
r = new(field_name, inst_name);
pool.add(lookup, r);
end
else begin
r = pool.get(lookup);
exists = ;
end if(curr_phase != null && curr_phase.get_name() == "build")
r.precedence = uvm_resource_base::default_precedence - (cntxt.get_depth());
else
r.precedence = uvm_resource_base::default_precedence; r.write(value, cntxt); if(exists) begin
uvm_resource_pool rp = uvm_resource_pool::get();
rp.set_priority_name(r, uvm_resource_types::PRI_HIGH);
end
else begin
//Doesn't exist yet, so put it in resource db at the head.
r.set_override();
end //trigger any waiters
if(m_waiters.exists(field_name)) begin
m_uvm_waiter w;
for(int i=; i<m_waiters[field_name].size(); ++i) begin
w = m_waiters[field_name].get(i);
if(uvm_re_match(uvm_glob_to_re(inst_name),w.inst_name) == )
->w.trigger;
end
end if(p != null)
p.set_randstate(rstate); if(uvm_config_db_options::is_tracing())
m_show_msg("CFGDB/SET", "Configuration","set", inst_name, field_name, cntxt, r);
endfunction // function: exists
//
// Check if a value for ~field_name~ is available in ~inst_name~, using
// component ~cntxt~ as the starting search point. ~inst_name~ is an explicit
// instance name relative to ~cntxt~ and may be an empty string if the
// ~cntxt~ is the instance that the configuration object applies to.
// ~field_name~ is the specific field in the scope that is being searched for.
// The ~spell_chk~ arg can be set to 1 to turn spell checking on if it
// is expected that the field should exist in the database. The function
// returns 1 if a config parameter exists and 0 if it doesn't exist.
// static function bit exists(uvm_component cntxt, string inst_name,
string field_name, bit spell_chk=);
uvm_coreservice_t cs = uvm_coreservice_t::get(); if(cntxt == null)
cntxt = cs.get_root();
if(inst_name == "")
inst_name = cntxt.get_full_name();
else if(cntxt.get_full_name() != "")
inst_name = {cntxt.get_full_name(), ".", inst_name}; return (uvm_resource_db#(T)::get_by_name(inst_name,field_name,spell_chk) != null);
endfunction // Function: wait_modified
//
// Wait for a configuration setting to be set for ~field_name~
// in ~cntxt~ and ~inst_name~. The task blocks until a new configuration
// setting is applied that effects the specified field. static task wait_modified(uvm_component cntxt, string inst_name,
string field_name);
process p = process::self();
string rstate = p.get_randstate();
m_uvm_waiter waiter;
uvm_coreservice_t cs = uvm_coreservice_t::get(); if(cntxt == null)
cntxt = cs.get_root();
if(cntxt != cs.get_root()) begin
if(inst_name != "")
inst_name = {cntxt.get_full_name(),".",inst_name};
else
inst_name = cntxt.get_full_name();
end waiter = new(inst_name, field_name); if(!m_waiters.exists(field_name))
m_waiters[field_name] = new;
m_waiters[field_name].push_back(waiter); p.set_randstate(rstate); // wait on the waiter to trigger
@waiter.trigger; // Remove the waiter from the waiter list
for(int i=; i<m_waiters[field_name].size(); ++i) begin
if(m_waiters[field_name].get(i) == waiter) begin
m_waiters[field_name].delete(i);
break;
end
end
endtask endclass
从上面可以看uvm_config_db#(type T=int) extends uvm_resource_db#(T),也是说uvm_config_db 只是对uvm_resource_db 重新封装了一次。对uvm_resource_db
的一些功能进行了扩展,在写入操作上重载了uvm_resource_db的set 函数,在读操作上新建了一个get 函数。
让我们来看看这两个静态函数set and get 函数(有点类似于存储器的写和读功能),首先来看,uvm_config_db 的set 函数。再看uvm_config_db 的get 函数。

uvm_config_db——半个全局变量的更多相关文章

  1. node.js相关

    node node最大的特点是单线程,因此一个只能有一个任务运行,大量采用异步操作. 某一个任务的后续操作一般采用回调函数的形式 var callback = function (error, val ...

  2. JavaScript模块化开发的那些事

    模块化开发在编程开发中是一个非常重要的概念,一个优秀的模块化项目的后期维护成本可以大大降低.本文主要介绍了JavaScript模块化开发的那些事,文中通过一个小故事比较直观地阐述了模块化开发的过程. ...

  3. 008--VS2013 C++ 位图半透明化(另一种显示)

    注:主要变化是在下面这张位图上的操作 //全局变量HBITMAP bg, girl;HDC mdc;//起始坐标const int xstart = 50;const int ystart = 20; ...

  4. 007--VS2013 C++ 显示位图半透明化

    以后所有图片都放在根目录下: 如有另放,会特别注明 //全局变量HBITMAP bg,girl;HDC mdc; //起始坐标const int xstart = 50;const int ystar ...

  5. 深入MySQL复制(三):半同步复制

    1.半同步复制 半同步复制官方手册:https://dev.mysql.com/doc/refman/5.7/en/replication-semisync.html 默认情况下,MySQL的复制是异 ...

  6. [转]java nio解决半包 粘包问题

    java nio解决半包 粘包问题 NIO socket是非阻塞的通讯模式,与IO阻塞式的通讯不同点在于NIO的数据要通过channel放到一个缓存池ByteBuffer中,然后再从这个缓存池中读出数 ...

  7. uvm_config_db在UVM验证环境中的应用

    如何在有效的使用uvm_config_db来搭建uvm验证环境对于许多验证团队来说仍然是一个挑战.一些验证团队完全避免使用它,这样就不能够有效利用它带来的好处:另一些验证团队却过多的使用它,这让验证环 ...

  8. 搭建MySQL的主从、半同步、主主复制架构

    复制其最终目的是让一台服务器的数据和另外的服务器的数据保持同步,已达到数据冗余或者服务的负载均衡.一台主服务器可以连接多台从服务器,并且从服务器也可以反过来作为主服务器.主从服务器可以位于不同的网络拓 ...

  9. 分布式缓存系统 Memcached 半同步/半异步模式

    在前面工作线程初始化的分析中讲到Memcached采用典型的Master_Worker模式,也即半同步/半异步的高效网络并发模式.其中主线程(异步线程)负责接收客户端连接,然后分发给工作线程,具体由工 ...

随机推荐

  1. bzoj 5092 分割序列 —— 高维前缀和

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5092 首先,处理出异或前缀和 s[i],i 位置的答案就是 s[j] + s[j]^s[i] ...

  2. JavaScript-Tool:validate.js-un

    ylbtech-JavaScript-Tool:validate.js 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. http://validatejs. ...

  3. 十、外键约束FK(foreign key)

    1.定义 a.外键涉及到的术语:外键约束.外键字段.外键值. b.外键约束.外键字段.外键值三者之间的关系? 答:给某个字段添加外键约束之后,该字段称为外键字段,外键字段中的值是外键值. c.外键根据 ...

  4. 一种C#开发ActiveX的思路

    由于某些原因,不得不在C#下开发ActiveX插件,而这会带来很多问题,主要有无法在线安装.无法自动更新.由于本人水平有些,这两个问题不一定是这样,如果有大侠知道C#下开发ActiveX插件可实现在线 ...

  5. StarUML中时序图

    StarUML中时序图 在看时序图的例子的时候,发现有些的时序图上有小人的图标,可是一些UML工具却没有找到小人的图标,这让我很闹心,一直没解决,今天终于将该问题给解决了.解决这个问题来自于网上的一个 ...

  6. ShutdownHook作用

    源地址:http://kim-miao.iteye.com/blog/1662550 void java.lang.Runtime.addShutdownHook(Thread hook) 该方法用来 ...

  7. Markdown编写github README.md

    Markdown编写github README.md 一.在线编辑器StackEdit Markdown在线编辑器地址 中文:https://www.zybuluo.com/mdeditor 英文:h ...

  8. 共相式GIS

    今天看到SuperMap中一直提到共相式GIS,于是乎搜索一下……SuperMap的共相式怎么理解呢?iServer Java有咋理解呢??? 再谈共相式GIS和ArcObjects:ttp://ww ...

  9. java web 学习-网络资源

    [网络收集] 1. JavaWeb学习总结——JSP中的九个内置对象 2. Jsp九大内置对象以及四个作用域 他人学习汇总资源 1. http://www.cnblogs.com/xdp-gacl/t ...

  10. Spring Boot 学习系列(07)—properties文件读取

    此文已由作者易国强授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 传统的properties读取方式 一般的,我们都可以自定义一个xxx.properties文件,然后在工程 ...