# Why use uvm\_config\_db to pass vif or configuration object is recommended?

**URL:** <https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310>\
**Category:** UVM\
**Tags:** UVM, uvm\_config\_db\
**Created:** [January 23, 2015, 1:58am UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310 "2015-01-23T01:58:09Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![seabeam](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@seabeam](https://verificationacademy.com/forums/u/seabeam)\
**Post date:** [January 23, 2015, 1:58am UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/1 "2015-01-23T01:58:09Z")

</div>

In uvm cookbook part:VirtInterfaceFunctionCallChain, it says that one of the disadvantage of assign\_vi:  
**It is not reusable** - If the test environment hierarchy changes, these functions must be updated  
In the testcase, there is a assign\_vi() like function assign\_if:

```verilog

class test_case extends uvm_test;
  test_env env;
  virtual interface test_if vif;
  ...
  function void build_phase (uvm_phase phase);
    this.vif = vif_pkg::vif;
    env = test_env::type_id::create("env", this);
  endfunction : build_phase

  function void connect_phase (uvm_phase phase);
    env.assign_if(vif);
  endfunction : connect_phase
  ...
endclass : test_case

```

If the hierarchy changed, use agent level instead of env:

```verilog

class test_case extends uvm_test;
  test_agent agent;
  virtual test_if vif;
  ...
  function void build_phase (uvm_phase phase);
    this.vif = vif_pkg::vif;
    agent = test_agent::type_id::create("agent", this);
  endfunction : build_phase

  function void connect_phase (uvm_phase phase);
    agent.assign_if(vif);
  endfunction : connect_phase
  ...
endclass : test_case

```

Use config\_db may not change the connect\_phase() method:

```verilog

class test_case extends uvm_test;
  test_env env;
  virtual test_if vif;
  ...
  function void build_phase (uvm_phase phase);
    this.vif = vif_pkg::vif;
    env = test_env::type_id::create("env", this);
  endfunction : build_phase

  function void connect_phase (uvm_phase phase);
    uvm_config_db #(virtual test_if)::set(this, "*", "test_if", vif);
  endfunction : connect_phase
  ...
endclass : test_case

```

and the changed one:

```verilog

class test_case extends uvm_test;
  test_agent agent;
  virtual test_if vif;
  ...
  function void build_phase (uvm_phase phase);
    this.vif = vif_pkg::vif;
    agent = test_agent::type_id::create("agent", this);
  endfunction : build_phase

  function void connect_phase (uvm_phase phase);
    uvm_config_db #(virtual test_if)::set(this, "*", "test_if", vif);
  endfunction : connect_phase
  ...
endclass : test_case

```

In uvm cookbook part:UVM/Performance Guidelines, it says “Use specific strings with the uvm\_config\_db set() and get() calls”, so

```verilog
uvm_config_db #(virtual test_if)::set(this, "*", "test_if", vif);

```

is not recommended. The connect\_phase() code must be change also if use a specific string when hierarchy changes.

So I wonder why don’t we make directly assignments to set virtual interface handle or configuration object?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Tudor\_Timi](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/tudor_timi/32/1897_2.png) [@Tudor\_Timi](https://verificationacademy.com/forums/u/Tudor_Timi)\
**Post date:** [January 23, 2015, 9:04am UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/2 "2015-01-23T09:04:39Z")

</div>

_In reply to [seabeam](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310):_

That’s a very good point! It seems to me that different people wrote the two sections and they didn’t align on this. I have been thinking lately that using the config DB might not be necessary. The config DB is a singleton (actually a collection of singletons) and overuse of singletons is a code smell.

---

<div class="post-metadata">

**Author:** ![seabeam](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@seabeam](https://verificationacademy.com/forums/u/seabeam)\
**Post date:** [January 31, 2015, 9:27am UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/3 "2015-01-31T09:27:06Z")

</div>

_In reply to [Tudor Timi](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/2):_

Hi Tudor:  
I’v tried to set-get 10,000 integer from parent to child, which uvm\_config\_db() methord takes 2.1s CPU time & nearly 87M Mem while direct assignment 0.3s CPU time & 3.7M Mem.  
However, uvm\_config\_db() may not take place in specific scenario: sequence get resources from m\_sequencer etc.  
But is it needed to pass vif or configuration object through UVC hierarchy?

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [February 2, 2015, 12:29pm UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/4 "2015-02-02T12:29:22Z")

</div>

Every agent should have a configuration object that encapsulates all of the parameters that can be modified to control the agent’s behavior. Examples of this include the notion of the agent being ACTIVE or PASSIVE. Included in the configuration object should be the vif handle.

The agent configuration objects should be created and configured at the test level, giving the user the ability to control the agent behavior on a per-test basis. These configuration objects should then be passed to the respective agent using the uvm\_config\_db().

Using the uvm\_config\_db() enables a single call to configure the agent instead of using many different calls to set the various agent parameters.

---

<div class="post-metadata">

**Author:** ![seabeam](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@seabeam](https://verificationacademy.com/forums/u/seabeam)\
**Post date:** [February 2, 2015, 2:52pm UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/5 "2015-02-02T14:52:05Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/4):_

Hi cgales:  
Here is an example,  
configuration object:

```verilog

class x_agent_config extends uvm_object;
  virtual x_if x_port;
  
  uvm_active_passive_enum active = UVM_ACTIVE;
  bit coverage_enable = 1'b1;
  ...
endclass : x_agent_config

```

agent

```verilog

class x_agent extends uvm_agent;
  x_agent_config cfg;
  ...
endclass : x_agent

```

perhaps an env level:

```verilog

class simple_env extends uvm_env;
  simple_env_config cfg;

  x_agent x_agt;
  y_agent y_agt;
  ...

  function void build_phase (uvm_phase phase);
    x_agt.cfg = cfg.x_agt_cfg;
    y_agt.cfg = cfg.y_agt_cfg;

    if (cfg.has_scoreboard)
    ...
  endfunction : build_phase
endclass : simple_env

```

Then make a base class of cases:

```verilog

class simple_case_base extends uvm_test;
  simple_env env;

  simple_env_config env_cfg;
  x_agent_config x_agt_cfg;
  y_agent_config y_agt_cfg;
  ...

  function void build_phase (uvm_phase phase);
    env_cfg = simple_env_config::type_id::create("env_cfg");
    config_env(env_cfg);
    
    x_agent_cfg = x_agent_config::type_id::create("x_agent_cfg");
    config_x_agent(x_agent_cfg);
    env_cfg.x_agent_cfg = x_agent_cfg;
    ...
    env.cfg = env_cfg;
  endfunction : build_phase
endclass : simple_case_base

```

In this situation, there is not many call. Instead, we use uvm\_config\_db(), we also need to call config\_env() then use uvm\_config\_db’s set() methord. I’m confused that why don’t use direct assignment like above?

Thanks!

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [February 2, 2015, 7:08pm UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/6 "2015-02-02T19:08:46Z")

</div>

_In reply to [seabeam](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/5):_

The reason that you can’t use assignments like you showed is because the environment and the agents will use some of the values provided in the configuration object during the build\_phase(). With assignments, you can’t assign the configuration object until the component is created, but the component requires the configuration object during the build\_phase(), which is called as part of create(). The most effective way to allow the component to retrieve its configuration object is by using the uvm\_config\_db().

---

<div class="post-metadata">

**Author:** ![seabeam](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@seabeam](https://verificationacademy.com/forums/u/seabeam)\
**Post date:** [February 3, 2015, 3:09am UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/7 "2015-02-03T03:09:34Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/6):_

Hi cgales:  
It’s correct that before component is created, the assignment can’t be done.  
By the way, build\_phase() will be called automatically when children use new() to create instance.  
I thinks build\_phase() is top-down phase, after making assignmet of agent config in env’s build\_phase(), even finish involking env’s build\_phase(), the children(agent)'s build\_phase() is involked. So it has no effect that agents can use these values provided in the configuration object to configurate it’s structure etc.

```verilog
class x_agent extends uvm_agent;
  x_agent_config cfg;

  x_coverage_collector collector;
  ...

  function void build_phase (uvm_phase phase);
    if (cfg.coverage_enable)
      collector = x_coverage_collector::type_id::create("collector");
    ...
  endfunction : build_phase
endclass : x_agent

```

The code above can work fine, is there any other reason please?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [February 3, 2015, 12:54pm UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/8 "2015-02-03T12:54:00Z")

</div>

_In reply to [seabeam](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/7):_

Your code won’t work how it is written. When your environment calls create() for your agent, the agent will be new’d() and have the build\_phase() called immediately. There is no way for the environment to set the value of the agent’s config object. The agent will need to get the value of its config object via the uvm\_config\_db.

When the build\_phase() is noted as top down, it doesn’t mean that the environment’s build phase will complete and then the sub-component(s) build\_phase() will be called. The build\_phase() of a component is called as part of the create() call.

---

<div class="post-metadata">

**Author:** ![pttran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/cab0a1/32.png) [@pttran](https://verificationacademy.com/forums/u/pttran)\
**Post date:** [February 7, 2015, 6:21am UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/9 "2015-02-07T06:21:22Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/8):_

Hi cgales,

I have some modifications with the idea of seabeam.

Instead of declare of automatic config object inside agent, I use static config object.

So config object of agent can be easily assign at test class before the agent component actually built.

→ Hence I see that when we used assignment config object directly is more effectively as we use uvm\_config\_db ( as seabeam pointout

> I’v tried to set-get 10,000 integer from parent to child, which uvm\_config\_db() methord takes 2.1s CPU time & nearly 87M Mem while direct assignment 0.3s CPU time & 3.7M Mem.

**Can you explain other reason to use uvm\_config\_db(), cgales?**

> Hi cgales:  
> Here is an example,  
> configuration object:  
> class x\_agent\_config extends uvm\_object;  
> virtual x\_if x\_port;  
> uvm\_active\_passive\_enum active = UVM\_ACTIVE;  
> bit coverage\_enable = 1’b1;  
> …  
> endclass : x\_agent\_config  
> agent  
> class x\_agent extends uvm\_agent;  
> x\_agent\_config cfg;  
> …  
> endclass : x\_agent  
> perhaps an env level:  
> class simple\_env extends uvm\_env;  
> simple\_env\_config cfg;  
> x\_agent x\_agt;  
> y\_agent y\_agt;  
> …  
> function void build\_phase (uvm\_phase phase);  
> x\_agt.cfg = cfg.x\_agt\_cfg;  
> y\_agt.cfg = cfg.y\_agt\_cfg;  
> if (cfg.has\_scoreboard)  
> …  
> endfunction : build\_phase  
> endclass : simple\_env  
> Then make a base class of cases:  
> class simple\_case\_base extends uvm\_test;  
> simple\_env env;  
> simple\_env\_config env\_cfg;  
> x\_agent\_config x\_agt\_cfg;  
> y\_agent\_config y\_agt\_cfg;  
> …  
> function void build\_phase (uvm\_phase phase);  
> env\_cfg = simple\_env\_config::type\_id::create(“env\_cfg”);  
> config\_env(env\_cfg);  
> x\_agent\_cfg = x\_agent\_config::type\_id::create(“x\_agent\_cfg”);  
> config\_x\_agent(x\_agent\_cfg);  
> env\_cfg.x\_agent\_cfg = x\_agent\_cfg;  
> …  
> env.cfg = env\_cfg;  
> endfunction : build\_phase  
> endclass : simple\_case\_base  
> In this situation, there is not many call. Instead, we use uvm\_config\_db(), we also need to call config\_env() then use uvm\_config\_db’s set() methord. I’m confused that why don’t use direct assignment like above?  
> Thanks!

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [February 8, 2015, 4:07pm UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/10 "2015-02-08T16:07:00Z")

</div>

_In reply to [pttran](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/9):_

When you use the ‘static’ property for the config object, all instances of your agent will have the same config object. This prevents you from using unique config objects for each agent.

See paragraph 8.9 of the SystemVerilog LRM for more information.

---

<div class="post-metadata">

**Author:** ![sujay\_rm](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/2acd7d/32.png) [@sujay\_rm](https://verificationacademy.com/forums/u/sujay_rm)\
**Post date:** [October 16, 2019, 1:21pm UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/11 "2019-10-16T13:21:46Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/10):_

Hi,  
Can you please tell me where to set and get agent config classes? I’ve set in environment and getting in agents, but error is coming. Please help me solve this issue.  
Thanks

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [October 16, 2019, 1:41pm UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/12 "2019-10-16T13:41:10Z")

</div>

_In reply to [sujay\_rm](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/11):_

Could you please explain what is  
config\_x\_agent?

---

<div class="post-metadata">

**Author:** ![sujay\_rm](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/2acd7d/32.png) [@sujay\_rm](https://verificationacademy.com/forums/u/sujay_rm)\
**Post date:** [October 17, 2019, 4:42am UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/13 "2019-10-17T04:42:18Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/12):_

I have set the uvm\_config\_db for agent\_config class in environment and i have getting that in wr\_agent and rd\_agent, this is causing the error.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [October 17, 2019, 7:42pm UTC](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/14 "2019-10-17T19:42:08Z")

</div>

_In reply to [sujay\_rm](https://verificationacademy.com/forums/t/why-use-uvm-config-db-to-pass-vif-or-configuration-object-is-recommended/30310/13):_

It would help if you asked this as new question and provided the exact error message along with the lines of code that do the set and get.
