Calling randomize of config object

Hi,

I am new to UVM and trying to get the proper understanding of using ::get, ::create, ::set_type_override for my config object.

I have a list of agents. Each agent has its own config (same type but with different randomization depending on each agent id). I generate my agent and also agent.config in my env using type_id::create. I realized that in my testcase when I do type_id::set_type_override, it does not change my config object. In each agent’s build phase I am randomizing config. The reason for that is that the config has fields like ACTIVE/PASSIVE, and many other specific fields which are to be configured by the user using constraints. Once randomization is done I can accordingly create driver and monitor.
So in brief my questions -

  1. For creating config in an agent – Is ::create() is enough to take the settings of set_override in effect or do I need to use config.get(…) from config_db. If not found than do ::create.
  2. When to call randomize()? Does my approach sound OK? I can ofcourse move agent’s config to env as a list of configs and than pass a pointer to the agent. But still the issue of when to randomize remains. Please note that I want to put all parameters related to the agent in the config.

I saw the an earlier post on when to call randomize() but it did not resolve my issue, so had to post this one in a new thread. The earlier one was -
https://verificationacademy.com/forums/uvm/during-which-phase-call-randomize-uvm

In reply to shrawan_vaidya:

Hello Shrawan,

  1. Use uvm_config_db in the build_phase() of ENV class to set the agent config handle. And get the agent config handle in build_phase() agent class.

  2. Did you face any issue while randomizing the values in start of simulation pahse. As it si given in the link.

In reply to sunils:

  1. My current code in env build_phase is something like this -
    for (int i=0; i<num_tx_lanes; i++) begin
      $sformat(instance_name, "tx_lane_agents[%0d]", i);
      // instantiate tx agent
      tx_lane_agents[i] = er_j204_lane_agent::type_id::create(instance_name, this);
      $sformat(instance_name, "TX_lane_config_%0d", i);
      // instantiate tx agent's config
      tx_lane_agents[i].cfg = er_j204_lane_config::type_id::create(instance_name, this);
      tx_lane_agents[i].cfg.lane_id = i;
      tx_lane_agents[i].cfg.lane_type = TX;
    end

Is it better to have list of configs instantiated in the env and then agent is passed the pointer of the config in env’s build phase, something like

  tx_lane_agent[i] = cfg_l[i];

  1. The config contains active_passive fields and many other parameters. active_passive won’t be generated until randomization of cfg will happen. If I wait till start of simulation phase then how will I instantiate driver and monitor in the agent? active_passive information is required to instantiate driver and sequencer.

thanks
shrawan

In reply to shrawan_vaidya:
set_type_override() must be used before calling create(). Typically you do the override from a component at a higher level, like your test if necessary. What most people do is a uvm_config_db::set() in the env or test, and a corresponding uvm_config_db::get() in each agent.

In reply to dave_59:

Thanks Dave!

Can I make provisions for both options given below -

  1. Having user create his own config in the test and do set(). In the env I must then have a get() to get the config set from top
  2. If in env get() fails I can do a ::create() to create a config. In this case any set_override() from the top will be effective as well.

I am still not able to understand where the config is randomized. If created in the test, no question of randomizing it again. We can simply do set() and get().
But if no one sets it from test, and it gets created in the env using ::create(), I need to randomize() it. Does this make sense?

thanks
shrawan

In reply to shrawan_vaidya:

I believe you are mixing 2 things together.
Creating a config object has nothing to do with the config_db.
If you have created a config object you can pass this to the config_db using a config_db set.
Normally you are doing this either in the test or in the top_env (test is the prefered place).
If the config_object is in the config_db you can retrieve this object from any other place in the testbench hierarchy or even in the sequences. If the get Fails you are doing something wrong, because the object is in the config_db. Then you should debug your get and not simply create the same object twice.