当前位置:网站首页>[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)

[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)

2022-07-07 15:34:00 luoganttcc

Reading guide : The author has the honor to be a pioneer in the field of electronic information in China “ University of electronic technology ” During postgraduate study , Touch the cutting edge Numbers IC Verification knowledge , I heard something like Huawei Hisilicon Tsinghua purple light MediaTek technology And other top IC related enterprises in the industry , Pairs of numbers IC Verify some knowledge accumulation and learning experience . Want to get started for help IC Verified friends , After one or two thoughts , This column is specially opened , In order to spend the shortest time , Take the least detours , Most learned IC Verify technical knowledge .

One 、 Description of content

  • Concurrent operation characteristics of logic simulation tools
  • Threads :fork...join | join_any | join_none
  • wait fork
  • disable fork

Two 、 Logic simulation tool Concurrent Handling characteristics

2.1、 Concurrency means

  • For all concurrent threads , Within the current simulation time of the simulation tool , The scheduled events will be completed before the simulation step to the next simulation time

 Insert picture description here

2.2、 Concurrent thread execution

  • When a thread executes , Only meet wait Statement will stop
    • There are sub threads generated by the executing thread Execute by queue
  • When the executing thread encounters Wait statement when , In the queue ready Threads in state can execute
  • When all threads enter wait In the state of , Simulation time update
  • Examples of waiting statements :
@(router.cb);

wait(var_a == 1);

##1 router.cb.din <= 4’hf;

join_any;

join

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2.3、 Concurrent thread execution mode

  • When a thread executes , All other threads enter the queue and wait

    • READY - Represents the thread executing within the current simulation time
    • WAIT - Indicates that the statement is blocked ( Thread cannot execute ), When a waiting condition is encountered, you can continue to execute
  • When the executing thread enters WAIT In the state of , Thread into WAIT Sequence , next READY The thread in state continues to execute

  • When all threads enter WAIT In the state of , The simulation time steps to the next simulation cycle

 Insert picture description here

3、 ... and 、 Concurrent thread thread

3.1、 Statement set

  • Veilog There is a typical set of concurrent statements

    • initial sentence : Only once in the entire simulation time ,initial Statements are concurrent
    • always sentence : It can model combinational circuits and sequential circuits ,always Statements are concurrent
    • assign sentence : It can model the combinational circuit ,assign Statements are concurrent
    • begin...end : Sentence from top to bottom , Sequential execution
    • fork...join: sentence Parallel execution , Independent of statement order
  • fork...join

    • fork...join Statement blocks can create processes that execute in parallel ; Two fork...join stay initial in begin..end Between , Two fork...join Is a serial relationship , If two fork...join The two outer edges are fork...join, Well, the two one. fork...join It's parallel .

3.2、fork-join Create concurrent threads

  • Use fork-join Statement to create a concurrent thread
int a, b, c;
fork
	statement0; // Threads 1
	begin // Threads 2 
		statement1;// Threads 2.1
		statement2;// Threads 2.2
	end
join | join_any | join_none
statement	

 
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • fork-join Thread in 1 And thread 2 Is executed in parallel
  • fork-join Statements are encapsulated in begin-end Statements in form a single child thread ( Threads 2.1 And thread 2.2), And in the order of statements , From top to bottom
  • Concurrent thread There is no fixed sequence of execution
  • All child threads share the variables of the parent thread

3.3、join Options

notes : The parent thread here refers to for...join Outside the statement block, below The thread of

 Insert picture description here

  • fork...join And The relationship between )
    • When all the sub threads are finished , The parent thread will continue to execute
    • stay fork...join In the block , have access to begin...end The statement block encapsulates a separate thread , All statements in this thread are executed sequentially

 Insert picture description here

  • fork...join_any or The relationship between )
    • When fork...join_any After any child thread in the statement block completes , The parent thread continues to execute

 Insert picture description here

  • fork...join_noe
    • Parent thread and for The sub threads in the statement block are executed in parallel
    • When the parent thread executes a blocking statement , The child thread starts to execute ( The parent thread executes first )

 Insert picture description here

  • fork...join and begin...end Example

 Insert picture description here

 Insert picture description here

  • fork...join_any and begin...end Example

 Insert picture description here

 Insert picture description here

  • fork...join_none and begin...end Example

 Insert picture description here

 Insert picture description here

Q: The above statements are preceded by time units , If there is no time unit in front of some sentences ,fork How to execute the statement ?

  • A: There is no time unit , The sequence of execution of these statements can be determined at the compilation stage , After the compilation phase is determined, it is executed in sequence at the actual run time .【 The actual project must have a time unit !】

3.4、 Concurrent thread control

  • wait fork
    • Wait for all fork Concurrent process execution completed
    • Before executing the parent thread , Ensure that all fork Parallel sub thread execution is completed
    • Wait for all fork Send all the sub threads to complete the execution

 Insert picture description here

  • without wait fork,exec5(); Need to wait until fork...join_any After any one of them is executed , and fork...join_none Need to wait until exec5() Only after the execution is completed .

  • disable fork

    • Stop the execution of all parallel sub threads

 Insert picture description here

3.5、 Test questions

 Insert picture description here

  • A: 2 individual ;B:2 individual ;C:1 individual ;D:1 individual

 Insert picture description here

 Insert picture description here

  • Cannot simulate normally : Threads 1 The clock is simulating 0 Act at all times , Threads 2 Is in 5 In time units , hold a become 5, Threads will not emulate to the 5 Time units !

 Insert picture description here

  • a = 4;b = 8;
  • Although the print results are parallel , But the simulator can't be fully parallel , The following can still use the above value !( There are tiny δ Time difference )

 Insert picture description here

  • a = 7; b = 4;

 Insert picture description here

 Insert picture description here

 Insert picture description here

 Insert picture description here

 Insert picture description here

  • Generally, we will not be in for Use in circulation fork...join
     Insert picture description here
  • Just understand this mistake !

X、 Practice

X.1、fork...join/join_any/join_none Demo

module thread();
initial begin
  fork
    // Thread 1
    begin
      #6;
      $display("******@%0t, fork join sub thread 1 begin", $time);
    end
    // Thread 2
    begin
      #5;
      $display("******@%0t, fork join sub thread 2 begin", $time);
    end
  join
  $display("******@%0t, fork join father thread begin", $time);
  #20;
  fork
    // Thread 1
    begin
      #6;
      $display("******@%0t, fork join_any sub thread 1 begin", $time);
    end
    // Thread 2
    begin
      #5;
      $display("******@%0t, fork join_any sub thread 2 begin", $time);
    end
  join_any
  $display("******@%0t, fork join_any father thread begin", $time);
  #20;
  fork
    // Thread 1
    begin
      #6;
      $display("******@%0t, fork join_none sub thread 1 begin", $time);
    end
    // Thread 2
    begin
      #5;
      $display("******@%0t, fork join_none sub thread 2 begin", $time);
    end
  join_none
  $display("******@%0t, fork join_none father thread begin", $time);
end
endmodule 
******@5000, fork join sub thread 2 begin
******@6000, fork join sub thread 1 begin
******@6000, fork join father thread begin
******@31000, fork join_any sub thread 2 begin
******@31000, fork join_any father thread begin
******@32000, fork join_any sub thread 1 begin
******@51000, fork join_none father thread begin
******@56000, fork join_none sub thread 2 begin
******@57000, fork join_none sub thread 1 begin
原网站

版权声明
本文为[luoganttcc]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071321524475.html