Fork usage

Hi, I want to check the link activity here along with traffic. I forked out all thread with corresponding condition. But looks like only first display is getting executed. Is there anything wrong in code.

 forever begin
      #1ns;
     fork : timeout_block
      //process 1  
      fork 
      if (dut_if.link_up && !dut_if.link_active)  
         if(dut_if.PAD_SM_ADDR[26] == 0) begin $display("LED is on"); end
      join

      //process 2
      fork
      if (!dut_if.link_up && !dut_if.link_active)
         if(dut_if.PAD_SM_ADDR[26] == 1) begin $display("LED is off"); end
      join

      //process 3
      fork
      begin
      if (dut_if.link_up && dut_if.link_active)
         begin
         wait(dut_if.PAD_SM_ADDR[26] == 1)
         current_time = $time; 
         wait(dut_if.PAD_SM_ADDR[26] == 0)
         extend_time = $time; 
         diff_time = extend_time - current_time;
         $display("Diff_time is %d, extend_time is %0t, current_time is %0t", diff_time, extend_time,current_time);

         end
      end
      join
      join
      #TIMEOUT disable timeout_block;
      end
      super.start();    This start will start traffic

In reply to nainesh:

fork : timeout_block
//process 1
fork
if (dut_if.link_up && !dut_if.link_active)
if(dut_if.PAD_SM_ADDR[26] == 0) begin $display(“LED is on”); end
join
//process 2
fork
if (!dut_if.link_up && !dut_if.link_active)
if(dut_if.PAD_SM_ADDR[26] == 1) begin $display(“LED is off”); end
join

Here Process 1 & Process 2 are starting together since it is inside fork-join.

But the case is you are checking for the same signal’s same bit for different values at same time – this leads to any one being true and display that particular process alone(in your case the bit is ‘0’ so process 1 is getting displayed).

//process 3
fork
begin
if (dut_if.link_up && dut_if.link_active)
begin
wait(dut_if.PAD_SM_ADDR[26] == 1)
current_time = $time;
wait(dut_if.PAD_SM_ADDR[26] == 0)
extend_time = $time;
diff_time = extend_time - current_time;
$display(“Diff_time is %d, extend_time is %0t, current_time is %0t”, diff_time, extend_time,current_time);
end

In the 3rd Process, there is only one thread. You are checking for the bit to be ‘1’ first and then to be ‘0’.
Since your bit is ‘0’ already, your wait statement blocks the further execution.

So, only your Process 1 will be completed.

In reply to Bharathy :
Ok. Thanks Bharathy. I see. But i am sure that, all the events in fork join is happening in simulation period time. How can i verify all condition independently ?

Thanks,
Nainesh

In reply to nainesh:

It would really help to use code tags and properly indent your code. Using fork/join with statements having no delays makes no sense,

In reply to dave_59:

Hi Dave,

You mean to apply code tag in this forum

forever begin
      #1ns;
     fork : timeout_block
      //process 1  
      fork 
      #1ns;
      if (dut_if.link_up && !dut_if.link_active)  
         if(dut_if.PAD_SM_ADDR[26] == 0) begin $display("LED is on"); end
      join
 
      //process 2
      fork
      #1ns;
      if (!dut_if.link_up && !dut_if.link_active)
         if(dut_if.PAD_SM_ADDR[26] == 1) begin $display("LED is off"); end
      join
 
      //process 3
      fork
     #1ns;
      begin
      if (dut_if.link_up && dut_if.link_active)
         begin
         wait(dut_if.PAD_SM_ADDR[26] == 1)
         current_time = $time; 
         wait(dut_if.PAD_SM_ADDR[26] == 0)
         extend_time = $time; 
         diff_time = extend_time - current_time;
         $display("Diff_time is %d, extend_time is %0t, current_time is %0t", diff_time, extend_time,current_time);
 
         end
      end
      join
      join
      #TIMEOUT disable timeout_block;
      end
      super.start();

This start will start traffic