Part 3 · Factory & Configuration · Intermediate

config_db set/get Contract: Four Arguments Must Align

The exact set/get API — context, instance path, field name, and template type — plus producer/consumer patterns and return-value discipline.

The API signature

Every config_db operation has exactly four parameters. Misalignment on any one causes silent failure on get() — the function returns 0 and the variable keeps its prior value.

systemverilog
// SET:  uvm_config_db#(T)::set(context, inst_path, field_name, value)
uvm_config_db#(int)::set(this, "env.agt.drv", "timeout", 1000);

// GET:  uvm_config_db#(T)::get(context, inst_path, field_name, variable)
int timeout;
if (!uvm_config_db#(int)::get(this, "", "timeout", timeout))
  `uvm_warning("CFG", "timeout not set, using default")
diagram
[CONFIG] four-argument contract

  Arg 1 — context:   component or null (defines scope root)
  Arg 2 — inst_path: relative path from context ("" on get = this component)
  Arg 3 — field_name: string key ("vif", "cfg", "timeout")
  Arg 4 — #(T):      template type must match exactly on set and get

Argument 1 — context

The component (or null) that anchors the scope. Combined with inst_path to form the full matching path.

  • Use this when setting from a UVM component — test, env, agent.

  • Use null from top.sv initial block — no UVM component exists yet.

  • Context + inst_path together define where the set is visible.

systemverilog
// From test — context is test component
uvm_config_db#(apb_config)::set(this, "env.apb", "cfg", acfg);

// From top.sv — no UVM context yet
uvm_config_db#(virtual apb_if)::set(null, "uvm_test_top.env.*", "vif", apb_if_i);

Argument 2 — instance path

Relative path from context. On get, empty string "" means 'look for config targeting this exact component'. Wildcards * match multiple children on set.

diagram
[UVM] path resolution example

  test sets:  context=test, path="env.apb", field="cfg"
  full key:   uvm_test_top.env.apb + "cfg"

  agent gets: context=agent, path="", field="cfg"
  lookup at:  uvm_test_top.env.apb + "cfg"   match 

  driver gets: context=drv, path="", field="cfg"
  lookup at:  uvm_test_top.env.apb.drv + "cfg"
  walks up:   uvm_test_top.env.apb + "cfg"   match 

Arguments 3 and 4 — field name and type

The field name is a string API — treat names like "vif", "cfg", "timeout" as documented constants. The template #(T) must match exactly between set and get.

systemverilog
// WRONG — type mismatch, get returns 0
uvm_config_db#(int)::set(this, "env.drv", "addr", 32'h1000);
bit [31:0] addr;
uvm_config_db#(bit[31:0])::get(this, "", "addr", addr);  // fails silently

// RIGHT — matching types
uvm_config_db#(bit[31:0])::set(this, "env.drv", "addr", 32'h1000);
bit [31:0] addr;
uvm_config_db#(bit[31:0])::get(this, "", "addr", addr);  // succeeds

Key takeaways

  • Context + path form the scope; field name + type form the key.

  • Empty path on get means 'this component' — the most common consumer pattern.

  • Always check get() return bit for critical configuration.

Common pitfalls

  • Using void'() on get() for required fields — hides missing config.

  • Different field names on set vs get — no compile error, get fails.

  • Setting from wrong context — path resolves to unexpected scope.