Module 5: Configuration and Extension | Intermediate UVM

UVM Resources

Learn how UVM resources provide a shared, name-based mechanism for distributing configuration and other reusable information across a verification environment.

Learning objectives

  • Explain the purpose of the UVM resource pool and resource-based lookup.
  • Read and adapt a focused uvm_resource_db implementation.
  • Understand how scope and precedence affect resource lookup.
  • Choose appropriately between uvm_resource_db and uvm_config_db.
  • Validate resource access with an observable report or check.

Step 1: Understand the concept

Large UVM environments frequently need to distribute information without tightly coupling producers and consumers. Examples include virtual interface handles, timeout values, feature controls, protocol settings, or shared test configuration.

UVM resources provide a name-based mechanism for storing and retrieving objects or values through the UVM resource pool. A component can publish a resource, while another component can retrieve it using a resource name and scope.

The key idea is separation:

  • The producer decides what information is available.
  • The resource name identifies the information.
  • The scope controls which components can find it.
  • The consumer retrieves the resource when it needs it.
Important: a resource is not a replacement for TLM communication. Use TLM ports, exports, and analysis ports to exchange transactions; use resources or configuration mechanisms to distribute shared settings and handles.

Resources and configuration

uvm_config_db is built on top of UVM's resource mechanism and is generally the clearer choice for hierarchical component configuration. Direct use of uvm_resource_db is useful when you specifically need resource-pool behavior or a broader name-based lookup model.

Step 2: Study the resource example

Consider a test that publishes a timeout value for components under a particular environment scope.

uvm_resource_db#(int)::set(


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

int timeout_cycles;

if (!uvm_resource_db#(int)::read_by_name(
get_full_name(),
"timeout_cycles",
timeout_cycles,
this
))
`uvm_fatal("RES", "timeout_cycles resource not found")

The first operation creates or updates a resource named timeout_cycles. The scope expression determines where that resource applies.

The consumer then attempts to find the resource by name. If the lookup succeeds, the value is copied into the local variable. If it fails, the component reports a configuration error rather than continuing with an unknown setting.

Why the scope matters

Suppose the environment contains:

env


├── agent0
│   └── driver
└── agent1
└── driver

A resource scoped to env.agent0* should be visible to matching components under agent0, while a resource scoped more broadly may be visible to multiple agents.

When debugging resource access, always ask two questions: what is the resource name? and what scope is being searched?

Step 3: Understand lookup and precedence

Resources become more interesting when several resources have the same name. UVM must determine which matching resource should be selected.

For example, a test might establish a default timeout while a more specific scope establishes a different value for one agent:

uvm_resource_db#(int)::set(


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

uvm_resource_db#(int)::set(
"env.agent0*",
"timeout_cycles",
25,
this
);

The intent is clear: use a general default for agents, but provide a more specific value for agent0. The exact result depends on the resource lookup rules and how resources were inserted, so avoid relying on accidental ordering.

Best practice: keep resource names unique and scopes intentional. If several components can write the same resource name, make the ownership and expected precedence obvious in the testbench.

Step 4: Choose the right mechanism

Before introducing a resource, identify what kind of information is being communicated.

Need Typical UVM mechanism
Send transactions between components TLM ports, exports, and analysis ports
Configure a component hierarchically uvm_config_db
Use a shared name-based resource uvm_resource_db
Replace a reusable implementation UVM factory override
Add optional behavior at a defined extension point UVM callback

The goal is not to use the most powerful mechanism. The goal is to choose the mechanism that makes the environment's architecture easiest to understand and maintain.

Step 5: Build it in small pieces

  1. Define the setting. Choose one value such as a timeout or retry limit.
  2. Choose a clear resource name. Use names that describe the meaning of the value rather than where it happens to be used.
  3. Set the resource. Publish it from the test or configuration layer.
  4. Retrieve it in the consumer. Check the return value instead of assuming that the resource exists.
  5. Report the resolved value. Use `uvm_info during development to make configuration decisions visible.
  6. Test scope deliberately. Give two components different scopes and confirm that each receives the intended value.
if (!uvm_resource_db#(int)::read_by_name(
  get_full_name(),
  "timeout_cycles",
  timeout_cycles,
  this
)) begin


`uvm_fatal("RES", "Required timeout_cycles resource is missing")
end

`uvm_info("RES",
$sformatf("Resolved timeout_cycles=%0d",
timeout_cycles),
UVM_MEDIUM)
Common mistake: treating a resource as global state without documenting its scope. A value that works only because of the current hierarchy is difficult to reuse and even harder to debug after the environment changes.

Step 6: Debug resource problems systematically

Resource lookup failures often look like ordinary configuration bugs. Debug them by checking the lookup chain in order.

  1. Confirm that the resource was actually created.
  2. Check the exact resource name, including spelling and capitalization.
  3. Print the consumer's get_full_name().
  4. Compare that hierarchy against the resource's scope.
  5. Check whether another resource with the same name can compete with the intended value.
  6. Log the final value received by the consumer.

This approach turns an invisible configuration problem into an observable sequence of facts.

Try it yourself

Create two agents that consume a resource named timeout_cycles.

  1. Set a default timeout of 100 cycles for both agents.
  2. Provide a more specific timeout for agent0.
  3. Read the resource from both drivers.
  4. Print each driver's resolved timeout.
  5. Change the hierarchy and observe whether the lookup still behaves as intended.

Challenge: repeat the exercise using uvm_config_db. Compare which implementation makes the intended hierarchy and ownership easier to understand.

Key takeaways

  • UVM resources provide name- and scope-based access to shared information through the resource pool.
  • Resource names and scopes are part of the testbench architecture, not incidental implementation details.
  • Always check whether a resource lookup succeeds before using the retrieved value.
  • Use TLM for transaction flow and configuration mechanisms for settings; do not use resources as a substitute for normal component communication.
  • Prefer uvm_config_db for straightforward hierarchical component configuration and use uvm_resource_db when its resource-oriented semantics are actually useful.
  • Make resource resolution observable with informative UVM reports so configuration problems can be diagnosed quickly.