How to get get config object handle in a sequence?

Hi,

I have the following requirements, which I do not understand how to implement.

  1. Getting a agent_config from the sequence.
  2. Getting env_config object from a virtual sequence.

Any example of set/get calls would be highly appreciated. I would like to achieve the above without corrupting the global scope, so that the unit level env can be safely ported to either top or other environments.

Thanks,
Madhu

Hi Madhu,

Sequences can get a config object by querying the database, but they need to know the path to the agent or environment, which could be obtained based on the sequencer on which the sequence is started.

However, since agents need to have a sequencer, I make all my agent-sequencers contain a copy of, or handle to, the agent’s config object (which may be used for sequencer options, etc.).

For environments, I’m in the camp that likes to have a virtual sequencer on which to run env-level virtual sequences. These virtual sequencers contain handles to any sub-sequencers (making it easier to run sequences on them) so I usually put a copy of, or handle to, the environment config object in there too.

Doing these two things means that all sequences can get the config object from the sequencer on which they’re running using the p_sequencer field (assuming you’ve used the `uvm_declare_p_sequencer macro).

James

In reply to James Ferris:

Hi James,

Thanks for the response. Yes. I do use `uvm_declare_p_sequencer macro. For the first case, do you get the object handle from the sequencer ?

However, for the env_config object, which you typically create and set from the test, I am not sure how you can set the path, without polluting the global scope to get from the virtual sequence. Did you mean, in the virtual sequencer also, you will have a handle to the env_config object?

Can you give the example of the set and get calls?

Thanks,
Madhu

In reply to mseyunni:

Hi Madhu,

Sorry for the delay. In answer to your questions, yes I put a copy of or handle to the config object in agent sequencers and in the top-level environment virtual sequencer. Since sequencers are part of the “static” hierarchy, in their build_phase I usually have something like:

if( !uvm_config_db#(my_config_class)::get(this, "*", "config", m_config)) begin
  `uvm_fatal("CONFIG", "Failed to fetch config object from ConfigDB");
end

For agents, the config object would normally be created and put into the ConfigDB by the environment (in it’s build_phase). For the environment, it’s config object would be created and inserted into the ConfigDB during the build_phase of the test (which creates and instances the environment). These would look something like:

In environment build_phase:

my_agent_config=my_agent_config_class::type_id::create("my_agent_config");
uvm_config_db#(my_agent_config_class)::set(this,"my_agent*","config",my_agent_config);
my_agent=my_agent_class::type_id::create("my_agent", this);

In test build_phase:

my_env_config=my_env_config_class::type_id::create("my_env_config");
uvm_config_db#(my_env_config_class)::set(this,"my_env*","config",my_env_config);
my_env=my_env_class::type_id::create("my_env", this);

Inside sequence running on an agent:

my_agent_config m_config = p_sequencer.m_config;

Inside virtual sequence running on virtual sequencer:

m_env_config = p_sequencer.m_config;

You could, of course, create different config objects (of different types) that might be required by specific sequences and put them into the ConfigDB in the same way.

Another way is to have sequences pick up the hierarchical path to their sequencer and pull config objects out of the ConfigDB directly - this is detailed at Config/ConfiguringSequences | Verification Academy.

However, since multiple sequences will be created many times in a test, and since ConfigDB access is quite slow, I prefer to put them into the sequencer and get the sequences to use them directly from there. There is a slight loss of flexibility perhaps, but I generally find sequences of a particular type tend to be tied to the same sequencer type each time so I’ve never had a problem yet.

Hope that helps.

James

In reply to James Ferris:

Hi James,

Thanks a lot for detailed explanation and some code snippets. I was able to implement what you said for the agent. Haven’t managed to get the env config object working, due to some hierarchy issues.

I have a slightly different requirement, where in I have 3 instances of the same agent all running the 3 instances of the same sequence. In this scenario, as the sequence is common, from which sequencer it takes the config object?

Thanks,
Madhu

In reply to mseyunni:

Each sequence should be started on the sequencer belonging to it’s instance of the agent. In which case, if it uses p_sequencer it will get the config object belonging to the sequencer on which it is running - i.e. the config of appropriate agent. You will of course need a separate config object per agent-instance:

uvm_config_db#(my_agent_config_class)::set(this,"my_agent_1*","config",my_agent_1_config);
uvm_config_db#(my_agent_config_class)::set(this,"my_agent_2*","config",my_agent_2_config);
uvm_config_db#(my_agent_config_class)::set(this,"my_agent_3*","config",my_agent_3_config);

Note that if all agent instance are configured identically, you could just put the same object into the ConfigDB for each instance, but note that any changes made to the config object later will affect all agents:

uvm_config_db#(my_agent_config_class)::set(this,"my_agent_1*","config",my_agent_config);
uvm_config_db#(my_agent_config_class)::set(this,"my_agent_2*","config",my_agent_config);
uvm_config_db#(my_agent_config_class)::set(this,"my_agent_3*","config",my_agent_config);

In all my code, I use one config object for each agent, and the config object applies to all components of that agent - sequencer, driver and monitor. If you use the “my_agent*” syntax when doing the ::set, the agent and sub-components will all ::get the same config object.