uvm_config_db vs uvm_resource_db cover: who wins when two components set a value, measured on VCS

uvm_config_db vs uvm_resource_db in UVM: Set, Get and Precedence, Tested on VCS

In short: uvm_config_db passes values down a UVM testbench by hierarchy path: you set() from above and get() in the component that needs it. In build_phase, a setting from higher in the hierarchy wins, even over an exact path from lower down. Inside one component the last set() wins. get() returns 0 silently on a wrong name or a wrong type. uvm_resource_db is the layer underneath: it has no hierarchy, and in my run the first set() of a name won.

Most “my driver has the wrong value” bugs are config_db bugs. Two components set the same field, or a get() quietly failed and the default stayed.

I built a four-level bench, test, env, agent and driver, and made every get() happen in the driver. Then I ran it on VCS. Every result below is one line from that log.

A simple way to picture it

Think of a company notice board. Anyone can pin a note, and each note says who it’s for, like “the driver in agent 1”. The driver walks past and reads the notes addressed to it.

uvm_config_db adds a rule: when two notes for the same person disagree, the one pinned by the more senior manager wins. uvm_resource_db is the same board with no org chart, so seniority means nothing.

uvm_config_db measured on VCS: the test, env, agent and driver settings, which value the driver got, two silent get failures, resource_db first set winning, and check_config_usage finding 5 unread settings
Who set what, and what the driver got, in one VCS run

uvm_config_db vs uvm_resource_db at a glance

uvm_config_dbuvm_resource_db
Scopea component plus a relative pathany string you choose
Two sets from different levelsthe higher component wins in build_phaseno notion of levels
Two sets of the same name, same placethe last one wins (part 4)the first one won in my run (part 6)
Typical usepassing a virtual interface or a knob down the treevalues that aren’t tied to the hierarchy
Under the hoodstores a resource with a matching scopeis the resource pool

1. The basic set and get, with tracing

The testbench top sets the virtual interface for the driver’s exact path:

uvm_config_db#(virtual tav_if)::set(null, "uvm_test_top.env.agt.drv", "vif", u_if);

The driver gets it with get(this, "", "vif", vif). I switched on uvm_config_db_options::turn_on_tracing() around that one call:

[CFGDB/GET] Configuration 'uvm_test_top.env.agt.drv.vif' (type virtual interface tav_if) read by uvm_test_top.env.agt.drv = (virtual interface tav_if) tav_tb.u_if : '{data:'hxx}
[TAV_1] get vif: returned 1, vif is null: 0

The trace line says exactly what was read, by whom and from where. When a value looks wrong, this is the first switch to flip. You can also turn it on for a whole run with +UVM_CONFIG_DB_TRACE on the command line.

2. Two components set the same field: the higher one wins

The test set n_items = 5 for the driver. Then the env, which builds after the test, set n_items = 9 for the same driver.

[TAV_2] get n_items: returned 1, value = 5

The test’s 5 won, even though the env’s set came later. During build_phase, config_db gives priority to the component higher in the hierarchy. That’s on purpose: a test should be able to override whatever its env sets by default.

3. A wildcard from above beats an exact path from below

The test used a wildcard, env.*. The env used the exact path, agt.drv.

[TAV_3] get mode: returned 1, value = test_wildcard

The wildcard won. A more exact path doesn’t beat a higher component, so the level of the setter matters, not how specific the path is.

4. Same component, same field: the last set wins

The test set retries to 1, then to 2, in the same build_phase.

[TAV_4] get retries: returned 1, value = 2

When the same component sets the same field twice, the last value wins.

5. Why get() returns 0

[TAV_5] get width as bit[7:0] (set as int): returned 0, value = 0
[TAV_5] get n_itmes (typo): returned 0, value = -1

Both gets failed, and neither printed a warning. The first one failed on type: width was set as int and read as bit [7:0], and config_db only matches the exact same type. The second failed on a misspelled name.

In both cases the variable kept its old value. If you ignore the return value, the test simply runs with the default. That’s why every get() that matters should check its return value and raise a uvm_fatal when it fails.

6. uvm_resource_db: no hierarchy, and the first set won

[TAV_6] resource_db set 100 then 200, read_by_name = 100

This is the opposite of part 4. With uvm_resource_db, setting timeout to 100 and then 200 in the same scope gave back 100. The second resource sat in the pool unread, and part 8 shows it there.

The resource pool also sits under config_db. Reading the driver’s n_items through uvm_resource_db with its full scope worked:

[TAV_6] resource_db read of config_db n_items: returned 1, value = 5

So config_db is a hierarchy-aware layer on top of the same resources, and it’s the one to use for anything that follows the component tree.

7. A change during run_phase isn’t automatic

The driver waited with wait_modified(). At 10 ns the test set mode to run_time.

[TAV_7] test set mode = run_time at 10 ns
[TAV_7] wait_modified returned. Stored mode is still test_wildcard
[TAV_7] after a new get: mode = run_time

wait_modified() woke up, but the driver’s own mode variable didn’t change. A get() copies the value once, and you have to call it again to see a new one.

8. check_config_usage(): settings nobody read

In end_of_elaboration_phase the test called uvm_top.check_config_usage():

[CFGNRD]  ::: The following resources have at least one write and no reads :::
 mode [/^uvm_test_top\.env\.agt\.drv$/] : (string) "env_exact"
 n_items [/^uvm_test_top\.env\.agt\.drv$/] : (int) 9
 n_iterms [/^uvm_test_top\.env\.agt\.drv$/] : (int) 3
 timeout [/^tav_shared$/] : (int) 200
 width [/^uvm_test_top\.env\.agt\.drv$/] : (int) 8

This one call found every problem in the bench. It listed the env’s two settings that the test overrode, the misspelled n_iterms, the width set with the wrong type, and the timeout = 200 that lost to the first set. Each entry also had an accessor line saying who wrote it.

It costs one line, so put it in the base test of every bench.

Which one should you use?

  • A virtual interface or a knob for a component: uvm_config_db, set from the test or the top.
  • A test needs to override an env default: set it from the test. The higher setter wins in build_phase.
  • A value that isn’t tied to the component tree: uvm_resource_db, and don’t set the same name twice.
  • A value that changes during the run: wait_modified(), then call get() again.
  • A value that looks wrong: turn on tracing, then read check_config_usage().

The bench: one file, one run

Everything above comes from one file, tav_cfgdb.sv: a test, env, agent and driver, with every result printed with `uvm_info. On EDA Playground, paste it into testbench.sv, leave design.sv empty, pick UVM 1.2 and press Run (download it as a zip).

// tav_cfgdb.sv
// The Art of Verification: uvm_config_db and uvm_resource_db, measured
// One UVM test, 8 parts. Every TAV result is printed with `uvm_info.
// EDA Playground: paste into testbench.sv, leave design.sv empty,
// pick UVM 1.2 and press Run.

`include "uvm_macros.svh"
import uvm_pkg::*;

interface tav_if;
  logic [7:0] data;
endinterface

// ---------------------------------------------------------------
// The driver: every get in the test happens here
// ---------------------------------------------------------------
class tav_driver extends uvm_component;
  `uvm_component_utils(tav_driver)
  virtual tav_if vif;
  int            n_items = -1;
  string         mode    = "unset";
  int            retries = -1;
  bit [7:0]      width   = 0;
  int            typo    = -1;

  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    bit ok;
    // Part 1: a virtual interface set from the testbench top, with tracing on
    uvm_config_db_options::turn_on_tracing();
    ok = uvm_config_db#(virtual tav_if)::get(this, "", "vif", vif);
    uvm_config_db_options::turn_off_tracing();
    `uvm_info("TAV_1", $sformatf("get vif: returned %0d, vif is null: %0d", ok, vif == null), UVM_LOW)

    // Part 2: test and env both set n_items for this driver
    ok = uvm_config_db#(int)::get(this, "", "n_items", n_items);
    `uvm_info("TAV_2", $sformatf("get n_items: returned %0d, value = %0d", ok, n_items), UVM_LOW)

    // Part 3: test wildcard "env.*" vs env exact path
    ok = uvm_config_db#(string)::get(this, "", "mode", mode);
    `uvm_info("TAV_3", $sformatf("get mode: returned %0d, value = %s", ok, mode), UVM_LOW)

    // Part 4: the test set retries twice in the same build_phase
    ok = uvm_config_db#(int)::get(this, "", "retries", retries);
    `uvm_info("TAV_4", $sformatf("get retries: returned %0d, value = %0d", ok, retries), UVM_LOW)

    // Part 5: two gets that fail
    ok = uvm_config_db#(bit [7:0])::get(this, "", "width", width);   // set as int
    `uvm_info("TAV_5", $sformatf("get width as bit[7:0] (set as int): returned %0d, value = %0d", ok, width), UVM_LOW)
    ok = uvm_config_db#(int)::get(this, "", "n_itmes", typo);        // misspelled name
    `uvm_info("TAV_5", $sformatf("get n_itmes (typo): returned %0d, value = %0d", ok, typo), UVM_LOW)
  endfunction

  // Part 7: a value changed during run_phase
  virtual task run_phase(uvm_phase phase);
    string m;
    uvm_config_db#(string)::wait_modified(this, "", "mode");
    `uvm_info("TAV_7", $sformatf("wait_modified returned. Stored mode is still %s", mode), UVM_LOW)
    void'(uvm_config_db#(string)::get(this, "", "mode", m));
    `uvm_info("TAV_7", $sformatf("after a new get: mode = %s", m), UVM_LOW)
  endtask
endclass

class tav_agent extends uvm_component;
  `uvm_component_utils(tav_agent)
  tav_driver drv;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    drv = tav_driver::type_id::create("drv", this);
  endfunction
endclass

class tav_env extends uvm_component;
  `uvm_component_utils(tav_env)
  tav_agent agt;
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
  function void build_phase(uvm_phase phase);
    // The env sets the same fields as the test, after the test did
    uvm_config_db#(int)::set(this, "agt.drv", "n_items", 9);
    uvm_config_db#(string)::set(this, "agt.drv", "mode", "env_exact");
    agt = tav_agent::type_id::create("agt", this);
  endfunction
endclass

// ---------------------------------------------------------------
// The test
// ---------------------------------------------------------------
class tav_cfg_test extends uvm_test;
  `uvm_component_utils(tav_cfg_test)
  tav_env env;

  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction

  function void build_phase(uvm_phase phase);
    int v;
    uvm_config_db#(int)::set(this, "env.agt.drv", "n_items", 5);        // part 2
    uvm_config_db#(string)::set(this, "env.*", "mode", "test_wildcard"); // part 3
    uvm_config_db#(int)::set(this, "env.agt.drv", "retries", 1);        // part 4
    uvm_config_db#(int)::set(this, "env.agt.drv", "retries", 2);        // part 4
    uvm_config_db#(int)::set(this, "env.agt.drv", "width", 8);          // part 5: an int
    uvm_config_db#(int)::set(this, "env.agt.drv", "n_iterms", 3);       // part 8: never read

    // Part 6: uvm_resource_db, no component context at all
    uvm_resource_db#(int)::set("tav_shared", "timeout", 100, this);
    uvm_resource_db#(int)::set("tav_shared", "timeout", 200, this);
    void'(uvm_resource_db#(int)::read_by_name("tav_shared", "timeout", v, this));
    `uvm_info("TAV_6", $sformatf("resource_db set 100 then 200, read_by_name = %0d", v), UVM_LOW)

    env = tav_env::type_id::create("env", this);
  endfunction

  function void connect_phase(uvm_phase phase);
    int v;
    bit ok;
    // Part 6: a config_db setting is a resource underneath, reachable by full scope
    ok = uvm_resource_db#(int)::read_by_name("uvm_test_top.env.agt.drv", "n_items", v, this);
    `uvm_info("TAV_6", $sformatf("resource_db read of config_db n_items: returned %0d, value = %0d", ok, v), UVM_LOW)
  endfunction

  // Part 8: settings nobody read
  function void end_of_elaboration_phase(uvm_phase phase);
    `uvm_info("TAV_8", "check_config_usage() output follows", UVM_LOW)
    uvm_top.check_config_usage();
  endfunction

  virtual task run_phase(uvm_phase phase);
    phase.raise_objection(this);
    #10;
    uvm_config_db#(string)::set(this, "env.agt.drv", "mode", "run_time");  // part 7
    `uvm_info("TAV_7", "test set mode = run_time at 10 ns", UVM_LOW)
    #10;
    phase.drop_objection(this);
  endtask
endclass

module tav_tb;
  tav_if u_if ();
  initial begin
    uvm_config_db#(virtual tav_if)::set(null, "uvm_test_top.env.agt.drv", "vif", u_if);
    run_test("tav_cfg_test");
  end
endmodule

What VCS printed

VCS X-2025.06-SP1 with UVM 1.2. The run ended at 20 ns with UVM_ERROR : 0 and UVM_WARNING : 0. Note that the two failed gets in part 5 added nothing to those counts. Every TAV line is shown in its part above, with the UVM_INFO testbench.sv(NN) @ 0: prefix and the component name trimmed.

Common mistakes (and the fix for each)

1. Ignoring the return value of get(). In part 5, two gets failed with no warning. Fix: wrap every get() that matters in an if (!...) and raise a uvm_fatal with the field name when it fails.

2. Setting with one type and getting with another. int set, bit [7:0] read: no match. Fix: use exactly the same type on both sides, often through a typedef.

3. Expecting the env to override the test. In part 2 the test’s 5 beat the env’s 9. Fix: set test-level overrides from the test, and defaults from the env.

4. Assuming an exact path beats a wildcard. In part 3 the test’s env.* won. Fix: think about who sets the value, not how exact the path is.

5. Setting the same resource_db name twice. In part 6 the first value won. Fix: set it once, or use config_db where the last set wins.

6. Expecting a run-time set to reach a stored copy. In part 7 the stored value stayed old. Fix: call get() again after wait_modified().

Where AI helps, and where it doesn’t

An AI assistant is quick at writing set() and get() pairs and the fatal check around them. It’s also handy for reading a long check_config_usage() report and grouping the entries.

Where I’d check it is precedence. Ask it whether an env can override its test, or which of two resource_db sets wins, and you can get a confident wrong answer. The run above is the quick way to settle it.

Practice challenge

Move the env’s n_items = 9 set into the agent instead, and add a third set of n_items = 7 from the driver’s own build_phase, before its get(). Predict the value the driver gets, then run it and compare with check_config_usage().

FAQ

What is the difference between uvm_config_db and uvm_resource_db? uvm_config_db is built on uvm_resource_db and adds the component hierarchy: a set is aimed at a path, and a higher component wins in build_phase. uvm_resource_db uses plain scope strings with no hierarchy.

Why does my uvm_config_db get return 0? Usually a wrong field name, a different type between set and get, or a path that doesn’t match. In my run, both a typo and an int set read as bit [7:0] returned 0 with no warning.

Which uvm_config_db set wins when two components set the same field? In build_phase, the component higher in the hierarchy. The test’s 5 beat the env’s 9, even with the env setting later.

Does an exact path beat a wildcard? No. The test’s env.* beat the env’s exact agt.drv.

Which value wins if uvm_resource_db sets the same name twice? The first one, in my run: 100 then 200 read back as 100.

How do I debug uvm_config_db? Turn on tracing with uvm_config_db_options::turn_on_tracing() or +UVM_CONFIG_DB_TRACE, and call check_config_usage() to list settings nobody read.

References

  • IEEE 1800.2, UVM class reference: uvm_config_db, uvm_resource_db, uvm_resource_pool and uvm_component::check_config_usage().
  • Accellera, Universal Verification Methodology (UVM) 1.2 class reference and user guide: the configuration database.

Keep learning

The most common config_db value is a virtual interface, so read why we need a virtual interface and how a virtual interface is passed with uvm_config_db.

Precedence depends on build_phase order, which UVM phasing explains. The factory works alongside config_db: see the UVM factory and the UVM testbench architecture.