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_dbimplementation. - Understand how scope and precedence affect resource lookup.
- Choose appropriately between
uvm_resource_dbanduvm_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.
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.
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
- Define the setting. Choose one value such as a timeout or retry limit.
- Choose a clear resource name. Use names that describe the meaning of the value rather than where it happens to be used.
- Set the resource. Publish it from the test or configuration layer.
- Retrieve it in the consumer. Check the return value instead of assuming that the resource exists.
- Report the resolved value. Use
`uvm_infoduring development to make configuration decisions visible. - 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)
Step 6: Debug resource problems systematically
Resource lookup failures often look like ordinary configuration bugs. Debug them by checking the lookup chain in order.
- Confirm that the resource was actually created.
- Check the exact resource name, including spelling and capitalization.
- Print the consumer's
get_full_name(). - Compare that hierarchy against the resource's scope.
- Check whether another resource with the same name can compete with the intended value.
- 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.
- Set a default timeout of
100cycles for both agents. - Provide a more specific timeout for
agent0. - Read the resource from both drivers.
- Print each driver's resolved timeout.
- 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_dbfor straightforward hierarchical component configuration and useuvm_resource_dbwhen its resource-oriented semantics are actually useful. - Make resource resolution observable with informative UVM reports so configuration problems can be diagnosed quickly.