uvm event

uvm_event

The uvm_event class is an extension of the uvm_event_base class. The uvm_event_base class is a wrapper class around the SystemVerilog event construct. uvm_event_base class is an abstract class.

Events are static objects useful for synchronization between the process. Event operations are of two staged processes in which one process will trigger the event, and the other processes will wait for an event to be triggered.

In order to ease the event usage, the uvm_event_base class has many methods implemented in it.

UVM Event Methods

  • new; Creates a new event object
  • wait_trigger; Waits for an event to be triggered
  • wait_ptrigger; Waits for a persistent trigger of the event, avoids race conditions
  • wait_on; Waits for the event to be activated for the first time, returns immediately if the event is already triggered
  • wait_off; Returns if the event is off, else waits for the event turned off via reset event call
  • is_on; Returns 1 if the event has triggered
  • is_off; Returns 1 if the event has not been triggered
  • reset; resets the event to its off state
  • get_trigger_time; Returns the last time at which the event got triggered is_on is_off reset
  • get_num_waiters; Returns the number of processes waiting on the event

UVM Event Syntax

uvm_event event_name;      // Event declaration

event_name = new();        // Creating an event

event_name.trigger();      // Triggering event

event_name.wait_trigger(); // Waiting for event trigger

UVM Event Examples

Wait for event trigger and then the event trigger

In the below example,
ev_1 is an uvm_event; There are two processes running in parallel, event triggering will happen in one of the processes and waiting for the event will happen in the other process.

The waiting for trigger will get unblocked after the event triggering and then the lines below it will get executed.

module uvm_events_ex;
  uvm_event ev_1; //Step-1. Declaring uvm_event ev_1
  
  initial begin
    ev_1 = new(); //Step-2. Creating an event
    
    fork
      //Process-1, triggers the event
      begin
        #40;
        $display($time," Triggering The Event");
        ev_1.trigger;  //Step-4. Trigger the event
      end
      
      //process-2, wait for the event to trigger
      begin
        $display($time," Waiting for the Event to trigger");
        ev_1.wait_trigger;  //Step-3. Waiting for event trigger
        $display($time," Event triggerd");  
      end
    join
  end
endmodule

Simulator Output

0 Waiting for the Event to trigger
40 Triggering The Event
40 Event triggered

Click to execute on   

event trigger and then Wait for event trigger

In the below example,
The event will be triggered before waiting for the event execution, the wait_trigger will keep waiting and leads to a deadlock, the statement after the wait_trigger will not get executed.

module uvm_events_ex;
  uvm_event ev_1; //declaring event ev_1
  
  initial begin
    ev_1 = new(); //Creating an event
    
    fork
      //process-1, triggers the event
      begin
        #40;
        $display($time," Triggering The Event");
        ev_1.trigger;
      end
      
      //process-2, wait for the event to trigger
      begin
        $display($time," Waiting for the Event to trigger");
        #60;
        ev_1.wait_trigger;
        $display($time," Event triggered");
      end
    join
  end
  initial begin
    #100;
    $display($time," Ending the Simulation");
    $finish;
  end
endmodule

Simulator Output

0 Waiting for the Event to trigger
40 Triggering The Event
100 Ending the Simulation

Click to execute on   

event trigger and wait for event trigger at the same time

In the below example,
The event triggering and wait_trigger will get executed simultaneously. Due to a race condition, wait_trigger will miss the trigger sampling which leads to a deadlock, the statement after the wait_trigger will not get executed.

module uvm_events_ex;
  uvm_event ev_1; //declaring uvm_event ev_1
  
  initial begin
    ev_1 = new(); //Creating an event
    
    fork
      //process-1, triggers the event
      begin
        $display($time," Triggering The Event");
        ev_1.trigger;
      end
      
      //process-2, wait for the event to trigger
      begin
        $display($time," Waiting for the Event to trigger");
        ev_1.wait_trigger;
        $display($time," Event triggered");
      end
    join
  end 
  
  initial begin
    #100;
    $display($time," Ending the Simulation");
    $finish;
  end
endmodule

Simulator Output

0 Triggering The Event
0 Waiting for the Event to trigger
100 Ending the Simulation

Click to execute on   

The Next example provides a solution to overcome from a race condition.
❮ Previous Next ❯