14 #if defined(__ARM_ARCH_7A__) || defined(ARM1176)
21 static const char *pcnt_names[PCNT_CNT] = { "", "gpu", "spu", "blit", "gte", "test" };
23 #define PCNT_FRAMES 10
25 extern unsigned int pcounters[PCNT_CNT];
26 extern unsigned int pcounter_starts[PCNT_CNT];
28 #define pcnt_start(id) \
29 pcounter_starts[id] = pcnt_get()
31 #define pcnt_end(id) \
32 pcounters[id] += pcnt_get() - pcounter_starts[id]
34 void pcnt_hook_plugins(void);
36 static inline void pcnt_print(float fps)
38 static int print_counter;
39 unsigned int total, rem;
42 for (i = 0; i < PCNT_CNT; i++)
43 pcounters[i] /= PCNT_DIV * PCNT_FRAMES;
45 rem = total = pcounters[PCNT_ALL];
46 for (i = 1; i < PCNT_CNT; i++)
51 if (--print_counter < 0) {
53 for (i = 1; i < PCNT_CNT; i++)
54 printf("%5s ", pcnt_names[i]);
55 printf("%5s\n", "rem");
59 printf("%4.1f ", fps);
61 static float pcounters_all[PCNT_CNT+1];
62 static int pcounter_samples;
65 for (i = 1; i < PCNT_CNT; i++) {
66 pcounters_all[i] += pcounters[i];
67 printf("%5.0f ", pcounters_all[i] / pcounter_samples);
69 pcounters_all[i] += rem;
70 printf("%5.0f\n", pcounters_all[i] / pcounter_samples);
72 for (i = 1; i < PCNT_CNT; i++)
73 printf("%5u ", pcounters[i]);
75 for (i = 1; i < PCNT_CNT; i++)
76 printf("%2u ", pcounters[i] * 100 / total);
77 printf("%2u) %u\n", rem * 100 / total, total);
79 memset(pcounters, 0, sizeof(pcounters));
82 static inline unsigned int pcnt_get(void)
85 #ifdef __ARM_ARCH_7A__
86 __asm__ volatile("mrc p15, 0, %0, c9, c13, 0"
88 #elif defined(ARM1176)
89 __asm__ volatile("mrc p15, 0, %0, c15, c12, 1"
94 //clock_gettime(CLOCK_MONOTONIC_RAW, &tv);
95 //val = tv.tv_sec * 1000000000 + tv.tv_nsec;
97 gettimeofday(&tv, NULL);
98 val = tv.tv_sec * 1000000 + tv.tv_usec;
103 static inline void pcnt_init(void)
105 #ifdef __ARM_ARCH_7A__
107 asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(v));
108 v |= 5; // master enable, ccnt reset
109 v &= ~8; // ccnt divider 0
110 asm volatile("mcr p15, 0, %0, c9, c12, 0" :: "r"(v));
111 // enable cycle counter
112 asm volatile("mcr p15, 0, %0, c9, c12, 1" :: "r"(1<<31));
113 #elif defined(ARM1176)
115 asm volatile("mrc p15, 0, %0, c15, c12, 0" : "=r"(v));
116 v |= 5; // master enable, ccnt reset
117 v &= ~8; // ccnt divider 0
118 asm volatile("mcr p15, 0, %0, c15, c12, 0" :: "r"(v));
122 void pcnt_gte_start(int op);
123 void pcnt_gte_end(int op);
127 #define pcnt_start(id)
129 #define pcnt_hook_plugins()
130 #define pcnt_print(fps)