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

Subversion Repositories or1k

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

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 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 65 lampret
struct mmustats_entry dmmu_stats;       /* data cache stats */
37 6 lampret
struct raw_stats raw_stats;             /* RAW hazard stats */
38 34 lampret
struct slp_stats slp_stats;             /* SLP stats */
39 2 cvs
 
40
/* Dependency */
41
 
42
int check_depend()
43
{
44
        debug("check_depend");
45
        if (depend_operands(icomplet[0].dependdst, iqueue[0].dependsrc1) +
46
            depend_operands(icomplet[0].dependdst, iqueue[0].dependsrc2))
47
                return 1;
48
        else
49
                return 0;
50
}
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
        debug("adddstats start\n");
78
 
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
              (fstats[i].insn1 != unknown) &&
105
              (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
        if ((addr < (MEMORY_START + MEMORY_LEN - 4000)) &&
165
            slp_stats.supercnt && (type == SLP_MEMWRITE)) {
166
                slp_stats.supercalls++;
167
                slp_stats.supercnt = 0;
168
        }
169
}
170
 
171
void slp_func_entry()
172
{
173
        if (++slp_stats.curdepth > slp_stats.maxdepth)
174
                slp_stats.maxdepth = slp_stats.curdepth;
175
 
176
        slp_stats.calls++;
177
        slp_stats.supercnt++;
178
}
179
 
180
void slp_func_exit()
181
{
182
        slp_stats.curdepth--;
183
}
184
 
185 6 lampret
void printstats(int which)
186 2 cvs
{
187
        int i, all = 0, dependall = 0;
188
 
189
        for(i = 0; i < SSTATS_LEN; i++)
190
                all += sstats[i].cnt_static;
191
 
192
        for(i = 0; i < SSTATS_LEN; i++)
193 6 lampret
                if (sstats[i].cnt_static && (which == 1))
194 2 cvs
                        printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_static, (sstats[i].cnt_static * 100)/all);
195
 
196
        printf("SUM: %d instructions (static, single stats)\n", all);
197 6 lampret
 
198 2 cvs
        all = 0;
199 6 lampret
 
200 2 cvs
        for(i = 0; i < SSTATS_LEN; i++)
201
                all += sstats[i].cnt_dynamic;
202
 
203
        for(i = 0; i < SSTATS_LEN; i++)
204 6 lampret
                if (sstats[i].cnt_dynamic && (which == 2))
205 2 cvs
                        printf(" %s\t\tused %6dx (%2d%%)\n", sstats[i].insn, sstats[i].cnt_dynamic, (sstats[i].cnt_dynamic * 100)/all);
206
 
207
        printf("SUM: %d instructions (dynamic, single stats)\n", all);
208
 
209
        all = 0;
210
        dependall = 0;
211
        for(i = 0; i < DSTATS_LEN; i++) {
212
                all += dstats[i].cnt_dynamic;
213
                dependall += dstats[i].depend;
214
        }
215
 
216
        for(i = 0; i < DSTATS_LEN; i++)
217 6 lampret
                if (dstats[i].cnt_dynamic && (which == 3)) {
218 2 cvs
                        printf(" %s, %s ", dstats[i].insn1, dstats[i].insn2);
219
                        printf("\t\t\t%6dx (%2d%%)", dstats[i].cnt_dynamic, (dstats[i].cnt_dynamic * 100)/all);
220
                        printf("   depend: %3d%%\n", (dstats[i].depend * 100) / dstats[i].cnt_dynamic);
221
                }
222
 
223
        printf("SUM: %d instructions (dynamic, dependency stats)  depend: %d%%\n", all, (dependall * 100) / all);
224
 
225
        all = 0;
226
        dependall = 0;
227
        for(i = 0; i < FSTATS_LEN; i++) {
228
                all += fstats[i].cnt_dynamic;
229
                dependall += fstats[i].depend;
230
        }
231
 
232
        for(i = 0; i < FSTATS_LEN; i++)
233 6 lampret
                if (fstats[i].cnt_dynamic && (which == 4)) {
234 2 cvs
                        printf(" %s,", func_unit_str[fstats[i].insn1]);
235
                        printf(" %s", func_unit_str[fstats[i].insn2]);
236
                        printf("\t\t\t%6dx (%2d%%)", fstats[i].cnt_dynamic, (fstats[i].cnt_dynamic * 100)/all);
237
                        printf("   depend: %3d%%\n", (fstats[i].depend * 100) / fstats[i].cnt_dynamic);
238
                }
239
 
240 6 lampret
        for(i = 0; (i < RAW_RANGE) && (which == 5); i++)
241
                printf(" Register set and reused in %d. cycle: %d cases\n", i, raw_stats.range[i]);
242
 
243 34 lampret
        if (which == 6) {
244
                printf("SLP:\n");
245
                printf("maxdepth: %6d  calls: %6d\n", slp_stats.maxdepth, slp_stats.calls);
246
                printf("calls: %6d    supercalls: %6d\n", slp_stats.calls, slp_stats.supercalls);
247
        }
248
 
249 30 lampret
        printf("SUM: %d instructions (dynamic, functional units stats)  depend: %d%%\n", all, (dependall * 100) / SD(all));
250 2 cvs
        printf("Byte ADD: %d instructions\n", mstats.byteadd);
251 30 lampret
        printf("bnf: %d (%d%%) taken,", mstats.beqz.taken, (mstats.beqz.taken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
252
        printf(" %d (%d%%) not taken,", mstats.beqz.nottaken, (mstats.beqz.nottaken * 100) / SD(mstats.beqz.taken + mstats.beqz.nottaken));
253
        printf(" %d (%d%%) forward,", mstats.beqz.forward, (mstats.beqz.forward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
254
        printf(" %d (%d%%) backward\n", mstats.beqz.backward, (mstats.beqz.backward * 100) / SD(mstats.beqz.forward + mstats.beqz.backward));
255
        printf("bf: %d (%d%%) taken,", mstats.bnez.taken, (mstats.bnez.taken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
256
        printf(" %d (%d%%) not taken,", mstats.bnez.nottaken, (mstats.bnez.nottaken * 100) / SD(mstats.bnez.taken + mstats.bnez.nottaken));
257
        printf(" %d (%d%%) forward,", mstats.bnez.forward, (mstats.bnez.forward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
258
        printf(" %d (%d%%) backward\n", mstats.bnez.backward, (mstats.bnez.backward * 100) / SD(mstats.bnez.forward + mstats.bnez.backward));
259
        printf("StaticBP bnf: correct %d%% (forward)\n", (mstats.sbp_bnf.correct * 100) / SD(mstats.sbp_bnf.all));
260
        printf("StaticBP bf: correct %d%% (backward)\n", (mstats.sbp_bf.correct * 100) / SD(mstats.sbp_bf.all));
261
        printf("BPB: hit %d (correct %d%%), miss %d\n", mstats.bpb.hit, (mstats.bpb.correct * 100) / SD(mstats.bpb.hit), mstats.bpb.miss);
262
        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);
263
        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);
264
        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);
265
        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);
266 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);
267 2 cvs
}

powered by: WebSVN 2.1.0

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