Saturday, 6 September 2014

Reason not to use disable LABLE in System Verilog



Have you ever used disable LABLE to kill some process or task ? If yes than be careful while killing that particular process. As LABLE is static for class it will kill all the processes that has been created by that particular label. 

Suppose you have one class named main_class which contains task named main_run. It is quite possible that you have taken multiple instances of that class in your Verification Environment. Suppose you have taken three objects of that class and each has one task running main_run. You have written your code such a way that you need to kill that task when you get some particular condition or event or trigger. And you are using disable LABLE for that case. Now guess what happens when you call disable LABLE form any one object. All the main_run task will get killed while using that disable. 

So it is better to not use disable LABLE when you are taking multiple instance of your class. Or I would say if it is avoidable to use disable LABLE then do not use it.  



Disable LABE example

 

 // Code to describe brutal nature of disable LABLE method to kill a process

class main_class;
  bit a = 0;
  task main_run(string name = "not assigned");
    $display($realtime,$psprintf("Task from %s class called",name));
    fork
      begin
        wait(a == 1);
        $display($realtime,$psprintf("class %s Disabling TEST_LABLE",name));
        disable TEST_LABLE;
      end
    join_none

    begin  : TEST_LABLE
      #1000;
      $display($realtime,$psprintf("class %s After 1000 wait in main_class",name));
    end
  
    $display($realtime,$psprintf("Class %s end of the main_run task",name));
  endtask : main_run
endclass : main_class


module disable_lable();

    main_class m1;
    main_class m2;
    main_class m3;

 initial begin

    m1 = new ();
    m2 = new ();
    m3 = new ();

    fork
      m1.main_run("m1");    
      m2.main_run("m2");    
      m3.main_run("m3");    
    join_none

    #20;
    $display($realtime,"Before setting class disable");
    m1.a = 1;
 end

initial begin
 #100000;
end

endmodule : disable_lable


Output : 

# 0Task from m1 class called
# 0Task from m2 class called
# 0Task from m3 class called
# 20Before setting class disable
# 20class m1 Disabling TEST_LABLE
# 20Class m1 end of the main_run task
# 20Class m2 end of the main_run task
# 20Class m3 end of the main_run task



You can see from this example that just calling disable TEST_LABLE of object m1 is sufficient to kill all processes running under TEST_LABLE


No comments:

Post a Comment