14dffdb7 |
1 | |
2 | enum pcounters { |
3 | PCNT_ALL, |
4 | PCNT_GPU, |
5 | PCNT_SPU, |
72228559 |
6 | PCNT_BLIT, |
7 | PCNT_TEST, |
14dffdb7 |
8 | PCNT_CNT |
9 | }; |
10 | |
fa9cfe0a |
11 | #ifdef PCNT |
12 | |
72228559 |
13 | static const char *pcnt_names[PCNT_CNT] = { "", "gpu", "spu", "blit", "test" }; |
14 | |
15 | #define PCNT_FRAMES 10 |
16 | |
14dffdb7 |
17 | extern unsigned int pcounters[PCNT_CNT]; |
18 | extern unsigned int pcounter_starts[PCNT_CNT]; |
19 | |
20 | #define pcnt_start(id) \ |
21 | pcounter_starts[id] = pcnt_get() |
22 | |
23 | #define pcnt_end(id) \ |
24 | pcounters[id] += pcnt_get() - pcounter_starts[id] |
25 | |
26 | void pcnt_hook_plugins(void); |
27 | |
28 | static inline void pcnt_print(float fps) |
29 | { |
72228559 |
30 | static int print_counter; |
31 | unsigned int total, rem; |
14dffdb7 |
32 | int i; |
33 | |
34 | for (i = 0; i < PCNT_CNT; i++) |
72228559 |
35 | pcounters[i] /= 1000 * PCNT_FRAMES; |
14dffdb7 |
36 | |
72228559 |
37 | rem = total = pcounters[PCNT_ALL]; |
38 | for (i = 1; i < PCNT_CNT; i++) |
39 | rem -= pcounters[i]; |
14dffdb7 |
40 | if (!total) |
41 | total++; |
42 | |
72228559 |
43 | if (--print_counter < 0) { |
44 | printf(" "); |
45 | for (i = 1; i < PCNT_CNT; i++) |
46 | printf("%5s ", pcnt_names[i]); |
47 | printf("%5s\n", "rem"); |
48 | print_counter = 30; |
49 | } |
50 | |
51 | printf("%4.1f ", fps); |
fc42805b |
52 | #if 0 |
53 | static float pcounters_all[PCNT_CNT+1]; |
54 | static int pcounter_samples; |
55 | pcounter_samples++; |
56 | |
57 | for (i = 1; i < PCNT_CNT; i++) { |
58 | pcounters_all[i] += pcounters[i]; |
59 | printf("%5.0f ", pcounters_all[i] / pcounter_samples); |
60 | } |
61 | pcounters_all[i] += rem; |
62 | printf("%5.0f\n", pcounters_all[i] / pcounter_samples); |
63 | #else |
72228559 |
64 | for (i = 1; i < PCNT_CNT; i++) |
65 | printf("%5u ", pcounters[i]); |
66 | printf("%5u (", rem); |
67 | for (i = 1; i < PCNT_CNT; i++) |
68 | printf("%2u ", pcounters[i] * 100 / total); |
69 | printf("%2u) %u\n", rem * 100 / total, total); |
fc42805b |
70 | #endif |
14dffdb7 |
71 | memset(pcounters, 0, sizeof(pcounters)); |
72 | } |
73 | |
74 | static inline unsigned int pcnt_get(void) |
75 | { |
76 | unsigned int val; |
77 | #ifdef __ARM_ARCH_7A__ |
78 | __asm__ volatile("mrc p15, 0, %0, c9, c13, 0" |
79 | : "=r"(val)); |
80 | #else |
81 | val = 0; |
82 | #endif |
83 | return val; |
84 | } |
85 | |
19e57cbf |
86 | static inline void pcnt_init(void) |
87 | { |
88 | #ifdef __ARM_ARCH_7A__ |
89 | int v; |
90 | asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(v)); |
91 | v |= 5; // master enable, ccnt reset |
92 | v &= ~8; // ccnt divider 0 |
93 | asm volatile("mcr p15, 0, %0, c9, c12, 0" :: "r"(v)); |
94 | // enable cycle counter |
95 | asm volatile("mcr p15, 0, %0, c9, c12, 1" :: "r"(1<<31)); |
96 | #endif |
97 | } |
98 | |
fa9cfe0a |
99 | #else |
100 | |
101 | #define pcnt_start(id) |
102 | #define pcnt_end(id) |
103 | #define pcnt_hook_plugins() |
69af03a2 |
104 | #define pcnt_print(fps) |
fa9cfe0a |
105 | |
106 | #endif |