Uvm_config_db

Hi All,

I am not able to receive the variable from agent which is registerd from env.

Test :
class my_test extends uvm_test;

`uvm_component_utils(my_test)
my_env my_env_h;
int a;

function new(string name, uvm_component parent);
super.new(name,parent);
endfunction: new

virtual function void build_phase(uvm_phase phase);
uvm_report_info(get_full_name(),“Start of build_phase”, UVM_HIGH);
super.build_phase(phase);
my_env_h = my_env::type_id::create(“my_env_h”,this);
a = 7;
uvm_config_db#(int)::set(this,“*”,“A”,a);
uvm_report_info(get_full_name(),“END of build_phase”, UVM_HIGH);
endfunction: build_phase

endclass : my_test

Env:
class my_env extends uvm_env;

`uvm_component_utils(my_env)

my_agent my_agent_h;
int a;

function new(string name, uvm_component parent);
super.new(name,parent);
endfunction: new

virtual function void build_phase(uvm_phase phase);
uvm_report_info(get_full_name(),“Start of build_phase”, UVM_HIGH);
super.build_phase(phase);
my_agent_h = my_agent::type_id::create(“my_agent_h”, this);
a = 5;
uvm_config_db#(int)::set(this,“*”,“A”,a); //Error - This is causing to not to set the value of a
uvm_report_info(get_full_name(),“End of build_phase”, UVM_HIGH);
endfunction: build_phase

endclass: my_env

AGent:
class my_agent extends uvm_agent;

`uvm_component_utils(my_agent)

int a ;

function new(string name,uvm_component parent);
super.new(name, parent);
endfunction: new

virtual function void build_phase(uvm_phase phase);
uvm_report_info(get_full_name(),“start of build phase”,UVM_HIGH);
super.build_phase(phase);
uvm_report_info(get_full_name(),“end of build phase”,UVM_HIGH);
endfunction: build_phase

virtual task run_phase(uvm_phase phase);
if(!uvm_config_db#(int)::get(null,“*”,“A”,a))
uvm_error("CONFIG_VALUE","Value of a is not available") else uvm_info(“CONFIG_VALUE”,$sformatf(“Value of a:%d”,a),UVM_LOW);
endtask: run_phase

endclass: my_agent

Top:
import uvm_pkg::*;
include "my_agent.sv"; include “my_env.sv” ;
`include “my_test.sv” ;

module top();

initial begin
run_test(“my_test”);
end

initial begin
#100;
$finish;
end

endmodule: top

Thanks & Regards,
Shriramvaraprasad B.

In reply to SHRI12326:

You should make all of the config_db set() calls prior to calling create() for the sub-components. This is because the build() phase of the sub-component is called as part of create(). If the set() hasn’t been done prior to the create(), then there is nothing to get().

In reply to SHRI12326:

It is a good practice to perform your set and get to the config_db outside the run_phase good places are end_of_elaboration_phase and start_of_simulation_phase. Performinmg all set to the config_db during end_of_elaboration_phase and all get during start_simulation_phase. Then you are on the safe side.
BTW why you are using in the get as the first argument null?

In reply to cgales:
Build phase executes all of the config db related functions in a component and then moves on to create the child component, so order doesn’t matter here. Although for code reading purpose it would be good practice to do any config db set before create is called for child component.

For your specific case, the problem is use of null during get call in agent. Since null looks for hierarchy from “*.” it doesn’t find any of your sets which are done from uvm_test_top level (since you are using this in all sets)

If you replace your get call from null to this as shown below, then you will get the value which matches with hierarchy staring from uvm_test top, in this case your test files has more wild card entries, so it will get that value (7) instead of env value(5)
if(!uvm_config_db#(int)::get(this,“*”,“A”,a))

Here is the config DB trace for your reference, you can get it by adding +UVM_CONFIG_DB_TRACE in command line. Hope this helps.

UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.recording_detail’ (type ) read by uvm_test_top = null (failed lookup)
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.recording_detail’ (type ) read by uvm_test_top = null (failed lookup)
UVM_INFO @ 0: reporter [RNTST] Running test my_test…
UVM_INFO @ 0: uvm_test_top [uvm_test_top] Start of build_phase
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.my_env_h.recording_detail’ (type ) read by uvm_test_top.my_env_h = null (failed lookup)
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.my_env_h.recording_detail’ (type ) read by uvm_test_top.my_env_h = null (failed lookup)
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/SET] Configuration ‘uvm_test_top..A’ (type ) set by uvm_test_top = (int) 7
UVM_INFO @ 0: uvm_test_top [uvm_test_top] END of build_phase
UVM_INFO @ 0: uvm_test_top.my_env_h [uvm_test_top.my_env_h] Start of build_phase
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.my_env_h.my_agent_h.recording_detail’ (type ) read by uvm_test_top.my_env_h.my_agent_h = null (failed lookup)
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.my_env_h.my_agent_h.recording_detail’ (type ) read by uvm_test_top.my_env_h.my_agent_h = null (failed lookup)
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/SET] Configuration 'uvm_test_top.my_env_h.
.A’ (type ) set by uvm_test_top.my_env_h = (int) 5
UVM_INFO @ 0: uvm_test_top.my_env_h [uvm_test_top.my_env_h] End of build_phase
UVM_INFO @ 0: uvm_test_top.my_env_h.my_agent_h [uvm_test_top.my_env_h.my_agent_h] start of build phase
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.my_env_h.my_agent_h.is_active’ (type ) read by uvm_test_top.my_env_h.my_agent_h = null (failed lookup)
UVM_INFO @ 0: uvm_test_top.my_env_h.my_agent_h [uvm_test_top.my_env_h.my_agent_h] end of build phase
UVM_INFO /usr/hw-tools/uvm/uvm-1.1c/src/base/uvm_resource_db.svh(129) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.my_env_h.my_agent_h.*.A’ (type ) read by uvm_test_top.my_env_h.my_agent_h = (int) 7
UVM_INFO config_db.sv(27) @ 0: uvm_test_top.my_env_h.my_agent_h [CONFIG_VALUE] Value of a: 7

In reply to bharat_vg:

I was incorrect in that create() calls the build() function. The create() will call the new() function, but the build() function won’t be called until the parent’s build() function completes. This will allow you to have a config_db set() after a create() call.

However, I have seen config_db get() calls in the new() function which will require the set() call before the create().

In reply to cgales:

Thanks cgales. I wasn’t aware of that nuanced detail where create() will still call new() and only delay build() until parent build is finished.

I guess, it would also be bad coding practice to put config_db_get() inside new() of any object/component , since it would limit reusability when extending.