Uvm_config_db behaviour wjile using it with objects

Hi all,

I have observed a condition like this. Is this expected behaviour?

I am setting a object in build_phase of my test to one of my agents using uvm_config_db::set(…,…,…,). Usually I’m getting the object in the build phase in the agent by using uvm_config_db::get(…,…,…,). In run_phase of my test I’m changing the objects field after sometime, but I have observed that the changes that I did are taking into effect in my agents where I’m using this configuration in all phases.

Like this I’m able to dynamically change the values in my object which I have set in my test only once in build phase, and getting the object in agent’s build_phase only once.

Please help me.

Regards,
Bhanu

Hi Bhanu,

The behaviour that you are seeing is an expected behaviour.
Unlike uvm_set_config(I think this is not available anymore in UVM), uvm_config_db will always pass the handle/pointer if you set a class into it.

Say, if you set the class as per your case, and you change the value of any member of the configuration under the class after the build_phase anywhere in your test/environment/agent/sequence, it will be applied to all consumers of the same configuration object.

You can avoid it, by doing something at your agent side or any components that consumes it. It is by not using the pointer that you got when you do get, but using the copied version of the configuration object. This will require that your configuration object to have all of the variables registered under UVM field automation macro, OR you implement the do_copy function into it.

Below is the example code that you can use in your Agent or anywhere that you do the get.


class my_agent extends uvm_agent;

   my_config m_cfg;
   ...

   function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      ...
      begin
         my_config __tmp_cfg;
         if (!uvm_config_db#(my_config)::get(this, "", "my_config", __tmp_cfg))
            `uvm_error("CFGFAIL", "failed to get the configuration from UVM Config DB")
         else
         begin
            // Create the object
            m_cfg = my_config::type_id::create("m_cfg");
            // Copy the content of the configuration that you set in higher level
            // components into the configuration that you want to use in this agent
            m_cfg.copy(__tmp_cfg);
         end
      end

Hope this helps.

Regards,
Baser

In reply to basheer55:

Thanks Basheer for clearing my confusion.

Regards,
Bhanu.