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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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