1 #include <linux/slab.h>
2 #include <linux/sched.h>
5 #include "ged_profile_dvfs.h"
7 static GED_LOG_BUF_HANDLE ghLogBuf
= 0;
8 static struct mutex gsMutex
;
9 static GED_BOOL gbAllowRecord
= GED_FALSE
;
11 GED_ERROR
ged_profile_dvfs_init(void)
16 ghLogBuf
= ged_log_buf_alloc(320, 64, GED_LOG_BUF_TYPE_QUEUEBUFFER_AUTO_INCREASE
, NULL
, "profile_dvfs");
22 GED_ERROR
ged_profile_dvfs_enable(void)
30 ghLogBuf
= ged_log_buf_alloc(320, 64, GED_LOG_BUF_TYPE_QUEUEBUFFER_AUTO_INCREASE
, NULL
, "profile_dvfs");
33 ret
= ghLogBuf
? GED_OK
: GED_ERROR_FAIL
;
35 mutex_unlock(&gsMutex
);
40 void ged_profile_dvfs_disable(void)
46 ged_log_buf_free(ghLogBuf
);
50 mutex_unlock(&gsMutex
);
53 void ged_profile_dvfs_start(void)
55 gbAllowRecord
= GED_TRUE
;
58 void ged_profile_dvfs_stop(void)
60 gbAllowRecord
= GED_FALSE
;
63 void ged_profile_dvfs_ignore_lines(int i32LineCount
)
69 ged_log_buf_ignore_lines(ghLogBuf
, i32LineCount
);
72 mutex_unlock(&gsMutex
);
75 void ged_profile_dvfs_exit(void)
77 ged_profile_dvfs_disable();
80 void ged_profile_dvfs_record_freq_volt(unsigned int ui32Frequency
, unsigned int ui32Voltage
)
84 if (ghLogBuf
&& gbAllowRecord
)
86 /* copy & modify from ./kernel/printk.c */
88 unsigned long nanosec_rem
;
90 t
= cpu_clock(smp_processor_id());
91 nanosec_rem
= do_div(t
, 1000000000) / 1000;
93 ged_log_buf_print(ghLogBuf
, "%5lu.%06lu,freq_volt,%u,%u", (unsigned long) t
, nanosec_rem
, ui32Frequency
, ui32Voltage
);
95 mutex_unlock(&gsMutex
);
98 void ged_profile_dvfs_record_temp(int i32Temp
)
100 mutex_lock(&gsMutex
);
102 if (ghLogBuf
&& gbAllowRecord
)
104 /* copy & modify from ./kernel/printk.c */
105 unsigned long long t
;
106 unsigned long nanosec_rem
;
108 t
= cpu_clock(smp_processor_id());
109 nanosec_rem
= do_div(t
, 1000000000) / 1000;
111 ged_log_buf_print(ghLogBuf
, "%5lu.%06lu,temp,%d", (unsigned long) t
, nanosec_rem
, i32Temp
);
113 mutex_unlock(&gsMutex
);
117 void ged_profile_dvfs_record_thermal_limit(unsigned int ui32FreqLimit
)
119 mutex_lock(&gsMutex
);
121 if (ghLogBuf
&& gbAllowRecord
)
123 /* copy & modify from ./kernel/printk.c */
124 unsigned long long t
;
125 unsigned long nanosec_rem
;
127 t
= cpu_clock(smp_processor_id());
128 nanosec_rem
= do_div(t
, 1000000000) / 1000;
130 ged_log_buf_print(ghLogBuf
, "%5lu.%06lu,thermal_limit,%u", (unsigned long) t
, nanosec_rem
, ui32FreqLimit
);
132 mutex_unlock(&gsMutex
);
135 void ged_profile_dvfs_record_gpu_loading(unsigned int ui32GpuLoading
)
137 mutex_lock(&gsMutex
);
139 if (ghLogBuf
&& gbAllowRecord
)
141 /* copy & modify from ./kernel/printk.c */
142 unsigned long long t
;
143 unsigned long nanosec_rem
;
145 t
= cpu_clock(smp_processor_id());
146 nanosec_rem
= do_div(t
, 1000000000) / 1000;
148 ged_log_buf_print(ghLogBuf
, "%5lu.%06lu,gpu_load,%u", (unsigned long) t
, nanosec_rem
, ui32GpuLoading
);
151 mutex_unlock(&gsMutex
);
154 void ged_profile_dvfs_record_clock_on(void)
156 mutex_lock(&gsMutex
);
158 if (ghLogBuf
&& gbAllowRecord
)
160 /* copy & modify from ./kernel/printk.c */
161 unsigned long long t
;
162 unsigned long nanosec_rem
;
164 t
= cpu_clock(smp_processor_id());
165 nanosec_rem
= do_div(t
, 1000000000) / 1000;
167 ged_log_buf_print(ghLogBuf
, "%5lu.%06lu,gpu_clock,1", (unsigned long) t
, nanosec_rem
);
170 mutex_unlock(&gsMutex
);
173 void ged_profile_dvfs_record_clock_off(void)
175 mutex_lock(&gsMutex
);
177 if (ghLogBuf
&& gbAllowRecord
)
179 /* copy & modify from ./kernel/printk.c */
180 unsigned long long t
;
181 unsigned long nanosec_rem
;
183 t
= cpu_clock(smp_processor_id());
184 nanosec_rem
= do_div(t
, 1000000000) / 1000;
186 ged_log_buf_print(ghLogBuf
, "%5lu.%06lu,gpu_clock,0", (unsigned long) t
, nanosec_rem
);
189 mutex_unlock(&gsMutex
);