Module 2: UVM Foundations | Lesson 20

Configuration Database Basics

Learn how UVM components share configuration data using uvm_config_db without creating tightly coupled testbenches.

Learning objectives

  • Explain why UVM provides a configuration database.
  • Understand the difference between set() and get().
  • Use uvm_config_db to pass configuration from a parent to a child component.
  • Understand how the UVM component hierarchy affects configuration lookup.
  • Pass a virtual interface using uvm_config_db.
  • Diagnose common configuration database mistakes.

Step 1: Why do we need a configuration database?

A UVM testbench contains many components: tests, environments, agents, drivers, monitors, scoreboards, and sequences.

These components often need configuration information. For example:

  • Should an agent be active or passive?
  • Which virtual interface should a driver use?
  • What address range should a sequence generate?
  • How many transactions should a test create?
  • Should a monitor enable protocol checking?

A poor design is to hard-code this information inside every component. That makes the environment difficult to reuse.

UVM provides uvm_config_db so a higher-level component can provide configuration and a lower-level component can retrieve it.

Key idea: Configuration usually flows down the UVM hierarchy. A test can configure an environment, an environment can configure an agent, and an agent can configure a driver or monitor.

Step 2: The basic set/get pattern

The two most important operations are:

  • set() — stores a configuration value.
  • get() — retrieves a configuration value.

The basic pattern looks like this:

// Store a configuration value


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

// Retrieve the configuration value
if (!uvm_config_db#(int)::get(this, "", "timeout", timeout))
`uvm_fatal("CFG", "timeout was not found")

Notice that uvm_config_db is parameterized by a data type. The type used by set() and get() must match.

Important: uvm_config_db#(int), uvm_config_db#(bit), and uvm_config_db#(virtual my_if) are different typed configuration databases.

Step 3: Understand set()

The commonly used form of set() is:

uvm_config_db#(T)::set(context, instance_name, field_name, value);

Think about the arguments this way:

  • T — the type of configuration data.
  • context — the component from which the path is evaluated.
  • instance_name — where the configuration should apply.
  • field_name — the name used to identify the setting.
  • value — the actual configuration value.

For example:

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


);

This stores an integer called timeout for the env.agent component relative to the calling context.

Step 4: Understand get()

A component uses get() to retrieve configuration:

uvm_config_db#(T)::get(context, instance_name, field_name, value);

get() returns a bit indicating whether the requested configuration was found.

A robust component should check the return value:

if (!uvm_config_db#(int)::get(this, "", "timeout", timeout))


`uvm_fatal("CFG", "timeout configuration was not found")

The empty string "" means that the component is looking for the configuration relative to its current hierarchical context.

Good verification habit: Do not silently continue when required configuration is missing. A missing virtual interface or required configuration should normally produce a clear UVM error or fatal message.

Step 5: A complete parent-to-child example

Consider this simple UVM hierarchy:

test


└── env
└── agent
└── driver

Suppose the test wants to configure the driver with a timeout value. The test can place the value into the configuration database:

class my_test extends uvm_test;


`uvm_component_utils(my_test)

my_env env;

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

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


env = my_env::type_id::create("env", this);

uvm_config_db#(int)::set(
  this,
  "env.agent.driver",
  "timeout",
  100
);


endfunction

endclass

The driver can retrieve the value during its build_phase:

class my_driver extends uvm_driver#(packet);


`uvm_component_utils(my_driver)

int timeout;

function new(string name = "my_driver", 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)::get(
      this,
      "",
      "timeout",
      timeout
    ))
  `uvm_fatal("CFG", "timeout was not configured")

`uvm_info(
  "CFG",
  $sformatf("Driver timeout = %0d", timeout),
  UVM_LOW
)


endfunction

endclass

The important point is that the driver does not need to know which test created the value. It simply asks for the configuration it needs.

Step 6: The most common real-world use — virtual interfaces

One of the most important uses of uvm_config_db is passing a SystemVerilog virtual interface into a UVM driver or monitor.

The DUT connects to a concrete interface instance in the top-level testbench. UVM components cannot directly connect to that instance, so the virtual interface is passed through the configuration database.

For example:

interface bus_if(input logic clk);


logic        valid;
logic        ready;
logic [7:0]  data;

endinterface

The top-level testbench can place the interface into the configuration database:

module tb_top;


logic clk;

bus_if bus_vif(clk);

initial begin
uvm_config_db#(virtual bus_if)::set(
null,
"uvm_test_top.env.agent.driver",
"vif",
bus_vif
);


run_test("my_test");


end

endmodule

The driver retrieves the same virtual interface:

class my_driver extends uvm_driver#(packet);


`uvm_component_utils(my_driver)

virtual bus_if vif;

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

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


if (!uvm_config_db#(virtual bus_if)::get(
      this,
      "",
      "vif",
      vif
    ))
  `uvm_fatal("NOVIF", "Virtual interface was not configured")


endfunction

endclass
This pattern is worth remembering:
Top-level testbench creates the interface → config_db::set() stores it → UVM driver/monitor uses config_db::get() to retrieve it.

Step 7: Why hierarchy matters

The configuration database is closely connected to the UVM component hierarchy.

Consider:

uvm_test_top


└── env
└── agent
├── driver
└── monitor

If the test executes:

uvm_config_db#(int)::set(


this,
"env.agent.driver",
"timeout",
100
);

the configuration targets the driver at that hierarchical location.

This means that configuration paths are not arbitrary strings. They need to correspond to the names of components in the UVM hierarchy.

Common mistake: A configuration lookup can fail simply because the instance path is wrong. If env.agent.driver does not match the actual hierarchy, the driver may not receive the setting.

Step 8: Configuration objects scale better

A small example may use several individual configuration values:

uvm_config_db#(bit)::set(this, "env.agent", "is_active", 1);


uvm_config_db#(int)::set(this, "env.agent", "timeout", 100);
uvm_config_db#(int)::set(this, "env.agent", "max_delay", 10);

This can become difficult to manage as the environment grows.

A common UVM design is to create a configuration object containing related settings:

class agent_config extends uvm_object;


`uvm_object_utils(agent_config)

bit is_active;
int timeout;
int max_delay;

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

endclass

The complete configuration object can then be stored in the database:

agent_config cfg;


cfg = agent_config::type_id::create("cfg");

cfg.is_active = 1;
cfg.timeout   = 100;
cfg.max_delay = 10;

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

The agent retrieves one object instead of searching for many individual settings.

You will use this pattern extensively as your UVM environments become larger and more reusable.

Step 9: Common configuration database mistakes

Mistake 1: The types do not match

uvm_config_db#(int)::set(this, "env", "timeout", 100);


// Incorrect type
uvm_config_db#(longint)::get(this, "", "timeout", timeout);

The configuration type must match between the writer and reader.

Mistake 2: The field name is different

uvm_config_db#(int)::set(this, "env", "timeout", 100);


// Looks for "time_out", not "timeout"
uvm_config_db#(int)::get(this, "", "time_out", timeout);

Configuration field names are strings, so spelling matters.

Mistake 3: The hierarchy path is wrong

If the actual component is named agent0, this will not target it:

uvm_config_db#(int)::set(


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

when the actual hierarchy is:

env.agent0.driver

Mistake 4: Ignoring the return value of get()

// Weak


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

Prefer:

if (!uvm_config_db#(int)::get(
  this,
  "",
  "timeout",
  timeout
))


`uvm_fatal("CFG", "timeout was not configured")

A clear failure message makes configuration bugs much easier to debug.

Step 10: A simple mental model

Think of uvm_config_db as a configuration service attached to the UVM hierarchy.

                 Configuration
                  |
                  v
             +---------+
             |   test  |
             +---------+
                  |
                  | set()
                  v
             +---------+
             |   env   |
             +---------+
                  |
                  v
             +---------+
             |  agent  |
             +---------+
                  |
                  | get()
                  v
             +---------+
             | driver  |
             +---------+

The higher-level code decides what configuration to provide. The lower-level component decides what configuration it requires.

Design principle: Components should depend on configuration values, not on the code that created those values.

Try it yourself

Build a small UVM hierarchy containing a test, environment, agent, and driver.

  1. Create an integer configuration value named timeout.
  2. Use uvm_config_db#(int)::set() in the test.
  3. Target the driver using its hierarchical instance path.
  4. Retrieve the value in the driver's build_phase().
  5. Print the value with uvm_info.
  6. Change the configuration value and verify that the driver sees the new value.
  7. Finally, intentionally change the field name and observe the configuration failure.
Challenge: Replace the integer with an agent_config object containing is_active, timeout, and max_delay. Pass the complete object through uvm_config_db.

Key takeaways

  • uvm_config_db allows UVM components to share configuration data through the component hierarchy.
  • set() stores configuration; get() retrieves it.
  • The configuration database is strongly typed.
  • Instance paths and field names must match the intended configuration target.
  • Always check the return value of get() when configuration is required.
  • Virtual interfaces are one of the most important real-world uses of uvm_config_db.
  • Configuration objects are useful when an agent or environment has multiple related settings.
  • Good UVM components receive configuration rather than hard-coding environment-specific behavior.