首页 > 其他分享 >SystemVerilog -- 3.0 SystemVerilog Threads

SystemVerilog -- 3.0 SystemVerilog Threads

时间:2024-05-12 21:53:58浏览次数:26  
标签:fork join 0t -- Threads time ns display SystemVerilog

SystemVerilog Threads

What are SystemVerilog threads or processes ?

thread 或 process 是作为单独实体执行的任何一段代码。在 verilog 中,每个initialalways块都作为单独的 thread 生成,这些 threads 从 0 time 开始并行运行。block 还会创建并运行的不同 threads。fork join

What are different fork - join styles ?

我们在 SystemVerilog 中有三种不同的风格。fork join

/ /
fork join Finshes when all child threads are over
fork join_any Finshes when any child thread ges over
fork join_none Finshes when soon after child threads are spawned

Where is this used in the testbench ?

验证环境中的组件可能需要能够同行运行多个tasks。例如,一个 process 可能会等待某些事情发生,而另一个 process 继续执行其他一些 tasks。他们都通过fork ... join作为单独的线程生成。例如,checker 可以并行生成不同的tasks,以捕获和验证来自测试平台不同部分的数据。 fork ... join

What is the limitation of a Verilog fork join ?

只有在 fork-join 内生成的所有 threads 都完成时,才会执行 a 之后的代码。因此,checker 必须等到在 fork-join 中生成的所有 thrads 完成,然后才能继续。 fork ... join

fork join Example

SystemVerilog 会等到所有 forked processes 都完成。 fork join

module tb_top;
  initial begin
    #1 $display ("[%0t ns] Start fork ...", $time);

    // Main Process: Fork these processes in parallel and wait untill all of them finish
    fork
      // Thread1 : Print this statement after 5ns from start of fork
      #5 $display ("[%0t ns] Thread1: Orange is named after orange", $time);
      // Thread2 : Print these two statements after the given delay from start of fork
      begin
      #2 $display ("[%0t ns] Thread2: Apple keeps the doctor away", $time);
      #4 $display ("[%0t ns] Thread2: But not anymore", $time);
      end
      // Thread3 : Print this statement after 10ns from start of fork
      #10 $display ("[%0t ns] Thread3: Banana is a good fruit", $time);
    join

    // Main Process: Continue with rest of statements once fork-join is over
    $display ("[%0t ns] After Fork-Join", $time);
  end
endmodule

模拟日志

ncsim> run
[1 ns] Start fork ...
[3 ns] Thread2: Apple keeps the doctor away
[6 ns] Thread1: Orange is named after orange
[7 ns] Thread2: But not anymore
[11 ns] Thread3: Banana is a good fruit
[11 ns] After Fork-Join
ncsim: *W,RNQUIE: Simulation is complete.

fork join_any Example

SystemVerilog 会等待,直到任何一个 forked processes 是完成的。fork join_any

module tb_top;
  initial begin
    #1 $display ("[%0t ns] Start fork ...", $time);

    // Main Process: Fork these processes in parallel and wait untill any one of them finish
    fork
      // Thread1 : Print this statement after 5ns from start of fork
      #5 $display ("[%0t ns] Thread1: Orange is named after orange", $time);
      // Thread2 : Print these two statements after the given delay from start of fork
      begin
      #2 $display ("[%0t ns] Thread2: Apple keeps the doctor away", $time);
      #4 $display ("[%0t ns] Thread2: But not anymore", $time);
      end
      // Thread3 : Print this statement after 10ns from start of fork
      #10 $display ("[%0t ns] Thread3: Banana is a good fruit", $time);
      
    join_any

    // Main Process: Continue with rest of statements once fork-join is exited
    $display ("[%0t ns] After Fork-Join", $time);
  end
endmodule

模拟日志

ncsim> run
[1 ns] Start fork ...
[3 ns] Thread2: Apple keeps the doctor away
[6 ns] Thread1: Orange is named after orange
[6 ns] After Fork-Join
[7 ns] Thread2: But not anymore
[11 ns] Thread3: Banana is a good fruit
ncsim: *W,RNQUIE: Simulation is complete.

fork join_none Example

SystemVerilog 不会等待并立即退出block,允许 forked processes 在后台运行。main thread 恢复执行block之后的语句。 fork join_none fork join_none

module tb_top;
  initial begin
    #1 $display ("[%0t ns] Start fork ...", $time);

    // Main Process: Fork these processes in parallel and exits immediately
    fork
      // Thread1 : Print this statement after 5ns from start of fork
      #5 $display ("[%0t ns] Thread1: Orange is named after orange", $time);
      // Thread2 : Print these two statements after the given delay from start of fork
      begin
      #2 $display ("[%0t ns] Thread2: Apple keeps the doctor away", $time);
      #4 $display ("[%0t ns] Thread2: But not anymore", $time);
      end
      // Thread3 : Print this statement after 10ns from start of fork
      #10 $display ("[%0t ns] Thread3: Banana is a good fruit", $time);
      
    join_none

    // Main Process: Continue with rest of statements once fork-join is exited
    $display ("[%0t ns] After Fork-Join", $time);
  end
endmodule

模拟日志

ncsim> run
[1 ns] Start fork ...
[1 ns] After Fork-Join
[3 ns] Thread2: Apple keeps the doctor away
[6 ns] Thread1: Orange is named after orange
[7 ns] Thread2: But not anymore
[11 ns] Thread3: Banana is a good fruit
ncsim: *W,RNQUIE: Simulation is complete.

标签:fork,join,0t,--,Threads,time,ns,display,SystemVerilog
From: https://www.cnblogs.com/sys-123456/p/18187668

相关文章

  • 第一换元积分法
    eduction\[\begin{align}假设:F(u)是以x为自变量的复合函数\\\quadF^{\prime}(u)=f(u)\\\text{设:}u=\varphi(x)\\\Rightarrow\intf(u)dx=F^{\prime}(u)+C,\quad(式0.0.0)\\\\根据链式法则:\\F^{\prime}(u)=F^{\prime}(u)\cdot(u)^{\pr......
  • gitlab迁移到gitea可行方案
    gitea与gitlab优势比较明显,实际占用资源占比大约1:4gitlab迁移所有仓库到gitea,目前有自动化脚本,但是有个bug需要修复原始自动化迁移工具https://github.com/h44z/gitlab_to_gitea遇到的问题:importfailed:{"message":"Authenticationfailed:Clone:exitstatus128-rem......
  • FFT 优化常系数齐次线性递推式
    \(f_i\)序列满足\(f_i=\displaystyle\sum_{j=1}^kc_jf_{i-j}\)。\(k\le32000,n\le10^9\)。已知\(f_1\simf_k\)和\(c_1\simc_k\)。求\(f_n\)。这称为"\(k\)次齐次常系数线性递推式"。如果\(k\)比较小,可以用矩阵快速幂;但\(k\)太大,一次矩阵乘法都很慢。我们可......
  • 树上跳棋
    题目链接`戳我\(Solution\)对于一个点如果能够被跳到当且仅当这个点的深度\(mod\)一次跳的长度等于起始节点\(mod\)一次跳的长度假设能够被\(p1,p2\)两个点都能到达的点为\(z\)需要满足以下条件\[dep[z]<=dep[lca]\]\[dep[z]\equivdep[p1]\(mod\d1)\]\[dep[z]\equivde......
  • Jenkins script example
    1.参数化构建2.JenkinsscriptpodTemplate(name:'jenkins-slave-4000',cloud:'kubernetes',namespace:'default',label:'jenkins-slave-4000',containers:[containerTemplate(name:'j......
  • 在LCD屏内显示任意尺寸任意大小的bmp图像
    在LCD屏内显示任意尺寸任意大小的bmp图像定义结构体/******************************************************************************filename:ShowBmp.c*author:Dazz*date:2024-05-12*function:在LCD上显示任意大小任意尺寸的bmp图片*note......
  • thusc2024 题目
    day1t1题目描述求\(\left(\sum\limits_{i_1=0}^{n_1-1}\sum\limits_{i_2=0}^{n_2-1}\cdots\sum\limits_{i_d=0}^{n_k-1}\max\left(0,(i_1\operatorname{xor}i_2\operatorname{xor}\cdots\operatorname{xor}i_d)-l\right)\right)\bmodp\)。输入格式输入包含多......
  • 不是,哥们
    题目链接戳我\(Solution\)很容易发现对于每个\(ai^2\)的因子最多在5000以内,所以先将\(ai\)质因数分解然后求出\(ai^2\)的因子然后看每个因子出现了多少次加起来即可\(Code\)#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;typedeflonglongll;intr......
  • 24年5.12流片复盘
    非常值得纪念的一天,因为去年这个时候流片delay,今年顺利流出去了,这是一个大的进步,但是还是要做复盘。首先是进度整体上的复盘。这次流片从一月初开始进行规划,到五月初投片,总共花费五个月时间,五个月内,按照最初的时间规划,一月是把规划基本都做完,给项目参与人员一段上手熟悉任务的时......
  • kettle从入门到精通 第五十九课 ETL之kettle 邮件发送多个附件,使用正则轻松解决
    问题场景:一个朋友说他用kettle将生成好的多个文件(a.xls和b.xls,文件在data目录下)发送给客户,但是data目录下还有其他的文件,他如果指定data目录发送会把data目录下面的所有文件都作为附件进行发送,显然不符合要求,所以他当时的临时解决方法是创建个临时目录,里面只放a.xls和b.xls两个......