跳转至

输入查询内容

    本页内容

    TLM2 socket 基类全部改为 virtual class

    影响范围

    直接构造 TLM2 socket_base。

    具体差异

    uvm_tlm_{b,nb}_{target,initiator}_socket_base 及 4 个 passthrough 基类由 class 改为 virtual class。直接 new() 这些基类(而非用 uvm_tlm_b_initiator_socket 等派生类)的代码在 2.0 下编译报错。正常 socket 用法不受影响。

    修改方案

    基类句柄可保留,构造对象改为对应具体 socket。阻塞发起端用 uvm_tlm_b_initiator_socket#(T),阻塞目标端用 uvm_tlm_b_target_socket#(IMP,T) 并提供实现 b_transport 的 IMP;非阻塞端使用 uvm_tlm_nb_initiator_socket / uvm_tlm_nb_target_socket 并实现相应方向的 nb_transport。透传端改用对应的 uvm_tlm_{b,nb}passthrough_socket。保留原 payload/phase 类型参数和连接方向,不要只删除 _base 后忽略新增的 IMP 参数。

    旧代码可能直接构造阻塞发起端基类:

    uvm_tlm_b_initiator_socket_base#() socket = new("socket", null);
    

    目标基类抽象化后,构造具体 uvm_tlm_b_initiator_socket。下面给出一组可运行的阻塞 initiator/target:默认 payload 为 uvm_tlm_generic_payload;目标 socket 的首个参数 payload_target 是提供 b_transport 的实现类 IMP

    class payload_target extends uvm_component;
      uvm_tlm_b_target_socket#(payload_target) socket;
      int calls;
      function new(string name, uvm_component parent);
        super.new(name, parent);
        socket = new("socket", this, this);
      endfunction
      virtual task b_transport(uvm_tlm_generic_payload tx, uvm_tlm_time delay);
        calls++;
        if (tx.get_command() == UVM_TLM_WRITE_COMMAND && tx.get_address() == 'h20)
          tx.set_response_status(UVM_TLM_OK_RESPONSE);
        else tx.set_response_status(UVM_TLM_ADDRESS_ERROR_RESPONSE);
      endtask
    endclass
    

    构造目标 socket 时,第二个 this 表示父组件,第三个 this 是执行 b_transport 的对象。连接方向为 initiator → target。对应的 test:

    class socket_test extends uvm_test;
      `uvm_component_utils(socket_test)
      uvm_tlm_b_initiator_socket#() socket;
      payload_target target;
      function new(string name, uvm_component parent); super.new(name, parent); endfunction
      function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        socket = new("socket", this);
        target = new("target", this);
      endfunction
      function void connect_phase(uvm_phase phase);
        socket.connect(target.socket);
      endfunction
      task run_phase(uvm_phase phase);
        uvm_tlm_generic_payload tx = new("tx");
        uvm_tlm_time delay = new("delay");
        phase.raise_objection(this);
        tx.set_command(UVM_TLM_WRITE_COMMAND);
        tx.set_address('h20);
        socket.b_transport(tx, delay);
        $display("REVIEW|response_ok|%0d", tx.get_response_status() == UVM_TLM_OK_RESPONSE);
        tx.set_address('h24);
        socket.b_transport(tx, delay);
        $display("REVIEW|bad_address_rejected|%0d", tx.get_response_status() == UVM_TLM_ADDRESS_ERROR_RESPONSE);
        $display("REVIEW|target_calls|%0d", target.calls);
        $display("REVIEW|done|1");
        phase.drop_objection(this);
      endtask
    endclass
    

    两类定义放在 include uvm_macros.svh、import uvm_pkg::* 之后,再由顶层 initial run_test("socket_test"); 启动。正常地址 'h20 返回成功,地址 'h24 返回地址错误;delay 使用两库都支持的 uvm_tlm_time 名称,本例没有延迟注记。非阻塞和 passthrough 仍按各自前向/后向接口实现,不能由这个阻塞示例推断其完整行为等价。

    兼容措施与范围:兼容措施不恢复 socket 基类的可构造性;使用匹配 IMP、payload/phase 类型和方向的具体 socket。

    迁移后验证

    构造具体 socket 并连接匹配接口,核对目标 IMP 收到的调用次数与响应;至少一笔成功和一笔错误返回。非阻塞或透传路径按实际方向与 phase 契约另验。

    记录本条结果M08-006 · 状态与证据

    已有实测与复现

    直接构造阻塞 initiator 基类在 1.2 编译通过,目标报 SV-ACCNBIsocket_migration_probe 的具体 socket 在两库均完成连接;目标收到两次调用,合法地址返回 UVM_TLM_OK_RESPONSE,非法地址返回 UVM_TLM_ADDRESS_ERROR_RESPONSE。实验验证 IMP 派发、连接方向和响应返回,不覆盖 payload 数据搬运、时间注记、非阻塞 phase 或背压。

    补充查阅

    扫描定位与记录结果

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

    • C25 · 启发式:直接构造目标抽象 backdoor、callback 或 socket 基类。 区分基类句柄声明和直接 new,支持先声明后赋值及嵌套类型参数;同文件按词法作用域和局部遮蔽关联,复杂路径、typedef、类外定义与预处理仍需人工核对。
    uv run tools/uvm_migration_scan.py <SoC代码目录> --rules C25
    

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

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

    源码与标准依据

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

    证据tests/uvm_review/socket_migration_probe.sv 的阻塞传输;tests/uvm_review/construction_compile_probe.sv 的 REVIEW_SOCKET 构造断点。

    1. 具体阻塞 target socket 用 IMP 提供 b_transport,构造时可显式传实现对象

    VCS 内置 UVM-1.2uvm_tlm2_sockets.svh:104–130 声明 IMP/T 参数并在构造时绑定实现对象。

    VCS 内置 uvm-ieee-2020-2.0uvm_tlm2_sockets.svh:107–128 保留相同 IMP 绑定方式;基类抽象化不要求重写正常具体 socket 流程。

    补充定位

    VCS 内置 UVM-1.2uvm_tlm2_sockets_base.svh:47(b_target)、uvm_tlm2_sockets_base.svh:65(b_initiator)、uvm_tlm2_sockets_base.svh:78uvm_tlm2_sockets_base.svh:100uvm_tlm2_sockets_base.svh:123uvm_tlm2_sockets_base.svh:148uvm_tlm2_sockets_base.svh:173uvm_tlm2_sockets_base.svh:187 共 8 个基类

    VCS 内置 uvm-ieee-2020-2.0uvm_tlm2_sockets_base.svh:49uvm_tlm2_sockets_base.svh:67uvm_tlm2_sockets_base.svh:80uvm_tlm2_sockets_base.svh:102uvm_tlm2_sockets_base.svh:125uvm_tlm2_sockets_base.svh:150uvm_tlm2_sockets_base.svh:175uvm_tlm2_sockets_base.svh:189

    标准依据:IEEE 1800.2-2020 §12.3.5(socket 类族)

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

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

    src/vcs-uvm-1.2/tlm2/uvm_tlm2_sockets_base.svh
    // IS-A forward imp; has no backward path except via the payload
    // contents.
    //----------------------------------------------------------------------
    class uvm_tlm_b_target_socket_base #(type T=uvm_tlm_generic_payload)
      extends uvm_port_base #(uvm_tlm_if #(T));
    
      function new (string name, uvm_component parent);
        super.new (name, parent, UVM_IMPLEMENTATION, 1, 1);
        m_if_mask = `UVM_TLM_B_MASK;
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_b_target_socket")
    
    endclass
    
    //----------------------------------------------------------------------
    // Class: uvm_tlm_b_initiator_socket_base
    //
    // IS-A forward port; has no backward path except via the payload
    // contents
    //----------------------------------------------------------------------
    class uvm_tlm_b_initiator_socket_base #(type T=uvm_tlm_generic_payload)
      extends uvm_port_base #(uvm_tlm_if #(T));
    
      `UVM_PORT_COMMON(`UVM_TLM_B_MASK, "uvm_tlm_b_initiator_socket")
      `UVM_TLM_B_TRANSPORT_IMP(this.m_if, T, t, delay)
    
    endclass
    
    //----------------------------------------------------------------------
    // Class: uvm_tlm_nb_target_socket_base
    //
    // IS-A forward imp; HAS-A backward port
    //----------------------------------------------------------------------
    class uvm_tlm_nb_target_socket_base #(type T=uvm_tlm_generic_payload,
                                       type P=uvm_tlm_phase_e)
      extends uvm_port_base #(uvm_tlm_if #(T,P));
    
      uvm_tlm_nb_transport_bw_port #(T,P) bw_port;
    
      function new (string name, uvm_component parent);
        super.new (name, parent, UVM_IMPLEMENTATION, 1, 1);
        m_if_mask = `UVM_TLM_NB_FW_MASK;
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_nb_target_socket")
    
      `UVM_TLM_NB_TRANSPORT_BW_IMP(bw_port, T, P, t, p, delay)
    
    endclass
    

    src/vcs-uvm-1.2/tlm2/uvm_tlm2_sockets_base.svh
    //
    // IS-A forward port; HAS-A backward imp
    //----------------------------------------------------------------------
    class uvm_tlm_nb_initiator_socket_base #(type T=uvm_tlm_generic_payload,
                                          type P=uvm_tlm_phase_e)
      extends uvm_port_base #(uvm_tlm_if #(T,P));
    
      function new (string name, uvm_component parent);
        super.new (name, parent, UVM_PORT, 1, 1);
        m_if_mask = `UVM_TLM_NB_FW_MASK;
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_nb_initiator_socket")
    
      `UVM_TLM_NB_TRANSPORT_FW_IMP(this.m_if, T, P, t, p, delay)
    
    endclass
    

    src/vcs-uvm-1.2/tlm2/uvm_tlm2_sockets_base.svh
    //
    // IS-A forward port; HAS-A backward export
    //----------------------------------------------------------------------
    class uvm_tlm_nb_passthrough_initiator_socket_base #(type T=uvm_tlm_generic_payload,
                                                      type P=uvm_tlm_phase_e)
      extends uvm_port_base #(uvm_tlm_if #(T,P));
    
      uvm_tlm_nb_transport_bw_export #(T,P) bw_export;
    
      function new (string name, uvm_component parent,
                    int min_size=1, int max_size=1);
        super.new (name, parent, UVM_PORT, min_size, max_size);
        m_if_mask = `UVM_TLM_NB_FW_MASK;
        bw_export = new("bw_export", get_comp());
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_nb_passthrough_initiator_socket")
    
      `UVM_TLM_NB_TRANSPORT_FW_IMP(this.m_if, T, P, t, p, delay)
    

    src/vcs-uvm-1.2/tlm2/uvm_tlm2_sockets_base.svh
    //
    // IS-A forward export; HAS-A backward port
    //----------------------------------------------------------------------
    class uvm_tlm_nb_passthrough_target_socket_base #(type T=uvm_tlm_generic_payload,
                                                   type P=uvm_tlm_phase_e)
      extends uvm_port_base #(uvm_tlm_if #(T,P));
    
      uvm_tlm_nb_transport_bw_port #(T,P) bw_port;
    
      function new (string name, uvm_component parent,
                    int min_size=1, int max_size=1);
        super.new (name, parent, UVM_EXPORT, min_size, max_size);
        m_if_mask = `UVM_TLM_NB_FW_MASK;
        bw_port = new("bw_port", get_comp());
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_nb_passthrough_target_socket")
    
      `UVM_TLM_NB_TRANSPORT_FW_IMP(this.m_if, T, P, t, p, delay)
    

    src/vcs-uvm-1.2/tlm2/uvm_tlm2_sockets_base.svh
    //
    // IS-A forward port
    //----------------------------------------------------------------------
    class uvm_tlm_b_passthrough_initiator_socket_base #(type T=uvm_tlm_generic_payload)
      extends uvm_port_base #(uvm_tlm_if #(T));
    
      `UVM_PORT_COMMON(`UVM_TLM_B_MASK, "uvm_tlm_b_passthrough_initiator_socket")
      `UVM_TLM_B_TRANSPORT_IMP(this.m_if, T, t, delay)
    
    endclass
    
    
    //----------------------------------------------------------------------
    // Class: uvm_tlm_b_passthrough_target_socket_base
    //
    // IS-A forward export
    //----------------------------------------------------------------------
    class uvm_tlm_b_passthrough_target_socket_base #(type T=uvm_tlm_generic_payload)
      extends uvm_port_base #(uvm_tlm_if #(T));
    
      `UVM_EXPORT_COMMON(`UVM_TLM_B_MASK, "uvm_tlm_b_passthrough_target_socket")
      `UVM_TLM_B_TRANSPORT_IMP(this.m_if, T, t, delay)
    
     endclass
    

    完整源码 · SHA256:3ab9a8c1fee6baec61b2d97a8f6135f831d8a4c583b4a42cc9f32beb3d9aad63

    src/vcs-uvm-ieee-2020-2.0/tlm2/uvm_tlm2_sockets_base.svh
    // IS-A forward imp; has no backward path except via the payload
    // contents.
    //----------------------------------------------------------------------
    virtual class uvm_tlm_b_target_socket_base #(type T=uvm_tlm_generic_payload)
      extends uvm_port_base #(uvm_tlm_if #(T));
    
      function new (string name, uvm_component parent);
        super.new (name, parent, UVM_IMPLEMENTATION, 1, 1);
        m_if_mask = `UVM_TLM_B_MASK;
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_b_target_socket")
    
    endclass
    
    //----------------------------------------------------------------------
    // Class -- NODOCS -- uvm_tlm_b_initiator_socket_base
    //
    // IS-A forward port; has no backward path except via the payload
    // contents
    //----------------------------------------------------------------------
    virtual class uvm_tlm_b_initiator_socket_base #(type T=uvm_tlm_generic_payload)
      extends uvm_port_base #(uvm_tlm_if #(T));
    
      `UVM_PORT_COMMON(`UVM_TLM_B_MASK, "uvm_tlm_b_initiator_socket")
      `UVM_TLM_B_TRANSPORT_IMP(this.m_if, T, t, delay)
    
    endclass
    
    //----------------------------------------------------------------------
    // Class -- NODOCS -- uvm_tlm_nb_target_socket_base
    //
    // IS-A forward imp; HAS-A backward port
    //----------------------------------------------------------------------
    virtual class uvm_tlm_nb_target_socket_base #(type T=uvm_tlm_generic_payload,
                                       type P=uvm_tlm_phase_e)
      extends uvm_port_base #(uvm_tlm_if #(T,P));
    
      uvm_tlm_nb_transport_bw_port #(T,P) bw_port;
    
      function new (string name, uvm_component parent);
        super.new (name, parent, UVM_IMPLEMENTATION, 1, 1);
        m_if_mask = `UVM_TLM_NB_FW_MASK;
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_nb_target_socket")
    
      `UVM_TLM_NB_TRANSPORT_BW_IMP(bw_port, T, P, t, p, delay)
    
    endclass
    

    src/vcs-uvm-ieee-2020-2.0/tlm2/uvm_tlm2_sockets_base.svh
    //
    // IS-A forward port; HAS-A backward imp
    //----------------------------------------------------------------------
    virtual class uvm_tlm_nb_initiator_socket_base #(type T=uvm_tlm_generic_payload,
                                          type P=uvm_tlm_phase_e)
      extends uvm_port_base #(uvm_tlm_if #(T,P));
    
      function new (string name, uvm_component parent);
        super.new (name, parent, UVM_PORT, 1, 1);
        m_if_mask = `UVM_TLM_NB_FW_MASK;
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_nb_initiator_socket")
    
      `UVM_TLM_NB_TRANSPORT_FW_IMP(this.m_if, T, P, t, p, delay)
    
    endclass
    

    src/vcs-uvm-ieee-2020-2.0/tlm2/uvm_tlm2_sockets_base.svh
    //
    // IS-A forward port; HAS-A backward export
    //----------------------------------------------------------------------
    virtual class uvm_tlm_nb_passthrough_initiator_socket_base #(type T=uvm_tlm_generic_payload,
                                                      type P=uvm_tlm_phase_e)
      extends uvm_port_base #(uvm_tlm_if #(T,P));
    
      uvm_tlm_nb_transport_bw_export #(T,P) bw_export;
    
      function new (string name, uvm_component parent,
                    int min_size=1, int max_size=1);
        super.new (name, parent, UVM_PORT, min_size, max_size);
        m_if_mask = `UVM_TLM_NB_FW_MASK;
        bw_export = new("bw_export", get_comp());
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_nb_passthrough_initiator_socket")
    
      `UVM_TLM_NB_TRANSPORT_FW_IMP(this.m_if, T, P, t, p, delay)
    

    src/vcs-uvm-ieee-2020-2.0/tlm2/uvm_tlm2_sockets_base.svh
    //
    // IS-A forward export; HAS-A backward port
    //----------------------------------------------------------------------
    virtual class uvm_tlm_nb_passthrough_target_socket_base #(type T=uvm_tlm_generic_payload,
                                                   type P=uvm_tlm_phase_e)
      extends uvm_port_base #(uvm_tlm_if #(T,P));
    
      uvm_tlm_nb_transport_bw_port #(T,P) bw_port;
    
      function new (string name, uvm_component parent,
                    int min_size=1, int max_size=1);
        super.new (name, parent, UVM_EXPORT, min_size, max_size);
        m_if_mask = `UVM_TLM_NB_FW_MASK;
        bw_port = new("bw_port", get_comp());
      endfunction
    
      `UVM_TLM_GET_TYPE_NAME("uvm_tlm_nb_passthrough_target_socket")
    
      `UVM_TLM_NB_TRANSPORT_FW_IMP(this.m_if, T, P, t, p, delay)
    

    src/vcs-uvm-ieee-2020-2.0/tlm2/uvm_tlm2_sockets_base.svh
    //
    // IS-A forward port
    //----------------------------------------------------------------------
    virtual class uvm_tlm_b_passthrough_initiator_socket_base #(type T=uvm_tlm_generic_payload)
      extends uvm_port_base #(uvm_tlm_if #(T));
    
      `UVM_PORT_COMMON(`UVM_TLM_B_MASK, "uvm_tlm_b_passthrough_initiator_socket")
      `UVM_TLM_B_TRANSPORT_IMP(this.m_if, T, t, delay)
    
    endclass
    
    
    //----------------------------------------------------------------------
    // Class -- NODOCS -- uvm_tlm_b_passthrough_target_socket_base
    //
    // IS-A forward export
    //----------------------------------------------------------------------
    virtual class uvm_tlm_b_passthrough_target_socket_base #(type T=uvm_tlm_generic_payload)
      extends uvm_port_base #(uvm_tlm_if #(T));
    
      `UVM_EXPORT_COMMON(`UVM_TLM_B_MASK, "uvm_tlm_b_passthrough_target_socket")
      `UVM_TLM_B_TRANSPORT_IMP(this.m_if, T, t, delay)
    
     endclass
    

    完整源码 · SHA256:56dee1564839dc6c1c78d5a14d989ee813ef06e28fb141b6084dc8b7be5f3b8c

    src/vcs-uvm-1.2/tlm2/uvm_tlm2_sockets.svh
    //
    //----------------------------------------------------------------------
    
    class uvm_tlm_b_target_socket #(type IMP=int,
                                    type T=uvm_tlm_generic_payload)
      extends uvm_tlm_b_target_socket_base #(T);
    
      local IMP m_imp;
    
      // Function: new
      // Construct a new instance of this socket
      // ~imp~ is a reference to the class implementing the
      // b_transport() method.
      // If not specified, it is assume to be the same as ~parent~.
      function new (string name, uvm_component parent, IMP imp = null);
        super.new (name, parent);
        if (imp == null) $cast(m_imp, parent);
        else m_imp = imp;
        if (m_imp == null)
           `uvm_error("UVM/TLM2/NOIMP", {"b_target socket ", name,
                                         " has no implementation"});
      endfunction
    
       // Function: Connect
       //
       // Connect this socket to the specified <uvm_tlm_b_initiator_socket>
      function void connect(this_type provider);
    
        uvm_component c;
    

    完整源码 · SHA256:da53833a484f04f46b72aba93cab553c5102854951c4c9c5e252adfdff7736fe

    src/vcs-uvm-ieee-2020-2.0/tlm2/uvm_tlm2_sockets.svh
    //----------------------------------------------------------------------
    
    // @uvm-ieee 1800.2-2020 auto 12.3.5.1.1
    class uvm_tlm_b_target_socket #(type IMP=int,
                                    type T=uvm_tlm_generic_payload)
      extends uvm_tlm_b_target_socket_base #(T);
    
      local IMP m_imp;
    
    
      // @uvm-ieee 1800.2-2020 auto 12.3.5.1.3
      function new (string name, uvm_component parent, IMP imp = null);
        super.new (name, parent);
        if (imp == null) $cast(m_imp, parent);
        else m_imp = imp;
        if (m_imp == null)
           `uvm_error("UVM/TLM2/NOIMP", {"b_target socket ", name,
                                         " has no implementation"})
      endfunction
    
    
      // @uvm-ieee 1800.2-2020 auto 12.3.5.1.4
      function void connect(this_type provider);
    
        uvm_component c;
    

    完整源码 · SHA256:4e6b3ade6302f7bcb002b3eb4bc4558cae9cec08a50fa10951f4ec29ae95d1a7

    术语解释 · 兼容配置

    返回TLM · 迁移清单

    版本适用范围