Uvm_config_db issue while setting from top and getting at lower hierarchy

Hi
As per uvm spec if we set a lower level component configuration from different top hierarchy level components then upper hierarchy component always has precedence over lower. but in the given scenario I am setting a variable from the different hierarchy for different scope but I am getting the same value in both scope. Please have a look on the below code and let me know your output, why I am getting the same value for different scope.

  1. I am setting a variable name “from_top” from the top module and keeping its scope till uvm_test_top as given below
    file top module :
    int from_top =10;
    uvm_config_db#(int)::set(null, “”, “from_top”, from_top);

  2. I am setting the same variable from agent and keeping its scope to driver only.
    file : agent class
    int from_top =5;
    uvm_config_db#(int)::set(this, “driver”, “from_top”, from_agent);

  3. I am trying to get the values from driver class as given below

caseA : if(!uvm_config_db#(int)::get(uvm_root::get(), “”, “from_top”, from_top)) begin
`uvm_error(“”, “From top :uvm_config_db::get failed”)
end

caseB : if(!uvm_config_db#(int)::get(this, “”, “from_top”,from_agent)) begin
`uvm_error(“”, “From agent : uvm_config_db::get failed”)
end
As per my understanding the output for the caseA should be “10” and the output from the caseB should be “5” as the setting scope of this variable are different. but I am getting the value “10” for the both the cases.
from the log massage I can see that the setting/getting scope are different for both case as given below :

set method in top module:
UVM_INFO /home/build/vlib1/vlib/uvm-1.1d/src/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/SET] Configuration ‘.from_top’ (type bit signed[31:0]) set by = (bit signed[31:0]) 10

set method in agent class :
UVM_INFO /home/build/vlib1/vlib/uvm-1.1d/src/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/SET] Configuration ‘uvm_test_top.env.agent.driver.from_top’ (type bit signed[31:0]) set by uvm_test_top.env.agent = (bit signed[31:0]) 5

Now get method from driver :
caseA :
UVM_INFO /home/build/vlib1/vlib/uvm-1.1d/src/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/GET] Configuration ‘.from_top’ (type bit signed[31:0]) read by = (bit signed[31:0]) 10

caseB :
UVM_INFO /home/build/vlib1/vlib/uvm-1.1d/src/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.env.agent.driver.from_top’ (type bit signed[31:0]) read by uvm_test_top.env.agent.driver = (bit signed[31:0]) 10

Thanks
Vipan Kumar

In reply to vipan_kumar:

The simulation behaviour you can see is UVM-compliant and correct. For the right understanding you need the knowledge how the data are stored in the config-database. For the first argument (context) of the uvm_config_db set/get command you have two options. ‘null’ indicates the database has to deal with the full hierarchical path and ‘this’ is indicating it uses a relative hierarchical path. With the second argument you can specify more details of the hierarchical path. If you don’t want to restrict the access of a data field a ‘*’ is always fine in the set command. The third argument is the name under which the value (last argument) will be stored. The config-database does not check how often you are storing a variable with the same name. Executing the uvm_config_db get command it searches from top to bottom and returns the first entry with the right name. In your case you do not specify any path, i.e. the first set command form the toplevel module stores the variable ‘from_top’ in the global space. The command finds on the highest level exactly this variable and the corresponding value ‘10’ and returns it.

Thanks for your reply.

It is correct that the get function search from the top to bottom and the return the first entry with exact match of whole key.
Please provide your time to go through the description given below and scenario I have generated as per your reply and provide your inputs
But as per my knowledge and research which I have done in uvm library and found that key is made by, key = {“context”.“inst_name”.“field_name”} and value is stored with respect to this key in uvm database. First two argument make the hierarchy path of the test-bench after that the desired “field_name” will be visible in tb. The “context” can have one more option which is uvm_root::get().
uvm_root::get() or “null” both are starting point and replaced with “uvm_test_top” while making a key. the second argument can have “*” or the further hierarchy path of desired component in down hierarchy form the current component.

The get function search for full key and return the value for which key is matched but in my previous example the key was different even though I was getting the same value.

As per your reply I created a new example in which I have made a small changes, in top module set function, I modified second argument with “env” rather then keeping it empty “”. same I did for get function for caseA(Point 3).

1. I am setting a variable name “from_top” from the top module and keeping its scope till env as given below
file top module :
int from_top =10;
uvm_config_db#(int)::set(null, “env”, “from_top”, from_top);
UVM_INFO /home/build/vlib1/vlib/uvm-1.1d/src/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/SET] Configuration ‘env.from_top’ (type bit signed[31:0]) set by = (bit signed[31:0]) 10
2. I am setting the same variable from agent and keeping its scope to driver only.
file : agent class
int from_top =5;
uvm_config_db#(int)::set(this, “driver”, “from_top”, from_agent);
UVM_INFO /home/build/vlib1/vlib/uvm-1.1d/src/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/SET] Configuration ‘uvm_test_top.env.agent.driver.from_top’ (type bit signed[31:0]) set by uvm_test_top.env.agent = (bit signed[31:0]) 5

3. I am trying to get the values from driver class as given below

caseA : if(!uvm_config_db#(int)::get(uvm_root::get(), “env”, “from_top”, from_top)) begin
`uvm_error(“”, “From top :uvm_config_db::get failed”)
end

UVM_INFO /home/build/vlib1/vlib/uvm-1.1d/src/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/GET] Configuration ‘env.from_top’ (type bit signed[31:0]) read by = (bit signed[31:0]) 10

caseB : if(!uvm_config_db#(int)::get(this, “”, “from_top”,from_agent)) begin
`uvm_error(“”, “From agent : uvm_config_db::get failed”)
end

UVM_INFO /home/build/vlib1/vlib/uvm-1.1d/src/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.env.agent.driver.from_top’ (type bit signed[31:0]) read by uvm_test_top.env.agent.driver = (bit signed[31:0]) 5

Now I am getting the correct value for caseA = “10” and for caseB = “5”.

with this example it is clear that it search with the whole key made by first three argument of set/get function.
But I am very curious to know that why the whole case changes with second argument keeping as empty “” rather than “" or “inst_name”. Here one more thing need to clear that, for the second parameter of set/get function if I keep it “” or put "” have the same meaning than the whole things are fine,but if not then this seems like an issue…