#UVM# 关于 config_db 机制中的直线非直线设置和获取讲解
在 UVM 验证环境中,uvm_config_db
是一种强大的机制,用于在不同组件之间传递配置参数。根据你的描述,我们可以结合UVM 树结构来解释直线和非直线的设置与获取。
UVM 树结构示例
假设 UVM 树结构如下:
uvm_test_top
├── env
│ ├── i_agt
│ │ └── drv (driver)
│ ├── scb (scoreboard)
│ └── ref_model (reference model)
其中,driver
的路径为 uvm_test_top.env.i_agt.drv
。
直线设置与非直线设置
-
直线设置:
-
如果在
uvm_test_top
、env
或i_agt
中对driver
的某些变量进行设置,这种设置称为直线设置。 -
例如,在
env
中设置driver
的pre_num
参数:
-
function void env::build_phase(uvm_phase phase);
super.build_phase(phase);
uvm_config_db#(int)::set(this, "i_agt.drv", "pre_num", 100);
endfunction
-
这种设置方式符合 UVM 的层次结构,路径清晰且易于管理。
非直线设置:
-
如果在其他组件(如
scoreboard
或reference model
)中对driver
的某些变量进行设置,则称为非直线设置。 -
例如,在
scoreboard
中设置driver
的pre_num
参数:
function void my_scoreboard::build_phase(uvm_phase phase);
super.build_phase(phase);
uvm_config_db#(int)::set(this.m_parent, "i_agt.drv", "pre_num", 200);
endfunction
或者:
function void my_scoreboard::build_phase(uvm_phase phase);
super.build_phase(phase);
uvm_config_db#(int)::set(uvm_root::get(), "uvm_test_top.env.i_agt.drv", "pre_num", 200);
endfunction
-
非直线设置可能会带来风险,因为 UVM 并未明文规定同一级别组件(如
scb
和i_agt
)的build_phase
执行顺序。因此,当driver
获取参数时,scoreboard
的build_phase
可能尚未执行,导致参数设置失败。
直线获取与非直线获取
-
直线获取:
-
在
driver
中通过uvm_config_db::get
获取其他组件设置的参数,称为直线获取。 -
例如,在
driver
中获取pre_num
参数:
-
function void my_driver::build_phase(uvm_phase phase);
super.build_phase(phase);
int pre_num;
void'(uvm_config_db#(int)::get(this, "", "pre_num", pre_num));
`uvm_info("my_driver", $sformatf("pre_num = %0d", pre_num), UVM_LOW)
endfunction
非直线获取:
-
如果在其他组件(如
reference model
)中获取其他组件设置给driver
的参数值,则称为非直线获取。 -
例如,在
reference model
中获取driver
的pre_num
参数:
function void my_ref_model::build_phase(uvm_phase phase);
super.build_phase(phase);
int pre_num;
void'(uvm_config_db#(int)::get(this.m_parent, "i_agt.drv", "pre_num", pre_num));
`uvm_info("my_ref_model", $sformatf("pre_num = %0d", pre_num), UVM_LOW)
endfunction
-
这种方式同样需要确保路径正确,并且设置操作在获取操作之前完成。
注意事项
-
路径正确性:无论是直线还是非直线设置/获取,路径必须正确。可以使用
get_full_name()
或相对路径来确保路径的准确性。 -
执行顺序:非直线设置可能会因执行顺序问题导致失败。建议尽量避免非直线设置,除非有明确的必要。
-
调试:如果设置或获取失败,可以使用
uvm_config_db::check_config_usage
来检查配置参数的使用情况。