Comprehension question: apply_config_settings, config_db,

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:


  `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:


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

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.

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.

In reply to dave_59:

Thank you, now I understand.

In reply to Auras:

Another possibly related question:


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?