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 |
30 |
lampret |
|
27 |
2 |
cvs |
const char func_unit_str[30][30] = { "unknown", "arith", "shift", "compare",
|
28 |
|
|
"branch", "jump", "load", "store", "movimm", "move", "extend", "nop" };
|
29 |
|
|
|
30 |
|
|
struct dstats_entry dstats[DSTATS_LEN]; /* dependency stats */
|
31 |
|
|
struct sstats_entry sstats[SSTATS_LEN]; /* single stats */
|
32 |
|
|
struct fstats_entry fstats[FSTATS_LEN]; /* functional units stats */
|
33 |
|
|
struct mstats_entry mstats; /* misc units stats */
|
34 |
6 |
lampret |
struct cachestats_entry ic_stats; /* instruction cache stats */
|
35 |
|
|
struct cachestats_entry dc_stats; /* data cache stats */
|
36 |
77 |
lampret |
struct immustats_entry immu_stats; /* insn mmu stats */
|
37 |
|
|
struct dmmustats_entry dmmu_stats; /* data mmu stats */
|
38 |
6 |
lampret |
struct raw_stats raw_stats; /* RAW hazard stats */
|
39 |
34 |
lampret |
struct slp_stats slp_stats; /* SLP stats */
|
40 |
2 |
cvs |
|
41 |
|
|
/* Dependency */
|
42 |
|
|
|
43 |
|
|
int check_depend()
|
44 |
|
|
{
|
45 |
|
|
debug("check_depend");
|
46 |
|
|
if (depend_operands(icomplet[0].dependdst, iqueue[0].dependsrc1) +
|
47 |
|
|
depend_operands(icomplet[0].dependdst, iqueue[0].dependsrc2))
|
48 |
|
|
return 1;
|
49 |
|
|
else
|
50 |
|
|
return 0;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
void addsstats(char *item, int cnt_dynamic, int cnt_static)
|
54 |
|
|
{
|
55 |
|
|
int i = 0;
|
56 |
|
|
|
57 |
|
|
while(strcmp(sstats[i].insn, item) && (sstats[i].cnt_static > 0) &&
|
58 |
|
|
(sstats[i].cnt_static > 0) && (i < SSTATS_LEN))
|
59 |
|
|
i++;
|
60 |
|
|
|
61 |
|
|
if (i >= SSTATS_LEN - 1) return;
|
62 |
|
|
|
63 |
|
|
if (strcmp(sstats[i].insn, item) == 0) {
|
64 |
|
|
sstats[i].cnt_dynamic += cnt_dynamic;
|
65 |
|
|
sstats[i].cnt_static += cnt_static;
|
66 |
|
|
}
|
67 |
|
|
else {
|
68 |
|
|
strcpy(sstats[i].insn, item);
|
69 |
|
|
sstats[i].cnt_dynamic = cnt_dynamic;
|
70 |
|
|
sstats[i].cnt_static = cnt_static;
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
void adddstats(char *item1, char *item2, int cnt_dynamic, int depend)
|
75 |
|
|
{
|
76 |
|
|
int i = 0;
|
77 |
|
|
|
78 |
|
|
debug("adddstats start\n");
|
79 |
|
|
|
80 |
|
|
while((strcmp(dstats[i].insn1, item1) || strcmp(dstats[i].insn2, item2)) &&
|
81 |
|
|
(strlen(dstats[i].insn1)) &&
|
82 |
|
|
(i < DSTATS_LEN))
|
83 |
|
|
i++;
|
84 |
|
|
|
85 |
|
|
if (i >= DSTATS_LEN - 1) return;
|
86 |
|
|
|
87 |
|
|
if ((strcmp(dstats[i].insn1, item1) == 0) &&
|
88 |
|
|
(strcmp(dstats[i].insn2, item2) == 0)) {
|
89 |
|
|
dstats[i].cnt_dynamic += cnt_dynamic;
|
90 |
|
|
dstats[i].depend += depend;
|
91 |
|
|
}
|
92 |
|
|
else {
|
93 |
|
|
strcpy(dstats[i].insn1, item1);
|
94 |
|
|
strcpy(dstats[i].insn2, item2);
|
95 |
|
|
dstats[i].cnt_dynamic = cnt_dynamic;
|
96 |
|
|
dstats[i].depend = depend;
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
void addfstats(enum insn_type item1, enum insn_type item2, int cnt_dynamic, int depend)
|
101 |
|
|
{
|
102 |
|
|
int i = 0;
|
103 |
|
|
|
104 |
|
|
while(((fstats[i].insn1 != item1) || (fstats[i].insn2 != item2)) &&
|
105 |
|
|
(fstats[i].insn1 != unknown) &&
|
106 |
|
|
(i < FSTATS_LEN))
|
107 |
|
|
i++;
|
108 |
|
|
|
109 |
|
|
if (i >= FSTATS_LEN - 1) return;
|
110 |
|
|
|
111 |
|
|
if ((fstats[i].insn1 == item1) &&
|
112 |
|
|
(fstats[i].insn2 == item2)) {
|
113 |
|
|
fstats[i].cnt_dynamic += cnt_dynamic;
|
114 |
|
|
fstats[i].depend += depend;
|
115 |
|
|
}
|
116 |
|
|
else {
|
117 |
|
|
fstats[i].insn1 = item1;
|
118 |
|
|
fstats[i].insn2 = item2;
|
119 |
|
|
fstats[i].cnt_dynamic = cnt_dynamic;
|
120 |
|
|
fstats[i].depend = depend;
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
void initstats()
|
125 |
|
|
{
|
126 |
|
|
memset(sstats, 0, sizeof(sstats));
|
127 |
|
|
memset(dstats, 0, sizeof(dstats));
|
128 |
|
|
memset(fstats, 0, sizeof(fstats));
|
129 |
|
|
memset(&mstats, 0, sizeof(mstats));
|
130 |
6 |
lampret |
memset(&ic_stats, 0, sizeof(ic_stats));
|
131 |
|
|
memset(&dc_stats, 0, sizeof(dc_stats));
|
132 |
|
|
memset(&raw_stats, 0, sizeof(raw_stats));
|
133 |
34 |
lampret |
memset(&slp_stats, 0, sizeof(slp_stats));
|
134 |
2 |
cvs |
}
|
135 |
|
|
|
136 |
34 |
lampret |
/* SLP
|
137 |
|
|
|
138 |
|
|
1: R
|
139 |
|
|
2: R
|
140 |
|
|
3: R
|
141 |
|
|
OK
|
142 |
|
|
|
143 |
|
|
1: W
|
144 |
|
|
2: R
|
145 |
|
|
3: R
|
146 |
|
|
flush 2 3
|
147 |
|
|
|
148 |
|
|
1: R
|
149 |
|
|
2: W
|
150 |
|
|
3: R
|
151 |
|
|
OK
|
152 |
|
|
|
153 |
|
|
1: R
|
154 |
|
|
2: W
|
155 |
|
|
3: R
|
156 |
|
|
flush 3
|
157 |
|
|
|
158 |
|
|
flushing: don't flush if written location hasn't change after the write since
|
159 |
|
|
original read got correct data.
|
160 |
|
|
|
161 |
|
|
*/
|
162 |
|
|
|
163 |
|
|
void slp_checkaccess(unsigned long addr, char type)
|
164 |
|
|
{
|
165 |
|
|
if ((addr < (MEMORY_START + MEMORY_LEN - 4000)) &&
|
166 |
|
|
slp_stats.supercnt && (type == SLP_MEMWRITE)) {
|
167 |
|
|
slp_stats.supercalls++;
|
168 |
|
|
slp_stats.supercnt = 0;
|
169 |
|
|
}
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
void slp_func_entry()
|
173 |
|
|
{
|
174 |
|
|
if (++slp_stats.curdepth > slp_stats.maxdepth)
|
175 |
|
|
slp_stats.maxdepth = slp_stats.curdepth;
|
176 |
|
|
|
177 |
|
|
slp_stats.calls++;
|
178 |
|
|
slp_stats.supercnt++;
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
void slp_func_exit()
|
182 |
|
|
{
|
183 |
|
|
slp_stats.curdepth--;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
6 |
lampret |
void printstats(int which)
|
187 |
2 |
cvs |
{
|
188 |
|
|
int i, all = 0, dependall = 0;
|
189 |
|
|
|
190 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
191 |
|
|
all += sstats[i].cnt_static;
|
192 |
|
|
|
193 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
194 |
6 |
lampret |
if (sstats[i].cnt_static && (which == 1))
|
195 |
2 |
cvs |
printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_static, (sstats[i].cnt_static * 100)/all);
|
196 |
|
|
|
197 |
|
|
printf("SUM: %d instructions (static, single stats)\n", all);
|
198 |
6 |
lampret |
|
199 |
2 |
cvs |
all = 0;
|
200 |
6 |
lampret |
|
201 |
2 |
cvs |
for(i = 0; i < SSTATS_LEN; i++)
|
202 |
|
|
all += sstats[i].cnt_dynamic;
|
203 |
|
|
|
204 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
205 |
6 |
lampret |
if (sstats[i].cnt_dynamic && (which == 2))
|
206 |
2 |
cvs |
printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_dynamic, (sstats[i].cnt_dynamic * 100)/all);
|
207 |
|
|
|
208 |
|
|
printf("SUM: %d instructions (dynamic, single stats)\n", all);
|
209 |
|
|
|
210 |
|
|
all = 0;
|
211 |
|
|
dependall = 0;
|
212 |
|
|
for(i = 0; i < DSTATS_LEN; i++) {
|
213 |
|
|
all += dstats[i].cnt_dynamic;
|
214 |
|
|
dependall += dstats[i].depend;
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
for(i = 0; i < DSTATS_LEN; i++)
|
218 |
6 |
lampret |
if (dstats[i].cnt_dynamic && (which == 3)) {
|
219 |
2 |
cvs |
printf(" %s, %s ", dstats[i].insn1, dstats[i].insn2);
|
220 |
|
|
printf("\t\t\t%6dx (%2d%%)", dstats[i].cnt_dynamic, (dstats[i].cnt_dynamic * 100)/all);
|
221 |
|
|
printf(" depend: %3d%%\n", (dstats[i].depend * 100) / dstats[i].cnt_dynamic);
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
printf("SUM: %d instructions (dynamic, dependency stats) depend: %d%%\n", all, (dependall * 100) / all);
|
225 |
|
|
|
226 |
|
|
all = 0;
|
227 |
|
|
dependall = 0;
|
228 |
|
|
for(i = 0; i < FSTATS_LEN; i++) {
|
229 |
|
|
all += fstats[i].cnt_dynamic;
|
230 |
|
|
dependall += fstats[i].depend;
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
for(i = 0; i < FSTATS_LEN; i++)
|
234 |
6 |
lampret |
if (fstats[i].cnt_dynamic && (which == 4)) {
|
235 |
2 |
cvs |
printf(" %s,", func_unit_str[fstats[i].insn1]);
|
236 |
|
|
printf(" %s", func_unit_str[fstats[i].insn2]);
|
237 |
|
|
printf("\t\t\t%6dx (%2d%%)", fstats[i].cnt_dynamic, (fstats[i].cnt_dynamic * 100)/all);
|
238 |
|
|
printf(" depend: %3d%%\n", (fstats[i].depend * 100) / fstats[i].cnt_dynamic);
|
239 |
|
|
}
|
240 |
|
|
|
241 |
6 |
lampret |
for(i = 0; (i < RAW_RANGE) && (which == 5); i++)
|
242 |
|
|
printf(" Register set and reused in %d. cycle: %d cases\n", i, raw_stats.range[i]);
|
243 |
|
|
|
244 |
34 |
lampret |
if (which == 6) {
|
245 |
|
|
printf("SLP:\n");
|
246 |
|
|
printf("maxdepth: %6d calls: %6d\n", slp_stats.maxdepth, slp_stats.calls);
|
247 |
|
|
printf("calls: %6d supercalls: %6d\n", slp_stats.calls, slp_stats.supercalls);
|
248 |
|
|
}
|
249 |
|
|
|
250 |
30 |
lampret |
printf("SUM: %d instructions (dynamic, functional units stats) depend: %d%%\n", all, (dependall * 100) / SD(all));
|
251 |
2 |
cvs |
printf("Byte ADD: %d instructions\n", mstats.byteadd);
|
252 |
30 |
lampret |
printf("bnf: %d (%d%%) taken,", mstats.beqz.taken, (mstats.beqz.taken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
|
253 |
|
|
printf(" %d (%d%%) not taken,", mstats.beqz.nottaken, (mstats.beqz.nottaken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
|
254 |
|
|
printf(" %d (%d%%) forward,", mstats.beqz.forward, (mstats.beqz.forward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
|
255 |
|
|
printf(" %d (%d%%) backward\n", mstats.beqz.backward, (mstats.beqz.backward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
|
256 |
|
|
printf("bf: %d (%d%%) taken,", mstats.bnez.taken, (mstats.bnez.taken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
|
257 |
|
|
printf(" %d (%d%%) not taken,", mstats.bnez.nottaken, (mstats.bnez.nottaken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
|
258 |
|
|
printf(" %d (%d%%) forward,", mstats.bnez.forward, (mstats.bnez.forward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
|
259 |
|
|
printf(" %d (%d%%) backward\n", mstats.bnez.backward, (mstats.bnez.backward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
|
260 |
|
|
printf("StaticBP bnf: correct %d%% (forward)\n", (mstats.sbp_bnf.correct * 100) / SD(mstats.sbp_bnf.all));
|
261 |
|
|
printf("StaticBP bf: correct %d%% (backward)\n", (mstats.sbp_bf.correct * 100) / SD(mstats.sbp_bf.all));
|
262 |
|
|
printf("BPB: hit %d (correct %d%%), miss %d\n", mstats.bpb.hit, (mstats.bpb.correct * 100) / SD(mstats.bpb.hit), mstats.bpb.miss);
|
263 |
|
|
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);
|
264 |
|
|
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);
|
265 |
|
|
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);
|
266 |
|
|
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);
|
267 |
77 |
lampret |
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);
|
268 |
65 |
lampret |
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);
|
269 |
2 |
cvs |
}
|