16 #if defined(__ARM_ARCH_7A__) || defined(ARM1176)
23 static const char *pcnt_names[PCNT_CNT] = { "", "gpu", "spu", "blit", "gte", "test" };
25 #define PCNT_FRAMES 10
27 extern unsigned int pcounters[PCNT_CNT];
28 extern unsigned int pcounter_starts[PCNT_CNT];
30 #define pcnt_start(id) \
31 pcounter_starts[id] = pcnt_get()
33 #define pcnt_end(id) \
34 pcounters[id] += pcnt_get() - pcounter_starts[id]
36 void pcnt_hook_plugins(void);
38 static inline void pcnt_print(float fps)
40 static int print_counter;
41 unsigned int total, rem;
44 for (i = 0; i < PCNT_CNT; i++)
45 pcounters[i] /= PCNT_DIV * PCNT_FRAMES;
47 rem = total = pcounters[PCNT_ALL];
48 for (i = 1; i < PCNT_CNT; i++)
53 if (--print_counter < 0) {
55 for (i = 1; i < PCNT_CNT; i++)
56 printf("%5s ", pcnt_names[i]);
57 printf("%5s\n", "rem");
61 printf("%4.1f ", fps);
63 static float pcounters_all[PCNT_CNT+1];
64 static int pcounter_samples;
67 for (i = 1; i < PCNT_CNT; i++) {
68 pcounters_all[i] += pcounters[i];
69 printf("%5.0f ", pcounters_all[i] / pcounter_samples);
71 pcounters_all[i] += rem;
72 printf("%5.0f\n", pcounters_all[i] / pcounter_samples);
74 for (i = 1; i < PCNT_CNT; i++)
75 printf("%5u ", pcounters[i]);
77 for (i = 1; i < PCNT_CNT; i++)
78 printf("%2u ", pcounters[i] * 100 / total);
79 printf("%2u) %u\n", rem * 100 / total, total);
81 memset(pcounters, 0, sizeof(pcounters));
84 static inline unsigned int pcnt_get(void)
87 #ifdef __ARM_ARCH_7A__
88 __asm__ volatile("mrc p15, 0, %0, c9, c13, 0"
90 #elif defined(ARM1176)
91 __asm__ volatile("mrc p15, 0, %0, c15, c12, 1"
96 //clock_gettime(CLOCK_MONOTONIC_RAW, &tv);
97 //val = tv.tv_sec * 1000000000 + tv.tv_nsec;
99 gettimeofday(&tv, NULL);
100 val = tv.tv_sec * 1000000 + tv.tv_usec;
105 static inline void pcnt_init(void)
107 #ifdef __ARM_ARCH_7A__
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));
115 #elif defined(ARM1176)
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));
124 void pcnt_gte_start(int op);
125 void pcnt_gte_end(int op);
129 #define pcnt_start(id)
131 #define pcnt_hook_plugins()
132 #define pcnt_print(fps)
136 #endif /* __PCNT_H__ */