Why can not my agent be passive

Hi
I am trying to set my o_agt( output agent) passive.
In the env.sv ( environment ) I am trying to pass the is_active as 0(set config database). Then in the agent.sv (I am trying to get config db)
I am doing as below:

///build phase of env.sv
foreach (o_agt[jj] ) begin
$sformat(instance_name, “o_agt[%0d]”, jj);
o_agt[jj] = agent::type_id::create(instance_name, this);
//uvm_config_db#(int)::set(this, instance_name, “is_active”,UVM_PASSIVE ) ;
end

Now in the build phase of agent.sv
virtual function void build_phase(uvm_phase phase);
int active ;
super.build_phase(phase);
//uvm_config_db#(int)::get(this,“”, “is_active”,is_active);
mon = imonitor::type_id::create(“imonitor”,this);

When the set/get config are commented , the agaents are created as active.
When I remove the set and get config ( to set agent PASSIVE) , its hanging at compilation.

Can you pls tell me how to set agent passive. ( right now I donot want to create a config file)

Thanks
Lagna

In reply to lagnaray:

Its not possible for compilation to hang. Try clearing previous compilation database and run it again.

And it’s better to use if(config_db#()::get) as get() method returns success or failure.

In reply to MayurKubavat:

In your test you can set
uvm_config_db #(uvm_bitstream_t)::set(this, “m_env.agent1”, “is_active”, UVM_PASSIVE);
Note the type of is_active!
In the agent you can perform a get on your config_db:

ok = uvm_config_db #(uvm_bitstream_t)::get(this, “”, “is_active”, active);
If you do not call super.build_phase(phase) you have to perform a cast like this:
is_active = uvm_active_passive_enum’(active);

In reply to chr_sue:

Hi
Thanks for the reply. I tried the above set / get way but still its getting stuck while compiling. I think my way would not work as UVM_agent has a method which returns is_active. Rather I should have a config file . Now I have a config file i am setting
uvm_active_passing_enum active = UVM_PASSAIVE;
then in the env.sv

foreach (o_agt[jj] ) begin
$sformat(instance_name, “o_agt[%0d]”, jj);
m_my_agent_config = new();
uvm_config_db #(my_agent_config)::set(this,instance_name ,“m_my_agent_config”, m_my_agent_config);
//uvm_config_db #(uvm_bitstream_t)::set(this, “o_agt[0]”, “is_active”, UVM_PASSIVE);
o_agt[jj] = agent::type_id::create(instance_name, this);

Now in the agent.sv how can I get the config db value ?

Thanks

In reply to lagnaray:

In addition to my last reply:
If you call super.build_phase(phase)
the variable indicating UVM_ACTIVE or UVM_PASSIVE is ‘is_active’.
If you want to use a configuration object then you have to define the configuration class accordingly.
After m_my_agent_config = new(); all data memebres of this class are initialized to their initial values this is for all 4-state data members 'x. I do not believe you want to see this.
BTW using a configuration class is not as flexible as the approach setting this in the test.

In reply to chr_sue:

Hi chr
Thanks. setting a config file was not usedful for me .
I am doing as you have suggested :, in the test_top , I am doing as such

uvm_config_db#(uvm_bitstream_t)::set(uvm_root::get(), “uvm_test_top.env_obj.o_agt[0]”, “is_active”, UVM_PASSIVE);

Now in the agent.sv in the build stage
uvm_config_db#(uvm_bitstream_t)::get(this,“”, “is_active”,active);
if(active == null) begin
`uvm_fatal("ERROR ", " Active is NULL " )
end

The error I see is
UVM_INFO etc/uvm-1.2/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/GET] Configuration ‘uvm_test_top.env_obj.o_agt[0].is_active’ (type logic signed[4095:0]) read by uvm_test_top.env_obj.o_agt[0] = (logic signed[4095:0]) 0
UVM_FATAL agent.sv(25) @ 0: uvm_test_top.env_obj.o_agt[0] [ERROR ] Active is NULL
UVM_INFO etc/uvm-1.2/base/uvm_report_catcher.svh(705) @ 0: reporter [UVM/REPORT/CATCHER]

I fail to understand why …

In reply to lagnaray:

Sorry forget to mention that in the log report SET of config db seems to be good
UVM_INFO etc/uvm-1.2/base/uvm_resource_db.svh(121) @ 0: reporter [CFGDB/SET] Configuration ‘uvm_test_top.env_obj.o_agt[0].is_active’ (type logic signed[4095:0]) set by = (logic signed[4095:0]) 0

In reply to lagnaray:

Created the simple example that uses is_active from uvm_config_db. You can use this example and try to match with yours.


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


module top ;
  
initial begin 
  run_test("test");
end 

  initial begin 
    uvm_config_db#(int)::set(uvm_root::get(),"*","is_active",UVM_PASSIVE);
  end 
  typedef class agent ;
  class env extends uvm_env ;
    `uvm_component_utils(env)
    agent agt;
    function new (string name="env",uvm_component parent);
      super.new(name,parent);
    endfunction 
    
    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      agt = agent::type_id::create("agt",this);
    endfunction 
  endclass 
  
  class agent extends uvm_agent ;
    `uvm_component_utils(agent)
    
    uvm_active_passive_enum is_active ;
    
    function new (string name="agent",uvm_component parent);
      super.new(name,parent);
    endfunction 
    
    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
    endfunction 
    
    function void connect_phase(uvm_phase phase);
      super.connect_phase(phase);
      if(uvm_config_db#(int)::get(this,"","is_active",is_active))
        $display("%s",is_active.name());
      if(is_active == UVM_PASSIVE)
        $display("agent is in passive mode");
         
    endfunction 
  endclass 
  
  class test extends uvm_test ;
    `uvm_component_utils(test)
    env ev ;
    function new (string name="test",uvm_component parent);
      super.new(name,parent);
    endfunction 
    function void build_phase(uvm_phase phase);
      super.build_phase(phase);
      ev = env::type_id::create("ev",this);
    endfunction 
    
  endclass 
  
  
endmodule 

output :
UVM_INFO @ 0: reporter [RNTST] Running test test…
UVM_PASSIVE
agent is in passive mode

In reply to kddholak:
I think it is necessary to make a few remarks to the solution of kddholak.
(1) Setting is_active from the toplevel module of your UVM testbench is not useful, because you have to recompile all time you want to change it. You should set it from your test class as said in my previous contribution.
(2) Using the set command as proposed will set all agents passive. You might not want to do this.
(3) The first argument in your set command looks strange. I know it is working, but finally you should do it differently. For the 1st argument (context) there are only 2 options:
(a) null: you use this in a module or in a class-based object. This indicates the second argument has to show an absolute path;
(b) this: cam be used only in a class-based object and it is indicating the second argument shows a relative path.

BTW an experienced UVM developer is never using a $display in his code. Use `uvm_info instead.