source: svn/trunk/newcon3bcm2_21bu/BSEAV/lib/bprofile/bperf_counter.c @ 27

Last change on this file since 27 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 11.1 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2006-2007, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bperf_counter.c $
11 * $brcm_Revision: 8 $
12 * $brcm_Date: 1/15/07 10:50a $
13 *
14 * Module Description:
15 *
16 * Perfomance counter module
17 *
18 * Revision History:
19 *
20 * $brcm_Log: /BSEAV/lib/bprofile/bperf_counter.c $
21 *
22 * 8   1/15/07 10:50a vsilyaev
23 * PR 25997: Added 7038 performance counters
24 *
25 * 7   12/22/06 12:03p vsilyaev
26 * PR 26792: Added rac_access, rac_prefetch and rac_hits configurations
27 * for the peformance counter
28 *
29 * 6   12/14/06 4:38p vsilyaev
30 * PR 25997: Added counter configuration to capture issue rate
31 *
32 * 5   12/13/06 7:46p vsilyaev
33 * PR 25997: Removed debug output
34 *
35 * 4   12/8/06 7:24p vsilyaev
36 * PR 25997: Fixed warning
37 *
38 * 3   12/7/06 2:44p vsilyaev
39 * PR 25997: Added fixes for 3.4 GCC compiler
40 *
41 * 2   12/5/06 11:08a vsilyaev
42 * PR 25997: Improved perf counter interface
43 *
44 * 1   12/1/06 5:58p vsilyaev
45 * PR 25997: CPU perfomance counter interface
46 *
47 *
48 *******************************************************************************/
49#include "bstd.h"
50#include "bkni.h"
51#include "bperf_counter.h"
52#include "biobits.h"
53
54BDBG_MODULE(bperf_counter);
55
56
57static const char b_insructions[] = "Instructions";
58static const char b_cycles[] = "Cycles";
59static const char b_dcache_miss[]= "D-Cache miss";
60
61#if B_PERF_BMIPS3300
62/* bcmips3300-arch.pdf pages 63..66 */
63#define B_ICACHE_MOD_ID 0x06
64#define B_ICACHE_ID             0x00
65#define B_ICACHE_HIT    0x06
66#define B_ICACHE_MISS   0x05
67
68#define B_DCACHE_MOD_ID 0x04
69#define B_DCACHE_ID             0x01
70#define B_DCACHE_HIT    0x0A
71#define B_DCACHE_MISS   0x09
72
73#define B_RAC_MOD_ID    0x0B
74#define B_RAC_ACCESS_ID 0x00
75#define B_RAC_ACCESS    0x42
76#define B_RAC_PREFETCH_ID 0x01
77#define B_RAC_PREFETCH 0x4B
78
79#define B_BIU_MOD_ID    0x01
80#define B_RAC_HIT_ID    0x02
81#define B_RAC_HIT               0x45
82
83#define B_CYCLES                0x12
84#define B_INSTRUCTIONS  0x11
85
86const  bperf_counter_mode bperf_counter_dcache  = {
87        {
88                b_dcache_miss,
89                "D-Cache hit",
90                b_insructions,
91                b_cycles
92        },
93        {
94                /* $25 #6 */
95                B_SET_BIT(PCE, 1 /* enable */, 31) |
96                B_SET_BIT(magic, 1 /* enable */, 9) |
97                B_SET_BIT(PCSD, 0 /* enable */, 8) |
98                B_SET_BITS(ModID, B_DCACHE_MOD_ID, 5, 2) |
99                B_SET_BITS(SetID, B_DCACHE_ID, 1, 0),
100
101                /* $25 #4 */
102                B_SET_BIT(CE, 1 /* enable */, 15) |
103                B_SET_BITS(EVT, B_DCACHE_MISS,  8, 2) |
104                B_SET_BIT(TIE, 0 /* disable */, 0) |
105
106                B_SET_BIT(CE, 1 /* enable */, 15+16) |
107                B_SET_BITS(EVT, B_DCACHE_HIT,  8+16, 2+16) |
108                B_SET_BIT(TIE, 0 /* disable */, 0+16),
109
110                /* $25 #5 */
111                B_SET_BIT(CE, 1 /* enable */, 15) |
112                B_SET_BITS(EVT, B_INSTRUCTIONS,  8, 2) |
113                B_SET_BIT(TIE, 0 /* disable */, 0) |
114
115                B_SET_BIT(CE, 1 /* enable */, 15+16) |
116                B_SET_BITS(EVT, B_CYCLES,  8+16, 2+16) |
117                B_SET_BIT(TIE, 0 /* disable */, 0+16)
118        }
119};
120
121const  bperf_counter_mode bperf_counter_instructions = {
122        {
123                b_insructions,
124                b_dcache_miss,
125                b_insructions,
126                b_cycles
127        },
128        {
129                /* $25 #6 */
130                B_SET_BIT(PCE, 1 /* enable */, 31) |
131                B_SET_BIT(magic, 1 /* enable */, 9) |
132                B_SET_BIT(PCSD, 0 /* enable */, 8) |
133                B_SET_BITS(ModID, B_DCACHE_MOD_ID, 5, 2) |
134                B_SET_BITS(SetID, B_DCACHE_ID, 1, 0),
135
136                /* $25 #4 */
137                B_SET_BIT(CE, 1 /* enable */, 15) |
138                B_SET_BITS(EVT, B_INSTRUCTIONS,  8, 2) |
139                B_SET_BIT(TIE, 0 /* disable */, 0) |
140
141                B_SET_BIT(CE, 1 /* enable */, 15+16) |
142                B_SET_BITS(EVT, B_DCACHE_MISS,  8+16, 2+16) |
143                B_SET_BIT(TIE, 0 /* disable */, 0+16),
144
145                /* $25 #5 */
146                B_SET_BIT(CE, 1 /* enable */, 15) |
147                B_SET_BITS(EVT, B_INSTRUCTIONS,  8, 2) |
148                B_SET_BIT(TIE, 0 /* disable */, 0) |
149
150                B_SET_BIT(CE, 1 /* enable */, 15+16) |
151                B_SET_BITS(EVT, B_CYCLES,  8+16, 2+16) |
152                B_SET_BIT(TIE, 0 /* disable */, 0+16)
153        }
154};
155
156const  bperf_counter_mode bperf_counter_icache  = {
157        {
158                "I-Cache miss",
159                "I-Cache hit",
160                b_insructions,
161                b_cycles
162        },
163        {
164                /* $25 #6 */
165                B_SET_BIT(PCE, 1 /* enable */, 31) |
166                B_SET_BIT(magic, 1 /* enable */, 9) |
167                B_SET_BIT(PCSD, 0 /* enable */, 8) |
168                B_SET_BITS(ModID, B_ICACHE_MOD_ID, 5, 2) |
169                B_SET_BITS(SetID, B_ICACHE_ID, 1, 0),
170
171                /* $25 #4 */
172                B_SET_BIT(CE, 1 /* enable */, 15) |
173                B_SET_BITS(EVT, B_ICACHE_MISS,  8, 2) |
174                B_SET_BIT(TIE, 0 /* disable */, 0) |
175
176                B_SET_BIT(CE, 1 /* enable */, 15+16) |
177                B_SET_BITS(EVT, B_ICACHE_HIT,  8+16, 2+16) |
178                B_SET_BIT(TIE, 0 /* disable */, 0+16),
179
180                /* $25 #5 */
181                B_SET_BIT(CE, 1 /* enable */, 15) |
182                B_SET_BITS(EVT, B_INSTRUCTIONS,  8, 2) |
183                B_SET_BIT(TIE, 0 /* disable */, 0) |
184
185                B_SET_BIT(CE, 1 /* enable */, 15+16) |
186                B_SET_BITS(EVT, B_CYCLES,  8+16, 2+16) |
187                B_SET_BIT(TIE, 0 /* disable */, 0+16)
188        }
189};
190
191const  bperf_counter_mode bperf_counter_rac_access = {
192        {
193                "RAC access",
194                b_insructions,
195                b_insructions,
196                b_cycles
197        },
198        {
199                /* $25 #6 */
200                B_SET_BIT(PCE, 1 /* enable */, 31) |
201                B_SET_BIT(magic, 1 /* enable */, 9) |
202                B_SET_BIT(PCSD, 0 /* enable */, 8) |
203                B_SET_BITS(ModID, B_RAC_MOD_ID, 5, 2) |
204                B_SET_BITS(SetID, B_RAC_ACCESS_ID, 1, 0),
205
206                /* $25 #4 */
207                B_SET_BIT(CE, 1 /* enable */, 15) |
208                B_SET_BITS(EVT, B_RAC_ACCESS,  8, 2) |
209                B_SET_BIT(TIE, 0 /* disable */, 0) |
210
211                B_SET_BIT(CE, 1 /* enable */, 15+16) |
212                B_SET_BITS(EVT, B_INSTRUCTIONS,  8+16, 2+16) |
213                B_SET_BIT(TIE, 0 /* disable */, 0+16),
214
215                /* $25 #5 */
216                B_SET_BIT(CE, 1 /* enable */, 15) |
217                B_SET_BITS(EVT, B_INSTRUCTIONS,  8, 2) |
218                B_SET_BIT(TIE, 0 /* disable */, 0) |
219
220                B_SET_BIT(CE, 1 /* enable */, 15+16) |
221                B_SET_BITS(EVT, B_CYCLES,  8+16, 2+16) |
222                B_SET_BIT(TIE, 0 /* disable */, 0+16)
223        }
224};
225
226const  bperf_counter_mode bperf_counter_rac_prefetch = {
227        {
228                "RAC prefetch", 
229                b_insructions,
230                b_insructions,
231                b_cycles
232        },
233        {
234                /* $25 #6 */
235                B_SET_BIT(PCE, 1 /* enable */, 31) |
236                B_SET_BIT(magic, 1 /* enable */, 9) |
237                B_SET_BIT(PCSD, 0 /* enable */, 8) |
238                B_SET_BITS(ModID, B_RAC_MOD_ID, 5, 2) |
239                B_SET_BITS(SetID, B_RAC_PREFETCH_ID, 1, 0),
240
241                /* $25 #4 */
242                B_SET_BIT(CE, 1 /* enable */, 15) |
243                B_SET_BITS(EVT, B_RAC_PREFETCH,  8, 2) |
244                B_SET_BIT(TIE, 0 /* disable */, 0) |
245
246                B_SET_BIT(CE, 1 /* enable */, 15+16) |
247                B_SET_BITS(EVT, B_INSTRUCTIONS,  8+16, 2+16) |
248                B_SET_BIT(TIE, 0 /* disable */, 0+16),
249
250                /* $25 #5 */
251                B_SET_BIT(CE, 1 /* enable */, 15) |
252                B_SET_BITS(EVT, B_INSTRUCTIONS,  8, 2) |
253                B_SET_BIT(TIE, 0 /* disable */, 0) |
254
255                B_SET_BIT(CE, 1 /* enable */, 15+16) |
256                B_SET_BITS(EVT, B_CYCLES,  8+16, 2+16) |
257                B_SET_BIT(TIE, 0 /* disable */, 0+16)
258        }
259};
260
261const  bperf_counter_mode bperf_counter_rac_hit = {
262        {
263                "RAC hits", 
264                b_insructions,
265                b_insructions,
266                b_cycles
267        },
268        {
269                /* $25 #6 */
270                B_SET_BIT(PCE, 1 /* enable */, 31) |
271                B_SET_BIT(magic, 1 /* enable */, 9) |
272                B_SET_BIT(PCSD, 0 /* enable */, 8) |
273                B_SET_BITS(ModID, B_BIU_MOD_ID, 5, 2) |
274                B_SET_BITS(SetID, B_RAC_HIT_ID, 1, 0),
275
276                /* $25 #4 */
277                B_SET_BIT(CE, 1 /* enable */, 15) |
278                B_SET_BITS(EVT, B_RAC_HIT,  8, 2) |
279                B_SET_BIT(TIE, 0 /* disable */, 0) |
280
281                B_SET_BIT(CE, 1 /* enable */, 15+16) |
282                B_SET_BITS(EVT, B_INSTRUCTIONS,  8+16, 2+16) |
283                B_SET_BIT(TIE, 0 /* disable */, 0+16),
284
285                /* $25 #5 */
286                B_SET_BIT(CE, 1 /* enable */, 15) |
287                B_SET_BITS(EVT, B_INSTRUCTIONS,  8, 2) |
288                B_SET_BIT(TIE, 0 /* disable */, 0) |
289
290                B_SET_BIT(CE, 1 /* enable */, 15+16) |
291                B_SET_BITS(EVT, B_CYCLES,  8+16, 2+16) |
292                B_SET_BIT(TIE, 0 /* disable */, 0+16)
293        }
294};
295#elif B_PERF_MIPSR5K
296/* MD00012-2B-5K-SUM-02.08.pdf pages 146..150 */
297#define B_EVENT_CYCLES  0
298#define B_EVENT_0_INST_FETCHED 1
299#define B_EVENT_1_INST_EXECUTED 1
300#define B_EVENT_CACHE_OPS       2
301#define B_EVENT_STORES  3
302#define B_EVENT_COND_STORES     4
303#define B_EVENT_0_FAIL_STORES   5
304#define B_EVENT_1_FPU_OPS       5
305#define B_EVENT_0_BRANCHES      6
306#define B_EVENT_1_DCACHE_EVICTED 6
307#define B_EVENT_0_ITLB_MISS     7
308#define B_EVENT_1_TLB_MISS_EXC  7
309#define B_EVENT_0_DTLB_MISS     8
310#define B_EVENT_1_BRANCH_MISS 8
311#define B_EVENT_0_ICACHE_MISS   9
312#define B_EVENT_1_DCACHE_MISS   9
313#define B_EVENT_0_INST_SCHED 10
314#define B_EVENT_1_INST_STALL 10
315#define B_EVENT_0_DUAL_ISSUE    14
316#define B_EVENT_0_INST_EXECUTED 15
317#define B_EVENT_1_INST_COP2 15
318
319const  bperf_counter_mode bperf_counter_dcache  = {
320        {
321                "I-Cache miss",
322                b_dcache_miss
323        }, {
324                /* $25 0 */
325                B_SET_BITS(Event, B_EVENT_0_ICACHE_MISS, 8, 5) |
326                B_SET_BIT(IE, 1, 4) |
327                B_SET_BIT(U, 1, 3) |
328                B_SET_BIT(S, 1, 2) |
329                B_SET_BIT(K, 1, 1) |
330                B_SET_BIT(EXL, 1, 0),
331
332                /* $25 2 */
333                B_SET_BITS(Event, B_EVENT_1_DCACHE_MISS, 8, 5) |
334                B_SET_BIT(IE, 1, 4) |
335                B_SET_BIT(U, 1, 3) |
336                B_SET_BIT(S, 1, 2) |
337                B_SET_BIT(K, 1, 1) |
338                B_SET_BIT(EXL, 1, 0),
339
340                /* unused */
341                0
342        }
343};
344
345const  bperf_counter_mode bperf_counter_icache  = {
346        {
347                "I-Cache miss",
348                b_dcache_miss
349        }, {
350                /* $25 0 */
351                B_SET_BITS(Event, B_EVENT_0_ICACHE_MISS, 8, 5) |
352                B_SET_BIT(IE, 1, 4) |
353                B_SET_BIT(U, 1, 3) |
354                B_SET_BIT(S, 1, 2) |
355                B_SET_BIT(K, 1, 1) |
356                B_SET_BIT(EXL, 1, 0),
357
358                /* $25 2 */
359                B_SET_BITS(Event, B_EVENT_1_DCACHE_MISS, 8, 5) |
360                B_SET_BIT(IE, 1, 4) |
361                B_SET_BIT(U, 1, 3) |
362                B_SET_BIT(S, 1, 2) |
363                B_SET_BIT(K, 1, 1) |
364                B_SET_BIT(EXL, 1, 0),
365
366                /* unused */
367                0
368        }
369};
370
371const  bperf_counter_mode bperf_counter_instructions = {
372        {
373                b_insructions,
374                b_cycles
375        },
376        {
377                /* $25 0 */
378                B_SET_BITS(Event, B_EVENT_0_INST_EXECUTED, 8, 5) |
379                B_SET_BIT(IE, 1, 4) |
380                B_SET_BIT(U, 1, 3) |
381                B_SET_BIT(S, 1, 2) |
382                B_SET_BIT(K, 1, 1) |
383                B_SET_BIT(EXL, 1, 0),
384
385                /* $25 2 */
386                B_SET_BITS(Event, B_EVENT_CYCLES, 8, 5) |
387                B_SET_BIT(IE, 1, 4) |
388                B_SET_BIT(U, 1, 3) |
389                B_SET_BIT(S, 1, 2) |
390                B_SET_BIT(K, 1, 1) |
391                B_SET_BIT(EXL, 1, 0),
392
393                /* unused */
394                0
395        }
396};
397
398#endif
399
400static const bperf_counter_mode *b_perf_mode = NULL;
401
402#define bcm_write_perf(sel, value)                                      \
403{               __asm__ __volatile__(".set\tpush\n\t"                   \
404                        ".set\tmips32\n\t"                                                      \
405                        "mtc0\t%0, $25, " #sel "\n\t"   \
406                        ".set\tpop\n\t"                                                 \
407                        : /* none */                                                            \
408                        : "r" ((unsigned int)value));                           \
409}
410
411
412int 
413b_perf_init(const bperf_counter_mode *mode)
414{
415        BDBG_ASSERT(mode);
416#if B_PERF_BMIPS3300
417        BDBG_MSG(("perf_init %#x %#x %#x",mode->config[0],mode->config[1],mode->config[2]));
418        bcm_write_perf(6, mode->config[0]);
419        bcm_write_perf(4, mode->config[1]);
420        bcm_write_perf(5, mode->config[2]);
421
422        bcm_write_perf(0, 0)  /* PerfCount0 reset to 0 (it is a decrementing count) */
423        bcm_write_perf(1, 0)  /* PerfCount1 reset to 0 (it is a decrementing count) */
424        bcm_write_perf(2, 0)  /* PerfCount2 reset to 0 (it is a decrementing count) */
425        bcm_write_perf(3, 0)  /* PerfCount3 reset to 0 (it is a decrementing count) */
426#elif B_PERF_MIPSR5K
427        BDBG_MSG(("perf_init %#x %#x",mode->config[0],mode->config[1]));
428        bcm_write_perf(0, mode->config[0]);
429        bcm_write_perf(2, mode->config[1]);
430
431        bcm_write_perf(1, 0)  /* PerfCount0 reset to 0 */
432        bcm_write_perf(3, 0)  /* PerfCount1 reset to 0 */
433#endif
434
435        b_perf_mode = mode;
436
437        return 0;
438}
439
440
441void 
442bperf_print(const bperf_counter_mode *mode, const bperf_sample *stop, const bperf_sample *start)
443{
444        unsigned i;
445        if (mode==NULL) {
446                mode = b_perf_mode;
447        }
448        BDBG_ASSERT(mode);
449        for(i=0;i<BPERF_N_COUNTERS;i++) {
450                unsigned diff = bperf_sample_diff(stop->data[i], start->data[i]);
451                BKNI_Printf("%c%s(%u) ", ' ', mode->counter_names[i], diff);
452        }
453        BKNI_Printf("\n");
454        return;
455}
456
457const bperf_counter_mode *
458bperf_get_mode(void)
459{
460        return b_perf_mode;
461}
462
Note: See TracBrowser for help on using the repository browser.