Module 5: Configuration and Extension | Intermediate UVM

Configuration Database Patterns

Learn how to pass environment configuration through UVM hierarchy without hard-coding reusable components to a particular testbench.

Learning objectives

  • Explain why reusable UVM components need configurable behavior.
  • Use uvm_config_db to set and retrieve configuration values.
  • Understand the relationship between component hierarchy, configuration paths, and configuration values.
  • Choose appropriate configuration scopes for individual components and groups of components.
  • Use configuration objects to group related settings.
  • Distinguish configuration data from transaction data and factory overrides.
  • Diagnose missing, incorrectly scoped, or unexpectedly overridden configuration.
  • Build a small multi-agent environment with distinct configuration for each agent.

Step 1: Why configuration matters in a reusable environment

A reusable verification component should not hard-code every environment-specific decision. The same agent may need to operate differently in different tests or different DUT instances.

For example, one test might require:

Agent A: active


Agent B: passive

while another test might require:

Agent A: passive


Agent B: passive

The agent implementation should not need to be edited for each test. Configuration allows the testbench to select behavior from outside the reusable component.

Core principle: Configuration changes how a reusable component operates; it does not change the transaction being transmitted through that component.

Step 2: Separate configuration from other UVM mechanisms

Several UVM mechanisms can appear similar because they all allow a test to influence a reusable environment. They solve different problems.

Mechanism Primary purpose Example
uvm_config_db Pass configuration information through hierarchy Active/passive mode, virtual interface, timeout
Sequence item Represent stimulus or transaction data Address, data, command
Factory Replace the implementation of a registered type or instance Replace one driver with a derived driver
TLM Move transactions between components Monitor to scoreboard

A timeout value belongs in configuration. A packet's address belongs in a transaction. Replacing one driver implementation belongs to the factory mechanism.

Lessons 44–46 will cover factory overrides in detail. For now, keep the distinction clear.

Step 3: Understand the configuration database

uvm_config_db provides a typed interface for storing and retrieving configuration values associated with UVM component hierarchy.

A simplified pattern is:

// Set


uvm_config_db#(int)::set(
context,
instance_path,
field_name,
value
);

// Get
uvm_config_db#(int)::get(
context,
instance_path,
field_name,
value
);

The four important ideas are:

  1. the type of the value;
  2. the context from which the path is interpreted;
  3. the target instance path;
  4. the configuration field name.

The type must match between the set and get.

Step 4: Start with a simple scalar value

Suppose an agent needs a timeout value. The test can provide it before the agent attempts to retrieve it.

uvm_config_db#(int unsigned)::set(


this,
"env.agent",
"timeout_cycles",
100
);

The agent can retrieve it during its construction or build process:

class protocol_agent extends uvm_agent;


`uvm_component_utils(protocol_agent)

int unsigned timeout_cycles;

function new(
string name = "protocol_agent",
uvm_component parent = null
);
super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);
super.build_phase(phase);


if (!uvm_config_db#(int unsigned)::get(
      this,
      "",
      "timeout_cycles",
      timeout_cycles
    )) begin
  `uvm_fatal(
    "CFG",
    "timeout_cycles was not configured"
  )
end

`uvm_info(
  "CFG",
  $sformatf(
    "timeout_cycles=%0d",
    timeout_cycles
  ),
  UVM_MEDIUM
)


endfunction

endclass

Notice the use of this and an empty instance path in the get. The empty path means "relative to this component."

Step 5: Understand relative paths

Suppose the component hierarchy is:

uvm_test_top


|
+-- env
|
+-- agent
|
+-- driver
+-- monitor

From the test, this:

uvm_config_db#(int unsigned)::set(


this,
"env.agent",
"timeout_cycles",
100
);

targets the component named agent under env.

From inside the agent:

uvm_config_db#(int unsigned)::get(


this,
"",
"timeout_cycles",
timeout_cycles
);

looks for the setting relative to the agent's hierarchical location.

Debug habit: Before debugging the value itself, write down the actual UVM component hierarchy and the exact configuration path being used.

Step 6: Configure multiple instances

A major reason to understand paths is that different instances may require different settings.

uvm_config_db#(int unsigned)::set(


this,
"env.agent_a",
"timeout_cycles",
100
);

uvm_config_db#(int unsigned)::set(
this,
"env.agent_b",
"timeout_cycles",
500
);

Both agents use the same configuration field name, but each receives a different value because the target paths are different.

env.agent_a -> timeout_cycles = 100


env.agent_b -> timeout_cycles = 500

This pattern is often preferable to creating separate configuration field names such as agent_a_timeout and agent_b_timeout. The component identity belongs in the hierarchy; the field name describes the setting.

Step 7: Use wildcards carefully

Wildcards can apply one configuration value to several components.

uvm_config_db#(int unsigned)::set(


this,
"env.agent*",
"timeout_cycles",
100
);

This can be convenient when all matching agents should use the same timeout.

However, broad paths can make configuration difficult to understand. A setting such as:

"*"

can affect many components and make it harder to determine where a value came from.

Use broad scopes deliberately. Wildcards are useful for shared defaults, but highly specific configuration is often easier to debug. Lesson 43 will examine scope and precedence in greater detail.

Step 8: Group related settings into a configuration object

A real agent often needs more than one setting:

active/passive mode


virtual interface
timeout
protocol options
error injection enable
coverage enable

Passing each field separately through uvm_config_db can become difficult to maintain. A configuration object groups related settings into one typed object.

class protocol_agent_config extends uvm_object;


`uvm_object_utils(protocol_agent_config)

uvm_active_passive_enum is_active = UVM_ACTIVE;

int unsigned timeout_cycles = 100;

bit enable_error_injection = 0;

function new(string name = "protocol_agent_config");
super.new(name);
endfunction

endclass

The configuration object itself can then be placed into the configuration database:

protocol_agent_config agent_cfg;


agent_cfg = protocol_agent_config::type_id::create("agent_cfg");

agent_cfg.is_active = UVM_ACTIVE;
agent_cfg.timeout_cycles = 100;
agent_cfg.enable_error_injection = 0;

uvm_config_db#(protocol_agent_config)::set(
this,
"env.agent",
"cfg",
agent_cfg
);

The agent retrieves one object instead of several unrelated fields:

protocol_agent_config cfg;


if (!uvm_config_db#(protocol_agent_config)::get(
this,
"",
"cfg",
cfg
)) begin
`uvm_fatal("CFG", "Missing protocol_agent_config")
end

Lesson 42 will develop this pattern in detail.

Step 9: Configure the virtual interface

A common UVM configuration use case is passing a virtual interface from the top-level testbench into an agent.

uvm_config_db#(virtual protocol_if)::set(


null,
"uvm_test_top.env.agent",
"vif",
protocol_vif
);

The agent can retrieve it:

virtual protocol_if vif;


if (!uvm_config_db#(virtual protocol_if)::get(
this,
"",
"vif",
vif
)) begin
`uvm_fatal("CFG", "Virtual interface not configured")
end

This is a useful example because the virtual interface is not a transaction. It is an environment resource required by components that interact with the DUT interface.

In this pattern, null is commonly used as the context when setting a configuration item from a module-level testbench rather than from a UVM component.

Step 10: Retrieve configuration early

Configuration should normally be available before a component needs to make structural decisions.

For example, an agent's active/passive mode determines whether it creates a driver and sequencer.

function void build_phase(uvm_phase phase);


super.build_phase(phase);

if (!uvm_config_db#(protocol_agent_config)::get(
this,
"",
"cfg",
cfg
)) begin
`uvm_fatal("CFG", "Agent configuration missing")
end

if (cfg.is_active == UVM_ACTIVE) begin
driver = protocol_driver::type_id::create(
"driver",
this
);


sequencer = protocol_sequencer::type_id::create(
  "sequencer",
  this
);


end

monitor = protocol_monitor::type_id::create(
"monitor",
this
);
endfunction

The important idea is that configuration is consumed at the phase where it is needed. If a value determines what components are created, retrieve it before that construction decision.

Step 11: Do not confuse configuration with runtime control

Configuration is especially useful for values that establish how the environment should operate.

For example:

agent mode


interface handle
timeout policy
protocol variant
feature enable
coverage enable

It is usually not the right mechanism for sending every runtime command to a component.

If a driver needs to receive a stream of transactions during simulation, use the normal sequence and sequencer mechanisms.

Sequence


|
v
Sequencer
|
v
Driver
|
v
DUT

Do not repeatedly update uvm_config_db just to emulate transaction communication.

Step 12: Validate the configuration

A successful get() only tells you that a value was found. It does not guarantee that the value is valid.

if (cfg.timeout_cycles == 0) begin


`uvm_fatal(
"CFG",
"timeout_cycles must be greater than zero"
)
end

Configuration objects are especially useful because validation can be centralized:

function bit is_valid();


if (timeout_cycles == 0)
return 0;

return 1;

endfunction

A test can then validate the configuration before starting a long simulation.

Step 13: Debug a missing configuration value

A missing configuration failure should be treated as an environment construction problem, not as DUT behavior.

Use this debugging sequence:

get() failed
|
v


What is the component's full hierarchy?
|
v
What path did set() target?
|
v
Does the field name match exactly?
|
v
Does the type match?
|
v
Was set() executed before get()?
|
v
Is a wildcard/path behaving differently than expected?
|
v
Is another setting taking precedence?

Print the component hierarchy when necessary:

uvm_top.print_topology();

The topology is often the fastest way to discover that the configuration path does not match the actual component hierarchy.

Step 14: Debug an unexpected configuration value

A more subtle problem occurs when get() succeeds but returns a value you did not expect.

Typical causes include:

  • a broad wildcard setting;
  • multiple configuration settings for the same field;
  • an unexpected component path;
  • configuration set at a different hierarchy level;
  • scope or precedence behavior;
  • configuration being changed or replaced later in the build process.

Lesson 43 will examine precedence systematically. For now, develop the habit of asking: "Where did this value come from?"

Step 15: Build a two-agent example

Consider an environment:

uvm_test_top


|
+-- env
|
+-- agent_a
+-- agent_b

Configure the agents independently:

protocol_agent_config cfg_a;


protocol_agent_config cfg_b;

cfg_a = protocol_agent_config::type_id::create("cfg_a");
cfg_b = protocol_agent_config::type_id::create("cfg_b");

cfg_a.is_active = UVM_ACTIVE;
cfg_a.timeout_cycles = 100;

cfg_b.is_active = UVM_PASSIVE;
cfg_b.timeout_cycles = 500;

uvm_config_db#(protocol_agent_config)::set(
this,
"env.agent_a",
"cfg",
cfg_a
);

uvm_config_db#(protocol_agent_config)::set(
this,
"env.agent_b",
"cfg",
cfg_b
);

The same reusable agent class can now operate in two different modes without any source-code change.

This is one of the central benefits of UVM configuration.

Step 16: Configuration flow in a reusable environment

A useful mental model is:

Test


|
| creates/configures values
v
Configuration database
|
| hierarchical lookup
v
Reusable component
|
| consumes configuration
v
Component behavior

The configuration database is therefore a mechanism for distribution, not the final owner of every configuration decision.

A configuration object usually owns the meaning of related settings, while uvm_config_db provides a way to deliver that object to the component that needs it.

Common mistakes

Debugging strategy

When configuration behaves unexpectedly, debug it from hierarchy outward:

1. Print/inspect UVM topology
      |
      v


2. Identify exact target component
|
v
3. Locate set()
|
v
4. Check context and path
|
v
5. Check field name and type
|
v
6. Check ordering of set() and get()
|
v
7. Check wildcards / competing settings
|
v
8. Print the retrieved value
|
v
9. Validate the component's final behavior

If an agent unexpectedly becomes passive, for example, do not immediately debug the driver. First prove that the agent received the intended is_active configuration.

Try it yourself

Build an environment containing two instances of the same protocol agent:

env.agent_a


env.agent_b

Configure:

agent_a:


active
timeout = 100

agent_b:
passive
timeout = 500

Then:

  1. Print the UVM topology.
  2. Print the retrieved configuration from each agent.
  3. Run the environment and verify that only the active agent creates a driver/sequencer.
  4. Change one configuration path intentionally so that the setting is missing.
  5. Observe and diagnose the resulting get() failure.

Challenge: Find the configuration bug

Suppose the test contains:

uvm_config_db#(int unsigned)::set(


this,
"env.agent_a",
"timeout_cycles",
100
);

But the agent reports:

UVM_FATAL: timeout_cycles was not configured

Investigate these possibilities:

  1. The actual hierarchy is env.agents.agent_a.
  2. The agent retrieves "timeout" instead of "timeout_cycles".
  3. The agent retrieves int while the test sets int unsigned.
  4. The set() occurs after the agent's build_phase performs the get().

For each case, explain exactly why the lookup fails and how you would fix it.

Knowledge check

  1. What problem does uvm_config_db solve?
    It provides a typed way to distribute configuration values through the UVM component hierarchy.
  2. Why does hierarchy matter?
    Configuration lookup uses component context and instance paths to determine which setting applies.
  3. Why might two agents use the same field name but receive different values?
    Their configuration paths can target different component instances.
  4. Why should broad wildcards be used carefully?
    They can unintentionally affect multiple components and make configuration sources harder to trace.
  5. When is a configuration object preferable to individual fields?
    When a component has several related settings that should be managed and passed together.
  6. Should runtime transactions be passed through uvm_config_db?
    Generally no. Use sequences, TLM, and other runtime communication mechanisms for transaction flow.
  7. What should you check when get() fails?
    Component hierarchy, context, path, field name, type, set/get ordering, and scope behavior.
  8. What is the difference between configuration and factory overrides?
    Configuration supplies settings or resources to components; factory overrides replace component or object implementations.

Key takeaways

  • uvm_config_db lets reusable UVM components receive environment-specific settings without hard-coding them.
  • Configuration is strongly tied to UVM hierarchy, context, path, field name, and value type.
  • Use specific paths when independent component instances need different settings.
  • Use wildcards for intentional shared configuration, not as a universal shortcut.
  • Configuration objects are a scalable way to group related agent or environment settings.
  • Retrieve configuration early when it affects component construction or initialization.
  • Use sequences and TLM for runtime transaction flow rather than repeatedly modifying configuration.
  • Always check required get() calls and validate retrieved values.
  • When configuration is wrong, debug hierarchy and lookup before debugging downstream component behavior.

What comes next?

This lesson introduced the mechanics and architectural role of the UVM configuration database. The next lesson makes the configuration-object pattern more systematic.

Lesson 41


Configuration Database Patterns
|
v
Lesson 42
Configuration Object Design
|
v
Lesson 43
Configuration Scope and Precedence
|
v
Lessons 44–46
Factory Overrides and Debugging

In Lesson 42, configuration objects become the main design unit for reusable agents: grouping settings, providing defaults, validating values, handling virtual interfaces, and keeping configuration logic maintainable as the environment grows.