import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / gpu / ged / src / ged_profile_dvfs.c
1 #include <linux/slab.h>
2 #include <linux/sched.h>
3 #include "ged_base.h"
4 #include "ged_log.h"
5 #include "ged_profile_dvfs.h"
6
7 static GED_LOG_BUF_HANDLE ghLogBuf = 0;
8 static struct mutex gsMutex;
9 static GED_BOOL gbAllowRecord = GED_FALSE;
10
11 GED_ERROR ged_profile_dvfs_init(void)
12 {
13 mutex_init(&gsMutex);
14
15 #if 0
16 ghLogBuf = ged_log_buf_alloc(320, 64, GED_LOG_BUF_TYPE_QUEUEBUFFER_AUTO_INCREASE, NULL, "profile_dvfs");
17 #endif
18
19 return GED_OK;
20 }
21
22 GED_ERROR ged_profile_dvfs_enable(void)
23 {
24 GED_ERROR ret;
25
26 mutex_lock(&gsMutex);
27
28 if (NULL == ghLogBuf)
29 {
30 ghLogBuf = ged_log_buf_alloc(320, 64, GED_LOG_BUF_TYPE_QUEUEBUFFER_AUTO_INCREASE, NULL, "profile_dvfs");
31 }
32
33 ret = ghLogBuf ? GED_OK : GED_ERROR_FAIL;
34
35 mutex_unlock(&gsMutex);
36
37 return ret;
38 }
39
40 void ged_profile_dvfs_disable(void)
41 {
42 mutex_lock(&gsMutex);
43
44 if (NULL != ghLogBuf)
45 {
46 ged_log_buf_free(ghLogBuf);
47 ghLogBuf = NULL;
48 }
49
50 mutex_unlock(&gsMutex);
51 }
52
53 void ged_profile_dvfs_start(void)
54 {
55 gbAllowRecord = GED_TRUE;
56 }
57
58 void ged_profile_dvfs_stop(void)
59 {
60 gbAllowRecord = GED_FALSE;
61 }
62
63 void ged_profile_dvfs_ignore_lines(int i32LineCount)
64 {
65 mutex_lock(&gsMutex);
66
67 if (ghLogBuf)
68 {
69 ged_log_buf_ignore_lines(ghLogBuf, i32LineCount);
70 }
71
72 mutex_unlock(&gsMutex);
73 }
74
75 void ged_profile_dvfs_exit(void)
76 {
77 ged_profile_dvfs_disable();
78 }
79
80 void ged_profile_dvfs_record_freq_volt(unsigned int ui32Frequency, unsigned int ui32Voltage)
81 {
82 mutex_lock(&gsMutex);
83
84 if (ghLogBuf && gbAllowRecord)
85 {
86 /* copy & modify from ./kernel/printk.c */
87 unsigned long long t;
88 unsigned long nanosec_rem;
89
90 t = cpu_clock(smp_processor_id());
91 nanosec_rem = do_div(t, 1000000000) / 1000;
92
93 ged_log_buf_print(ghLogBuf, "%5lu.%06lu,freq_volt,%u,%u", (unsigned long) t, nanosec_rem, ui32Frequency, ui32Voltage);
94 }
95 mutex_unlock(&gsMutex);
96 }
97
98 void ged_profile_dvfs_record_temp(int i32Temp)
99 {
100 mutex_lock(&gsMutex);
101
102 if (ghLogBuf && gbAllowRecord)
103 {
104 /* copy & modify from ./kernel/printk.c */
105 unsigned long long t;
106 unsigned long nanosec_rem;
107
108 t = cpu_clock(smp_processor_id());
109 nanosec_rem = do_div(t, 1000000000) / 1000;
110
111 ged_log_buf_print(ghLogBuf, "%5lu.%06lu,temp,%d", (unsigned long) t, nanosec_rem, i32Temp);
112 }
113 mutex_unlock(&gsMutex);
114
115 }
116
117 void ged_profile_dvfs_record_thermal_limit(unsigned int ui32FreqLimit)
118 {
119 mutex_lock(&gsMutex);
120
121 if (ghLogBuf && gbAllowRecord)
122 {
123 /* copy & modify from ./kernel/printk.c */
124 unsigned long long t;
125 unsigned long nanosec_rem;
126
127 t = cpu_clock(smp_processor_id());
128 nanosec_rem = do_div(t, 1000000000) / 1000;
129
130 ged_log_buf_print(ghLogBuf, "%5lu.%06lu,thermal_limit,%u", (unsigned long) t, nanosec_rem, ui32FreqLimit);
131 }
132 mutex_unlock(&gsMutex);
133 }
134
135 void ged_profile_dvfs_record_gpu_loading(unsigned int ui32GpuLoading)
136 {
137 mutex_lock(&gsMutex);
138
139 if (ghLogBuf && gbAllowRecord)
140 {
141 /* copy & modify from ./kernel/printk.c */
142 unsigned long long t;
143 unsigned long nanosec_rem;
144
145 t = cpu_clock(smp_processor_id());
146 nanosec_rem = do_div(t, 1000000000) / 1000;
147
148 ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_load,%u", (unsigned long) t, nanosec_rem, ui32GpuLoading);
149 }
150
151 mutex_unlock(&gsMutex);
152 }
153
154 void ged_profile_dvfs_record_clock_on(void)
155 {
156 mutex_lock(&gsMutex);
157
158 if (ghLogBuf && gbAllowRecord)
159 {
160 /* copy & modify from ./kernel/printk.c */
161 unsigned long long t;
162 unsigned long nanosec_rem;
163
164 t = cpu_clock(smp_processor_id());
165 nanosec_rem = do_div(t, 1000000000) / 1000;
166
167 ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_clock,1", (unsigned long) t, nanosec_rem);
168 }
169
170 mutex_unlock(&gsMutex);
171 }
172
173 void ged_profile_dvfs_record_clock_off(void)
174 {
175 mutex_lock(&gsMutex);
176
177 if (ghLogBuf && gbAllowRecord)
178 {
179 /* copy & modify from ./kernel/printk.c */
180 unsigned long long t;
181 unsigned long nanosec_rem;
182
183 t = cpu_clock(smp_processor_id());
184 nanosec_rem = do_div(t, 1000000000) / 1000;
185
186 ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_clock,0", (unsigned long) t, nanosec_rem);
187 }
188
189 mutex_unlock(&gsMutex);
190 }