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