Config_db From Component To an Object not getting set

Hello !

  1. I have a int variable which I get inside an block environment configuration object. This basically gets the number of agents to create.

if (!uvm_config_db#(int)::get(null, get_full_name(), "num_agt", num_agt))
 begin
   num_agt = `NUM_AGT;
  `uvm_info($psprintf("%s_WARNING", get_type_name()), $psprintf("num_agt setting is not found in config_db! Setting default value of %0d\n", num_agt), UVM_HIGH);
 end

  1. From the top base test, I am trying to set this int variable before creating this environment configuration, so that based on the value set, within the environment configuration, I do some agent configuration creation. Within this top_env_cfg, I create the other block_env_cfg.

uvm_config_db#(int)::set(uvm_root::get(), "top_env_cfg.block_env_cfg", "num_agt", 2);
top_env_cfg = top_environment_config::type_id::create("top_environment_cfg",this);

  1. When I dump the trace this is what I see…

UVM_INFO reporter [CFGDB/SET] Configuration 'top_environment_cfg.block_env_cfg.num_agt' (type int) set by  = (int) 2
UVM_INFO reporter [CFGDB/GET] Configuration 'block_env_cfg.num_agt' (type int) read by  = null (failed lookup)

I tried setting with regular expression “*”, but still the results are same. Am I missing something very basic ? Let me know. Thanks.

In reply to desperadorocks:
While setting the num_agt, try to replace the context “uvm_root::get()” with “this” as below.

uvm_config_db#(int)::set(this, "top_env_cfg.block_env_cfg", "num_agt", 2);

In reply to bdreku:

Hello Bdreku, I did try that way, but the results are same.

Well the intention is like, though there is no hierarchy concept for the objects, but still I was trying a similar sort of thing.

For example,

  1. I have a top level env and inside which there are multiple block_env’s.
  2. Within each block_env’s there is this block_env_cfg.
  3. And I wanted to set different values for each variable inside the config object something like given below.

top_env_cfg.block_env_cfg[0].num_agts = 0,
top_env_cfg.block_env_cfg[1].num_agts = 2,
top_env_cfg.block_env_cfg[2].num_agts = 6, 

  1. So only was trying to set the value of num_agts targeting specifically inside the each block_env_cfg with different values.

But somehow during the get, its missing or not sure if its missing searching for that complete string path for the value. Wondering if am I making any error in the get as well?

In reply to desperadorocks:

I recommend that you change your methodology.

One of the main purposes of the test is to create and configure all of the configuration objects for your environment(s) and the sub-agent(s) of the environment(s). Every configuration variable of these objects should be set by the test, and the configuration objects passed to the environment(s) using the config_db().

I don’t understand why you would create a configuration object, then try to use the config_db() to get a variable inside the configuration object from the config_db(). Just use the test and set each variable appropriately.

In your example, why would you try and pass num_agents using the config_db() instead of just setting the variable in the environment(s) config object(s) directly?

In reply to cgales:

Hello @cgales,

Thanks for going over the post and responding back.

  1. Have like a two way mechanism, i.e. top_env_cfg gets created in the top_test, it also creates the block_env_cfgs. So, when the block_env_cfg gets created, during the new process I check if there is any “num_agts” being set via the config_db else it uses a default value using `NUM_AGTS set in the defines.

  2. After getting the default value of num_agts while it gets created, I also call a function which configures the num_agts, then the agent_cfgs and its default setup on the fly. Code excerpts as given below.


class block_env_configuration;
...

function new();
 ...
 if (!uvm_config_db#(int)::get(null, get_full_name(), "num_agt", num_agt))
 begin
   num_agt = `NUM_AGT;
  `uvm_info($psprintf("%s_WARNING", get_type_name()), $psprintf("num_agt setting is not found in config_db! Setting default value of %0d\n", num_agt), UVM_HIGH);
 end
 ...

 // calling agt setup
 cfg_agts(num_agt);
endfunction: new

function cfg_agts(num_agt);
  blk_agt_cfg = new[num_agt];
  ...
endfunction: cfg_agts
...
endclass: block_env_configuration

  1. So that way, either the user can set the num_agts via config_db before the block_env_cfg is created or they can set the num_agts via the defines Or else, they can specifically call the cfg_agts function to set the num_agts and configure.

block_env_cfg.cfg_agts(2);

  1. Say if the block_env is being used at multiple places [i.e. within multiple sub_envs], then I can set different values via the config_db to the particular block_env_cfg instead of calling the function cfg_agts. That’s the reason why I was trying to get the num_agts via config_db.

But your recommendation is to individually set the variables in the test and configure them right? Let me know which would be the best way. Thanks again !

In reply to desperadorocks:

As I stated, the best method is to set the configuration variables in the test. You are wasting resources in the config_db() by setting a value and then immediately reading it back at the same level of hierarchy. Just set the value in the configuration object directly.

Also, don’t use `defines to configure default values. The default values should be parameters in your test package.

I recommend defining a configuration_function() in the base test class that creates the top level environment configuration containing all the environment parameters, sub-environment configurations and agent configurations. It will put this single configuration object into the config_db() for the environment to retrieve during the build_phase.

By using a configuration_function, you allow your tests extended from the base_test to create their own configuration objects that vary based on the test.


class block_env_configuration extends uvm_object;
  rand int unsigned num_agt;
  agent_cfg blk_agt_cfg[];
  
  constraint num_agt_c {num_agt inside {[1:MAX_AGENTS]};};
 
  function new(string name="block_env_configuration");
    super.new(name);
  endfunction: new
 
  function void post_randomize();
    cfg_agents(num_agt);
  endfunction
                                               
  function cfg_agts(int unsigned num_agt_);
    num_agt = num_agt_;
    blk_agt_cfg = new[num_agt];
    foreach(blk_agt_cfg[i]) begin
      blk_agt_cfg[i] = agent_cfg::type_id::create($sformatf("blk_agt_cfg[%0d]", i));
    end
  endfunction: cfg_agts

endclass: block_env_configuration