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