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 |
518 |
markom |
#include "sprs.h"
|
28 |
102 |
lampret |
#include "spr_defs.h"
|
29 |
30 |
lampret |
|
30 |
535 |
markom |
struct branchstat {
|
31 |
|
|
int taken;
|
32 |
|
|
int nottaken;
|
33 |
|
|
int forward;
|
34 |
|
|
int backward;
|
35 |
|
|
};
|
36 |
2 |
cvs |
|
37 |
535 |
markom |
/* See also enum insn_type in abstract.h */
|
38 |
|
|
const char func_unit_str[30][30] = { "unknown", "exception", "arith", "shift", "compare",
|
39 |
|
|
"branch", "jump", "load", "store", "movimm", "move", "extend", "nop", "mac" };
|
40 |
|
|
|
41 |
694 |
markom |
struct dstats_entry dstats[DSTATS_LEN]; /* dependency stats */
|
42 |
|
|
struct sstats_entry sstats[SSTATS_LEN]; /* single stats */
|
43 |
|
|
struct fstats_entry fstats[FSTATS_LEN]; /* functional units stats */
|
44 |
692 |
markom |
struct mstats_entry mstats = {0}; /* misc units stats */
|
45 |
|
|
struct cachestats_entry ic_stats = {0}; /* instruction cache stats */
|
46 |
|
|
struct cachestats_entry dc_stats = {0}; /* data cache stats */
|
47 |
|
|
struct immustats_entry immu_stats = {0}; /* insn mmu stats */
|
48 |
|
|
struct dmmustats_entry dmmu_stats = {0}; /* data mmu stats */
|
49 |
|
|
struct raw_stats raw_stats = {0}; /* RAW hazard stats */
|
50 |
2 |
cvs |
|
51 |
|
|
/* Dependency */
|
52 |
|
|
|
53 |
|
|
int check_depend()
|
54 |
532 |
markom |
{
|
55 |
479 |
markom |
debug(5,"check_depend\n");
|
56 |
138 |
markom |
return depend_operands(&icomplet[0], &iqueue[0]);
|
57 |
2 |
cvs |
}
|
58 |
|
|
|
59 |
535 |
markom |
void addsstats(int item, int cnt_dynamic)
|
60 |
2 |
cvs |
{
|
61 |
532 |
markom |
int i = 0;
|
62 |
|
|
|
63 |
535 |
markom |
while(sstats[i].insn != item && sstats[i].insn >= 0 && i < SSTATS_LEN) i++;
|
64 |
2 |
cvs |
|
65 |
532 |
markom |
if (i >= SSTATS_LEN - 1) return;
|
66 |
|
|
|
67 |
535 |
markom |
if (sstats[i].insn >= 0) {
|
68 |
532 |
markom |
sstats[i].cnt_dynamic += cnt_dynamic;
|
69 |
535 |
markom |
} else {
|
70 |
|
|
sstats[i].insn = item;
|
71 |
532 |
markom |
sstats[i].cnt_dynamic = cnt_dynamic;
|
72 |
|
|
}
|
73 |
2 |
cvs |
}
|
74 |
|
|
|
75 |
535 |
markom |
void adddstats(int item1, int item2, int cnt_dynamic, int depend)
|
76 |
2 |
cvs |
{
|
77 |
532 |
markom |
int i = 0;
|
78 |
|
|
|
79 |
702 |
ivang |
debug(7,"adddstats start\n");
|
80 |
2 |
cvs |
|
81 |
535 |
markom |
while((dstats[i].insn1 != item1 || dstats[i].insn2 != item2) && (i < DSTATS_LEN) && dstats[i].insn1 >= 0) i++;
|
82 |
2 |
cvs |
|
83 |
532 |
markom |
if (i >= DSTATS_LEN - 1) return;
|
84 |
|
|
|
85 |
535 |
markom |
if (dstats[i].insn1 >= 0) {
|
86 |
532 |
markom |
dstats[i].cnt_dynamic += cnt_dynamic;
|
87 |
|
|
dstats[i].depend += depend;
|
88 |
535 |
markom |
} else {
|
89 |
|
|
dstats[i].insn1 = item1;
|
90 |
|
|
dstats[i].insn2 = item2;
|
91 |
532 |
markom |
dstats[i].cnt_dynamic = cnt_dynamic;
|
92 |
|
|
dstats[i].depend = depend;
|
93 |
|
|
}
|
94 |
2 |
cvs |
}
|
95 |
|
|
|
96 |
|
|
void addfstats(enum insn_type item1, enum insn_type item2, int cnt_dynamic, int depend)
|
97 |
|
|
{
|
98 |
532 |
markom |
int i = 0;
|
99 |
|
|
|
100 |
|
|
while(((fstats[i].insn1 != item1) || (fstats[i].insn2 != item2)) &&
|
101 |
|
|
(fstats[i].insn1 != it_unknown) &&
|
102 |
|
|
(i < FSTATS_LEN))
|
103 |
|
|
i++;
|
104 |
2 |
cvs |
|
105 |
532 |
markom |
if (i >= FSTATS_LEN - 1) return;
|
106 |
|
|
|
107 |
|
|
if ((fstats[i].insn1 == item1) &&
|
108 |
|
|
(fstats[i].insn2 == item2)) {
|
109 |
|
|
fstats[i].cnt_dynamic += cnt_dynamic;
|
110 |
|
|
fstats[i].depend += depend;
|
111 |
|
|
}
|
112 |
|
|
else {
|
113 |
|
|
fstats[i].insn1 = item1;
|
114 |
|
|
fstats[i].insn2 = item2;
|
115 |
|
|
fstats[i].cnt_dynamic = cnt_dynamic;
|
116 |
|
|
fstats[i].depend = depend;
|
117 |
|
|
}
|
118 |
2 |
cvs |
}
|
119 |
|
|
|
120 |
|
|
void initstats()
|
121 |
|
|
{
|
122 |
535 |
markom |
int i;
|
123 |
532 |
markom |
memset(sstats, 0, sizeof(sstats));
|
124 |
535 |
markom |
for (i = 0; i < DSTATS_LEN; i++)
|
125 |
|
|
sstats[i].insn = -1;
|
126 |
532 |
markom |
memset(dstats, 0, sizeof(dstats));
|
127 |
535 |
markom |
for (i = 0; i < DSTATS_LEN; i++)
|
128 |
|
|
dstats[i].insn1 = dstats[i].insn2 = -1;
|
129 |
532 |
markom |
memset(fstats, 0, sizeof(fstats));
|
130 |
|
|
memset(&mstats, 0, sizeof(mstats));
|
131 |
|
|
memset(&ic_stats, 0, sizeof(ic_stats));
|
132 |
|
|
memset(&dc_stats, 0, sizeof(dc_stats));
|
133 |
|
|
memset(&raw_stats, 0, sizeof(raw_stats));
|
134 |
2 |
cvs |
}
|
135 |
|
|
|
136 |
535 |
markom |
void printotherstats(int which)
|
137 |
2 |
cvs |
{
|
138 |
532 |
markom |
int i, all = 0, dependall = 0;
|
139 |
102 |
lampret |
|
140 |
535 |
markom |
printf ("\n");
|
141 |
541 |
markom |
if (config.bpb.enabled) {
|
142 |
535 |
markom |
struct branchstat bf;
|
143 |
|
|
struct branchstat bnf;
|
144 |
|
|
long bf_all, bnf_all;
|
145 |
|
|
bf.taken = mstats.bf[1][0] + mstats.bf[1][1];
|
146 |
|
|
bf.nottaken = mstats.bf[0][0] + mstats.bf[0][1];
|
147 |
|
|
bf.forward = mstats.bf[0][1] + mstats.bf[1][1];
|
148 |
|
|
bf.backward = mstats.bf[0][0] + mstats.bf[1][0];
|
149 |
|
|
bf_all = bf.forward + bf.backward;
|
150 |
|
|
|
151 |
|
|
bnf.taken = mstats.bnf[1][0] + mstats.bf[1][1];
|
152 |
|
|
bnf.nottaken = mstats.bnf[0][0] + mstats.bf[0][1];
|
153 |
|
|
bnf.forward = mstats.bnf[0][1] + mstats.bf[1][1];
|
154 |
|
|
bnf.backward = mstats.bnf[0][0] + mstats.bf[1][0];
|
155 |
|
|
bnf_all = bnf.forward + bnf.backward;
|
156 |
|
|
|
157 |
|
|
printf("bnf: %d (%d%%) taken,", bf.taken, (bf.taken * 100) / SD(bf_all));
|
158 |
|
|
printf(" %d (%d%%) not taken,", bf.nottaken, (bf.nottaken * 100) / SD(bf_all));
|
159 |
|
|
printf(" %d (%d%%) forward,", bf.forward, (bf.forward * 100) / SD(bf_all));
|
160 |
|
|
printf(" %d (%d%%) backward\n", bf.backward, (bf.backward * 100) / SD(bf_all));
|
161 |
|
|
printf("bf: %d (%d%%) taken,", bnf.taken, (bnf.taken * 100) / SD(bnf_all));
|
162 |
|
|
printf(" %d (%d%%) not taken,", bnf.nottaken, (bnf.nottaken * 100) / SD(bnf_all));
|
163 |
|
|
printf(" %d (%d%%) forward,", bnf.forward, (bnf.forward * 100) / SD(bnf_all));
|
164 |
|
|
printf(" %d (%d%%) backward\n", bnf.backward, (bnf.backward * 100) / SD(bnf_all));
|
165 |
|
|
|
166 |
541 |
markom |
printf("StaticBP bnf(%s): correct %d%%\n", config.bpb.sbp_bnf_fwd ? "forward" : "backward",
|
167 |
|
|
(mstats.bnf[0][config.bpb.sbp_bnf_fwd] * 100) / SD(bnf_all));
|
168 |
|
|
printf("StaticBP bf(%s): correct %d%%\n", config.bpb.sbp_bf_fwd ? "forward" : "backward",
|
169 |
|
|
(mstats.bnf[1][config.bpb.sbp_bf_fwd] * 100) / SD(bf_all));
|
170 |
532 |
markom |
printf("BPB: hit %d (correct %d%%), miss %d\n", mstats.bpb.hit, (mstats.bpb.correct * 100) / SD(mstats.bpb.hit), mstats.bpb.miss);
|
171 |
|
|
} else
|
172 |
|
|
printf("BPB simulation disabled. Enable it to see BPB analysis\n");
|
173 |
102 |
lampret |
|
174 |
541 |
markom |
if (config.bpb.btic) {
|
175 |
532 |
markom |
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);
|
176 |
|
|
} else
|
177 |
|
|
printf("BTIC simulation disabled. Enabled it to see BTIC analysis\n");
|
178 |
556 |
markom |
|
179 |
692 |
markom |
if (config.ic.enabled) {
|
180 |
532 |
markom |
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);
|
181 |
|
|
} else
|
182 |
692 |
markom |
printf("No ICache. Enable it to see IC results.\n");
|
183 |
532 |
markom |
|
184 |
692 |
markom |
if (config.dc.enabled) {
|
185 |
532 |
markom |
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);
|
186 |
|
|
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);
|
187 |
|
|
} else
|
188 |
692 |
markom |
printf("No DCache. Enable it to see DC results.\n");
|
189 |
102 |
lampret |
|
190 |
532 |
markom |
if (testsprbits(SPR_UPR, SPR_UPR_IMP)) {
|
191 |
|
|
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);
|
192 |
|
|
} else
|
193 |
|
|
printf("No IMMU. Set UPR[IMP]\n");
|
194 |
102 |
lampret |
|
195 |
532 |
markom |
if (testsprbits(SPR_UPR, SPR_UPR_DMP)) {
|
196 |
|
|
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);
|
197 |
|
|
} else
|
198 |
|
|
printf("No DMMU. Set UPR[DMP]\n");
|
199 |
535 |
markom |
|
200 |
|
|
{
|
201 |
558 |
markom |
extern int loadcycles, storecycles;
|
202 |
535 |
markom |
printf("Additional LOAD CYCLES: %u STORE CYCLES: %u\n", loadcycles, storecycles);
|
203 |
|
|
}
|
204 |
102 |
lampret |
}
|
205 |
|
|
|
206 |
|
|
void printstats(int which)
|
207 |
|
|
{
|
208 |
535 |
markom |
int i, all = 0, dependall = 0;
|
209 |
|
|
|
210 |
555 |
markom |
if (which > 1 && which <= 5 && !config.cpu.dependstats) {
|
211 |
535 |
markom |
printf("Hazard analysis disabled. Enable it to see analysis results.\n");
|
212 |
|
|
return;
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
switch (which) {
|
216 |
|
|
case 1:
|
217 |
|
|
printf("stats 1: Misc stats\n");
|
218 |
532 |
markom |
printotherstats(which);
|
219 |
535 |
markom |
break;
|
220 |
|
|
case 2:
|
221 |
|
|
printf ("stats 2: Instruction usage\n");
|
222 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
223 |
|
|
all += sstats[i].cnt_dynamic;
|
224 |
|
|
|
225 |
|
|
for(i = 0; i < SSTATS_LEN; i++)
|
226 |
|
|
if (sstats[i].cnt_dynamic)
|
227 |
|
|
printf(" %-15s used %6dx (%5.1f%%)\n", insn_name(sstats[i].insn), sstats[i].cnt_dynamic, (sstats[i].cnt_dynamic * 100.)/SD(all));
|
228 |
|
|
|
229 |
|
|
printf("%d instructions (dynamic, single stats)\n", all);
|
230 |
|
|
break;
|
231 |
|
|
|
232 |
|
|
case 3:
|
233 |
|
|
printf ("stats 3: Instruction dependencies\n");
|
234 |
|
|
for(i = 0; i < DSTATS_LEN; i++) {
|
235 |
|
|
all += dstats[i].cnt_dynamic;
|
236 |
|
|
dependall += dstats[i].depend;
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
for(i = 0; i < DSTATS_LEN; i++)
|
240 |
|
|
if (dstats[i].cnt_dynamic) {
|
241 |
|
|
char temp[100];
|
242 |
|
|
sprintf(temp, "%s, %s ", insn_name(dstats[i].insn1), insn_name(dstats[i].insn2));
|
243 |
|
|
printf(" %-30s %6dx (%5.1f%%)", temp, dstats[i].cnt_dynamic, (dstats[i].cnt_dynamic * 100.)/SD(all));
|
244 |
|
|
printf(" depend: %5.1f%%\n", (dstats[i].depend * 100.) / dstats[i].cnt_dynamic);
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
printf("%d instructions (dynamic, dependency stats) depend: %d%%\n", all, (dependall * 100) / SD(all));
|
248 |
|
|
break;
|
249 |
|
|
|
250 |
|
|
case 4:
|
251 |
|
|
printf("stats 4: Functional units dependencies\n");
|
252 |
|
|
for(i = 0; i < FSTATS_LEN; i++) {
|
253 |
|
|
all += fstats[i].cnt_dynamic;
|
254 |
|
|
dependall += fstats[i].depend;
|
255 |
|
|
}
|
256 |
|
|
|
257 |
|
|
for(i = 0; i < FSTATS_LEN; i++)
|
258 |
|
|
if (fstats[i].cnt_dynamic) {
|
259 |
|
|
char temp[100];
|
260 |
|
|
sprintf(temp, "%s, %s", func_unit_str[fstats[i].insn1], func_unit_str[fstats[i].insn2]);
|
261 |
|
|
printf(" %-30s %6dx (%5.1f%%)", temp, fstats[i].cnt_dynamic, (fstats[i].cnt_dynamic * 100.)/SD(all));
|
262 |
|
|
printf(" depend: %5.1f%%\n", (fstats[i].depend * 100.) / fstats[i].cnt_dynamic);
|
263 |
|
|
}
|
264 |
|
|
printf ("%d instructions (dynamic, functional units stats) depend: %d%%\n\n", all, (dependall * 100) / SD(all));
|
265 |
|
|
break;
|
266 |
|
|
|
267 |
|
|
case 5:
|
268 |
615 |
markom |
printf("stats 5: Raw register usage over time\n");
|
269 |
535 |
markom |
for(i = 0; (i < config.cpu.raw_range); i++)
|
270 |
|
|
printf(" Register set and reused in %d. cycle: %d cases\n", i, raw_stats.range[i]);
|
271 |
|
|
break;
|
272 |
626 |
markom |
case 6:
|
273 |
|
|
if (config.cpu.sbuf_len) {
|
274 |
|
|
extern int sbuf_total_cyc, sbuf_wait_cyc;
|
275 |
|
|
printf ("stats 6: Store buffer analysis\n");
|
276 |
629 |
markom |
printf ("Using store buffer of length %i.\n", config.cpu.sbuf_len);
|
277 |
630 |
markom |
printf ("Number of total memory store cycles: %i/%i\n", sbuf_total_cyc, cycles + sbuf_total_cyc - sbuf_wait_cyc);
|
278 |
626 |
markom |
printf ("Number of cycles waiting for memory stores: %i\n", sbuf_wait_cyc);
|
279 |
629 |
markom |
printf ("Number of memory cycles spared: %i\n", sbuf_total_cyc - sbuf_wait_cyc);
|
280 |
|
|
printf ("Store speedup %3.2f%%, total speedup %3.2f%%\n", 100.*(sbuf_total_cyc - sbuf_wait_cyc)/sbuf_total_cyc,
|
281 |
630 |
markom |
100.*(sbuf_total_cyc - sbuf_wait_cyc) / (cycles + sbuf_total_cyc - sbuf_wait_cyc));
|
282 |
626 |
markom |
} else
|
283 |
|
|
printf ("Store buffer analysis disabled. Enable it to see analysis results.\n");
|
284 |
|
|
break;
|
285 |
535 |
markom |
default:
|
286 |
626 |
markom |
printf ("Please specify a stats group (1-6).\n");
|
287 |
535 |
markom |
break;
|
288 |
|
|
}
|
289 |
|
|
#if 0
|
290 |
|
|
printf("Byte ADD: %d instructions\n", mstats.byteadd);
|
291 |
|
|
#endif
|
292 |
102 |
lampret |
}
|