2.1、配置组件的 DUT 接口2.2、UVM 组件基类2.3、UVM 组件的逻辑层次:父子(parent-child)关系2.4、组件显示和查询2.5、查询组件的层次关系2.6、使用逻辑层次配置组件2.7、配置组件字段2.8、动态控制变量2.9、物理接口的配置2.10、全局 UVM 资源2.11、UVM 配置机制的选择2.12、UVM 配置机制的调试2.12.1、调试配置遇到的问题(1/4)2.12.2、调试配置遇到的问题(2/4):解决方法2.12.3、调试配置遇到的问题(3/4)2.12.3、调试配置遇到的问题(4/4)2.12.4、UVM 资源和配置的调式2.13、小结
UVM 相比 SystemVerilog 比较优价值的地方就在于工厂机制和配置机制!这两点是必须要深入掌握透彻的,并且要能够熟练使用。
- UVM 组件的逻辑层次结构【本节】
- 使用逻辑层次 set/get UVM 组件的配置字段【本节】
- 使用工厂模式创建测试用例,替换事物和组件中的字段【下一节】
2.1、配置组件的 DUT 接口
对于 DUT 的接口(interface),在 SV 里面是在建立实体(new 函数)时一级一级传递进去的,在 UVM 里面只能通过 uvm_config_db。学习之前,先来回顾一下 UVM 验证环境的逻辑架构,如下图。
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F7b641876-0090-43eb-ac09-3e5faccc6ad0%2Ff2355c81-eb6b-42cf-9b55-5ce6a31546a6.png?table=block&id=5e1e323e-6d54-4106-ac2a-0ec0932b0b88&t=5e1e323e-6d54-4106-ac2a-0ec0932b0b88)
- Testcase 使用
uvm_config_db #(vif)::set();
vif
是virtual interface
的名字,传的类型
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fed93ed1f-b3fa-4aec-817b-f0c9e68fb076%2F2efba62d-17de-4011-87a2-467e882a5249.png?table=block&id=1530dcca-03e7-4d50-a431-326d97b11532&t=1530dcca-03e7-4d50-a431-326d97b11532)
- Agent get 并 set 子组件的接口
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fb46cf432-8b49-4e87-ab10-e63c76725aef%2F189ae0cd-7c69-48b0-8988-fbf3eb342900.png?table=block&id=f14ab139-cce6-4337-b77f-79b97f8fd6af&t=f14ab139-cce6-4337-b77f-79b97f8fd6af)
- Component 使用
uvm_config_db #(vif)::get()
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F61df1eb0-2595-4088-88d1-af1c864f7df8%2F4874b556-c420-4e41-b475-125175c38737.png?table=block&id=c7e57f85-8abd-4c61-8d0b-8a955732f243&t=c7e57f85-8abd-4c61-8d0b-8a955732f243)
当然上面是通过 agent 中转之后到的 driver,也可以直接指定 driver 实体路径,实现 env 直接到 driver!使用 agent 的好处,可以分发到多个地方,比如 monitor 要用也可以分发到 monitor!灵活运用即可,这里仅仅是个示意。
2.2、UVM 组件基类
- UVM 组件的行为描述基类:uvm_component/uvm_object
- 具有逻辑层级结构:父子(parent-child )关系
- 提供控制验证流程和配置机制
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fa8f3117f-f910-485c-bc3b-3072f739756b%2F850dedd0-fe5f-4f20-badb-98c13d2a94b3.png?table=block&id=2f01b378-cc49-40eb-99de-98b60e6b1923&t=2f01b378-cc49-40eb-99de-98b60e6b1923)
Component 具有 run 的属性;object 只能去做一些 build 和 connect!即对于 object,phase 只有 build 和 connect!
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F4e0e595f-5c63-4297-8f10-22aa69beeec5%2F3e81792d-0a2c-4ed4-9050-49b043e518f8.png?table=block&id=dfea59c3-9810-4d7a-bb73-2c14e0f339c2&t=dfea59c3-9810-4d7a-bb73-2c14e0f339c2)
2.3、UVM 组件的逻辑层次:父子(parent-child)关系
- 在创建组件的对象时建立逻辑层次关系
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fc477d31b-19a2-478a-95cf-4cb9048bf37e%2Ffae3e190-e164-4834-aa2d-d7e5380bbffd.png?table=block&id=ced8ed0b-5508-4a51-9e1f-724dce4f5a09&t=ced8ed0b-5508-4a51-9e1f-724dce4f5a09)
2.4、组件显示和查询
- 丰富的显示和查询程序(内置函数查询)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F44c27823-8378-4b8b-824d-989805de642c%2Fdbeba675-3a8d-4879-a931-4f474b2d1d4a.png?table=block&id=4b171504-73e1-44c4-9e34-1925b875543e&t=4b171504-73e1-44c4-9e34-1925b875543e)
2.5、查询组件的层次关系
- 获取指向 parent/children 对象的句柄
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F4e862e13-e219-4426-abe1-4ef82c674060%2Fc28a31bb-26f0-4471-a2c6-f7adcce9cb39.png?table=block&id=afc486f5-6090-400d-8d66-a3281e308e93&t=afc486f5-6090-400d-8d66-a3281e308e93)
2.6、使用逻辑层次配置组件
- 通过 UVM 配置机制,设置对象的变量
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Feae6e8a4-9ff8-4b09-8839-5958fee4aaa8%2F07621c5f-e20b-4975-b1ee-5db7348adf18.png?table=block&id=ae51ec85-5d2a-4acd-9493-b7f32d007ade&t=ae51ec85-5d2a-4acd-9493-b7f32d007ade)
2.7、配置组件字段
- Agent 组件中的字段配置
- 目标是 agent
- 在 agent 中配置 child 组件
- 通常是在 build_phase 阶段完成 config_db 配置(没有 run 之前),又可称为静态配置!
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F28879f87-233d-46a4-a077-275e1c9a1e30%2F44501211-259b-42a6-9eda-b4f6099a2329.png?table=block&id=d8372d58-826b-40da-a4cf-a181fdbd3b4d&t=d8372d58-826b-40da-a4cf-a181fdbd3b4d)
2.8、动态控制变量
- 动态控制 component/sequence
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fe3c29d02-3816-427d-ad4a-89adba9047a5%2Ff3f12aa6-3fc0-4416-a716-59e0da6e77e5.png?table=block&id=4efb9624-fb93-40e1-af04-b392a61afd4d&t=4efb9624-fb93-40e1-af04-b392a61afd4d)
2.9、物理接口的配置
- 在接口物理连接时,不能将虚拟接口(virtual interface)作为构造函数的参数
- 代理类(type_id)的 create() 函数不支持
- 使用 UVM 的配置机制:即 uvm_config_db 的 set/get 机制
- UVM 里面的 virtual interface 不能通过参数 new 来传递,只能通过 uvm_config_db 去连接。
- 《参见 2.1 小节》,主要过程如下图。
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F61df1eb0-2595-4088-88d1-af1c864f7df8%2F4874b556-c420-4e41-b475-125175c38737.png?table=block&id=9c53578f-c3d2-42d2-8376-4c778f3b4804&t=9c53578f-c3d2-42d2-8376-4c778f3b4804)
面试题:UVM 的 interface 是怎么连接 Testbench 和 DUT 的?(答案见上)
2.10、全局 UVM 资源
- uvm_config_db 设置对象的本地配置
- uvm_resource_db 可以进行全局资源的配置
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F0a57cad5-cff9-4c55-a0d9-eb6d78128c1d%2F222203d3-973a-41c2-b778-2c1479ed3a5e.png?table=block&id=bf80d412-7aaa-4440-b3d5-c295f989efe5&t=bf80d412-7aaa-4440-b3d5-c295f989efe5)
- 获取资源配置信息的方式有两种
- 按照 name 获取配置信息
- 按照 type 获取配置信息
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F596fa983-2335-4557-9353-c2541dc12480%2Faa5bad40-ea34-4f4f-a1b0-e4400356ad45.png?table=block&id=4f201d47-3bc1-4b61-a99d-8fa41e489482&t=4f201d47-3bc1-4b61-a99d-8fa41e489482)
2.11、UVM 配置机制的选择
- uvm_config_db 还是 uvm_resource_db?
- uvm_config_db 和 uvm_resource_db 都可以操作相同的全局资源池(global resource pool)
- uvm_config_db 使用
context
- 用于配置组件的实例
- uvm_resource_db 使用
string
- 用于全局配置
- 都是用 string 搜索并获取资源配置信息
- 在 testcase 中配置效果一样
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F3b5f301e-44c4-4ef7-9dcd-50eb3b33e895%2Ff43648cf-28a0-4010-8d94-52b71fd60de0.png?table=block&id=1f4dd540-3f1d-4810-b633-a2069e84626b&t=1f4dd540-3f1d-4810-b633-a2069e84626b)
- 在 component 中配置效果一样
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F4fed013f-c920-4a99-a18d-d5dd01eda17a%2Fd133282e-3644-4ffd-b470-3a62bb14f54b.png?table=block&id=2291a4ee-c267-414f-80b1-c2afc33375ea&t=2291a4ee-c267-414f-80b1-c2afc33375ea)
注:两个没有太大差异,一般常用 uvm_config_db!
2.12、UVM 配置机制的调试
2.12.1、调试配置遇到的问题(1/4)
- 配置信息的类型:types
- set 和 get 的数据类型不匹配时,EDA 仿真工具不会在 get 时报错
- 因为数据类型或者逻辑层级结构导致的字段名称或作用范围不匹配时,不会报错
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff3eb6190-31b2-444d-8f6f-2d6e2f522371%2F0fcf9b12-aef7-407f-aa77-751caabd69c3.png?table=block&id=9ac37b87-0e71-4c27-ac79-d02efd870c7d&t=9ac37b87-0e71-4c27-ac79-d02efd870c7d)
2.12.2、调试配置遇到的问题(2/4):解决方法
- 1、检查 read_by_name/_type() 或者 get() 函数的返回状态值,如果获取不到打印错误信息,用 if 自己去判断(推荐)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F5c9565c3-6284-49b3-80f4-7a3a38d5cd47%2F168d41a7-750b-4ba9-827c-c233510327b3.png?table=block&id=0586cad0-427b-42d0-9f18-7d8fbd2bc32a&t=0586cad0-427b-42d0-9f18-7d8fbd2bc32a)
- 2、使用仿真命令选项,跟踪 sets 和 gets 的信息(推荐)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F9f52536c-7a11-40b8-9cf9-4e1aba3ddcb5%2Fd3c6d1f0-de30-4540-a8c3-94da6cd4d342.png?table=block&id=d506a202-2ba9-4d97-8e4f-b421ddda7433&t=d506a202-2ba9-4d97-8e4f-b421ddda7433)
- 3、在 testcase 中使用跟踪控制
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fb049a268-0515-4737-bc16-5b4a0c7a8786%2F1d0ffa37-bf12-410a-8ff4-bc71917fff4b.png?table=block&id=c7ab265b-4996-40e8-b21f-200139daa76f&t=c7ab265b-4996-40e8-b21f-200139daa76f)
2.12.3、调试配置遇到的问题(3/4)
- 使用全局句柄可以操作 UVM 的资源池
- uvm_resources
- 使用仿真命令选项,跟踪所有的配置 set 和 gets(uvm_config_db)
- 使用 dump() 程序可以将资源池的中所有资源 dump 进来
uvm_resources.dump(.audit(1));
- DUMP 所有的
uvm_resource_db::read_by_name()/_type()
操作(uvm_resource_db) uvm_resources.dump_get_records();
2.12.3、调试配置遇到的问题(4/4)
- 查询所有没有使用的资源(get 函数没有正确执行)
uvm_resources.find_unused_resources();
2.12.4、UVM 资源和配置的调式
- 在代码中使能 dump
- resources.dump(audit);
- 在命令行中使用
- +UVM_RESOURCE_DB_TRACE
- +UVM_CONFIG_DB_TRACE
2.13、小结
本篇主要介绍了 UVM 的配置机制,要知道 UVM 的配置类型可以是常规的变量,如 int、logic 等,也可以是 interface、object 等。另外还需要知道,UVM 的 interface 是通过 config_db 机制去连接 DUT 的,要与 SystemVerilog 区分。当然本节只是理论的学习,不免有些抽象,后面的实践代码中还会进行进一步强化学习!对于本节,知道 UVM 配置机制基本概念,了解如何使用,知道参数含义这些知识点就够了!