Jump to content

How to pass the value to the variable of uvm_sequence object


Recommended Posts

Hi all,

How to pass the value to the variable of uvm_sequence object?

1. use uvm_config_db

2. assign directly

When i use the first way, i found that maybe uvm_config_db::get() can only use in the uvm_component  class. Then i use the second way, I cann't pass the value to the variable successfully.

Does anybody know the reason? Thanks in advance.

 

pieces of code of the first way:

In top:

uvm_config_db#(uvm_bitstream_t)::set(uvm_root::get(), "*", "my_cpu_id", HOST_NUM);

 

In my_sub_sequence which extends from uvm_sequence:

void'(uvm_config_db#(uvm_bitstream_t)::get(this, "", "my_cpu_id", my_cpu_id));

 

Result: VCS reports error.

 

pieces of code of the second way:

In v_sequence:

    for (int i = 0; i < host_num; i++) begin
      inst_name = $sformatf("sub_seq[%0d]", i);
      //sub_seq[i] = my_sub_sequence::type_id::create(inst_name,,get_full_name());
      sub_seq[i] = new(inst_name);
      sub_seq[i].my_cpu_id = i;
    end

 

In my_sub_sequence:

int my_cpu_id;
...
virtual task body();
...
$display("my_cpu_id = %0d", my_cpu_id);
...
endtask

 

Result: every my_cpu_id's value display 0, not 0, 1, 2, 3.

Link to comment
Share on other sites

It would be helpful if you actually post the error message.

 

When doing a config_db::get from a sequence I use the following pattern:

 

uvm_config_db#(TYPE)::get(null, this.get_full_name(), "field", field);

 

Noteworthy about this.  Sequences/sequence_items do not have hierarchy until they have been started on a sequencer.   Once started, get_full_name() will return a hierarchy string for your sequence that includes either the parent sequence's hierarchy (if there is a parent sequence), or the hierarchy of the sequencer that the sequence was started on.

Link to comment
Share on other sites

It would be helpful if you actually post the error message.

 

When doing a config_db::get from a sequence I use the following pattern:

 

uvm_config_db#(TYPE)::get(null, this.get_full_name(), "field", field);

 

Noteworthy about this.  Sequences/sequence_items do not have hierarchy until they have been started on a sequencer.   Once started, get_full_name() will return a hierarchy string for your sequence that includes either the parent sequence's hierarchy (if there is a parent sequence), or the hierarchy of the sequencer that the sequence was started on.

 

Hi logger,

Thanks for your reply, I will have a try. Buy the way, usually the uvm_config_db#(TYPE)::get() should not be invoked earlier than uvm_config_db#(TYPE)::set(), where do you invoked uvm_config_db#(TYPE)::get()? In the pre_body(), body() or new(), etc. on sequence?

Link to comment
Share on other sites

My default method is to do get() calls in pre_start().  That always runs wether started as a sub-sequence or directly on a sequencer.  In the unusual (for us) circumstance where that would be too early, I move the get() calls into the body().  I often have several sequences which all need to grab the same information out of the config_db, so I write a base class sequence that gets those fields in the pre_start() task.

Link to comment
Share on other sites

My default method is to do get() calls in pre_start().  That always runs wether started as a sub-sequence or directly on a sequencer.  In the unusual (for us) circumstance where that would be too early, I move the get() calls into the body().  I often have several sequences which all need to grab the same information out of the config_db, so I write a base class sequence that gets those fields in the pre_start() task.

 

Hi Logger,

thanks for your reply.

Best regards

Link to comment
Share on other sites

The uvm_config_db is used primarily to configure uvm_components. This is a snippet from the reference manual (italics are mine):

 

The uvm_config_db class provides a convenience interface on top of the uvm_resource_db to simplify the basic interface that is used for configuring uvm_component instances.

 

Regardless, I find that it is far better to set the variable directly. The real power of the resource DB is when the wildcard can be used in the path, but that doesn't apply to you in this case.

Link to comment
Share on other sites

The uvm_config_db is used primarily to configure uvm_components. This is a snippet from the reference manual (italics are mine):

 

I've noticed, and it seems to be a major oversite in UVM in my opinion.  I find using the config_db inside of sequence_items invaluable for getting static configuration information that affects randomization.

 

Say you have a system like a HDD or an SSD, which can handle a variety of sector sizes, but it does not support multiple sectors sizes simultaneously.  In this case, it is highly desirable that the sector_item know what the sector_size is for the current simulation.  Now I suppose one solution would be to extend the sector class with a constraint that sets the sector_size, and then use a type_override to insert that into the testbench.  Or, each of the components or tests that generate sector_items could push the value into the sector_items. However, if the sector_item did a config_db::get to for that value, then you just need a config_db::set.  And you likely were doing that for some of the components in the environment anyway, and none of the components need to push this value in.

 

So for my purposes the use model has worked very well.  What I'm annoyed with is, that since uvm_objects don't have hierarchy, I can't apply it to those as well.  However, I'm told that is changing in a future version of UVM.

Link to comment
Share on other sites

I really should try the resource_db again.  I tried to use it once in the past, but I never quite figured it out. While trying to learn it, I couldn't help but think that the config_db interface seemed easier to use.  I concluded that doing uvm_config_db#(Foo)::get(null, "Foo", "foo", foo) was equivalent to using the resource_db.  And I don't have to remember two different use models.  However, just to account for some unforeseen future use case, I use uvm_config_db#(Foo)::get(null, get_full_name(), "foo", foo) unless I know that that won't work, because it at least gives me some ability to do selective sets if necessary.

Link to comment
Share on other sites

  • 2 weeks later...

I'd call it from the sequencer once and store the value to be retrieved whenever a sequence wants it. That does assume that you're setting some global parameter and not something that's applied to particular sequence instances.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...