# Populating array in check phase

**URL:** <https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160>\
**Category:** UVM\
**Tags:** UVM, run\_phase-check\_phase\
**Created:** [June 8, 2021, 11:35am UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160 "2021-06-08T11:35:53Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 11:35am UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/1 "2021-06-08T11:35:53Z")

</div>

hi.  
how shall i populate the array in check phase? here iam trying to capture the time into an array in run phase and do the necessary calculations in check phase. a pseudo code is shown below

```verilog
 task void run_phase(uvm_phase phase);
int fd; // file handle
// array declaration for capturing start and run time
 time s[1:0];// start time
time e[1:0];// end time
 //to open file in write mode
       fd = $fopen ("file.txt","w");
        $fdisplay(fd," Printing time into the file");
fork begin
forever begin
@posedge(clk);
 startt[1:0] = $time;
 $fdisplay( fd," s[%0d]: %0t", s);
end 
end

begin
forever begin
@posedge(clk);
 endt[1:0] = $time;
 $fdisplay( fd," e[%0d]: %0t", e);
end 
end
join
endtask :run_phase

```

i need to use both s and e to calculate my latency . the formula is end time- start time. can you tell me how can I use these array in check phase and do the calculation?

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 8, 2021, 2:46pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/2 "2021-06-08T14:46:36Z")

</div>

_In reply to [Pooja.balachandran](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160):_

What is the need to declare s and e as a vector? And you do not write anything to your file. Is the printing your problem or what is it?  
You can use

```verilog
$sformat
$sprintf
$fprintf

```

to write to a file.

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 3:06pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/3 "2021-06-08T15:06:58Z")

</div>

sorry there has been a mistake in the code it should be  
s[1:0] = $time; and similarly e[1:0] =$time;

i want to know how can i use the arrays s and e and do the latency calculation in check phase. how can i read back these arrays in check phase ? here iam completely using array operations and not file handling operation.

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 8, 2021, 3:17pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/4 "2021-06-08T15:17:29Z")

</div>

_In reply to [Pooja.balachandran](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/3):_

$time returns 1 value. But you are assigning this value to a 2-dim array.  
You can write only a string to the file.  
Reading back the data from the file you have to re-format this string.  
Look here to see the details:

> **[Verilog File I/0,Verilog file handling](http://www.asic.co.in/Index_files/verilog_files/File_IO.htm)**
>
> Verilog File I/0,Verilog file handling,Verilog files

If you want to use an array (without file I/O) you need for each entry an array element. It might result in a huge array.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [June 8, 2021, 3:21pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/5 "2021-06-08T15:21:12Z")

</div>

_In reply to [Pooja.balachandran](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/4):_

If you want to set a variable in one phase and read it in another phase of of the same uvm\_component, they need to be declared as class members, not local to the phase methods. If the phases are in different components, then they should be shared is a uvm\_config\_db object.

The pseudocode you show does not make much sense. How are you expecting to index into the array? You also might want to use realtime instead of time.

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 3:22pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/6 "2021-06-08T15:22:24Z")

</div>

here the time comes from simulation that is its coming from the design.also how can i use $time to capture the start n end time from the simulation. according to me s[1:0] = $time captures the current simulation time into the respective arrays.

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 3:26pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/7 "2021-06-08T15:26:54Z")

</div>

did you mean to say i should declare those arrays outside the run phase? like below:

class my\_monitor extends uvm\_monitor;  
time s[1:0];  
time e[1:0];  
.  
.  
.  
.  
task void run\_phase(uvm\_phase phase);  
.  
.  
.  
also should i use $realtime instead of $time?

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 3:28pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/8 "2021-06-08T15:28:16Z")

</div>

i am unable to open the link you have given for reference . can you give some other link?

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 3:30pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/9 "2021-06-08T15:30:42Z")

</div>

can i use s[i] = $realtime instead of s[1:0] = $time?

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 3:39pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/10 "2021-06-08T15:39:57Z")

</div>

can you help me with a pseudo code to capture the start and end time of 10 packets into an array in run phase and populate or use that array to calculate the latency in check phase?  
latency = end time- start time

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 3:41pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/11 "2021-06-08T15:41:45Z")

</div>

in both array operation and file handling operation.

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 8, 2021, 3:43pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/12 "2021-06-08T15:43:43Z")

</div>

_In reply to [Pooja.balachandran](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/11):_

> i am unable to open the link you have given for reference . can you give some other link?

Pleas try the link again. There was a dot at the end. I have corrected this.

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 8, 2021, 3:44pm UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/13 "2021-06-08T15:44:32Z")

</div>

thank you iam able to open it now

---

<div class="post-metadata">

**Author:** ![bdreku](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/bdreku/32/2197_2.png) [@bdreku](https://verificationacademy.com/forums/u/bdreku)\
**Post date:** [June 9, 2021, 2:37am UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/14 "2021-06-09T02:37:14Z")

</div>

_In reply to [Pooja.balachandran](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/13):_

> can you help me with a pseudo code to capture the start and end time of 10 packets into an array in run phase and populate or use that array to calculate the latency in check phase?  
> latency = end time- start time

Instead of calculating latency in check phase, why don’t you calculate it in run phase and pass the information to check phase?

You can declare latency as an array and just you have to store previous timestamp. Something like,

```verilog
real latency[$];
realtime start_time;
latency.push_back($realtime-start_time);

```

As Dave suggested, you can pass it to check phase without using another file.

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 9, 2021, 3:32am UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/15 "2021-06-09T03:32:04Z")

</div>

can you explain me how does it work latency.push\_back($realtime-start\_time);

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 9, 2021, 6:09am UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/16 "2021-06-09T06:09:56Z")

</div>

_In reply to [Pooja.balachandran](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/15):_

It should be something like this:

```verilog
class my_driver extends uvm_driver #(9my_seq_item);
  real latenzy[$];
  realtime start_time;

task void run_phase(uvm_phase phase);
    forever begin
      @posedge(clk);
      start_time = $realtime;
// add your driver functionality here 
      @posedge(clk);
      latency.push_back($realtime - start_time);
     end 
endtask :run_phase

```

---

<div class="post-metadata">

**Author:** ![Pooja.balachandran](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/dbc845/32.png) [@Pooja.balachandran](https://verificationacademy.com/forums/u/Pooja.balachandran)\
**Post date:** [June 9, 2021, 6:15am UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/17 "2021-06-09T06:15:05Z")

</div>

here start and end time are two interface signals and its impossible to avoid end time signal Thats the reason why i mentioned end time and start time. And both the timings need to be captured in array in run phase and then in check phase using that array doing the calculations

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 9, 2021, 6:44am UTC](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/18 "2021-06-09T06:44:02Z")

</div>

_In reply to [Pooja.balachandran](https://verificationacademy.com/forums/t/populating-array-in-check-phase/39160/17):_

Could you please show how your interafce looks like and how you can assign the interface signals to local variables.
