Module 5: Configuration and Extension | Intermediate UVM

Configuration Scope and Precedence

Control exactly which UVM components receive configuration, understand how matching and precedence work, and debug conflicting settings in multi-agent environments.

Learning objectives

  • Explain how uvm_config_db uses hierarchical scope and instance paths.
  • Distinguish relative paths, absolute paths, and wildcard paths.
  • Configure one component, a group of components, or an entire subtree intentionally.
  • Explain why configuration precedence matters when multiple settings match the same component.
  • Choose specific paths over broad wildcards when independent configuration is required.
  • Configure multiple agent instances without accidentally sharing settings.
  • Debug configuration problems by inspecting hierarchy, paths, field names, types, and precedence.
  • Recognize the difference between configuration scope and factory override scope.
  • Use configuration objects together with precise uvm_config_db paths.

Step 1: Why scope matters

Lesson 41 introduced uvm_config_db. Lesson 42 introduced configuration objects that group related settings into a typed object.

The next problem appears when the environment contains several instances of the same component:

uvm_test_top


|
+-- env
|
+-- command_agent
|    +-- driver
|    +-- monitor
|
+-- response_agent
+-- driver
+-- monitor

Suppose both agents use the same configuration class. The test may nevertheless need:

command_agent:
active
timeout = 100


response_agent:
passive
timeout = 500

The configuration object's fields describe what the agent should do. The configuration database path determines which instance receives that object.

Key idea: Configuration correctness depends on both the value and the path used to deliver it.

Step 2: Understand the configuration database path

A typical call has this form:

uvm_config_db#(T)::set(
context,
instance_path,
field_name,
value


);

The important pieces are:

Argument Purpose
T Type of the configuration value.
context Component from which the path is interpreted.
instance_path Target path relative to the context, or a hierarchical path when using a suitable context.
field_name Name used by the receiving component to retrieve the value.
value The actual configuration value or object handle.

For example:

uvm_config_db#(int)::set(
this,
"env.command_agent",
"timeout_cycles",
100


);

If the calling component is the test, this targets the command_agent below that test's hierarchy.

Step 3: Relative paths and context

The meaning of an instance path depends on the context used in the call.

Consider:

uvm_test_top


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

From the test, this path can target the agent:

uvm_config_db#(int)::set(
this,
"env.agent",
"timeout_cycles",
100


);

From the environment, the equivalent relative target can be:

uvm_config_db#(int)::set(
this,
"agent",
"timeout_cycles",
100


);

The context changes the starting point from which the instance path is interpreted.

Step 4: Target one exact instance

The safest starting point for independent agent configuration is an exact path.

protocol_agent_config command_cfg;


protocol_agent_config response_cfg;

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

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

command_cfg.is_active = UVM_ACTIVE;
command_cfg.timeout_cycles = 100;

response_cfg.is_active = UVM_PASSIVE;
response_cfg.timeout_cycles = 500;

uvm_config_db#(protocol_agent_config)::set(
this,
"env.command_agent",
"cfg",
command_cfg
);

uvm_config_db#(protocol_agent_config)::set(
this,
"env.response_agent",
"cfg",
response_cfg
);

Both agents use the same configuration type, but each receives a different object.

Step 5: Use wildcards deliberately

Wildcards are useful when several components should intentionally receive the same setting.

uvm_config_db#(int)::set(
this,
"env.agent*",
"timeout_cycles",
100


);

This can match multiple agent instances whose paths satisfy the pattern.

Wildcards are useful for shared policy:

env.agent_a


env.agent_b
env.agent_c

All agents:
timeout_cycles = 100

They become dangerous when different instances require different values.

command_agent: 100


response_agent: 500

Broad wildcard:
env.agent*


         |
         v


Both may receive the broad setting

If two components need different values, prefer explicit instance paths.

Step 6: Understand the difference between scope and precedence

Scope answers:

"Which components can this setting apply to?"

Precedence answers:

"If multiple settings apply, which setting wins?"

This distinction is essential when broad and specific configuration settings coexist.

For example, a test might establish a general default:

uvm_config_db#(int)::set(
this,
"env.*",
"timeout_cycles",
100


);

and then attempt to specialize one instance:

uvm_config_db#(int)::set(
this,
"env.response_agent",
"timeout_cycles",
500


);

Whether the more specific setting wins depends on the configuration database's precedence rules and the context and phase in which the settings are made.

Important: Do not reduce configuration precedence to "the most specific string always wins." UVM configuration is implemented through the resource database, and precedence is affected by hierarchical context and when the setting is established.

Step 7: Understand build-time precedence

UVM's configuration database uses hierarchical precedence during the build process. Settings made from higher levels of the component hierarchy have different precedence from settings made lower in the hierarchy.

In practical terms, a test commonly establishes configuration for its environment and agents, while a component may also establish defaults for its children.

test


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

A useful architectural pattern is:

Reusable component
|
+-- provides sensible defaults


Test
|
+-- supplies test-specific configuration

Agent instance
|
+-- consumes final configuration

This keeps reusable components configurable without requiring every test to know their internal implementation.

However, do not create competing configuration sources unnecessarily. The more places that write the same field, the harder it becomes to determine why a value won.

Step 8: Avoid competing writers

A difficult configuration problem often looks like this:

test:
timeout_cycles = 500


env:
timeout_cycles = 100

agent:
timeout_cycles = 50

Even if the simulation runs, the final value may not be obvious from the source code.

Prefer one clear ownership model:

Test owns test-specific policy
    |
    v


Configuration object
|
v
Agent consumes configuration
|
v
Driver/monitor use relevant fields

Reusable components can have defaults, but project-level tests should not have to fight those defaults through several layers of configuration writes.

Step 9: Configure a subtree intentionally

Sometimes one policy genuinely belongs to an entire subtree.

uvm_test_top


|
+-- env
|
+-- command_agent
|    +-- driver
|    +-- monitor
|
+-- response_agent
+-- driver
+-- monitor

For example, a common diagnostic or timeout policy may be intended for all agents beneath the environment.

uvm_config_db#(int)::set(
this,
"env.*",
"timeout_cycles",
100


);

The important point is that the wildcard expresses an architectural decision: this policy is intentionally shared by this subtree.

Step 10: Use configuration objects with precise scope

Lesson 42 introduced the configuration object. Combining it with precise paths gives a scalable pattern.

class protocol_agent_config extends uvm_object;


`uvm_object_utils(protocol_agent_config)

virtual protocol_if vif;
uvm_active_passive_enum is_active = UVM_ACTIVE;
int unsigned timeout_cycles = 100;
bit enable_protocol_checks = 1;

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

endclass

The test can then configure instances independently:

command_cfg.vif = command_vif;


command_cfg.is_active = UVM_ACTIVE;
command_cfg.timeout_cycles = 100;

response_cfg.vif = response_vif;
response_cfg.is_active = UVM_PASSIVE;
response_cfg.timeout_cycles = 500;

uvm_config_db#(protocol_agent_config)::set(
this,
"env.command_agent",
"cfg",
command_cfg
);

uvm_config_db#(protocol_agent_config)::set(
this,
"env.response_agent",
"cfg",
response_cfg
);

This is generally easier to maintain than dozens of independent scalar configuration entries.

Step 11: Understand exact field-name matching

The configuration database lookup must use the same field name and compatible type.

uvm_config_db#(int)::set(
this,
"env.agent",
"timeout_cycles",
100


);

The receiver must request the same field:

int timeout_cycles;


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

These are different configuration entries:

"timeout_cycles"


"timeout"
"timeout_cycle"

A path can be correct and still fail because the field name is wrong.

Step 12: Remember that configuration types must match

The parameterized type is part of the configuration database interface.

uvm_config_db#(int)::set(
this,
"env.agent",
"timeout_cycles",
100


);

Retrieve it as an int:

int timeout_cycles;


uvm_config_db#(int)::get(
this,
"",
"timeout_cycles",
timeout_cycles
);

Likewise, an agent configuration object must be retrieved using the corresponding configuration type:

protocol_agent_config cfg;


uvm_config_db#(protocol_agent_config)::get(
this,
"",
"cfg",
cfg
);

Step 13: Understand lookup from inside the receiving component

A common pattern is to configure an agent from the test and retrieve the value from the agent itself.

// Test


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


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", "Missing protocol_agent_config")
end

if (!cfg.is_valid()) begin
`uvm_fatal("CFG", "Invalid protocol_agent_config")
end
endfunction

The agent uses an empty relative instance path because it is asking for configuration associated with itself.

Step 14: Do not assume a wildcard is inherited configuration

It is tempting to think of:

"env.*"

as if it were a programming-language inheritance mechanism. It is not.

It is a configuration database matching pattern. The matching component must perform a compatible lookup, and the field name and type still matter.

For example, a configuration entry for:

"env.*", "cfg"

does not automatically cause every component to receive every field inside the object independently. The receiving component still retrieves the configuration object under the configured field name.

Step 15: Prefer a clear scope strategy

Requirement Preferred approach
One agent needs a unique VIF Exact agent path
Two agents need different timeouts Separate exact paths
All agents share one policy Intentional subtree wildcard
Different agent instances need different config objects One object per instance
Component needs a local default Establish a documented default at the appropriate hierarchy level
Runtime state changes continuously Use runtime communication/control rather than config_db

Step 16: Debug the complete configuration path

When a component reports an unexpected configuration value, use a fixed diagnostic sequence.

Unexpected configuration
    |
    v


1. Which component is receiving it?
   |
   v
2. What is its full hierarchical name?
   |
   v
3. What field name is being requested?
   |
   v
4. What type is being requested?
   |
   v
5. Which set() calls can match?
   |
   v
6. Which settings have the relevant precedence?
   |
   v
7. When were those settings established?
   |
   v
8. Was the configuration object later modified?
   |
   v
9. What value did the component actually consume?

Start with the hierarchy rather than randomly changing wildcard strings.

Step 17: Print the hierarchy before debugging paths

When the expected path is unclear, print the UVM topology:

uvm_top.print_topology();

For example, verify whether the actual hierarchy is:

uvm_test_top.env.command_agent

or something unexpected such as:

uvm_test_top.env.command_agent_0

A configuration path that looks correct on paper can fail simply because the component was created under a different instance name.

Step 18: Add configuration evidence

After retrieving the final configuration, report the values that matter.

`uvm_info(
   

"CFG",
$sformatf(
"%s: active=%0d timeout=%0d checks=%0d",
get_full_name(),
cfg.is_active,
cfg.timeout_cycles,
cfg.enable_protocol_checks
),
UVM_MEDIUM
)

This turns a hidden configuration problem into observable evidence.

A useful debug log might show:

uvm_test_top.env.command_agent:
active=1 timeout=100 checks=1


uvm_test_top.env.response_agent:
active=0 timeout=500 checks=1

Now a configuration mismatch can be investigated before debugging driver or monitor code.

Step 19: Separate configuration scope from factory scope

Configuration scope and factory override scope solve different problems.

Mechanism Main question
uvm_config_db What settings should this component receive?
Factory override Which implementation should be created?

For example:

Configuration:
command_agent.timeout_cycles = 100


Factory:
replace protocol_driver with debug_protocol_driver

A configuration change does not replace a component class. A factory override does not normally replace a configuration value.

Lessons 44–46 will focus on factory overrides and their own scope and debugging rules.

Step 20: Build a clean ownership model

A reusable environment becomes easier to reason about when each configuration value has a clear owner.

Test


|
+-- chooses test-specific policy
|
v
Environment configuration
|
+-- command_agent_cfg
+-- response_agent_cfg
+-- global policy
|
v
Agents
|
+-- validate and consume configuration
|
v
Driver / Monitor
|
+-- use only the fields they need

Avoid this architecture:

Test writes timeout


Environment rewrites timeout
Agent rewrites timeout
Driver rewrites timeout


             |
             v


Nobody can easily explain the final value.

Common mistakes

Debugging exercise: why did the timeout change?

Suppose the test contains:

uvm_config_db#(int)::set(
this,
"env.*",
"timeout_cycles",
100


);

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

The response agent reports:

timeout_cycles = 100

Do not immediately change the wildcard.

Investigate:

  1. What is the exact full name of response_agent?
  2. Which context performed each set()?
  3. When were the settings established?
  4. Were there additional configuration writes elsewhere?
  5. Is the receiving component requesting the exact field and type?
  6. Was the retrieved value subsequently modified?

The goal is not merely to make the number become 500. The goal is to identify why the configuration database selected the observed value.

Try it yourself: two independent agents

Create this hierarchy:

uvm_test_top


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

Create two protocol_agent_config objects:

agent_a:
UVM_ACTIVE
timeout = 100


agent_b:
UVM_PASSIVE
timeout = 500

Store them under the exact paths for the two agents. In each agent's build_phase(), retrieve and print its configuration.

Expected result:

agent_a -> active=1 timeout=100


agent_b -> active=0 timeout=500

Exercise: wildcard policy

Configure three agents:

agent_a


agent_b
agent_c

Give all three a common enable_protocol_checks = 1 policy using an intentional subtree wildcard.

Then configure agent_b with a different timeout using an exact path.

Document which settings are intentionally shared and which are instance-specific.

Challenge: Find the configuration conflict

A reusable environment contains:

uvm_test_top


|
+-- env
|
+-- master_agent
+-- slave_agent

Configuration sources are:

Test:
env.* -> timeout = 100


Environment:
master_agent -> timeout = 200

Slave agent:
timeout = 50

The final value observed by slave_agent is not the value expected by the test author.

Your task:

  1. Identify all potential writers.
  2. Resolve the complete paths.
  3. Determine the hierarchy level and phase in which each setting is written.
  4. Determine which setting wins according to UVM configuration precedence.
  5. Redesign the configuration ownership so that only the intended layer controls the final policy.

Advanced extension: Replace the scalar timeout settings with separate configuration objects for the two agents. Decide which settings belong at environment level and which belong at agent level.

Practical configuration checklist

  1. Print the actual UVM topology when path behavior is uncertain.
  2. Write down the full hierarchical name of the receiving component.
  3. Verify the context used by every relevant set().
  4. Verify the instance path and wildcard.
  5. Verify the field name exactly.
  6. Verify the uvm_config_db#(T) type.
  7. Find all writers for the same field.
  8. Consider hierarchy and build-time precedence.
  9. Retrieve configuration before structural decisions that depend on it.
  10. Print the effective configuration after retrieval.
  11. Prefer explicit paths when instances require independent policies.
  12. Use wildcards only when shared scope is intentional.

Knowledge check

  1. What does configuration scope determine?
    Which component instances a configuration entry can apply to.
  2. What does precedence determine?
    Which matching configuration setting takes effect when multiple settings apply.
  3. Why can "*" be dangerous?
    It can unintentionally affect many components and make configuration ownership difficult to trace.
  4. Why does the context argument matter?
    It determines how a relative instance path is interpreted.
  5. What should you check if get() fails?
    Component hierarchy, context, instance path, field name, and configuration type.
  6. Should every agent instance share one configuration object?
    Only when sharing the same configuration object is intentional. Independent policies generally deserve independent objects.
  7. Does a configuration object replace the need for scope?
    No. The object organizes the settings; the database path determines where the object is delivered.
  8. Should configuration and runtime state be mixed?
    Normally no. Configuration establishes policy; runtime state belongs to the components performing the simulation.
  9. How is configuration different from a factory override?
    Configuration changes settings or policy; a factory override changes which implementation is constructed.

Key takeaways

  • uvm_config_db is hierarchical; the context and instance path determine where configuration can apply.
  • Configuration scope answers where a setting applies; precedence answers which matching setting wins.
  • Exact instance paths are usually the clearest choice when different agent instances need different policies.
  • Wildcards are useful for intentionally shared configuration, but broad wildcards can create hidden coupling.
  • The field name and uvm_config_db type must match between set() and get().
  • Multiple writers for the same field make configuration harder to debug and should be minimized.
  • Build-time hierarchy and precedence matter when configuration is established from different levels of the UVM tree.
  • A configuration object organizes related settings; it does not eliminate the need for correct hierarchical scope.
  • Printing topology and effective configuration values provides concrete evidence when debugging.
  • Configuration scope and factory override scope are different mechanisms and should be reasoned about separately.

What comes next?

Lessons 41 and 42 established the two halves of structured configuration:

Lesson 41


Configuration Database Patterns
|
v
Lesson 42
Configuration Object Design
|
v
Lesson 43
Configuration Scope and Precedence
|
v
Lesson 44
Factory Type Overrides
|
v
Lesson 45
Factory Instance Overrides
|
v
Lesson 46
Factory Debugging

Lesson 43 answers:

"Which component receives this configuration,


and why does this value win?"

The next lessons apply the same architectural discipline to the UVM factory. Instead of deciding which settings a component receives, you will learn how to decide which implementation the factory creates.

Lesson 44: Factory Type Overrides introduces type-level replacement, allowing a reusable environment to substitute one component or object implementation without modifying the environment source.