跳转至

输入查询内容

    本页内容

    uvm_resource#(T) 自管理接口 set() / set_override() / get_by_name() / get_by_type() 被删除

    影响范围

    直接调用资源对象的 set/set_override 或静态查询时需要修改;常规 config_db 调用按 M05-003 核对。

    具体差异

    IEEE 1800.2-2020 中 uvm_resource#(T) 只保留 read/write 类型安全访问接口,资源的入池/置顶/按名按型查找职责全部上移到 uvm_resource_pooluvm_resource_db。1.2 中的 rsrc.set()rsrc.set_override()uvm_resource#(T)::get_by_name(scope,name,rpterr)uvm_resource#(T)::get_by_type(scope,type_handle) 在 2.0 中编译即报错。附带影响:1.2 供派生资源子类型使用的 `UVM_RESOURCE_GET_FCNS 宏在 2.0 仍有定义(uvm_resource_specializations.svh:48)但其展开体引用了已删除的静态方法,用户一旦使用该宏即编译失败;内置 uvm_int_rsrc/uvm_string_rsrc 等特化类 2.0 已不再使用它。

    修改方案

    • rsrc.set()uvm_resource_pool::get().set_scope(rsrc, scope)
    • rsrc.set_override(ovr):默认 name+type 双置顶用 rp.set_override(rsrc, scope);仅 name/type 时分别用 set_name_override / set_type_override;ovr=0 用 set_scope。保留原掩码意图,不能无条件替换为双置顶。
    • uvm_resource#(T)::get_by_name(scope, name, rpterr)uvm_resource_db#(T)::get_by_name(scope, name, rpterr)
    • uvm_resource#(T)::get_by_type(scope, type_handle):仅在 type_handle 就是 T 的类型句柄时改用 uvm_resource_db#(T)::get_by_type(scope);动态类型句柄应保留 pool 查询和 cast/null 检查。
    • 自定义资源子类型中使用了 `UVM_RESOURCE_GET_FCNS 的,删除该宏调用,改用 uvm_resource_db/uvm_resource_pool 查询。

    下面的普通 uvm_resource#(int)env.agent 中发布 limit=42。旧版通过资源对象入池;目标改用 pool,构造函数的显式 scope 可以保留。声明和操作位于同一 initial 或 function 中,且先声明变量。

    1
    2
    3
    4
    5
    6
    // UVM 1.2
    uvm_resource#(int) r;
    r = new("limit", "env.agent");
    r.write(42);
    r.set();
    r.precedence = 2000;
    
    // UVM 2.0
    uvm_resource_pool rp = uvm_resource_pool::get();
    uvm_resource#(int) r, selected;
    r = new("limit", "env.agent");
    r.write(42);
    rp.set_scope(r, "env.agent");
    rp.set_precedence(r, 2000); // 特殊优先级在入池后设置
    selected = uvm_resource_db#(int)::get_by_name("env.agent", "limit");
    if (selected == null) `uvm_fatal("RESOURCE", "Missing resource")
    if (selected.read() != 42) `uvm_fatal("RESOURCE", "Unexpected value")
    selected = uvm_resource_db#(int)::get_by_type("env.agent");
    if (selected != r) `uvm_fatal("RESOURCE", "Unexpected resource")
    

    此处 scope 内只有一个 int 资源;get_by_type 不按名字筛选。同名同类型出现不同 precedence 的竞争资源后,直接 get_by_name 的目标实现风险见 M05-010,可按其边界使用下面的显式选择;此块是独立代码片段,拼接到前例时复用已有 rp/selected 声明:

    1
    2
    3
    4
    5
    6
    7
    8
    uvm_resource_types::rsrc_q_t candidates;
    uvm_resource_base winner;
    uvm_resource#(int) selected;
    uvm_resource_pool rp = uvm_resource_pool::get();
    candidates = rp.lookup_name("env.agent", "limit", uvm_resource#(int)::get_type());
    winner = rp.get_highest_precedence(candidates);
    if (winner == null) `uvm_fatal("RESOURCE", "Empty selection")
    if (!$cast(selected, winner)) `uvm_fatal("RESOURCE", "Unexpected resource type")
    

    Override 在资源入池时选择,一次注册使用一种入口;不要先 set_scope 再对同一资源重复入池。replacement 为尚未入池且已写好值的资源,原 name-only 意图对应:

    1
    2
    3
    4
    // UVM 1.2
    replacement.set_override(uvm_resource_types::NAME_OVERRIDE);
    // UVM 2.0
    rp.set_name_override(replacement, "override_case");
    

    上面两行是两版替换关系,不同时执行。Type-only 对应 set_type_override,name+type 对应 set_override。单侧 override 控制相同 precedence 时的索引顺序;需要特殊 precedence 时,在选定的入池调用之后设置。动态 type handle 或返回子类型的情况仍按上方映射处理。

    兼容措施与范围:资源对象的 set/set_override 和旧静态查询不再提供;pool/DB 替代仍须保留 scope、类型和 override 意图。

    迁移后验证

    按下方连续示例核对入池前不可查询、入池后对象身份和值、特殊 precedence 及 name/type 查询顺序;多 scope、多 type 和动态 type handle 按实际代码扩展检查。

    记录本条结果M05-001 · 状态与证据

    已有实测与复现

    resource_migration_probe 在两库均确认:入池前显式 scope 可匹配、数据库查不到该普通资源;入池后按名读回 42、按 type 得到同一对象,precedence 保持 2000。加入值 99、precedence 1000 的竞争项后,显式选最高项仍读回 42;相同 precedence 的 name-only override 按名得到 22,按 type 仍得到原值 11。实验不覆盖动态类型句柄、任意审计副作用或定制 coreservice

    补充查阅

    扫描定位与记录结果

    有扫描规则,覆盖部分可识别写法。脚本检查名称、参数和部分 FLAG 表达式,并对少数直接声明关联使用点;未做完整类型解析或预处理,行为结果仍需验证。

    • C7 · 启发式:uvm_resource#(T) 自管理接口删除(set/set_override/get_by_name/get_by_type/UVM_RESOURCE_GET_FCNS)。 覆盖静态查询、UVM_RESOURCE_GET_FCNS,以及调用处可见 resource 句柄的 set/set_override;支持标准包限定、嵌套特化、类成员后声明和可解析的 for 作用域,typedef、复杂层级路径与跨文件类型仍需核对。
    uv run tools/uvm_migration_scan.py <SoC代码目录> --rules C7
    

    核对命中对象及生效分支后,在条目清单记录修改与验证证据;扫描规则记录用于整理命中位置。

    扫描器下载、输入范围与报告说明

    源码与标准依据

    核查方式:源码与实测核对。实测仅覆盖本条所列场景。

    VCS 内置 UVM-1.2uvm_resource.svh:1496(set)、uvm_resource.svh:1511(set_override)、uvm_resource.svh:1527(get_by_name)、uvm_resource.svh:1559(get_by_type)

    VCS 内置 uvm-ieee-2020-2.0uvm_resource.svh:42(整个类已无这些方法,见 42–245 行);替代接口在 uvm_resource_pool.svh:208(set_scope)与 uvm_resource_db.svh:70

    标准依据:IEEE 1800.2-2020 §C.2.5(uvm_resource#(T) 仅提供 store/read/write 访问方法)、§C.3.2(uvm_resource_db)

    标为“源码标注”或未注明原文核对的条款仅作定位;具体库行为以源码和实测为准。

    引用代码(高亮为引用行);上方行号链接可直接定位。

    src/vcs-uvm-1.2/base/uvm_resource.svh
      //
      // 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: set_override
      //
      // Put a resource into the global resource pool as an override.  This
      // means it gets put at the head of the list and is searched before
      // other existing resources that occupy the same position in the name
      // map or the type map.  The default is to override both the name and
      // type maps.  However, using the ~override~ argument you can specify
      // that either the name map or type map is overridden.
    
      function void set_override(uvm_resource_types::override_t override = 2'b11);
        uvm_resource_pool rp = uvm_resource_pool::get();
        rp.set(this, override);
      endfunction
    
      // Function: get_by_name
      //
      // looks up a resource by ~name~ in the name map. The first resource
      // with the specified name, whose type is the current type, and is
      // visible in the specified ~scope~ is returned, if one exists.  The
      // ~rpterr~ flag indicates whether or not an error should be reported
      // if the search fails.  If ~rpterr~ is set to one then a failure
      // message is issued, including suggested spelling alternatives, based
      // on resource names that exist in the database, gathered by the spell
      // checker.
    
      static function this_type get_by_name(string scope,
                                            string name,
                                            bit rpterr = 1);
    
        uvm_resource_pool rp = uvm_resource_pool::get();
        uvm_resource_base rsrc_base;
        this_type rsrc;
        string msg;
    
        rsrc_base = rp.get_by_name(scope, name, my_type, rpterr);
        if(rsrc_base == null)
          return null;
    
        if(!$cast(rsrc, rsrc_base)) begin
          if(rpterr) begin
            $sformat(msg, "Resource with name %s in scope %s has incorrect type", name, scope);
    

    src/vcs-uvm-1.2/base/uvm_resource.svh
      // returned, if one exists. If there is no resource matching the specifications,
      // ~null~ is returned.
    
      static function this_type get_by_type(string scope = "",
                                            uvm_resource_base type_handle);
    
        uvm_resource_pool rp = uvm_resource_pool::get();
        uvm_resource_base rsrc_base;
        this_type rsrc;
        string msg;
    
        if(type_handle == null)
          return null;
    
        rsrc_base = rp.get_by_type(scope, type_handle);
        if(rsrc_base == null)
          return null;
    
        if(!$cast(rsrc, rsrc_base)) begin
    

    完整源码 · SHA256:6dd457f7586da01b713fb94bdb5472e7fdb3e741219398f87f341c21f5a0f8af

    src/vcs-uvm-ieee-2020-2.0/base/uvm_resource.svh
    //----------------------------------------------------------------------
    
    // @uvm-ieee 1800.2-2020 auto C.2.5.1
    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;
    
      // Because of uvm_resource#(T)::get_type, we can't use
      // the macros.  We need to do it all manually.
      typedef uvm_object_registry#(this_type) type_id;
      virtual function uvm_object_wrapper get_object_type();
        return type_id::get();
      endfunction : get_object_type
    

    完整源码 · SHA256:7ea343e2caccbe066149268c978931c0190db327ec6940dffc17dfff00d5fc90

    src/vcs-uvm-ieee-2020-2.0/base/uvm_resource_pool.svh
      endfunction
    
      // @uvm-ieee 1800.2-2020 auto C.2.4.3.1
      function void set_scope (uvm_resource_base rsrc, string scope); 
    
        table_q_t rq;
        string name;
        uvm_resource_base type_handle;
        uvm_resource_base r;
        int unsigned i;
    
        // If resource handle is ~null~ then there is nothing to do.
        if(rsrc == null) begin
          uvm_report_warning("NULLRASRC", "attempting to set scope of a null resource");
          return;
        end
    
        // Insert into the name map.  Resources with empty names are
        // anonymous resources and are not entered into the name map
    

    完整源码 · SHA256:e617ba32a3b09e84913a841080b708ccbb69943976d2e48f3a92c72bf5c99806

    src/vcs-uvm-ieee-2020-2.0/base/uvm_resource_db.svh
      // ~scope~.
    
      // @uvm-ieee 1800.2-2020 auto C.3.2.3.5
      static function rsrc_t get_by_type(string scope);
        uvm_resource_db_implementation_t #(T) imp;
        imp = uvm_resource_db_implementation_t #(T)::get_imp();
        return imp.get_by_type(scope);
      endfunction
    
      // function -- NODOCS -- get_by_name
      //
      // Imports a resource by ~name~.  The first argument is the current 
      // ~scope~ of the resource to be retrieved and the second argument is
      // the ~name~. The ~rpterr~ flag indicates whether or not to generate
      // a warning if no matching resource is found.
    
      // @uvm-ieee 1800.2-2020 auto C.3.2.3.4
      static function rsrc_t get_by_name(string scope,
                                         string name,
    

    完整源码 · SHA256:a3370f288fc28f50563187ad1cd6b7feb3925c06327df7b2eb03d940a66dc17f

    术语解释 · 兼容配置

    uvm_config_db#(T)::set 改进非空 context 下 /regex/ 拼接(M05-003) · resource_db::get_by_name 在 2.0 可能选中较低优先级资源(M05-010)

    返回Config DB / Resource DB · 迁移清单

    版本适用范围