7a8d521f |
1 | #ifndef __PCNT_H__ |
2 | #define __PCNT_H__ |
14dffdb7 |
3 | |
4 | enum pcounters { |
5 | PCNT_ALL, |
6 | PCNT_GPU, |
7 | PCNT_SPU, |
72228559 |
8 | PCNT_BLIT, |
82ed88eb |
9 | PCNT_GTE, |
72228559 |
10 | PCNT_TEST, |
14dffdb7 |
11 | PCNT_CNT |
12 | }; |
13 | |
fa9cfe0a |
14 | #ifdef PCNT |
15 | |
603efa29 |
16 | #if defined(__ARM_ARCH_7A__) || defined(ARM1176) |
17 | #define PCNT_DIV 1000 |
18 | #else |
a2d91a5d |
19 | #include <sys/time.h> |
20 | #define PCNT_DIV 1 |
a2d91a5d |
21 | #endif |
22 | |
82ed88eb |
23 | static const char *pcnt_names[PCNT_CNT] = { "", "gpu", "spu", "blit", "gte", "test" }; |
72228559 |
24 | |
25 | #define PCNT_FRAMES 10 |
26 | |
14dffdb7 |
27 | extern unsigned int pcounters[PCNT_CNT]; |
28 | extern unsigned int pcounter_starts[PCNT_CNT]; |
29 | |
30 | #define pcnt_start(id) \ |
31 | pcounter_starts[id] = pcnt_get() |
32 | |
33 | #define pcnt_end(id) \ |
34 | pcounters[id] += pcnt_get() - pcounter_starts[id] |
35 | |
36 | void pcnt_hook_plugins(void); |
37 | |
38 | static inline void pcnt_print(float fps) |
39 | { |
72228559 |
40 | static int print_counter; |
41 | unsigned int total, rem; |
14dffdb7 |
42 | int i; |
43 | |
44 | for (i = 0; i < PCNT_CNT; i++) |
a2d91a5d |
45 | pcounters[i] /= PCNT_DIV * PCNT_FRAMES; |
14dffdb7 |
46 | |
72228559 |
47 | rem = total = pcounters[PCNT_ALL]; |
48 | for (i = 1; i < PCNT_CNT; i++) |
49 | rem -= pcounters[i]; |
14dffdb7 |
50 | if (!total) |
51 | total++; |
52 | |
72228559 |
53 | if (--print_counter < 0) { |
54 | printf(" "); |
55 | for (i = 1; i < PCNT_CNT; i++) |
56 | printf("%5s ", pcnt_names[i]); |
57 | printf("%5s\n", "rem"); |
58 | print_counter = 30; |
59 | } |
60 | |
61 | printf("%4.1f ", fps); |
fc42805b |
62 | #if 0 |
63 | static float pcounters_all[PCNT_CNT+1]; |
64 | static int pcounter_samples; |
65 | pcounter_samples++; |
66 | |
67 | for (i = 1; i < PCNT_CNT; i++) { |
68 | pcounters_all[i] += pcounters[i]; |
69 | printf("%5.0f ", pcounters_all[i] / pcounter_samples); |
70 | } |
71 | pcounters_all[i] += rem; |
72 | printf("%5.0f\n", pcounters_all[i] / pcounter_samples); |
73 | #else |
72228559 |
74 | for (i = 1; i < PCNT_CNT; i++) |
75 | printf("%5u ", pcounters[i]); |
76 | printf("%5u (", rem); |
77 | for (i = 1; i < PCNT_CNT; i++) |
78 | printf("%2u ", pcounters[i] * 100 / total); |
79 | printf("%2u) %u\n", rem * 100 / total, total); |
fc42805b |
80 | #endif |
14dffdb7 |
81 | memset(pcounters, 0, sizeof(pcounters)); |
82 | } |
83 | |
84 | static inline unsigned int pcnt_get(void) |
85 | { |
86 | unsigned int val; |
87 | #ifdef __ARM_ARCH_7A__ |
88 | __asm__ volatile("mrc p15, 0, %0, c9, c13, 0" |
89 | : "=r"(val)); |
603efa29 |
90 | #elif defined(ARM1176) |
91 | __asm__ volatile("mrc p15, 0, %0, c15, c12, 1" |
92 | : "=r"(val)); |
14dffdb7 |
93 | #else |
a2d91a5d |
94 | // all slow on ARM :( |
95 | //struct timespec tv; |
96 | //clock_gettime(CLOCK_MONOTONIC_RAW, &tv); |
97 | //val = tv.tv_sec * 1000000000 + tv.tv_nsec; |
98 | struct timeval tv; |
99 | gettimeofday(&tv, NULL); |
100 | val = tv.tv_sec * 1000000 + tv.tv_usec; |
14dffdb7 |
101 | #endif |
102 | return val; |
103 | } |
104 | |
19e57cbf |
105 | static inline void pcnt_init(void) |
106 | { |
107 | #ifdef __ARM_ARCH_7A__ |
108 | int v; |
109 | asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(v)); |
110 | v |= 5; // master enable, ccnt reset |
111 | v &= ~8; // ccnt divider 0 |
112 | asm volatile("mcr p15, 0, %0, c9, c12, 0" :: "r"(v)); |
113 | // enable cycle counter |
114 | asm volatile("mcr p15, 0, %0, c9, c12, 1" :: "r"(1<<31)); |
603efa29 |
115 | #elif defined(ARM1176) |
116 | int v; |
117 | asm volatile("mrc p15, 0, %0, c15, c12, 0" : "=r"(v)); |
118 | v |= 5; // master enable, ccnt reset |
119 | v &= ~8; // ccnt divider 0 |
120 | asm volatile("mcr p15, 0, %0, c15, c12, 0" :: "r"(v)); |
19e57cbf |
121 | #endif |
122 | } |
123 | |
82ed88eb |
124 | void pcnt_gte_start(int op); |
125 | void pcnt_gte_end(int op); |
126 | |
fa9cfe0a |
127 | #else |
128 | |
129 | #define pcnt_start(id) |
130 | #define pcnt_end(id) |
131 | #define pcnt_hook_plugins() |
69af03a2 |
132 | #define pcnt_print(fps) |
fa9cfe0a |
133 | |
134 | #endif |
7a8d521f |
135 | |
136 | #endif /* __PCNT_H__ */ |