1 |
2 |
cvs |
/* stats.c -- Various statistics about instruction scheduling etc.
|
2 |
|
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
3 |
|
|
|
4 |
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
5 |
|
|
|
6 |
|
|
This program is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
9 |
|
|
(at your option) any later version.
|
10 |
|
|
|
11 |
|
|
This program is distributed in the hope that it will be useful,
|
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with this program; if not, write to the Free Software
|
18 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
19 |
|
|
|
20 |
|
|
#include <stdio.h>
|
21 |
|
|
#include <ctype.h>
|
22 |
|
|
#include <string.h>
|
23 |
|
|
|
24 |
|
|
#include "abstract.h"
|
25 |
|
|
#include "stats.h"
|
26 |
102 |
lampret |
#include "sim-config.h"
|
27 |
|
|
#include "spr_defs.h"
|
28 |
30 |
lampret |
|
29 |
2 |
cvs |
const char func_unit_str[30][30] = { "unknown", "arith", "shift", "compare",
|
30 |
|
|
"branch", "jump", "load", "store", "movimm", "move", "extend", "nop" };
|
31 |
|
|
|
32 |
|
|
struct dstats_entry dstats[DSTATS_LEN]; /* dependency stats */
|
33 |
|
|
struct sstats_entry sstats[SSTATS_LEN]; /* single stats */
|
34 |
|
|
struct fstats_entry fstats[FSTATS_LEN]; /* functional units stats */
|
35 |
|
|
struct mstats_entry mstats; /* misc units stats */
|
36 |
6 |
lampret |
struct cachestats_entry ic_stats; /* instruction cache stats */
|
37 |
|
|
struct cachestats_entry dc_stats; /* data cache stats */
|
38 |
77 |
lampret |
struct immustats_entry immu_stats; /* insn mmu stats */
|
39 |
|
|
struct dmmustats_entry dmmu_stats; /* data mmu stats */
|
40 |
6 |
lampret |
struct raw_stats raw_stats; /* RAW hazard stats */
|
41 |
34 |
lampret |
struct slp_stats slp_stats; /* SLP stats */
|
42 |
2 |
cvs |
|
43 |
|
|
/* Dependency */
|
44 |
|
|
|
45 |
|
|
int check_depend()
|
46 |
102 |
lampret |
{
|
47 |
138 |
markom |
debug("check_depend");
|
48 |
|
|
return depend_operands(&icomplet[0], &iqueue[0]);
|
49 |
2 |
cvs |
}
|
50 |
|
|
|
51 |
|
|
void addsstats(char *item, int cnt_dynamic, int cnt_static)
|
52 |
|
|
{
|
53 |
|
|
int i = 0;
|
54 |
|
|
|
55 |
|
|
while(strcmp(sstats[i].insn, item) && (sstats[i].cnt_static > 0) &&
|
56 |
|
|
(sstats[i].cnt_static > 0) && (i < SSTATS_LEN))
|
57 |
|
|
i++;
|
58 |
|
|
|
59 |
|
|
if (i >= SSTATS_LEN - 1) return;
|
60 |
|
|
|
61 |
|
|
if (strcmp(sstats[i].insn, item) == 0) {
|
62 |
|
|
sstats[i].cnt_dynamic += cnt_dynamic;
|
63 |
|
|
sstats[i].cnt_static += cnt_static;
|
64 |
|
|
}
|
65 |
|
|
else {
|
66 |
|
|
strcpy(sstats[i].insn, item);
|
67 |
|
|
sstats[i].cnt_dynamic = cnt_dynamic;
|
68 |
|
|
sstats[i].cnt_static = cnt_static;
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
void adddstats(char *item1, char *item2, int cnt_dynamic, int depend)
|
73 |
|
|
{
|
74 |
|
|
int i = 0;
|
75 |
|
|
|
76 |
|
|
debug("adddstats start\n");
|
77 |
|
|
|
78 |
|
|
while((strcmp(dstats[i].insn1, item1) || strcmp(dstats[i].insn2, item2)) &&
|
79 |
|
|
(strlen(dstats[i].insn1)) &&
|
80 |
|
|
(i < DSTATS_LEN))
|
81 |
|
|
i++;
|
82 |
|
|
|
83 |
|
|
if (i >= DSTATS_LEN - 1) return;
|
84 |
|
|
|
85 |
|
|
if ((strcmp(dstats[i].insn1, item1) == 0) &&
|
86 |
|
|
(strcmp(dstats[i].insn2, item2) == 0)) {
|
87 |
|
|
dstats[i].cnt_dynamic += cnt_dynamic;
|
88 |
|
|
dstats[i].depend += depend;
|
89 |
|
|
}
|
90 |
|
|
else {
|
91 |
|
|
strcpy(dstats[i].insn1, item1);
|
92 |
|
|
strcpy(dstats[i].insn2, item2);
|
93 |
|
|
dstats[i].cnt_dynamic = cnt_dynamic;
|
94 |
|
|
dstats[i].depend = depend;
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
void addfstats(enum insn_type item1, enum insn_type item2, int cnt_dynamic, int depend)
|
99 |
|
|
{
|
100 |
|
|
int i = 0;
|
101 |
|
|
|
102 |
|
|
while(((fstats[i].insn1 != item1) || (fstats[i].insn2 != item2)) &&
|
103 |
|
|
(fstats[i].insn1 != unknown) &&
|
104 |
|
|
(i < FSTATS_LEN))
|
105 |
|
|
i++;
|
106 |
|
|
|
107 |
|
|
if (i >= FSTATS_LEN - 1) return;
|
108 |
|
|
|
109 |
|
|
if ((fstats[i].insn1 == item1) &&
|
110 |
|
|
(fstats[i].insn2 == item2)) {
|
111 |
|
|
fstats[i].cnt_dynamic += cnt_dynamic;
|
112 |
|
|
fstats[i].depend += depend;
|
113 |
|
|
}
|
114 |
|
|
else {
|
115 |
|
|
fstats[i].insn1 = item1;
|
116 |
|
|
fstats[i].insn2 = item2;
|
117 |
|
|
fstats[i].cnt_dynamic = cnt_dynamic;
|
118 |
|
|
fstats[i].depend = depend;
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
void initstats()
|
123 |
|
|
{
|
124 |
|
|
memset(sstats, 0, sizeof(sstats));
|
125 |
|
|
memset(dstats, 0, sizeof(dstats));
|
126 |
|
|
memset(fstats, 0, sizeof(fstats));
|
127 |
|
|
memset(&mstats, 0, sizeof(mstats));
|
128 |
6 |
lampret |
memset(&ic_stats, 0, sizeof(ic_stats));
|
129 |
|
|
memset(&dc_stats, 0, sizeof(dc_stats));
|
130 |
|
|
memset(&raw_stats, 0, sizeof(raw_stats));
|
131 |
34 |
lampret |
memset(&slp_stats, 0, sizeof(slp_stats));
|
132 |
2 |
cvs |
}
|
133 |
|
|
|
134 |
34 |
lampret |
/* SLP
|
135 |
|
|
|
136 |
|
|
1: R
|
137 |
|
|
2: R
|
138 |
|
|
3: R
|
139 |
|
|
OK
|
140 |
|
|
|
141 |
|
|
1: W
|
142 |
|
|
2: R
|
143 |
|
|
3: R
|
144 |
|
|
flush 2 3
|
145 |
|
|
|
146 |
|
|
1: R
|
147 |
|
|
2: W
|
148 |
|
|
3: R
|
149 |
|
|
OK
|
150 |
|
|
|
151 |
|
|
1: R
|
152 |
|
|
2: W
|
153 |
|
|
3: R
|
154 |
|
|
flush 3
|
155 |
|
|
|
156 |
|
|
flushing: don't flush if written location hasn't change after the write since
|
157 |
|
|
original read got correct data.
|
158 |
|
|
|
159 |
|
|
*/
|
160 |
|
|
|
161 |
|
|
void slp_checkaccess(unsigned long addr, char type)
|
162 |
|
|
{
|
163 |
102 |
lampret |
if (!config.slp)
|
164 |
|
|
return;
|
165 |
|
|
|
166 |
34 |
lampret |
if ((addr < (MEMORY_START + MEMORY_LEN - 4000)) &&
|
167 |
|
|
slp_stats.supercnt && (type == SLP_MEMWRITE)) {
|
168 |
|
|
slp_stats.supercalls++;
|
169 |
|
|
slp_stats.supercnt = 0;
|
170 |
|
|
}
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
void slp_func_entry()
|
174 |
|
|
{
|
175 |
102 |
lampret |
if (!config.slp)
|
176 |
|
|
return;
|
177 |
|
|
|
178 |
34 |
lampret |
if (++slp_stats.curdepth > slp_stats.maxdepth)
|
179 |
|
|
slp_stats.maxdepth = slp_stats.curdepth;
|
180 |
|
|
|
181 |
|
|
slp_stats.calls++;
|
182 |
|
|
slp_stats.supercnt++;
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
void slp_func_exit()
|
186 |
|
|
{
|
187 |
102 |
lampret |
if (!config.slp)
|
188 |
|
|
return;
|
189 |
|
|
|
190 |
34 |
lampret |
slp_stats.curdepth--;
|
191 |
|
|
}
|
192 |
|
|
|
193 |
102 |
lampret |
|
194 |
|
|
void printistats(int which)
|
195 |
2 |
cvs |
{
|
196 |
|
|
int i, all = 0, dependall = 0;
|
197 |
102 |
lampret |
|
198 |
|
|
if (!config.dependstats) {
|
199 |
|
|
printf("Hazard analysis disabled. Enable it to see analysis results.\n");
|
200 |
|
|
return;
|
201 |
|
|
}
|
202 |
2 |
cvs |
|
203 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
204 |
|
|
all += sstats[i].cnt_static;
|
205 |
|
|
|
206 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
207 |
6 |
lampret |
if (sstats[i].cnt_static && (which == 1))
|
208 |
2 |
cvs |
printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_static, (sstats[i].cnt_static * 100)/all);
|
209 |
|
|
|
210 |
|
|
printf("SUM: %d instructions (static, single stats)\n", all);
|
211 |
6 |
lampret |
|
212 |
2 |
cvs |
all = 0;
|
213 |
6 |
lampret |
|
214 |
2 |
cvs |
for(i = 0; i < SSTATS_LEN; i++)
|
215 |
|
|
all += sstats[i].cnt_dynamic;
|
216 |
|
|
|
217 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
218 |
6 |
lampret |
if (sstats[i].cnt_dynamic && (which == 2))
|
219 |
2 |
cvs |
printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_dynamic, (sstats[i].cnt_dynamic * 100)/all);
|
220 |
|
|
|
221 |
|
|
printf("SUM: %d instructions (dynamic, single stats)\n", all);
|
222 |
|
|
|
223 |
|
|
all = 0;
|
224 |
|
|
dependall = 0;
|
225 |
|
|
for(i = 0; i < DSTATS_LEN; i++) {
|
226 |
|
|
all += dstats[i].cnt_dynamic;
|
227 |
|
|
dependall += dstats[i].depend;
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
for(i = 0; i < DSTATS_LEN; i++)
|
231 |
6 |
lampret |
if (dstats[i].cnt_dynamic && (which == 3)) {
|
232 |
2 |
cvs |
printf(" %s, %s ", dstats[i].insn1, dstats[i].insn2);
|
233 |
|
|
printf("\t\t\t%6dx (%2d%%)", dstats[i].cnt_dynamic, (dstats[i].cnt_dynamic * 100)/all);
|
234 |
|
|
printf(" depend: %3d%%\n", (dstats[i].depend * 100) / dstats[i].cnt_dynamic);
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
printf("SUM: %d instructions (dynamic, dependency stats) depend: %d%%\n", all, (dependall * 100) / all);
|
238 |
|
|
|
239 |
|
|
all = 0;
|
240 |
|
|
dependall = 0;
|
241 |
|
|
for(i = 0; i < FSTATS_LEN; i++) {
|
242 |
|
|
all += fstats[i].cnt_dynamic;
|
243 |
|
|
dependall += fstats[i].depend;
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
for(i = 0; i < FSTATS_LEN; i++)
|
247 |
6 |
lampret |
if (fstats[i].cnt_dynamic && (which == 4)) {
|
248 |
2 |
cvs |
printf(" %s,", func_unit_str[fstats[i].insn1]);
|
249 |
|
|
printf(" %s", func_unit_str[fstats[i].insn2]);
|
250 |
|
|
printf("\t\t\t%6dx (%2d%%)", fstats[i].cnt_dynamic, (fstats[i].cnt_dynamic * 100)/all);
|
251 |
|
|
printf(" depend: %3d%%\n", (fstats[i].depend * 100) / fstats[i].cnt_dynamic);
|
252 |
|
|
}
|
253 |
|
|
|
254 |
6 |
lampret |
for(i = 0; (i < RAW_RANGE) && (which == 5); i++)
|
255 |
|
|
printf(" Register set and reused in %d. cycle: %d cases\n", i, raw_stats.range[i]);
|
256 |
|
|
|
257 |
102 |
lampret |
printf("SUM: %d instructions (dynamic, functional units stats) depend: %d%%\n", all, (dependall * 100) / SD(all));
|
258 |
|
|
printf("Byte ADD: %d instructions\n", mstats.byteadd);
|
259 |
|
|
|
260 |
|
|
}
|
261 |
|
|
|
262 |
|
|
void printslpstats(int which)
|
263 |
|
|
{
|
264 |
|
|
int i, all = 0, dependall = 0;
|
265 |
|
|
|
266 |
|
|
if (!config.slp) {
|
267 |
|
|
printf("SLP analysis disabled. Enable it to see analysis results.\n");
|
268 |
|
|
return;
|
269 |
|
|
}
|
270 |
|
|
|
271 |
34 |
lampret |
if (which == 6) {
|
272 |
|
|
printf("SLP:\n");
|
273 |
|
|
printf("maxdepth: %6d calls: %6d\n", slp_stats.maxdepth, slp_stats.calls);
|
274 |
|
|
printf("calls: %6d supercalls: %6d\n", slp_stats.calls, slp_stats.supercalls);
|
275 |
|
|
}
|
276 |
|
|
|
277 |
2 |
cvs |
}
|
278 |
102 |
lampret |
|
279 |
|
|
void printotherstats(int which)
|
280 |
|
|
{
|
281 |
|
|
int i, all = 0, dependall = 0;
|
282 |
|
|
|
283 |
|
|
if (config.bp.bpb_sim) {
|
284 |
|
|
printf("bnf: %d (%d%%) taken,", mstats.beqz.taken, (mstats.beqz.taken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
|
285 |
|
|
printf(" %d (%d%%) not taken,", mstats.beqz.nottaken, (mstats.beqz.nottaken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
|
286 |
|
|
printf(" %d (%d%%) forward,", mstats.beqz.forward, (mstats.beqz.forward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
|
287 |
|
|
printf(" %d (%d%%) backward\n", mstats.beqz.backward, (mstats.beqz.backward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
|
288 |
|
|
printf("bf: %d (%d%%) taken,", mstats.bnez.taken, (mstats.bnez.taken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
|
289 |
|
|
printf(" %d (%d%%) not taken,", mstats.bnez.nottaken, (mstats.bnez.nottaken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
|
290 |
|
|
printf(" %d (%d%%) forward,", mstats.bnez.forward, (mstats.bnez.forward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
|
291 |
|
|
printf(" %d (%d%%) backward\n", mstats.bnez.backward, (mstats.bnez.backward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
|
292 |
|
|
printf("StaticBP bnf: correct %d%% (forward)\n", (mstats.sbp_bnf.correct * 100) / SD(mstats.sbp_bnf.all));
|
293 |
|
|
printf("StaticBP bf: correct %d%% (backward)\n", (mstats.sbp_bf.correct * 100) / SD(mstats.sbp_bf.all));
|
294 |
|
|
printf("BPB: hit %d (correct %d%%), miss %d\n", mstats.bpb.hit, (mstats.bpb.correct * 100) / SD(mstats.bpb.hit), mstats.bpb.miss);
|
295 |
|
|
} else
|
296 |
|
|
printf("BPB simulation disabled. Enable it to see BPB analysis\n");
|
297 |
|
|
|
298 |
|
|
if (config.bp.btic_sim) {
|
299 |
|
|
printf("BTIC: hit %d(%d%%), miss %d\n", mstats.btic.hit, (mstats.btic.hit * 100) / SD(mstats.btic.hit + mstats.btic.miss), mstats.btic.miss);
|
300 |
|
|
} else
|
301 |
|
|
printf("BTIC simulation disabled. Enabled it to see BTIC analysis\n");
|
302 |
|
|
|
303 |
|
|
if (getsprbits(SPR_UPR, SPR_UPR_ICP)) {
|
304 |
|
|
printf("IC read: hit %d(%d%%), miss %d\n", ic_stats.readhit, (ic_stats.readhit * 100) / SD(ic_stats.readhit + ic_stats.readmiss), ic_stats.readmiss);
|
305 |
|
|
} else
|
306 |
|
|
printf("No ICache. Set UPR[ICP]\n");
|
307 |
|
|
|
308 |
|
|
if (getsprbits(SPR_UPR, SPR_UPR_DCP)) {
|
309 |
|
|
printf("DC read: hit %d(%d%%), miss %d\n", dc_stats.readhit, (dc_stats.readhit * 100) / SD(dc_stats.readhit + dc_stats.readmiss), dc_stats.readmiss);
|
310 |
|
|
printf("DC write: hit %d(%d%%), miss %d\n", dc_stats.writehit, (dc_stats.writehit * 100) / SD(dc_stats.writehit + dc_stats.writemiss), dc_stats.writemiss);
|
311 |
|
|
} else
|
312 |
|
|
printf("No DCache. Set UPR[DCP]\n");
|
313 |
|
|
|
314 |
|
|
if (getsprbits(SPR_UPR, SPR_UPR_IMP)) {
|
315 |
|
|
printf("IMMU read: hit %d(%d%%), miss %d\n", immu_stats.fetch_tlbhit, (immu_stats.fetch_tlbhit * 100) / SD(immu_stats.fetch_tlbhit + immu_stats.fetch_tlbmiss), immu_stats.fetch_tlbmiss);
|
316 |
|
|
} else
|
317 |
|
|
printf("No IMMU. Set UPR[IMP]\n");
|
318 |
|
|
|
319 |
|
|
if (getsprbits(SPR_UPR, SPR_UPR_DMP)) {
|
320 |
|
|
printf("DMMU read: hit %d(%d%%), miss %d\n", dmmu_stats.loads_tlbhit, (dmmu_stats.loads_tlbhit * 100) / SD(dmmu_stats.loads_tlbhit + dmmu_stats.loads_tlbmiss), dmmu_stats.loads_tlbmiss);
|
321 |
|
|
} else
|
322 |
|
|
printf("No DMMU. Set UPR[DMP]\n");
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
void printstats(int which)
|
326 |
|
|
{
|
327 |
|
|
printistats(which);
|
328 |
|
|
printslpstats(which);
|
329 |
|
|
if (which == 5)
|
330 |
|
|
printotherstats(which);
|
331 |
|
|
}
|