[UVM]UVM進程同步之UVM Barrier(一)

                                       UVM Barrier

     The uvm barrier class enables synchronization control between the processes.

  • uvm_barrier allows a set of processes to be blocked until the desired number of processes get to the
  • synchronization point
  • Processes get released Once after all the process reaching synchronization point

     If the threshold is set to a value less than the number of currently waiting for processes, then the barrier is reset and waiting processes are activated

一、The uvm_barrier class has below built-in methods,

  • new
  • set_auto_reset
  • set_threshold
  • get_threshold
  • get_num_waiters
  • wait_for
  • reset
  • cancel

二、uvm_barrier methods

1、new()

function new (
  string name = "",
  int threshold = 0
)

    Creates a new barrier object.

2、wait_for()

virtual task wait_for()

    This method call, Waits for enough processes to reach the barrier before continuing.

3、set_threshold()

virtual function void set_threshold (
  int threshold
)

       The number of processes to wait for is set by the set_threshold method.This determines how many processes must be waiting on the barrier before the processes may proceed.

4、get_threshold()

virtual function int get_threshold();

       Gets the current threshold setting for the barrier.

5、get_num_waiters()

virtual function int get_num_waiters ()

       Returns the number of processes currently waiting at the barrier.

6、reset()

virtual function void reset (
  bit wakeup = 1
)

       Resets the barrier. This sets the waiter count back to zero.

       The threshold is unchanged. After reset, the barrier will force processes to wait for the threshold again. If the wake-up bit is set, any currently waiting processes will be activated.

7、set_auto_reset()

virtual function void set_auto_reset (
  bit value = 1
)

       Determines if the barrier should reset itself after the threshold is reached.
       The default is on, so when a barrier hits its threshold it will reset, and new processes will block until the threshold is reached again. If auto-reset is off, then once the threshold is achieved, new processes pass through without being blocked until the barrier is reset.

8、cancel()

virtual function void cancel ()

三、uvm_barrier usage

      Using uvm_barrier involves below methods,

  1. Declare and create the uvm_barrier
  2. Set the process to be waiting
  3. Calling wait_for() method inside the process

四、uvm_barrier examples

1、using new and wait_for methods

     The below example shows using the uvm_barrier,

  • uvm_barrier is declared with the name ba
  • the barrier is created by calling ba.new() method, threshold or number of process to wait is an argument for the new method
  • This example has 4 processes with delay in it, and the wati_for method is called after the delay
  • The statements after the wait_for will get executed only after the 3 process reaches to wait_for (3 is threshold have been set during creating the barrier)
module uvm_barrier_ex;
  uvm_barrier ba;
  
  initial begin
    ba = new("ba",3);
    
    fork
      begin       //process-1
        $display($time," Inside the process-a");
        #20;
        $display($time," process-a completed");
        $display($time," process-a Waiting for barrier");
        ba.wait_for();
        $display($time," process-a after wait_for");
      end
      
      begin       //process-2
        $display($time," Inside the process-b");
        #10;
        $display($time," process-b completed");
        $display($time," process-b Waiting for barrier");
        ba.wait_for();
        $display($time," process-b after wait_for");
      end
      
      begin       //process-3
        $display($time," Inside the process-c");
        #30;
        $display($time," process-c completed");
        $display($time," process-c Waiting for barrier");
        ba.wait_for();
        $display($time," process-c after wait_for");
      end
      
      begin       //process-4
        $display($time," Inside the process-d");
        #5;
        $display($time," process-d completed");
        $display($time," process-d Waiting for barrier");
        ba.wait_for();
        $display($time," process-d after wait_for");
      end
    join
  end
endmodule
  • Simulator Output 
0 Inside the process-a
0 Inside the process-b
0 Inside the process-c
0 Inside the process-d
5 process-d completed
5 process-d Waiting for barrier
10 process-b completed
10 process-b Waiting for barrier
20 process-a completed
20 process-a Waiting for barrier
20 process-d after wait_for
20 process-b after wait_for
20 process-a after wait_for
30 process-c completed
30 process-c Waiting for barrier
发布了185 篇原创文章 · 获赞 118 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/gsjthxy/article/details/105253238