Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perlmod / tso_analyze,1.37
CommitLineData
86530b38
AT
1#----------------------------------------
2# note:
3# see the usage function for description
4#----------------------------------------
5
6use strict;
7use Cwd;
8use Getopt::Long;
9
10print "===============================================\n";
11print "=== tso_analyze ===\n";
12print "===============================================\n";
13system("date");
14
15my @Options = qw(debug help);
16my %opt = ();
17$opt{debug} = 0;
18$opt{help} = 0;
19
20GetOptions(\%opt, @Options) or die "Error in arguments!\n";
21my($debug) = $opt{debug};
22
23if($opt{help}){
24 &usage;
25 exit 0;
26}
27
28#---------------------------------------------------------
29
30my $dirname = cwd();
31print "$dirname \n";
32
33$dirname =~ s/^.*\///;
34$dirname =~ s/:/_/g;
35print "$dirname \n";
36
37my $old = 0;
38my %agent_id;
39my $size = 64;
40
41print "Preparing the prop file.\n";
42open(DIAG, "diag.s") || die " BAD BAD diag.s";
43open(TEMP , ">prop") || die " BAD BAD prop";
44
45my($printit) = 0;
46my($found) = 0;
47while(<DIAG>){
48 if(/no tsotool postprocessing/){
49 $found = 0;
50 last;
51 }
52 if(/old tsotool postprocessing/){
53 $old = 1;
54 }
55 elsif(/\!\s+TSOTOOL.PROCESSOR/){
56 $printit = 1;
57 $found = 1;
58 }
59 elsif(/_MEMBARS\s+N/){
60 $found = 0;
61 last;
62 }
63 elsif(/^\s*$/){
64 $printit = 0;
65 last;
66 }
67
68 if($printit){
69 if(/TSOTOOL.MODE/){
70 print TEMP "TSOTOOL.MODE ANALYZE\n";
71 }
72 else{
73 s/^\!\s+(.*)/$1/;
74 print TEMP $1, "\n";;
75 }
76 }
77}
78close(DIAG);
79close(TEMP);
80
81if($found){
82 print "Prepared the prop file.\n";
83 unlink("tsotool.log");
84 system("date");
85 print "Extracting\n";
86 system("date");
87 extract();
88
89 my $logfile= (-f "sim.log") ? "sim.log" :
90 (-f "sim.log.gz") ? "sim.log.gz" :
91 die "Logfile not found\n";
92
93 print " Now will extract per location store order\n";
94
95 print "Finished Extracting\n";
96 system("date");
97
98 if ($logfile =~ /\.gz$/) {
99 open (LOG_TR, "gunzip -c $logfile | tail |");
100 }
101 else {
102 open (LOG_TR, "tail $logfile |");
103 }
104
105 my $fail = 0;
106
107 while (<LOG_TR>) {
108 if (/hit\s*good\s*trap/) {
109 $fail = 1;
110 last;
111 }
112 }
113
114 do {
115 system("touch diag.failure");
116 print "Simulation failed, results will NOT be analyzed\n";
117 exit;
118 } if $fail;
119
120 print "Now will run tsotool\n";
121 print "Finished running tsotool\n";
122
123 system("date");
124}
125else{
126 print "This diag is not a tsotool diag or is a tsotool diag which should not be analyzed.\n";
127}
128
129#========================================================================
130# extract - extract from sim.log whatever is relevant - FP regs, INT regs
131# as well as JBUS stuff.
132#========================================================================
133sub extract{
134
135 my ($i, $k, $time, $spc, $thr, $proc, $reg, $val, $win);
136 my(@tl, @FPLINES, @INTLINES, %SJMLINES);
137
138 for ($i = 0; $i < 32; $i++){
139 $tl[$i] = 5;
140 }
141 my $logfile= (-f "sim.log") ? "sim.log" :
142 (-f "sim.log.gz") ? "sim.log.gz" :
143 die "Logfile not found\n";
144
145 if($logfile =~ /\.gz$/) {
146 open(VCS, "gunzip -c $logfile | egrep 'jbus_mon|reg' |") || die "cannot open gunzip -c $logfile";
147 }else{
148 open(VCS, "egrep 'jbus_mon|reg' $logfile| ") || die "cannot open $logfile";
149 }
150
151 my $currtime = 0;
152 my $fatal = "";
153 while(<VCS>) {
154 chop;
155 s/-MATCH/-updated/g;
156 if(/^(\d+):.*reg.updated\s*->\s*spc.(\d).\s*thread.(\d)/){
157 $time = $1;
158 $spc = $2;
159 $thr = $3;
160 $proc = 4 * $spc + $thr;
161
162 if(/float_reg.updated.*reg#\((\w+)\).*val = (\w+)/){
163 $reg = "%" . $1;
164 $val = $2;
165 if(!($reg =~ /f/)){
166 $reg =~ s/%/%f/;
167 }
168
169 if($tl[$proc] == 0){
170 push @{$FPLINES[$proc]}, sprintf("%-4s %-4d %-20s\t\t\t %-30s\n",$reg, $proc, $val, $time);
171 }
172 }
173 elsif(/window.(\w+).*reg#\((\w+)\).*val = (\w+)/){
174 $win = $1;
175 $reg = "%" . $2;
176 $val = &add0($3);
177 if($tl[$proc] == 0){
178 push @{$INTLINES[$proc]}, sprintf("%-4s %-4d %-20s\t\t\t%-20s\n", $reg, $proc, $val, $time);
179 }
180 }
181 elsif(/tl_reg.updated.*window.(\w+).*val = (\w+)/){
182 $tl[$proc] = $2;
183 printf "%-10s: C%dT%d\t\tTL REG UPDATE <TL = %d>\n", $time, $spc, $thr, $tl[$proc] if($debug);
184 }
185
186 $currtime = $time +0;
187 }
188#37275441: jbus_monitor(jbus_mon): started ReadToDiscard agent_id=12, transaction_id=0 address=01171800000, identifier=27
189#---------
190 elsif(/(\d+):\s*jbus_mon.*:\s*started ReadToDiscard\s*agent_id=(\d+).*identifier=(\d+)/){
191 $agent_id{$3} = $2;
192 print "agent id = $2 identifier = $3\n" if($debug);
193 }
194
195# alex, taking care of NCRD transactions
196#15905: jbus_monitor(jbus_mon): started NonCachedRead agent_id=12, transaction_id=0 address=7cf10800050, identifier=179, dbg=4
197#---------
198 elsif(/(\d+):\s*jbus_mon.*:\s*started NonCachedRead\s*agent_id=(\d+).*identifier=(\d+)/){
199 $agent_id{$3} = $2;
200 print "agent id = $2 identifier = $3\n" if($debug);
201 }
202
203#---------
204#37203537: jbus_monitor(jbus_mon): RDD 01170000000 data driver=0 state = I identifier=23 start time=36782385
205#---------
206 elsif(/(\d+):\s*jbus_mon.*:\s*RDD\s*([\dabcdefABCDEF]+)\s*([\dabcdefABCDEF]+).*identifier=(\d+)/){
207 my $time = $1;
208 my $addr = $2;
209 my $data = $3;
210 my $identifier = $4;
211
212 my @da = split '', $data;
213 my @dafinal = ();
214 $dafinal[0] = $da[0];
215 my $k = 1;
216 for(my $i = 1; $i <=$#da; $i++){
217 if( ($i % 16) == 0){
218 $dafinal[$k++] = ' ';
219 }
220 $dafinal[$k++] = $da[$i];
221 }
222
223 $data = join '', @dafinal;
224
225 if(! exists $agent_id{$identifier}) {
226 die "Could not find agent id for $identifier \n";
227 }
228 #push @SJMLINES, sprintf("%-20s %-2d %-20s %-2d %-128s\n", $time, $agent_id{$identifier}, $addr, $size, $data);
229 # alex - SJMLINES hashing lines by identifier
230 $SJMLINES{$identifier} = sprintf("%-20s %-2d %-20s %-2d %-128s\n", $time, $agent_id{$identifier}, $addr, $size, $data);
231 }
232#----------
233# alex - taking care of NCRD transactions
234# to make tsotool happy:
235# count number of -'s before data, adjust address
236# count data size, calculate size
237#113: jbus_monitor(jbus_mon): NCRD 7cf10800100 000186a3------------------------ driver=4 identifier=194 start time=17
238#----------
239 elsif(/(\d+):\s*jbus_mon.*:\s*NCRD\s*([\dabcdefABCDEF]+)\s+(-*)([\dabcdefABCDEF]+)-*.*identifier=(\d+)/){
240 my $time = $1;
241 my $addr = $2;
242 my $data = $4;
243 my $ld_dashes = $3;
244 my $identifier = $5;
245
246 # my is important - don't want to override global $size
247 my $size = length($data)/2;
248
249 if (length($ld_dashes) == 8) {
250 $addr =~ s/0$/4/;
251 }
252 elsif (length($ld_dashes) == 16) {
253 $addr =~ s/0$/8/;
254 }
255 elsif (length($ld_dashes) == 24) {
256 $addr =~ s/0$/c/;
257 }
258
259 if(! exists $agent_id{$identifier}) {
260 die "Could not find agent id for $identifier \n";
261 }
262 $SJMLINES{$identifier} = sprintf("%-20s %-2d %-20s %-2d %-128s\n", $time, $agent_id{$identifier}, $addr, $size, $data);
263 }
264
265} # while
266close(VCS);
267
268#--------------------------------------------------------------------
269
270 open(TSOINT, ">diag.load-values.int") || die " BAD BAD int";
271 open(TSOFP , ">diag.load-values.fp") || die " BAD BAD fp";
272 open(TSOSJM, ">diag.load-values.sjm") || die " BAD BAD sjm";
273
274 my($writeout) = 0;
275 foreach $i (0..$#INTLINES){
276 my $tmp = $INTLINES[$i];
277 foreach $k (0..$#{$tmp}){
278 my $line = $tmp->[$k];
279 $line =~ /^(%\S+)\s+(\d+)\s+(.*)/;
280 print "$1 $writeout $3\n" if($debug);;
281 print TSOINT "$1 $writeout $3\n";
282 }
283 $writeout++ if($#{$tmp} >=0);
284 }
285
286 $writeout = 0;
287 foreach $i (0..$#FPLINES){
288 my $tmp = $FPLINES[$i];
289 foreach $k (0..$#{$tmp}){
290 my $line = $tmp->[$k];
291 $line =~ /^(%\S+)\s+(\d+)\s+(.*)/;
292 print TSOFP "$1 $writeout $3\n";
293 }
294 $writeout++ if($#{$tmp} >=0);
295 }
296
297# sorting SJM lines by identifier and output
298
299 foreach $i (sort {$a <=> $b} keys(%SJMLINES)){
300 print $SJMLINES{$i} if($debug);
301 print TSOSJM $SJMLINES{$i};
302 }
303
304 close(TSOINT);
305 close(TSOFP);
306 close(TSOSJM);
307}
308
309#====================================================================
310# not sure why the function came here in the first place
311# performs a simple check.
312#====================================================================
313sub add0{
314
315 my $pc = $_[0];
316 my($length) = length($pc);
317
318 if($length != 16){
319 die " tso_analyze: ERROR something is wrong with the datum length $length\n";
320 }
321 $pc;
322}
323
324
325#=========================================================================
326
327sub usage {
328 print <<EOH;
329---------------------------------------------------------------------------
330Usage: tso_analyze
331
332<options>: [default]
333
334 -debug debug [off]
335
336Function:
337 Do a tsotool post-processing analysis.
338
339---------------------------------------------------------------------------
340EOH
341}