Populating array in check phase

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

 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?

In reply to Pooja.balachandran:

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

$sformat
$sprintf
$fprintf

to write to a file.

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.

In reply to Pooja.balachandran:

$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:

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.

In reply to Pooja.balachandran:

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.

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.

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?

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

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

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

in both array operation and file handling operation.

In reply to Pooja.balachandran:

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.

thank you iam able to open it now

In reply to Pooja.balachandran:

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,

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.

can you explain me how does it work latency.push_back($realtime-start_time);

In reply to Pooja.balachandran:

It should be something like this:

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

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

In reply to Pooja.balachandran:

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