SNUG10 Fork Slides
SNUG10 Fork Slides
APPLICATIONS FOR
SYSTEMVERILOG
DYNAMIC PROCESSES
What is a “process”?
3
Static processes
// Synchronous process
always_ff @( posedge clk )
begin
...
end
endmodule : Design
4
Static and dynamic processes
5
fork .. join
begin 2
task2; task2 and task3 run in sequence
task1 runs in parallel with these
task3;
end
join
$display("All tasks have completed");
end
6
fork .. join_none
begin 2
task2;
task3;
end
processes start when parent blocks
join_none
#0 $display("All tasks have started");
end
7
fork .. join_any
begin 2
task2;
task3;
end
join_any The other is still running
initial
begin
fork
...
Blocks (waits) until one spawned
join_any
process has finished ...
disable fork;
end ... then kills the rest
10
Identifying processes
• It is sometimes useful to give processes a unique identifier
initial
begin
for (int i; i<3; i++) Spawns 3 processes
fork
automatic int id = i;
... Local copy of id for each process
join_none
...
end
class process;
Blocking kill() or disable fork
enum state {
FINISHED, RUNNING, WAITING, SUSPENDED, KILLED };
static function process self();
function state status(); Returns handle to
current process
function void kill();
task await();
function void suspend();
task resume();
endclass
13
Processes
Fine-grained process control
Foreign code adapters
Creating stimulus
Summary
APPLICATIONS FOR
SYSTEMVERILOG
DYNAMIC PROCESSES
Verilog net resolution
“Higher” strength wins
driver
filters
Not in Verilog!
Resolution bus
time Function
real
analog
+ real driver
real
16
Mixed-signal resolution function
interface analog_if();
real driver_vals[process];
real result;
driver_vals[this_proc] = val;
resolve();
endfunction: write
endinterface: analog_if
18
Example
19
Processes
Fine-grained process control
Foreign code adapters
Creating stimulus
Summary
APPLICATIONS FOR
SYSTEMVERILOG
DYNAMIC PROCESSES
Foreign Code Adapters
SystemVerilog
Adapter
Foreign Code
(C / SystemC /
C++ / etc. )
21
Example
SystemVerilog
Adapter
Perl Unix
Script Filter
DPI
Pipe
Pipe
Operating System
22
DPI Code (1)
#!perl # stimgen.pl
@all_ops = ( @operate_ops, @branch_ops, ... ); Adapter
for ( $i = 0; $i< 100; $i++ ) {
my $index = rand @all_ops; Perl
print $all_ops[$index], "\n"; Script
} DPI
#include <stdio.h>
#include <stdlib.h>
#define PERLCMD "./stimgen.pl” // Script
#define MAXLINE 256 Pipe
FILE *fpin;
char line[MAXLINE];
int open_pipe() {
// Open the pipe to the Perl script
if ( (fpin = popen( PERLCMD, "r" )) == NULL )
// Print error if null
...
}
23
DPI Code (2)
return NULL;
}
24
Adaptor code (1)
import "DPI-C" function string get_stimulus();
import "DPI-C" function void filter(input string line);
task run();
fork
begin
1 string op, in;
while (( in = get_stimulus()) != "" )
begin
assert( $sscanf( in, "%s", op ));
tr = new ( op ); SystemVerilog
Adapter
Perl Unix
// Send transaction Script Filter
DPI
...
end
Pipe
end
Pipe
... Operating System
25
Adaptor code (2)
SystemVerilog
task run(); Adapter
... Perl Unix
Script Filter
fork DPI
begin
// Process perl input Pipe
1 ... Pipe
end Operating System
begin
forever begin
@( /* named event */ );
2 // Call DPI function to send to pipe
filter( tr.sprint() );
end
end
join_any
disable fork;
endtask
26
Processes
Fine-grained process control
Foreign code adapters
Creating stimulus
Summary
APPLICATIONS FOR
SYSTEMVERILOG
DYNAMIC PROCESSES
Layered sequential stimulus
Virtual or layered
seq1 seq2 seq2
sequences
Constrained random
sequence of transactions tx1 tx2 tx3
28
Virtual sequences
uvm_env
uvm_sequencer
uvm_agent uvm_agent
uvm_sequencer uvm_sequencer
uvm_driver uvm_driver
dut_if dut_if
DUT
29
Forking sequences
class my_virtual_sequence extends uvm_sequence;
...
wait fork;
`uvm_do_on(eseq_inst0, p_sequencer.sequencer0)
`uvm_do_on(esqe_inst1, p_sequencer.sequencer1)
endtask: body
endclass: my_virtual_sequence
30
Processes
Fine-grained process control
Foreign code adapters
Creating stimulus
Summary
APPLICATIONS FOR
SYSTEMVERILOG
DYNAMIC PROCESSES
Summary
32
Any Questions?
33