# Comprehension question: apply\_config\_settings, config\_db,

**URL:** <https://verificationacademy.com/forums/t/comprehension-question-apply-config-settings-config-db/30145>\
**Category:** UVM\
**Tags:** apply\_config\_settings, UVM, config\_db\
**Created:** [November 18, 2014, 3:56pm UTC](https://verificationacademy.com/forums/t/comprehension-question-apply-config-settings-config-db/30145 "2014-11-18T15:56:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Auras](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/aca169/32.png) [@Auras](https://verificationacademy.com/forums/u/Auras)\
**Post date:** [November 18, 2014, 3:56pm UTC](https://verificationacademy.com/forums/t/comprehension-question-apply-config-settings-config-db/30145/1 "2014-11-18T15:56:54Z")

</div>

Hi,

I have seen the following situation in uart\_env.sv from the uvm\_ref\_flow\_1.2 package.

The configuration is registered with a field macro:

```verilog

  `uvm_component_utils_begin(uart_env)
    `uvm_field_object(cfg, UVM_DEFAULT)
    `uvm_field_int(checks_enable, UVM_DEFAULT)
    `uvm_field_int(coverage_enable, UVM_DEFAULT)
  `uvm_component_utils_end

```

The build phase calls super.build\_phase, thus the automatic configuration:

```verilog

function void uart_env::build_phase(uvm_phase phase);
  super.build_phase(phase);
  // Configure
  if ( cfg == null)
    if (!uvm_config_db#(uart_config)::get(this, "", "cfg", cfg)) begin
      `uvm_info("NOCONFIG", "No uart_config, creating...", UVM_MEDIUM)
      cfg = uart_config::type_id::create("cfg", this);
      if (!cfg.randomize())
         `uvm_error("RNDFAIL", "Could not randomize uart_config using default values")
      `uvm_info(get_type_name(), {"Printing cfg:\n", cfg.sprint()}, UVM_MEDIUM)
    end

```

If I use the config db, then the automatic configuration (apply\_config\_settings) called by the build phase of uvm\_component should set “cfg”, right? Then why does this code, if cfg = null, query the config DB _again_? Am I misunderstanding how this works?

BR, Dominik

---

<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:** [November 18, 2014, 4:17pm UTC](https://verificationacademy.com/forums/t/comprehension-question-apply-config-settings-config-db/30145/2 "2014-11-18T16:17:12Z")

</div>

This confusion over which types get automatically configured, plus the extremely poor performance it introduces, are a few of the many reason we [recommend against using the field automation macros](https://verificationacademy.com/cookbook/macrocostbenefit).

For this to have worked, you would have to set the config\_db using the base uvm\_object, thus eliminating the type based configuration database.

---

<div class="post-metadata">

**Author:** ![Auras](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/aca169/32.png) [@Auras](https://verificationacademy.com/forums/u/Auras)\
**Post date:** [November 19, 2014, 8:17am UTC](https://verificationacademy.com/forums/t/comprehension-question-apply-config-settings-config-db/30145/3 "2014-11-19T08:17:16Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/comprehension-question-apply-config-settings-config-db/30145/2):_

Thank you, now I understand.

---

<div class="post-metadata">

**Author:** ![Auras](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/aca169/32.png) [@Auras](https://verificationacademy.com/forums/u/Auras)\
**Post date:** [November 19, 2014, 8:44am UTC](https://verificationacademy.com/forums/t/comprehension-question-apply-config-settings-config-db/30145/4 "2014-11-19T08:44:52Z")

</div>

_In reply to [Auras](https://verificationacademy.com/forums/t/comprehension-question-apply-config-settings-config-db/30145/3):_

Another possibly related question:

```verilog

function void apb_master_agent::build_phase(uvm_phase phase);
  uvm_object config_obj;
  super.build_phase(phase);
  if (cfg == null) begin
    if (!uvm_config_db#(apb_config)::get(this, "", "cfg", cfg))
     `uvm_warning("NOCONFIG", 
          "Config not set for master agent, using default is_active field")
    end
  else is_active = cfg.master_config.is_active;

```

So, if the cfg class member was assigned, then we take is\_active from the config object. Otherwise we use the default is\_active field of uvm\_agent, set via the auto-configuration? Wouldn’t that mean that if we use the config db to set the configuration object, then practically cfg.master\_config.is\_active will be ignored?
