OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_46/] [or1ksim/] [cpu/] [common/] [stats.c] - Blame information for rev 518

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 2 cvs
const char func_unit_str[30][30] = { "unknown", "arith", "shift", "compare",
31
        "branch", "jump", "load", "store", "movimm", "move", "extend", "nop" };
32
 
33
struct dstats_entry dstats[DSTATS_LEN]; /* dependency stats */
34
struct sstats_entry sstats[SSTATS_LEN]; /* single stats */
35
struct fstats_entry fstats[FSTATS_LEN]; /* functional units stats */
36
struct mstats_entry mstats;             /* misc units stats */
37 6 lampret
struct cachestats_entry ic_stats;       /* instruction cache stats */
38
struct cachestats_entry dc_stats;       /* data cache stats */
39 77 lampret
struct immustats_entry immu_stats;      /* insn mmu stats */
40
struct dmmustats_entry dmmu_stats;      /* data mmu stats */
41 6 lampret
struct raw_stats raw_stats;             /* RAW hazard stats */
42 34 lampret
struct slp_stats slp_stats;             /* SLP stats */
43 2 cvs
 
44
/* Dependency */
45
 
46
int check_depend()
47 102 lampret
{
48 479 markom
  debug(5,"check_depend\n");
49 138 markom
  return depend_operands(&icomplet[0], &iqueue[0]);
50 2 cvs
}
51
 
52
void addsstats(char *item, int cnt_dynamic, int cnt_static)
53
{
54
        int i = 0;
55
 
56
        while(strcmp(sstats[i].insn, item) && (sstats[i].cnt_static > 0) &&
57
              (sstats[i].cnt_static > 0) && (i < SSTATS_LEN))
58
                i++;
59
 
60
        if (i >= SSTATS_LEN - 1) return;
61
 
62
        if (strcmp(sstats[i].insn, item) == 0) {
63
                sstats[i].cnt_dynamic += cnt_dynamic;
64
                sstats[i].cnt_static += cnt_static;
65
        }
66
        else {
67
                strcpy(sstats[i].insn, item);
68
                sstats[i].cnt_dynamic = cnt_dynamic;
69
                sstats[i].cnt_static = cnt_static;
70
        }
71
}
72
 
73
void adddstats(char *item1, char *item2, int cnt_dynamic, int depend)
74
{
75
        int i = 0;
76
 
77 344 markom
        debug(3,"adddstats start\n");
78 2 cvs
 
79
        while((strcmp(dstats[i].insn1, item1) || strcmp(dstats[i].insn2, item2)) &&
80
              (strlen(dstats[i].insn1)) &&
81
              (i < DSTATS_LEN))
82
                i++;
83
 
84
        if (i >= DSTATS_LEN - 1) return;
85
 
86
        if ((strcmp(dstats[i].insn1, item1) == 0) &&
87
            (strcmp(dstats[i].insn2, item2) == 0)) {
88
                dstats[i].cnt_dynamic += cnt_dynamic;
89
                dstats[i].depend += depend;
90
        }
91
        else {
92
                strcpy(dstats[i].insn1, item1);
93
                strcpy(dstats[i].insn2, item2);
94
                dstats[i].cnt_dynamic = cnt_dynamic;
95
                dstats[i].depend = depend;
96
        }
97
}
98
 
99
void addfstats(enum insn_type item1, enum insn_type item2, int cnt_dynamic, int depend)
100
{
101
        int i = 0;
102
 
103
        while(((fstats[i].insn1 != item1) || (fstats[i].insn2 != item2)) &&
104 479 markom
              (fstats[i].insn1 != it_unknown) &&
105 2 cvs
              (i < FSTATS_LEN))
106
                i++;
107
 
108
        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
}
122
 
123
void initstats()
124
{
125
        memset(sstats, 0, sizeof(sstats));
126
        memset(dstats, 0, sizeof(dstats));
127
        memset(fstats, 0, sizeof(fstats));
128
        memset(&mstats, 0, sizeof(mstats));
129 6 lampret
        memset(&ic_stats, 0, sizeof(ic_stats));
130
        memset(&dc_stats, 0, sizeof(dc_stats));
131
        memset(&raw_stats, 0, sizeof(raw_stats));
132 34 lampret
        memset(&slp_stats, 0, sizeof(slp_stats));
133 2 cvs
}
134
 
135 34 lampret
/* SLP
136
 
137
1: R
138
2:  R
139
3:   R
140
OK
141
 
142
1:     W
143
2: R
144
3: R
145
flush 2 3
146
 
147
1:     R
148
2: W
149
3:  R
150
OK
151
 
152
1: R
153
2:     W
154
3:  R
155
flush 3
156
 
157
flushing: don't flush if written location hasn't change after the write since
158
original read got correct data.
159
 
160
*/
161
 
162
void slp_checkaccess(unsigned long addr, char type)
163
{
164 263 markom
        if (!config.cpu.slp)
165 102 lampret
                return;
166
 
167 221 markom
        if (/*(addr < (MEMORY_START + MEMORY_LEN - 4000)) &&  MM1709: we have no knowledge of this anymore */
168 34 lampret
            slp_stats.supercnt && (type == SLP_MEMWRITE)) {
169
                slp_stats.supercalls++;
170
                slp_stats.supercnt = 0;
171
        }
172
}
173
 
174
void slp_func_entry()
175
{
176 263 markom
        if (!config.cpu.slp)
177 102 lampret
                return;
178
 
179 34 lampret
        if (++slp_stats.curdepth > slp_stats.maxdepth)
180
                slp_stats.maxdepth = slp_stats.curdepth;
181
 
182
        slp_stats.calls++;
183
        slp_stats.supercnt++;
184
}
185
 
186
void slp_func_exit()
187
{
188 263 markom
        if (!config.cpu.slp)
189 102 lampret
                return;
190
 
191 34 lampret
        slp_stats.curdepth--;
192
}
193
 
194 102 lampret
 
195
void printistats(int which)
196 2 cvs
{
197
        int i, all = 0, dependall = 0;
198 102 lampret
 
199 263 markom
        if (!config.cpu.dependstats) {
200 102 lampret
                printf("Hazard analysis disabled. Enable it to see analysis results.\n");
201
                return;
202
        }
203 2 cvs
 
204
        for(i = 0; i < SSTATS_LEN; i++)
205
                all += sstats[i].cnt_static;
206
 
207
        for(i = 0; i < SSTATS_LEN; i++)
208 6 lampret
                if (sstats[i].cnt_static && (which == 1))
209 2 cvs
                        printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_static, (sstats[i].cnt_static * 100)/all);
210
 
211
        printf("SUM: %d instructions (static, single stats)\n", all);
212 6 lampret
 
213 2 cvs
        all = 0;
214 6 lampret
 
215 2 cvs
        for(i = 0; i < SSTATS_LEN; i++)
216
                all += sstats[i].cnt_dynamic;
217
 
218
        for(i = 0; i < SSTATS_LEN; i++)
219 6 lampret
                if (sstats[i].cnt_dynamic && (which == 2))
220 2 cvs
                        printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_dynamic, (sstats[i].cnt_dynamic * 100)/all);
221
 
222
        printf("SUM: %d instructions (dynamic, single stats)\n", all);
223
 
224
        all = 0;
225
        dependall = 0;
226
        for(i = 0; i < DSTATS_LEN; i++) {
227
                all += dstats[i].cnt_dynamic;
228
                dependall += dstats[i].depend;
229
        }
230
 
231
        for(i = 0; i < DSTATS_LEN; i++)
232 6 lampret
                if (dstats[i].cnt_dynamic && (which == 3)) {
233 2 cvs
                        printf(" %s, %s ", dstats[i].insn1, dstats[i].insn2);
234
                        printf("\t\t\t%6dx (%2d%%)", dstats[i].cnt_dynamic, (dstats[i].cnt_dynamic * 100)/all);
235
                        printf("   depend: %3d%%\n", (dstats[i].depend * 100) / dstats[i].cnt_dynamic);
236
                }
237
 
238
        printf("SUM: %d instructions (dynamic, dependency stats)  depend: %d%%\n", all, (dependall * 100) / all);
239
 
240
        all = 0;
241
        dependall = 0;
242
        for(i = 0; i < FSTATS_LEN; i++) {
243
                all += fstats[i].cnt_dynamic;
244
                dependall += fstats[i].depend;
245
        }
246
 
247
        for(i = 0; i < FSTATS_LEN; i++)
248 6 lampret
                if (fstats[i].cnt_dynamic && (which == 4)) {
249 2 cvs
                        printf(" %s,", func_unit_str[fstats[i].insn1]);
250
                        printf(" %s", func_unit_str[fstats[i].insn2]);
251
                        printf("\t\t\t%6dx (%2d%%)", fstats[i].cnt_dynamic, (fstats[i].cnt_dynamic * 100)/all);
252
                        printf("   depend: %3d%%\n", (fstats[i].depend * 100) / fstats[i].cnt_dynamic);
253
                }
254
 
255 6 lampret
        for(i = 0; (i < RAW_RANGE) && (which == 5); i++)
256
                printf(" Register set and reused in %d. cycle: %d cases\n", i, raw_stats.range[i]);
257
 
258 102 lampret
        printf("SUM: %d instructions (dynamic, functional units stats)  depend: %d%%\n", all, (dependall * 100) / SD(all));
259
        printf("Byte ADD: %d instructions\n", mstats.byteadd);
260
 
261
}
262
 
263
void printslpstats(int which)
264
{
265
        int i, all = 0, dependall = 0;
266
 
267 263 markom
        if (!config.cpu.slp) {
268 102 lampret
                printf("SLP analysis disabled. Enable it to see analysis results.\n");
269
                return;
270
        }
271
 
272 34 lampret
        if (which == 6) {
273
                printf("SLP:\n");
274
                printf("maxdepth: %6d  calls: %6d\n", slp_stats.maxdepth, slp_stats.calls);
275
                printf("calls: %6d    supercalls: %6d\n", slp_stats.calls, slp_stats.supercalls);
276
        }
277
 
278 2 cvs
}
279 102 lampret
 
280
void printotherstats(int which)
281
{
282
        int i, all = 0, dependall = 0;
283
 
284 264 markom
        if (config.cpu.bpb) {
285 102 lampret
                printf("bnf: %d (%d%%) taken,", mstats.beqz.taken, (mstats.beqz.taken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
286
                printf(" %d (%d%%) not taken,", mstats.beqz.nottaken, (mstats.beqz.nottaken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
287
                printf(" %d (%d%%) forward,", mstats.beqz.forward, (mstats.beqz.forward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
288
                printf(" %d (%d%%) backward\n", mstats.beqz.backward, (mstats.beqz.backward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
289
                printf("bf: %d (%d%%) taken,", mstats.bnez.taken, (mstats.bnez.taken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
290
                printf(" %d (%d%%) not taken,", mstats.bnez.nottaken, (mstats.bnez.nottaken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
291
                printf(" %d (%d%%) forward,", mstats.bnez.forward, (mstats.bnez.forward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
292
                printf(" %d (%d%%) backward\n", mstats.bnez.backward, (mstats.bnez.backward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
293
                printf("StaticBP bnf: correct %d%% (forward)\n", (mstats.sbp_bnf.correct * 100) / SD(mstats.sbp_bnf.all));
294
                printf("StaticBP bf: correct %d%% (backward)\n", (mstats.sbp_bf.correct * 100) / SD(mstats.sbp_bf.all));
295
                printf("BPB: hit %d (correct %d%%), miss %d\n", mstats.bpb.hit, (mstats.bpb.correct * 100) / SD(mstats.bpb.hit), mstats.bpb.miss);
296
        } else
297
                printf("BPB simulation disabled. Enable it to see BPB analysis\n");
298
 
299 306 markom
        if (config.cpu.btic) {
300 102 lampret
                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);
301
        } else
302
                printf("BTIC simulation disabled. Enabled it to see BTIC analysis\n");
303
 
304 167 markom
        if (testsprbits(SPR_UPR, SPR_UPR_ICP)) {
305 102 lampret
                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);
306
        } else
307
                printf("No ICache. Set UPR[ICP]\n");
308
 
309 167 markom
        if (testsprbits(SPR_UPR, SPR_UPR_DCP)) {
310 102 lampret
                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);
311
                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);
312
        } else
313
                printf("No DCache. Set UPR[DCP]\n");
314
 
315 167 markom
        if (testsprbits(SPR_UPR, SPR_UPR_IMP)) {
316 102 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);
317
        } else
318
                printf("No IMMU. Set UPR[IMP]\n");
319
 
320 167 markom
        if (testsprbits(SPR_UPR, SPR_UPR_DMP)) {
321 102 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);
322
        } else
323
                printf("No DMMU. Set UPR[DMP]\n");
324
}
325
 
326
void printstats(int which)
327
{
328
        printistats(which);
329
        printslpstats(which);
330
        if (which == 5)
331
                printotherstats(which);
332
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.