When we use resource_db and/or config_db?

Hi,

My confusion is that when we use resource_db and config_db??
I seen in all UVM_1.2 class library examples is that generally they used config_db for set and get virtual interface and sometimes use for set and get the integer values,but they never used resource_db in any example… why??

In reply to deep123:

The scope is global in case of resource_db; so hierarchy is not important here. And always global scope is hardly required. Use config_db which itself extends from resource_db.

In reply to sunils:
Thanks for Reply…

yes,that’s okay…
But I can’t understood how resource_db is global scope and config_db is limited to particular class scope…
Can you give me example code for resource_db and config_db??..So from that i will clearly understand the concept of resource and config database…

In reply to deep123:

The resource_db has only 3 arguments: scope, name and value. If we want to store soem data have to give this as an absolute path.
config_db has 4 arguments. Instead of the scope we have the context and the hierarchy.If the context is ‘this’ the hierarchy is an absolute path, if it is ‘null’ it is an absolute path.
This approach gives the user more flexibility.

In reply to deep123:

See Config_db vs Resource_db | Verification Academy

In reply to dave_59:

Thanks a lot Dave… :)

Hi dave,

I having one more question on config_db and resource_db…
I saw the link which you previously shared,and i understood the concept of database.
Here i am try the code of config_db and resource_db.
In a config_db always last parent is wins it works fine,But
In a resource_db last write is wins but in my code top(first value) is wins…Why??

Thanks in advance… :)

Here i will share both codes:

1----->(Config_db)-- it works fine


`include "uvm.sv"
import uvm_pkg :: *;

class agent extends uvm_agent;
  `uvm_component_utils (agent)
  int a;

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

  function void build_phase (uvm_phase phase);
    super.build_phase (phase);
    uvm_config_db #(int)::get(this, "", "a", a);
   `uvm_info ("agent-get", $sformatf("a=%0d", a), UVM_MEDIUM)
  endfunction

  task run_phase (uvm_phase phase);
  endtask
endclass

class envi extends uvm_env;
  `uvm_component_utils (envi)
  int a;
  agent agnt;

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

  function void build_phase (uvm_phase phase);
    super.build_phase (phase);
    agnt = agent::type_id::create("agnt", this);
    a = 60;
    uvm_config_db #(int)::set(null, "*", "a", a);
    `uvm_info ("env-set", $sformatf("a=%0d", a), UVM_MEDIUM)
  endfunction

  task run_phase (uvm_phase phase);
  endtask
endclass

class my_test_1 extends uvm_test;
  `uvm_component_utils (my_test_1)
  int a;
  envi env;

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

  function void build_phase (uvm_phase phase);
    super.build_phase (phase);
    env = envi::type_id::create("env", this);
    a = 50;
    uvm_config_db #(int)::set(null, "*", "a", a);
    `uvm_info ("test-set", $sformatf("a=%0d", a), UVM_MEDIUM) 
  endfunction

  task run_phase (uvm_phase phase);
    phase.raise_objection(this);   
    #50;
    phase.drop_objection(this);
  endtask
endclass

module top();
  initial begin
    run_test("my_test_1");
  end
endmodule

output::
UVM_INFO @ 0: reporter [RNTST] Running test my_test_1…
UVM_INFO config_db.sv(57) @ 0: uvm_test_top [test-set] a=50
UVM_INFO config_db.sv(36) @ 0: uvm_test_top.env [env-set] a=60
UVM_INFO config_db.sv(15) @ 0: uvm_test_top.env.agnt [agent-get] a=60

2---->Resource_db(here top value is wins!!..How??)


class agent extends uvm_agent;
  `uvm_component_utils (agent)
  int a;
  function new (string name = "agent", uvm_component parent = null);
   super.new(name, parent);
  endfunction
  function void build_phase (uvm_phase phase);
    super.build_phase (phase);
    uvm_resource_db #(int)::read_by_name("*", "a", a,this);
     `uvm_info ("agnt-get", $sformatf("a=%0d", a), UVM_MEDIUM)
  endfunction
endclass
 
class env extends uvm_env;
  `uvm_component_utils (env)
  int a;
  agent agnt;
  function new (string name = "env", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  function void build_phase (uvm_phase phase);
    super.build_phase (phase);
    agnt = agent::type_id::create("agnt", this);
    a = 60;
    uvm_resource_db #(int)::set("*", "a", a, this);
    `uvm_info ("env-set", $sformatf("a=%0d", a), UVM_MEDIUM)
  endfunction
endclass
 
class my_test_1 extends uvm_test;
  `uvm_component_utils (my_test_1)
  int a;
  env envi;
  function new (string name = "my_test_1", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  function void build_phase (uvm_phase phase);
    super.build_phase (phase);
    envi = env::type_id::create("envi", this);
    a = 50;
    uvm_resource_db #(int)::set("*", "a", a,this);
    `uvm_info ("test-set", $sformatf("a=%0d", a), UVM_MEDIUM) 
  endfunction
  
  task run_phase (uvm_phase phase);
    phase.raise_objection(this);
    #50;
    phase.drop_objection(this);
  endtask
endclass
 
module top();
  initial begin
    run_test("my_test_1");
  end
endmodule

output::
UVM_INFO @ 0: reporter [RNTST] Running test my_test_1…
UVM_INFO resource_db.sv(43) @ 0: uvm_test_top [test-set] a=50
UVM_INFO resource_db.sv(27) @ 0: uvm_test_top.envi [env-set] a=60
UVM_INFO resource_db.sv(11) @ 0: uvm_test_top.envi.agnt [agnt-get] a=50

In reply to deep123:

What you see is correct the differenc comes from the get using ‘this’.This does not mean the global scope. If you are changing in the config_db get the context from ‘this’ to ‘null’. You see exactly the same result as using resource_db.

In reply to chr_sue:
Hi,
I already checked with “changing config_db get context from ‘this’ to ‘null’”,but i got same results…

In reply to deep123:

You are right. Yesterday I made a few different combinations and I was showing you the wrong content.

We said resource_db has the global scope.
From the link Dave mentioned above:

uvm_resource_db #(usb_env_config)::set({get_full_name(), ".*"}, "xHCI_usb_env_cfg", usb_env_cfg);

is equivalent to

uvm_config_db#(usb_env_config)::set(this, "*", "xHCI_usb_env_cfg", usb_env_cfg);

If you simply write the wildcard it behaves differently. The behavior will be different. This is what you can see in your example.