SlideShare a Scribd company logo
1 of 12
Fine grain process control
SV
Systemverilog has a built in class named Process that
allows one process to access and control other
processes/threads.
When we fork off any thread, a new object of
process class is created at that time. This object
contains status information about that thread.
An attempt to create a user defined object of
process class will result in error.
Process class includes the following
class process;
typedef enum { FINISHED, RUNNING, WAITING,
SUSPENDED, KILLED } state;
static function process self();
function state status();
function void kill();
task await();
function void suspend();
function void resume();
function void srandom( int seed );
function string get_randstate();
function void set_randstate( string state );
endclass
Practical ex.
Let’s say a protocol that sends five packets
concurrently to the RTL on five similar but distinct
interfaces. RTL triggers an event/signal when it has
accepted a packet.
But, when the RTL accepts fourth numbered
packet (this can be any random numbered packet
also), the second numbered packet (this can also
be some random numbered packet) must be
dropped off and not be sent to RTL.
But the rest of packets (1st, 3rd and 5th packet)
must be sent.
So, I will fork off five processes
(named fork_all_processes in code below)
in my testbench which invokes same task
(named run_task in the code below).
Take a handle of each process that gets forked
off.
Now, in the thread for the process that is to be
killed (2nd process over here),wait for the other
process completion (4th process here).
In the process 4, I will look for whether process
2 thread is running or not.
If it is still running, when the trigger event
for process 4 is triggered, then kill the process
2.
If process 2 is already completed before process
4, then we have to kill nothing.
In this way, we can have a fine grain control over
different threads executing concurrently.
example
module top();
class process_ex; // class that forks all processes
process p[]; // number of processes
event ev[]; // events triggered by RTL for each process
int wait_process,kill_process; // process number which is
to be awaited and killed
function new(int num_process); // constructor
p = new[num_process]; // handle of processes
ev = new[num_process];
endfunction
function void fork_all_processes(int num_process); // fork all
the processes
for(int i=0; i<num_process;i++)
fork
automatic int j=i;
begin
p[j] = process::self(); // get object of current processs
run_task(j); // send some stimulus to RTL
end
join_none
endfunction
function void assign_wait_kill_process(int wait_process,int kill_process);
this.wait_process = wait_process; // number of process that is to be awaited
this.kill_process = kill_process; // number of process that is to be killed
endfunction
task automatic run_task(int i);
process::state pstat;
wait(p[kill_process] != null); // wait till the killing process starts (Process-2)
pstat = p[kill_process].status(); // get status for killing process (Process-2)
$display($time,"tWaiting for trigger of %0d event",i);
wait(ev[i].triggered); // wait for current process event tirgger
if(i==wait_process) begin // if the current process is the process which was
to be awaited (Process-4)
$display($time,"tProcess %0d found that p[%0d] is
%0s",wait_process,kill_process,pstat.name);
if(pstat == process::RUNNING || pstat == process::WAITING) begin // check
the status of killing process (Process-2)
$display($time,"tProcess %0d found running/waiting",kill_process);
p[kill_process].kill(); // kill the process (Process-2)
$display($time,"tProcess %0d killed",kill_process);
end
end
$display($time,"tWait completed for trigger of %0d event",i); // current
process completed successfully
endtask
endclass
process_ex proc = new(5);
initial begin
proc.assign_wait_kill_process(4,2); // Some random number.
When process 4 completes, kill process 2 also
proc.fork_all_processes(5);
for(int i=0;i proc.ev[j]; // assume this is triggered by RTL
$display($time,"tTriggered %0d event",j);
end
join_none
end
end
initial begin
#1000 $finish;
end
endmodule
OUTPUT:
0 Waiting for trigger of 2 event
0 Waiting for trigger of 3 event
0 Waiting for trigger of 4 event
0 Waiting for trigger of 0 event
0 Waiting for trigger of 1 event
5 Triggered 4 event
5 Process 4 found that p[2] is WAITING
5 Process 2 found running/waiting
5 Process 2 killed
5 Wait completed for trigger of 4 event
8 Triggered 1 event
8 Triggered 2 event
8 Wait completed for trigger of 1 event
9 Triggered 0 event
9 Triggered 3 event
9 Wait completed for trigger of 0 event
9 Wait completed for trigger of 3 event

More Related Content

What's hot

Theorical 1
Theorical 1Theorical 1
Theorical 1everblut
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.UA Mobile
 
The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.6 book - Part 81 of 189The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.6 book - Part 81 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184Mahmoud Samir Fayed
 
Functional Reactive Programming avec RxSwift
Functional Reactive Programming avec RxSwiftFunctional Reactive Programming avec RxSwift
Functional Reactive Programming avec RxSwiftNicolas VERINAUD
 
Promise of an API
Promise of an APIPromise of an API
Promise of an APIMaxim Zaks
 
The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180Mahmoud Samir Fayed
 
並行処理プログラミングの深淵~Java仮想マシン仕様 スレッドとロック~
並行処理プログラミングの深淵~Java仮想マシン仕様 スレッドとロック~並行処理プログラミングの深淵~Java仮想マシン仕様 スレッドとロック~
並行処理プログラミングの深淵~Java仮想マシン仕様 スレッドとロック~Kazuhiro Eguchi
 

What's hot (20)

Theorical 1
Theorical 1Theorical 1
Theorical 1
 
NinjaSynch
NinjaSynchNinjaSynch
NinjaSynch
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.
 
Ia+ threading
Ia+ threadingIa+ threading
Ia+ threading
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.6 book - Part 81 of 189The Ring programming language version 1.6 book - Part 81 of 189
The Ring programming language version 1.6 book - Part 81 of 189
 
Operating systems
Operating systemsOperating systems
Operating systems
 
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184
 
Functional Reactive Programming avec RxSwift
Functional Reactive Programming avec RxSwiftFunctional Reactive Programming avec RxSwift
Functional Reactive Programming avec RxSwift
 
Proces
ProcesProces
Proces
 
Promise of an API
Promise of an APIPromise of an API
Promise of an API
 
Loops in c
Loops in cLoops in c
Loops in c
 
The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180The Ring programming language version 1.5.1 book - Part 74 of 180
The Ring programming language version 1.5.1 book - Part 74 of 180
 
Operating systems
Operating systemsOperating systems
Operating systems
 
Loops
LoopsLoops
Loops
 
MUST CS101 Lab11
MUST CS101 Lab11 MUST CS101 Lab11
MUST CS101 Lab11
 
並行処理プログラミングの深淵~Java仮想マシン仕様 スレッドとロック~
並行処理プログラミングの深淵~Java仮想マシン仕様 スレッドとロック~並行処理プログラミングの深淵~Java仮想マシン仕様 スレッドとロック~
並行処理プログラミングの深淵~Java仮想マシン仕様 スレッドとロック~
 
Crash Fast & Furious
Crash Fast & FuriousCrash Fast & Furious
Crash Fast & Furious
 
rxJava 2 tips and tricks
rxJava 2 tips and tricks rxJava 2 tips and tricks
rxJava 2 tips and tricks
 

Similar to Fine grain process control 2nd nov

Contiki introduction II-from what to how
Contiki introduction II-from what to howContiki introduction II-from what to how
Contiki introduction II-from what to howDingxin Xu
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterSimen Li
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.Dingxin Xu
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxhumphrieskalyn
 
Java Multithreading.pptx
Java Multithreading.pptxJava Multithreading.pptx
Java Multithreading.pptxRanjithaM32
 
Concurrency 2010
Concurrency 2010Concurrency 2010
Concurrency 2010敬倫 林
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingDan Morrill
 
JAVA - please help with the error regarding the bold line below- I am.docx
JAVA - please help with the error regarding the bold line below- I am.docxJAVA - please help with the error regarding the bold line below- I am.docx
JAVA - please help with the error regarding the bold line below- I am.docxBenjaminIjsDaviesq
 
Here is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfHere is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfdoshirajesh75
 
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsashukiller7
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfamrishinda
 
intro unix/linux 10
intro unix/linux 10intro unix/linux 10
intro unix/linux 10duquoi
 
OS presentation (1).pptx
OS presentation (1).pptxOS presentation (1).pptx
OS presentation (1).pptxJenish62
 
Threads Advance in System Administration with Linux
Threads Advance in System Administration with LinuxThreads Advance in System Administration with Linux
Threads Advance in System Administration with LinuxSoumen Santra
 

Similar to Fine grain process control 2nd nov (20)

Multithreading in Java
Multithreading in JavaMultithreading in Java
Multithreading in Java
 
Contiki introduction II-from what to how
Contiki introduction II-from what to howContiki introduction II-from what to how
Contiki introduction II-from what to how
 
Microkernel Development
Microkernel DevelopmentMicrokernel Development
Microkernel Development
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitter
 
Contiki introduction I.
Contiki introduction I.Contiki introduction I.
Contiki introduction I.
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
 
Java Multithreading.pptx
Java Multithreading.pptxJava Multithreading.pptx
Java Multithreading.pptx
 
Concurrency 2010
Concurrency 2010Concurrency 2010
Concurrency 2010
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
 
JAVA - please help with the error regarding the bold line below- I am.docx
JAVA - please help with the error regarding the bold line below- I am.docxJAVA - please help with the error regarding the bold line below- I am.docx
JAVA - please help with the error regarding the bold line below- I am.docx
 
LP-Unit3.docx
LP-Unit3.docxLP-Unit3.docx
LP-Unit3.docx
 
Here is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfHere is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdf
 
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
 
Implement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdfImplement threads and a GUI interface using advanced Java Swing clas.pdf
Implement threads and a GUI interface using advanced Java Swing clas.pdf
 
intro unix/linux 10
intro unix/linux 10intro unix/linux 10
intro unix/linux 10
 
OS presentation (1).pptx
OS presentation (1).pptxOS presentation (1).pptx
OS presentation (1).pptx
 
Os lab final
Os lab finalOs lab final
Os lab final
 
process creation OS
process creation OSprocess creation OS
process creation OS
 
Events
EventsEvents
Events
 
Threads Advance in System Administration with Linux
Threads Advance in System Administration with LinuxThreads Advance in System Administration with Linux
Threads Advance in System Administration with Linux
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Fine grain process control 2nd nov

  • 1. Fine grain process control SV
  • 2. Systemverilog has a built in class named Process that allows one process to access and control other processes/threads. When we fork off any thread, a new object of process class is created at that time. This object contains status information about that thread. An attempt to create a user defined object of process class will result in error.
  • 3. Process class includes the following class process; typedef enum { FINISHED, RUNNING, WAITING, SUSPENDED, KILLED } state; static function process self(); function state status(); function void kill(); task await(); function void suspend(); function void resume(); function void srandom( int seed ); function string get_randstate(); function void set_randstate( string state ); endclass
  • 4. Practical ex. Let’s say a protocol that sends five packets concurrently to the RTL on five similar but distinct interfaces. RTL triggers an event/signal when it has accepted a packet. But, when the RTL accepts fourth numbered packet (this can be any random numbered packet also), the second numbered packet (this can also be some random numbered packet) must be dropped off and not be sent to RTL. But the rest of packets (1st, 3rd and 5th packet) must be sent.
  • 5. So, I will fork off five processes (named fork_all_processes in code below) in my testbench which invokes same task (named run_task in the code below). Take a handle of each process that gets forked off.
  • 6. Now, in the thread for the process that is to be killed (2nd process over here),wait for the other process completion (4th process here). In the process 4, I will look for whether process 2 thread is running or not. If it is still running, when the trigger event for process 4 is triggered, then kill the process 2. If process 2 is already completed before process 4, then we have to kill nothing. In this way, we can have a fine grain control over different threads executing concurrently.
  • 7. example module top(); class process_ex; // class that forks all processes process p[]; // number of processes event ev[]; // events triggered by RTL for each process int wait_process,kill_process; // process number which is to be awaited and killed function new(int num_process); // constructor p = new[num_process]; // handle of processes ev = new[num_process]; endfunction
  • 8. function void fork_all_processes(int num_process); // fork all the processes for(int i=0; i<num_process;i++) fork automatic int j=i; begin p[j] = process::self(); // get object of current processs run_task(j); // send some stimulus to RTL end join_none endfunction
  • 9. function void assign_wait_kill_process(int wait_process,int kill_process); this.wait_process = wait_process; // number of process that is to be awaited this.kill_process = kill_process; // number of process that is to be killed endfunction task automatic run_task(int i); process::state pstat; wait(p[kill_process] != null); // wait till the killing process starts (Process-2) pstat = p[kill_process].status(); // get status for killing process (Process-2) $display($time,"tWaiting for trigger of %0d event",i); wait(ev[i].triggered); // wait for current process event tirgger if(i==wait_process) begin // if the current process is the process which was to be awaited (Process-4)
  • 10. $display($time,"tProcess %0d found that p[%0d] is %0s",wait_process,kill_process,pstat.name); if(pstat == process::RUNNING || pstat == process::WAITING) begin // check the status of killing process (Process-2) $display($time,"tProcess %0d found running/waiting",kill_process); p[kill_process].kill(); // kill the process (Process-2) $display($time,"tProcess %0d killed",kill_process); end end $display($time,"tWait completed for trigger of %0d event",i); // current process completed successfully endtask endclass
  • 11. process_ex proc = new(5); initial begin proc.assign_wait_kill_process(4,2); // Some random number. When process 4 completes, kill process 2 also proc.fork_all_processes(5); for(int i=0;i proc.ev[j]; // assume this is triggered by RTL $display($time,"tTriggered %0d event",j); end join_none end end initial begin #1000 $finish; end endmodule
  • 12. OUTPUT: 0 Waiting for trigger of 2 event 0 Waiting for trigger of 3 event 0 Waiting for trigger of 4 event 0 Waiting for trigger of 0 event 0 Waiting for trigger of 1 event 5 Triggered 4 event 5 Process 4 found that p[2] is WAITING 5 Process 2 found running/waiting 5 Process 2 killed 5 Wait completed for trigger of 4 event 8 Triggered 1 event 8 Triggered 2 event 8 Wait completed for trigger of 1 event 9 Triggered 0 event 9 Triggered 3 event 9 Wait completed for trigger of 0 event 9 Wait completed for trigger of 3 event