-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimes_hspice.perl
More file actions
158 lines (98 loc) · 2.99 KB
/
Times_hspice.perl
File metadata and controls
158 lines (98 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/local/bin/perl
#Gets current working directory
use Cwd;
#Lets us check if sub-process has completed
use POSIX ":sys_wait_h";
#Allows us to wait less than 1 second
use Time::HiRes qw (sleep);
#Set Header File Values For output
$str = " WN1; WN2; WP1; WP2; delay; vq; vqb; area; Percentage_Failure; alter \n" ;
$generic_file_name='ReadW.sp';
$dir1 = getcwd;
$i = 0;
$l = 0;
$k = 0;
$hang_count = 0;
#Specify the max time the simulation should take
$timeout_a = 30;
#Specify the increments to check completion
$slept = 1;
#Generates number of check loops executed
$timeout = int($timeout_a/$slept) ;
system("rm stat_result.txt &");wait;
system("touch stat_result.txt &");wait;
my $file = "$dir1/alter_block.sp";
open (FH, "< $file") or die "Can't open $file for read: $!";
my @lines;
while (<FH>) {
push (@lines, $_);
}
close FH or die "Cannot close $file: $!";
my $file = "$dir1/$generic_file_name";
open (FH, "< $file") or die "Can't open $file for read: $!";
my @lines1;
while (<FH>) {
$l = $l +1;
push (@lines1, $_);
}
close FH or die "Cannot close $file: $!";
my $filename = "$dir1/stat_result.txt";
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
print $fh "$str";
close $fh;
$j = 0;
$l = scalar @lines;
while($j<($l/5)){
$b = $j*5;
$c = $b+3;
$j = $j+1;
my $filename = "$dir1/mont_read.sp";
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
print {$fh} @lines1;
print {$fh} "\n";
print {$fh} @lines[$b..$c];
print {$fh} ".end \n\n";
close $fh;
my $pid = fork();
die "Could not fork\n" if not defined $pid;
if ($pid==0){
print "In child\n";
system("hspice -i mont_read.sp -o out -mt 4");wait;
sleep(.8);wait;
exit(0);
}
else{
print "In parent \n";
$i = 0;
$mont_number = $j - 1;
out: while (1){
$res=waitpid($pid, WNOHANG);
if ($res == -1) {
print "Successful Exit Process Detected\n";
system("mv out.mt0 mont_read.mt0");wait;
sleep(1);wait;
system("perl monte_stat.pl > rel_out.txt"); wait ;
system("cat stat_result.txt rel_out.txt > stat_result.tmp"); wait;
system("mv stat_result.tmp stat_result.txt");wait;
print "\nSim #$mont_number complete\n";wait;
last out;
}
if($res != -1){
if($i>=$timeout){
$hang_count = $hang_count+1;
system("killall hspice");wait;
sleep(1);
print("time_out complete\n");wait;
print "\nSim #$mont_number complete\n";wait;
last out;
}
if($i<$timeout){
sleep $slept;wait;
}
$i=$i+1;
}
}
}
}
print "Simulation Finished With $hang_count hangs\n" ;
exit;