跳转至

输入查询内容

    本页内容

    resource_db::get_by_name 在 2.0 可能选中较低优先级资源(S11)

    已复现的目标库问题

    目标库优先级选择问题已复现;查询替代在限定场景通过。

    影响范围

    同名同类型有多个资源,且代码使用 resource_db/resource_pool 按名查询时受影响;不能据此推断普通 config_db::get 同样有问题。

    具体差异

    对同名同类型、scope 均命中的两资源,优先级为 9999 与 4321 时,VCS 1.2 的 uvm_resource_db#(int)::get_by_name() 返回 9999 对应对象,VCS 2.0 返回 4321 对应对象。源码中 sort_by_precedence_q() 按关联数组索引升序重建队列,而调用者取首个命中。lookup_name() 后显式调用 get_highest_precedence() 的同一组实测仍选中 9999。

    修改方案

    审计直接使用 resource_db / resource_pool 按名查询并依赖优先级的代码;可使用 lookup_name(scope, name, type_handle)get_highest_precedence() 并检查 null、转换类型。该替代不复刻 DB 的全部审计记录,应在封装边界采用。不要仅因 config_db 内部使用资源池就推断普通 config_db::get 同样受影响。

    兼容措施与范围:兼容措施不修复按名查询的优先级选择;显式查找与选最高项仅覆盖所述查询边界,审计副作用另验。

    已知限制KI-001

    迁移后验证

    构造低/高优先级竞争资源,检查选中值;显式 lookup_name 后 get_highest_precedence 应选择预期最高项,并检查 null、cast 和审计副作用。

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

    已有实测与复现

    补充查阅

    扫描定位与记录结果

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

    • S11 · 启发式:resource_db 按名查询可能选择较低优先级资源。 按括号配对识别 resource_db 静态查询,支持嵌套类型参数;多个同名资源的实际优先级仍需验证。
    uv run tools/uvm_migration_scan.py <SoC代码目录> --rules S11
    

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

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

    源码与标准依据

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

    验证状态:已对跑复现,见 tests/uvm_review/policy_probe.sv;证据摘要和观察值已归档于 docs/review/evidence.md

    VCS 内置 UVM-1.2uvm_resource.svh:1010(get_by_name 经 get_highest_precedence 取最高优先级)

    VCS 内置 uvm-ieee-2020-2.0uvm_resource_pool.svh:617(sort_by_precedence_q)、uvm_resource_pool.svh:681(get_by_name 调排序后取首个 scope 命中);uvm_resource_db_implementation.svh:245(委托)

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

    src/vcs-uvm-1.2/base/uvm_resource.svh
          push_get_record(name, scope, null);
          return null;
        end
    
        rsrc = get_highest_precedence(q);
        push_get_record(name, scope, rsrc);
        return rsrc;
    
      endfunction
    
    
      // Function: lookup_type
      //
      // Lookup resources by type. Return a queue of resources that match
      // the ~type_handle~ and ~scope~.  If no resources match then the returned
      // queue is empty.
    
      function uvm_resource_types::rsrc_q_t lookup_type(string scope = "",
                                                        uvm_resource_base type_handle);
    

    完整源码 · SHA256:6dd457f7586da01b713fb94bdb5472e7fdb3e741219398f87f341c21f5a0f8af

    src/vcs-uvm-ieee-2020-2.0/base/uvm_resource_pool.svh
      //
      // Sorts a list of resources of resources in a standard SV
      // queue instead of a uvm_queue.
      static function void sort_by_precedence_q(ref uvm_resource_types::rsrc_sv_q_t q);
        uvm_resource_types::rsrc_sv_q_t all[int];
        uvm_resource_base r;
        int unsigned prec;
    
        for(int i=0; i<q.size(); ++i) begin
          r = q[i];
          prec = (r != null) ? r.precedence: 0;
          all[prec].push_back(r);
        end
        q.delete();
        foreach(all[iter]) begin
          q = {q, all[iter]};
        end
      endfunction // sort_by_precedence_q    
    

    src/vcs-uvm-ieee-2020-2.0/base/uvm_resource_pool.svh
        end
    
        // Sort the resource queue
        sort_by_precedence_q(svq);
    
        // Return the first scope match
        foreach (svq[iter]) begin
          rsrc = svq[iter];
          rsrcs = (rsrc != null) ? rsrc.get_scope(): "";
          if (uvm_is_match(rsrcs, scope))
            break;
          else
            rsrc = null;
        end
    
        push_get_record(name, scope, rsrc);
        return rsrc;
    
      endfunction
    

    完整源码 · SHA256:e617ba32a3b09e84913a841080b708ccbb69943976d2e48f3a92c72bf5c99806

    src/vcs-uvm-ieee-2020-2.0/base/uvm_resource_db_implementation.svh
          string msg;
    
          rsrc_base = rp.get_by_name(scope, name, rsrc_t::get_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);
              `uvm_warning("RSRCTYPE", msg)
            end
            return null;
          end
    
          return rsrc;
        endfunction : get_by_name
    
    
        // Function: set_default
    

    完整源码 · SHA256:1723734791fc6fa7e934c3210294a4e45425ce5ee7ea5b110a46a14985484ced

    术语解释 · 兼容配置

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

    版本适用范围