forked from yszheda/sim-outorder_RRIP-HP-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeview.pl
executable file
·289 lines (262 loc) · 7.11 KB
/
pipeview.pl
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/perl
#
# pipeview - pipeline trace pretty printer
#
# SimpleScalar(TM) Tool Suite
# Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC.
# All Rights Reserved.
#
# THIS IS A LEGAL DOCUMENT, BY USING SIMPLESCALAR,
# YOU ARE AGREEING TO THESE TERMS AND CONDITIONS.
#
# No portion of this work may be used by any commercial entity, or for any
# commercial purpose, without the prior, written permission of SimpleScalar,
# LLC ([email protected]). Nonprofit and noncommercial use is permitted
# as described below.
#
# 1. SimpleScalar is provided AS IS, with no warranty of any kind, express
# or implied. The user of the program accepts full responsibility for the
# application of the program and the use of any results.
#
# 2. Nonprofit and noncommercial use is encouraged. SimpleScalar may be
# downloaded, compiled, executed, copied, and modified solely for nonprofit,
# educational, noncommercial research, and noncommercial scholarship
# purposes provided that this notice in its entirety accompanies all copies.
# Copies of the modified software can be delivered to persons who use it
# solely for nonprofit, educational, noncommercial research, and
# noncommercial scholarship purposes provided that this notice in its
# entirety accompanies all copies.
#
# 3. ALL COMMERCIAL USE, AND ALL USE BY FOR PROFIT ENTITIES, IS EXPRESSLY
# PROHIBITED WITHOUT A LICENSE FROM SIMPLESCALAR, LLC ([email protected]).
#
# 4. No nonprofit user may place any restrictions on the use of this software,
# including as modified by the user, by any other authorized user.
#
# 5. Noncommercial and nonprofit users may distribute copies of SimpleScalar
# in compiled or executable form as set forth in Section 2, provided that
# either: (A) it is accompanied by the corresponding machine-readable source
# code, or (B) it is accompanied by a written offer, with no time limit, to
# give anyone a machine-readable copy of the corresponding source code in
# return for reimbursement of the cost of distribution. This written offer
# must permit verbatim duplication by anyone, or (C) it is distributed by
# someone who received only the executable form, and is accompanied by a
# copy of the written offer of source code.
#
# 6. SimpleScalar was developed by Todd M. Austin, Ph.D. The tool suite is
# currently maintained by SimpleScalar LLC ([email protected]). US Mail:
# 2395 Timbercrest Court, Ann Arbor, MI 48105.
#
# Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC.
#
#
# TODO: check live lengths...
#
if (@ARGV != 1)
{
print STDERR "Usage: pview <pipe_trace>\n";
exit -1;
}
open(TRC_FILE, $ARGV[0])
|| die "Cannot open pipeline trace file `$ARGV[0]'";
$cycle = 0;
print "Instruction event legend:\n";
print "\n";
print " * - cache miss\n";
print " ! - TLB miss\n";
print " / - branch misprediction\n";
print " \\ - branch misprediction detected\n";
print " + - address generation execution\n";
print "\n";
while (<TRC_FILE>)
{
# remove carriage return
chop;
# new instruction
if (/^\+\s+(\d+)\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+(.*)\n?$/)
{
# register this instruction in the live instruction hash table
$insts{$1} = 1;
$insts_pc{$1} = $2;
$insts_addr{$1} = $3;
$insts_asm{$1} = $4;
$insts_iid{$1} =
chr ((ord("a") + (($1 / 26) % 26))) .
chr (ord("a") + ($1 % 26));
# print instruction id and asm info
print "$insts_iid{$1} = `$2: $4'\n";
}
# deleted instruction
elsif (/^\-\s+(\d+)\n?$/)
{
# record deletion, these are processed after pipe info is printed
@dead_pseqs = ($1, @dead_pseqs);
}
# new cycle
elsif (/^@\s+(\d+)\n?$/)
{
# clear all instruction stage lists
@if_iids = ();
@da_iids = ();
@ex_iids = ();
@wb_iids = ();
@ct_iids = ();
# print last cycle pipeline state
foreach $pseq (keys %insts)
{
# partition by instruction stage
$stage = $insts_stage{$pseq};
# decode the instruction events
$events = hex($insts_events{$pseq});
$evstr = "";
if ($events & 0x00000001) # cache miss
{
$evstr = $evstr . "*";
}
if (($events & 0x00000002) != 0) # TLB miss
{
$evstr = $evstr . "!";
}
if ($events & 0x00000004) # mis-predict occurred
{
$evstr = $evstr . "/";
}
if ($events & 0x00000008) # mis-predict detected
{
$evstr = $evstr . "\\";
}
if ($events & 0x00000010) # addr generation
{
$evstr = $evstr . "+";
}
if ($stage eq "IF")
{
@if_iids = (@if_iids, $insts_iid{$pseq} . $evstr);
}
elsif ($stage eq "DA")
{
@da_iids = (@da_iids, $insts_iid{$pseq} . $evstr);
}
elsif ($stage eq "EX")
{
@ex_iids = (@ex_iids, $insts_iid{$pseq} . $evstr);
}
elsif ($stage eq "WB")
{
@wb_iids = (@wb_iids, $insts_iid{$pseq} . $evstr);
}
elsif ($stage eq "CT")
{
@ct_iids = (@ct_iids, $insts_iid{$pseq} . $evstr);
}
else
{
print "warning: unknown stage\n";
}
}
# print "** if_iids: ";
# foreach $iid (@if_iids)
# {
# print "$iid ";
# }
# print "\n";
# sort stage lists
@if_iids = sort @if_iids;
@da_iids = sort @da_iids;
@ex_iids = sort @ex_iids;
@wb_iids = sort @wb_iids;
@ct_iids = sort @ct_iids;
# print pipeline header
if ((@if_iids + @da_iids + @ex_iids + @wb_iids + @ct_iids) > 0)
{
print "\n";
print " [IF] ", " [DA] ", " [EX] ", " [WB] ", " [CT]", "\n";
}
# print stage data
while ((@if_iids + @da_iids + @ex_iids + @wb_iids + @ct_iids) > 0)
{
if (@if_iids > 0)
{
($iid, @if_iids) = @if_iids;
printf " %-6s ", $iid;
}
else
{
print " ";
}
if (@da_iids > 0)
{
($iid, @da_iids) = @da_iids;
printf " %-6s ", $iid;
}
else
{
print " ";
}
if (@ex_iids > 0)
{
($iid, @ex_iids) = @ex_iids;
printf " %-6s ", $iid;
}
else
{
print " ";
}
if (@wb_iids > 0)
{
($iid, @wb_iids) = @wb_iids;
printf " %-6s ", $iid;
}
else
{
print " ";
}
if (@ct_iids > 0)
{
($iid, @ct_iids) = @ct_iids;
printf " %-6s ", $iid;
}
else
{
print " ";
}
print "\n";
}
print "\n";
# delete instruction that finished in this cycle
foreach $pseq (@dead_pseqs)
{
delete $insts{$pseq};
delete $insts_pc{$pseq};
delete $insts_addr{$pseq};
delete $insts_asm{$pseq};
delete $insts_iid{$pseq};
delete $insts_stage{$pseq};
delete $insts_events{$pseq};
}
@dead_pseqs = ();
# go on to the next cycle
$cycle = $1;
print "@ $cycle\n";
}
# instruction transition to a new stage
elsif (/^\*\s+(\d+)\s+(\w+)\s+(0x[0-9a-fA-F]+)\n?$/)
{
if ($insts{$1})
{
# this instruction is live...
$insts_stage{$1} = $2;
$insts_events{$1} = $3;
}
else
{
# this instruction is dead...
# print STDERR "inst `$1' is dead...\n";
}
}
else
{
print "warning: could not parse line: `$_'\n";
}
}
close(TRC_FILE);