精品国产人成在线_亚洲高清无码在线观看_国产在线视频国产永久2021_国产AV综合第一页一个的一区免费影院黑人_最近中文字幕MV高清在线视频

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

一文詳解UVM設計模式

rfdqdzdg ? 來源:IC Verification Club ? 2023-08-06 10:38 ? 次閱讀

本篇是對UVM設計模式 ( 二 ) 參數化類、靜態變量/方法/類、單例模式、UVM_ROOT、工廠模式、UVM_FACTORY[1]中單例模式的補充,分析靜態類的使用,UVM中資源池的實現,uvm_config_db的使用。

Static class

Systemverilog中可以使用static修飾變量,方法,得到靜態變量和靜態函數。static也可以直接修飾class,獲得靜態類。但是static class class_name .... endclass這種直接定義一個靜態類的方式是不允許的,只可以在一個class的內部,通過static class_name的方式聲明一個靜態類。這一點SV與Java相同。(Java中的 static class[2])

靜態類的特征:

1.相比automatic class, 靜態類被new創建后,其對應的內存空間一直存在,伴隨仿真結束。配合單例模式使用,則是全局唯一類的實例,可以被當作全局變量使用。2.相比靜態變量,靜態類可以封裝更多內容,充當資源容器的角色。

所以UVM中對全局的資源管理,都是通過靜態類實現的。

uvm_pool

uvm_pool#(type KEY=int, T=uvm_void)是一個參數化的類,相當于SV中的聯合數組。參數KEY是聯合數組的索引,參數T是聯合數組存儲的變量類型。uvm_pool封裝了原有聯合數組的操作方法,供訪問內部的聯合數組pool。m_global_pool是uvm_pool #(KEY, T)類型的靜態類,通過靜態方法get_global_pool可以獲得唯一的實例。uvm_queue #(T)和uvm_pool#(type KEY=int, T=uvm_void)類似,實現一個class-based dynamic queue.

# uvm_pool.svh

class uvm_pool #(type KEY=int, T=uvm_void) extends uvm_object;

  const static string type_name = "uvm_pool";

  typedef uvm_pool #(KEY,T) this_type;

  static protected this_type m_global_pool;
  protected T pool[KEY];

  // Function: new
  // Creates a new pool with the given ~name~.
  function new (string name="");
    super.new(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("pool");
    return m_global_pool;
  endfunction

  // Function: get_global
  // Returns the specified item instance from the global item pool. 
  static function T get_global (KEY key);
    this_type gpool;
    gpool = get_global_pool(); 
    return gpool.get(key);
  endfunction
  // Function: get
  // Returns the item with the given ~key~.
  // If no item exists by that key, a new item is created with that key
  // and returned.
  virtual function T get (KEY key);
    if (!pool.exists(key)) begin
      T default_value;
      pool[key] = default_value;
    end
    return pool[key];
  endfunction

  virtual function void add (KEY key, T item);
    pool[key] = item;
  endfunction

  virtual function int num ();
    return pool.num();
  endfunction

......
...... 
......
endclass

uvm_event_pool

uvm_object_string_pool的KEY是string類型。uvm_event_pool由uvm_object_string_pool #(uvm_event)聲明,KEY是string類型,T是uvm_event類型。uvm_event是sv中event的class warpper,內建了很多方法。

# uvm_pool.svh

class uvm_object_string_pool #(type T=uvm_object) extends uvm_pool #(string,T);
......
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.svh

//------------------------------------------------------------------------------
// CLASS: uvm_event
// The uvm_event class is a wrapper class around the SystemVerilog event
// construct.  It provides some additional services such as setting callbacks
// and maintaining the number of waiters.
//------------------------------------------------------------------------------
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 new (string name="");
    super.new(name);
  endfunction  
......
......
......
  virtual task wait_on (bit delta=0);
  virtual task wait_off (bit delta=0);
  virtual task wait_trigger ();
  virtual task wait_ptrigger ();
  virtual task wait_trigger_data (output uvm_object data);
  virtual task wait_ptrigger_data (output uvm_object data);
  virtual function void trigger (uvm_object data=null);
  virtual function uvm_object get_trigger_data ();
  virtual function time get_trigger_time ();
  virtual function void add_callback (uvm_event_callback cb, bit append=1);
  virtual function int get_num_waiters ();
......
endclass : uvm_event

使用

uvm_event_pool作為全局唯一的uvm_evnet的資源池,可以在不同component中調用,實現事件的同步功能。比如sequence和scoreboard需要通過event來握手:

# event_sequence.sv
class event_sequence extends uvm_sequence;
    ......
    uvm_event_pool events_pool;
    uvm_event sync_e;
    ......
    function new (string name = "event_sequence");
        events_pool = uvm_event_pool::get_global_pool();
        sync_e = events_pool.get("sync_e");
        // 也可以直接調用 sync_e = uvm_event_pool::get_global("sync_e");
    endfunction
    ......
    virtual task body();
    ......
        sync_e.trigger();
    ......
    endtask
endclass

# event_scb.sv
class event_scb extends uvm_scoreboard;
    ......
    uvm_event_pool events_pool;
    uvm_event sync_e;
    ......
    function new (string name = "event_sequence");
        events_pool = uvm_event_pool::get_global_pool();
        sync_e = events_pool.get("sync_e");
    endfunction
    ......
    virtual task wait_sync_e();
    ......
        sync_e.wait_trigger();
    ......
    endtask
endclass

無論是uvm_component還是uvm_object,是否在同一個package中,都可以通過uvm_evnet_pool::get_global_pool()獲得全局唯一的uvm_event資源池。上述的uvm_event并不需要new(),因為調用get()函數時會自動創建:

# uvm_object_string_pool #(uvm_event)

  // 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

uvm_event不僅可以用于event同步,也可以傳遞一些簡單的數據。提供了兩個方法:wait_trigger_data (output uvm_object data)trigger (uvm_object data),可以傳遞uvm_object類型的數據。也可以add_callback加入回調函數。uvm_event[3]uvm中還提供了uvm_barrier用于多個組件之間的同步,uvm_barrier_pool存放所有的uvm_barrier。

uvm_config_db

結構

uvm_resource#(type T): 各類資源(*scalar objectsclass handlesqueueslistsvirtual interfaces等*)的一個wrapper,內部成員變量val是一個type T類型的句柄,通過調用write函數,將val指向資源的實例( *!!! 對于class handlesvirtual interfaces,val看作句柄指向實例;對于queueslists等,val是被直接賦值 !!!*)。set函數將uvm_resource加入全局資源池uvm_resources。

class uvm_resource #(type T=int) extends uvm_resource_base;
  typedef uvm_resource#(T) this_type;
  // singleton handle that represents the type of this resource
  static this_type my_type = get_type();
  // Can't be rand since things like rand strings are not legal.
  protected T val;
  ......
  // Function: get_type
  // Static function that returns the static type handle.  The return
  // type is this_type, which is the type of the parameterized class.
  static function this_type get_type();
    if(my_type == null)
      my_type = new();
    return my_type;
  endfunction
  ......
  // Function: set
  // Simply put this resource into the global resource pool
  function void set();
    uvm_resource_pool rp = uvm_resource_pool::get();
    rp.set(this);
  endfunction
  ......
  // Function: write
  // Modify the object stored in this resource container.  If the
  // resource is read-only then issue an error message and return
  // without modifying the object in the container.  If the resource is
  // not read-only and an ~accessor~ object has been supplied then also
  // update the accessor record.  Lastly, replace the object value in
  // the container with the value supplied as the argument, ~t~, and
  // release any processes blocked on
  // .  If the value to be written is
  // the same as the value already present in the resource then the
  // write is not done.  That also means that the accessor record is not
  // updated and the modified bit is not set.
  function void write(T t, uvm_object accessor = null);
    if(is_read_only()) begin
      uvm_report_error("resource", $sformatf("resource %s is read only -- cannot modify", get_name()));
      return;
    end
    // Set the modified bit and record the transaction only if the value
    // has actually changed.
    if(val == t)
      return;
    record_write_access(accessor);
    // set the value and set the dirty bit
    val = t;
    modified = 1;
  endfunction
  ......

uvm_resource_pool: 存放所有的uvm_resource, 全局唯一的實例uvm_resources。uvm_resource_pool::get()得到uvm_resources。(注意:這里的new函數使用了local修飾,而uvm_event_pool中的new沒有被local修飾。所以uvm_resource_pool和uvm_root擁有真正的全局唯一實例,而uvm_event_pool可以在外部手動new創建多個實例。

rtab[string]ttab[uvm_resource_base]分別以nametype為索引存放uvm_resource。

//----------------------------------------------------------------------
// Class: uvm_resource_pool
//
// The global (singleton) resource database.
//
// Each resource is stored both by primary name and by type handle.  The
// resource pool contains two associative arrays, one with name as the
// key and one with the type handle as the key.  Each associative array
// contains a queue of resources.  Each resource has a regular
// expression that represents the set of scopes over with it is visible.
//
//|  +------+------------+                          +------------+------+
//|  | name | rsrc queue |                          | rsrc queue | type |
//|  +------+------------+                          +------------+------+
//|  |      |            |                          |            |      |
//|  +------+------------+                  +-+-+   +------------+------+
//|  |      |            |                  | | |<--+---*        |  T   |
//|  +------+------------+   +-+-+          +-+-+   +------------+------+
//|  |  A   |        *---+-->| | |           |      |            |      |
//|  +------+------------+   +-+-+           |      +------------+------+
//|  |      |            |      |            |      |            |      |
//|  +------+------------+      +-------+  +-+      +------------+------+
//|  |      |            |              |  |        |            |      |
//|  +------+------------+              |  |        +------------+------+
//|  |      |            |              V  V        |            |      |
//|  +------+------------+            +------+      +------------+------+
//|  |      |            |            | rsrc |      |            |      |
//|  +------+------------+            +------+      +------------+------+
//
// The above diagrams illustrates how a resource whose name is A and
// type is T is stored in the pool.  The pool contains an entry in the
// type map for type T and an entry in the name map for name A.  The
// queues in each of the arrays each contain an entry for the resource A
// whose type is T.  The name map can contain in its queue other
// resources whose name is A which may or may not have the same type as
// our resource A.  Similarly, the type map can contain in its queue
// other resources whose type is T and whose name may or may not be A.
//
// Resources are added to the pool by calling ; they are retrieved
// from the pool by calling  or .  When an object 
// creates a new resource and calls  the resource is made available to be
// retrieved by other objects outside of itsef; an object gets a
// resource when it wants to access a resource not currently available
// in its scope.
//----------------------------------------------------------------------
// static global resource pool handle
//----------------------------------------------------------------------
const uvm_resource_pool uvm_resources = uvm_resource_pool::get();

class uvm_resource_pool;

  static bit m_has_wildcard_names;
  static local uvm_resource_pool rp = get();

  uvm_resource_types::rsrc_q_t rtab [string];
  uvm_resource_types::rsrc_q_t ttab [uvm_resource_base];
 ......
  local function new();
  endfunction
  // Function: get
  //
  // Returns the singleton handle to the resource pool
  static function uvm_resource_pool get();
    if(rp == null)
      rp = new();
    return rp;
  endfunction
  ......
  // Function: get_by_name
  //
  // Lookup a resource by ~name~, ~scope~, and ~type_handle~.  Whether
  // the get succeeds or fails, save a record of the get attempt.  The
  // ~rpterr~ flag indicates whether to report errors or not.
  // Essentially, it serves as a verbose flag.  If set then the spell
  // checker will be invoked and warnings about multiple resources will
  // be produced.

  function uvm_resource_base get_by_name(string scope = "",
                                         string name,
                                         uvm_resource_base type_handle,
                                         bit rpterr = 1);

  // Function: get_by_type
  //
  // Lookup a resource by ~type_handle~ and ~scope~.  Insert a record into
  // the get history list whether or not the get succeeded.

  function uvm_resource_base get_by_type(string scope = "",
                                         uvm_resource_base type_handle);
  ......
......
endclass

uvm_resource_db#(type T):訪問資源池的接口,內部都是static function。

uvm_config_db#(type T):繼承于uvm_resource_db#(type T),進行了一些功能擴展。內部都是static function。

接下來重點看一下uvm_config_db傳入的4個參數:

cntxt:uvm_component類型,context上下文的含義,由cntxt可以確定資源的優先級,對同一個資源set,從UVM樹頂層往下,優先級依次降低。cntxt = null時,為uvm_root::get(),優先級最高。

inst_name:string類型,通過{cntxt.get_full_name(), ".", inst_name}組成的字符串設置資源的scope。內部調用DPI,支持通配符。只有get中的scope可以和set中的scope匹配上,才可以正常訪問資源。

field_name: 資源名,scope內的資源。也支持通配符,一般setget設置相同即可。

value:type T類型,資源的類型。get中的是inout,調用get函數先給value賦值,結束后再將val傳出,但是get中并沒有處理傳入value的代碼,不知道為什么這樣用。

class uvm_config_db#(type T=int) extends uvm_resource_db#(T);
......
  static uvm_pool#(string,uvm_resource#(T)) m_rsc[uvm_component];
......

   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;

    if(cntxt == null) 
      cntxt = uvm_root::get();
    if(inst_name == "") 
      inst_name = cntxt.get_full_name();
    else if(cntxt.get_full_name() != "") 
      inst_name = {cntxt.get_full_name(), ".", inst_name};

   ......

    value = r.read(cntxt);

    return 1;
  endfunction

   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;

    //take care of random stability during allocation
    process p = process::self();
    string rstate = p.get_randstate();
    top = uvm_root::get();
    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};

    ......
    r.write(value, cntxt);
    ......
  endfunction

有一種特殊的情況,就是cntxt = null, 而uvm_root::get().get_full_name()為空字符串。其他情況都是以uvm_test_top為開頭設置scope。

總結如下:test中set, driver中get, 如果socpematch,則可以get到set的資源。| code | scope |match | |:--|:--|--| |uvm_config_db#(int):: set(this,"env.agt.drv","val",10)|"uvm_test_top.env.agt.drv"| |uvm_config_db#(int):: get(this,"","val",value)|"uvm_test_top.env.agt.drv"| YES | |uvm_config_db#(int):: set(this,"env.agt*","val",10)|"uvm_test_top.env.agt*"| |uvm_config_db#(int):: get(null,"uvm_test_top.env.agt.drv_error_spell","val",value)|"uvm_test_top. env.agt.drv_error_spell"| YES | |uvm_config_db#(int):: set(null,"","val",10)|""|uvm_config_db#(int):: get(null,"","val",value)|""| YES | |uvm_config_db#(int):: set(this,"env.agt","val",10)|"uvm_test_top.env.agt"|uvm_config_db#(int):: get(get_parent(),"","val",value)|"uvm_test_top.agt"| YES | |uvm_config_db#(int):: set(this,"env.agt.drv","val",10)|"uvm_test_top.env.agt.drv"|uvm_config_db#(int):: get(null,"","val",value)|""| NO | |uvm_config_db#(int):: set(this,"*drv","val",10)|"uvm_test_top.*drv"|uvm_config_db#(int):: get(null,get_full_name(),"val",value)|"uvm_test_top.env.agt.drv"| YES 由于第三個參數是string類型,書寫錯誤時,編譯不會報錯,仿真如果不加上assert判斷,也無法察覺錯誤,不利于debug。不過UVM中提供了check_config_usageprint_config函數協助debug。

Verdi也提供了GUI界面,可以看到setget的具體內容,方便debug:91940d38-32b8-11ee-9e74-dac502259ad0.png

使用

uvm_config_db機制本質就是在一個地方創建資源,通過set以uvm_resource的形式存儲到uvm_resource_pool上。然后在另一個地方,通過get獲得之前創建的資源。

uvm_config_db機制還為資源加上了scope限制資源的訪問,保證數據安全;precedence設置優先級;override資源重寫;record記錄資源訪問歷史用于debug等功能。

這里的資源可以是scalar objectsclass handlesqueueslistsvirtual interfaces等。

隊列,數組類型

對于隊列,數組的傳遞,int val_q[$]直接通過uvm_config_db#(int) :: set(this, "env.i_agt.drv","val_q",val_q);的方式會編譯報錯,因為uvm_config_db#(type T=int)中type是int類型,而不是隊列類型。需要typedef int t_q[$] ;定義隊列類型。t_q val_q;uvm_config_db#(t_q) :: set(this, "env.i_agt.drv","val_q",val_q);

還有另一種方式,通過class封裝隊列(uvm已提供了uvm_queue#(type T)。這種方式的好處是,隊列在一端改變,另一段也可以看到隊列的修改,因為變量對資源的訪問是通過句柄的形式,指向同一處資源。而直接傳遞隊列,一端修改,另一端看不到,因為兩端的隊列是各自class scope中的兩份不同的數據,只有再執行一次setget操作才會獲得隊列的新內容。

sequence中的資源訪問

UVM中sequence不屬uvm_component,存在固定的生命周期,對資源的訪問,分為直接和間接兩種類型。以reg_model為例,reg_model在env中create, sequence通過reg_model訪問寄存器

總結如下5種方式:

1.sequence沒有出現在樹形結構中,難以確定路徑參數,可以通過setnull, ""設定全局scope,這樣sequence在哪里都可以訪問資源。注意:sequence沒有phase,get可以放在pre_bodybodypre_randomizepre_start中,只要在調用reg_model之前get被調用即可。

# env
top_reg_model m_regmodel;
m_regmodel = top_reg_model::create("m_regmodel");
uvm_config_db #(top_reg_model)::set(null, "","reg_model",m_regmodel);

# seq
top_reg_model m_regmodel;
uvm_config_db #(top_reg_model)::get(null, "","reg_model",m_regmodel);

// 為什么說 null, ""的組合是全局scope呢?
// TODO

1.sequence的路徑可以通過get_full_name()獲得。

# env
top_reg_model m_regmodel;
m_regmodel = top_reg_model::create("m_regmodel");
uvm_config_db #(top_reg_model)::set(this, " agt.sqr.* ","reg_model",m_regmodel);

# seq
top_reg_model m_regmodel;
uvm_config_db #(top_reg_model)::get(null, get_full_name(),"reg_model",m_regmodel);

1.sequence雖然不在樹形結構上,但是其內部成員變量m_sequencer在樹形結構上,可以通過m_sequencer間接訪問資源。

# env
top_reg_model m_regmodel;
m_regmodel = top_reg_model::create("m_regmodel");
uvm_config_db #(top_reg_model)::set(this, " agt.sqr","reg_model",m_regmodel);

# seq
top_reg_model m_regmodel;
uvm_config_db #(top_reg_model)::get(m_sequencer, "","reg_model",m_regmodel);

1.直接通過p_sequener訪問資源。sequencer中get獲得資源,sequence中調用p_sequencer.m_regmodel訪問資源。2.直接賦值,在test中例化sequence時,seq.m_regmodel = m_regmodel。也可以封裝到sequence中的function。

#seq
virtual function set_regmodel(top_reg_model m_regmodel);
    this.m_regmodel = m_regmodel;
endfunction

當然也可以封裝到test中的function:

#test
virtual function set_regmodel(sequence_baes seq);
    seq.m_regmodel = m_regmodel;
endfunction

上述方法,本質都是一樣的,將m_model句柄指向在env中創建的top_reg_model實例。

自定義資源池

我們也可以模仿uvm_event_pooluvm_resource_pool的方式,自定義一個資源池。

不使用uvm_config_db,自定義一個interface pool,示例如下(UVM實戰 /ch10/section10.6/10.6.2):

# interface_pool

class if_object extends uvm_object;

   `uvm_object_utils(if_object)
   function new(string name = "if_object");
      super.new(name);
   endfunction

   static if_object me;

   static function if_object get();
      if(me == null) begin
         me = new("me");
      end
      return me;
   endfunction

   virtual my_if input_vif0;
   virtual my_if output_vif0;
   virtual my_if input_vif1;
   virtual my_if output_vif1;
endclass

# top_tb.sv 
module top_tb;
......
my_if input_if0(clk, rst_n);
my_if input_if1(clk, rst_n);
my_if output_if0(clk, rst_n);
my_if output_if1(clk, rst_n);

......
initial begin
   if_object if_obj; 
   if_obj = if_object::get();
   if_obj.input_vif0 = input_if0;
   if_obj.input_vif1 = input_if1;
   if_obj.output_vif0 = output_if0;
   if_obj.output_vif1 = output_if1;
end
endmodule

# base_test.sv
class base_test extends uvm_test;

   my_env         env0;
   my_env         env1;
   my_vsqr        v_sqr;   

   function new(string name = "base_test", uvm_component parent = null);
      super.new(name,parent);
   endfunction

   extern virtual function void build_phase(uvm_phase phase);
   extern virtual function void connect_phase(uvm_phase phase);
   extern virtual function void report_phase(uvm_phase phase);
   `uvm_component_utils(base_test)
endclass

......

function void base_test::connect_phase(uvm_phase phase);
   if_object if_obj; 
   if_obj = if_object::get();
   v_sqr.p_sqr0 = env0.i_agt.sqr;
   v_sqr.p_sqr1 = env1.i_agt.sqr;
   env0.i_agt.drv.vif = if_obj.input_vif0;
   env0.i_agt.mon.vif = if_obj.input_vif0;
   env0.o_agt.mon.vif = if_obj.output_vif0;
   env1.i_agt.drv.vif = if_obj.input_vif1;
   env1.i_agt.mon.vif = if_obj.input_vif1;
   env1.o_agt.mon.vif = if_obj.output_vif1;
endfunction

平臺中所有使用uvm_config_db的地方都可以通過這種方式替代,當然并不建議這樣使用,uvm_config_db提供了更豐富的功能。這種方式的一個優點是編寫錯誤可以在編譯階段發現,而uvm_config_db中字符串錯誤不容易發現。

wait_modified

uvm_config_db不僅可以共享資源,也可以像uvm_event那樣,用于事件的同步,可以通過wait_modified實現。

drv0_seq在get之前,case0_vseq中必須先set,否則wait_modified會一直阻塞。因為wait_modified中調用@waiter.trigger,trigger是event類型;在set的最后,->w.trigger會觸發該event。平臺中所有的等待事件都放在了m_waiters[string]中,其中的索引sting對應getset函數中第三個參數field_name。

class drv0_seq extends uvm_sequence #(my_transaction);
   ......
      virtual task body();
      bit send_en = 1;
      fork
         while(1) begin
            uvm_config_db#(bit)::wait_modified(null, get_full_name(), "send_en");
            void'(uvm_config_db#(bit)::get(null, get_full_name, "send_en", send_en)); 
            `uvm_info("drv0_seq", $sformatf("send_en value modified, the new value is %0d", send_en), UVM_LOW)
         end
      join_none
      repeat (10) begin
         `uvm_do(m_trans)
      end
   endtask
endclass

class case0_vseq extends uvm_sequence;
   ......
   virtual task body();
      my_transaction tr;
      drv0_seq seq0;
      drv1_seq seq1;
      if(starting_phase != null) 
         starting_phase.raise_objection(this);
      fork
         `uvm_do_on(seq0, p_sequencer.p_sqr0);
         `uvm_do_on(seq1, p_sequencer.p_sqr1);
         begin
            #10000;
            uvm_config_db#(bit)::set(uvm_root::get(), "uvm_test_top.v_sqr.*", "send_en", 0);
            #10000;
            uvm_config_db#(bit)::set(uvm_root::get(), "uvm_test_top.v_sqr.*", "send_en", 1);
         end
      join 
      #100;
      if(starting_phase != null) 
         starting_phase.drop_objection(this);
   endtask
endclass

class m_uvm_waiter;
  string inst_name;
  string field_name;
  event trigger;
  function new (string inst_name, string field_name);
    this.inst_name = inst_name;
    this.field_name = field_name;
  endfunction
endclass

class uvm_config_db#(type T=int) extends uvm_resource_db#(T);
......
  // Internal waiter list for wait_modified
  static local uvm_queue#(m_uvm_waiter) m_waiters[string];
......
  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;

    if(cntxt == null)
      cntxt = uvm_root::get();
    if(cntxt != uvm_root::get()) 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=0; iw.trigger;  
      end
    end

   ......
  endfunction

UVM_REGEX_NO_DPI

大量 ”濫用“uvm_config_db配置訪問資源,會降低仿真速度。db:set/get()會自動擴展正則匹配,uvm_re_match()調用DPI的方式,增加仿真內核切換時間,每一次get()需要遍歷set()的所有資源。而且不是簡單的線性降低仿真速度。可以優化原有代碼,減少set/get調用;使用UVM_REGEX_NO_DPI禁用正則匹配,僅僅使用*?+這種簡單的通配符。91c8706e-32b8-11ee-9e74-dac502259ad0.png

如果在SoC級別的平臺,發現build_phase占用太多時間,可以參考SNUG 2018 Auditing the UVM Resource Database[4]進行優化,對源碼進行相應修改,更好的Auditing平臺的資源配置。

審核編輯:湯梓紅
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • Verilog
    +關注

    關注

    28

    文章

    1343

    瀏覽量

    109983
  • System
    +關注

    關注

    0

    文章

    165

    瀏覽量

    36885
  • 函數
    +關注

    關注

    3

    文章

    4304

    瀏覽量

    62429
  • UVM
    UVM
    +關注

    關注

    0

    文章

    181

    瀏覽量

    19138
  • static
    +關注

    關注

    0

    文章

    33

    瀏覽量

    10356

原文標題:UVM設計模式 (三) 靜態類、資源管理、uvm_event、uvm_*_pool、uvm_config_db

文章出處:【微信號:數字芯片設計工程師,微信公眾號:數字芯片設計工程師】歡迎添加關注!文章轉載請注明出處。

收藏 人收藏

    評論

    相關推薦

    什么是uvmuvm的特點有哪些呢

    大家好,我是哥,上章內容我們介紹什么是uvmuvm的特點以及uvm為用戶提供了哪些資源?本章內容我們來看
    發表于 02-14 06:46

    談談UVM中的uvm_info打印

    uvm_report_info(xxx)函數調用當前m_rh的report(xxx)函數來打印message。但在m_rh.report(xxx)內部其實是調用uvm_report_server class來打印消息的。uvm
    發表于 03-17 16:41

    基于UVM的CPU卡芯片驗證平臺

    基于UVM的CPU卡芯片驗證平臺_錢
    發表于 01-07 19:00 ?4次下載

    詳解藍牙模塊原理與結構

    電子發燒友網站提供《詳解藍牙模塊原理與結構.pdf》資料免費下載
    發表于 11-26 16:40 ?94次下載

    詳解精密封裝技術

    詳解精密封裝技術
    的頭像 發表于 12-30 15:41 ?1625次閱讀

    詳解分立元件門電路

    詳解分立元件門電路
    的頭像 發表于 03-27 17:44 ?2983次閱讀
    <b class='flag-5'>一</b><b class='flag-5'>文</b><b class='flag-5'>詳解</b>分立元件門電路

    UVM學習筆記(

    driver應該派生自uvm_driver,而uvm_driver派生自uvm_component。
    的頭像 發表于 05-26 14:38 ?1334次閱讀
    <b class='flag-5'>UVM</b>學習筆記(<b class='flag-5'>一</b>)

    行為型設計模式UVM中的應用

    接下來介紹行為型設計模式UVM中的應用。
    的頭像 發表于 08-09 14:01 ?662次閱讀
    行為型設計<b class='flag-5'>模式</b>在<b class='flag-5'>UVM</b>中的應用

    迭代模式UVM中的應用有哪些

    行為型設計模式數量較多,上篇介紹了模板模式和策略模式,下面對迭代模式進行介紹,挖掘其在UVM
    的頭像 發表于 08-14 17:15 ?584次閱讀
    迭代<b class='flag-5'>模式</b>在<b class='flag-5'>UVM</b>中的應用有哪些

    詳解pcb和smt的區別

    詳解pcb和smt的區別
    的頭像 發表于 10-08 09:31 ?3201次閱讀

    詳解pcb地孔的作用

    詳解pcb地孔的作用
    的頭像 發表于 10-30 16:02 ?1561次閱讀

    詳解pcb不良分析

    詳解pcb不良分析
    的頭像 發表于 11-29 17:12 ?1128次閱讀

    詳解pcb的msl等級

    詳解pcb的msl等級
    的頭像 發表于 12-13 16:52 ?9092次閱讀

    詳解pcb微帶線設計

    詳解pcb微帶線設計
    的頭像 發表于 12-14 10:38 ?2854次閱讀

    詳解pcb的組成和作用

    詳解pcb的組成和作用
    的頭像 發表于 12-18 10:48 ?1441次閱讀