1 /* drivers/power/load_analyzer_exynos3250.c */
5 unsigned int get_bimc_clk(void);
6 unsigned int get_snoc_clk(void);
7 extern int mali_gpu_clk;
8 extern int mali_dvfs_utilization;
10 void store_cpu_load(unsigned int cpufreq[], unsigned int cpu_load[])
12 unsigned int j = 0, cnt = 0;
13 unsigned long long t, t_interval;
14 unsigned int t_interval_us;
15 static unsigned long long before_t;
16 unsigned long nanosec_rem;
17 int cpu_max = 0, cpu_min = 0;
18 struct cpufreq_policy *policy;
19 static int cpu_busy_level_before = 0;
21 if (cpu_task_history_onoff == 0)
24 if (++cpu_load_freq_history_cnt >= cpu_load_history_num)
25 cpu_load_freq_history_cnt = 0;
27 cnt = cpu_load_freq_history_cnt;
29 policy = cpufreq_cpu_get(0);
32 cpu_min = pm_qos_request(PM_QOS_CPU_FREQ_MIN);
33 if (cpu_min < policy->min)
34 cpu_min = policy->min;
36 cpu_max = pm_qos_request(PM_QOS_CPU_FREQ_MAX);
37 if (cpu_max > policy->max)
38 cpu_max = policy->max;
40 cpufreq_cpu_put(policy);
43 cpu_load_freq_history[cnt].cpu_min_locked_freq = cpu_min;
44 cpu_load_freq_history[cnt].cpu_max_locked_freq = cpu_max;
46 cpu_load_freq_history[cnt].cpu_min_locked_online = pm_qos_request(PM_QOS_CPU_ONLINE_MIN);
47 cpu_load_freq_history[cnt].cpu_max_locked_online = pm_qos_request(PM_QOS_CPU_ONLINE_MAX);
49 t = cpu_clock(UINT_MAX);
54 for (j = 0; j < CPU_NUM; j++) {
55 cpu_load_freq_history[cnt].task_history_cnt[j]
56 = cpu_task_history_cnt[j];
59 #if defined (CONFIG_CHECK_WORK_HISTORY)
60 for (j = 0; j < CPU_NUM; j++) {
61 cpu_load_freq_history[cnt].work_history_cnt[j]
62 = cpu_work_history_cnt[j];
66 #if defined (CONFIG_SLP_INPUT_REC)
67 cpu_load_freq_history[cnt].input_rec_history_cnt
68 = input_rec_history_cnt;
71 t_interval = t -before_t;
72 do_div(t_interval, 1000);
73 t_interval_us = t_interval;
76 if (t_interval != 0) {
77 cpu_load_freq_history[cnt].cpu_idle_time[0]
78 = (cpuidle_get_idle_residency_time(0) * 1000 + 5) / t_interval_us;
79 cpu_load_freq_history[cnt].cpu_idle_time[1]
80 = (cpuidle_get_idle_residency_time(1) * 1000 +5) / t_interval_us;
81 cpu_load_freq_history[cnt].cpu_idle_time[2]
82 = (cpuidle_get_idle_residency_time(2) * 1000 +5) / t_interval_us;
85 if (saved_load_factor.suspend_state == 1)
86 cpu_load_freq_history[cnt].status = 'S';
87 else if (saved_load_factor.suspend_state == 0)
88 cpu_load_freq_history[cnt].status = 'N';
89 else if (saved_load_factor.suspend_state == -1)
90 cpu_load_freq_history[cnt].status = 'F';
92 cpu_load_freq_history[cnt].time_stamp = t;
93 nanosec_rem = do_div(t, 1000000000);
94 snprintf(cpu_load_freq_history[cnt].time, sizeof(cpu_load_freq_history[cnt].time),
95 "%2lu.%02lu", (unsigned long) t,(unsigned long)nanosec_rem / 10000000);
97 for (j = 0; j < CPU_NUM; j++) {
98 cpu_load_freq_history[cnt].cpufreq[j] = cpufreq[j];
99 cpu_load_freq_history[cnt].cpu_load[j] = cpu_load[j];
101 cpu_load_freq_history[cnt].touch_event = 0;
102 cpu_load_freq_history[cnt].nr_onlinecpu = num_online_cpus();
103 cpu_load_freq_history[cnt].nr_run_avg
104 = saved_load_factor.nr_running_task;
106 cpu_load_freq_history[cnt].lcd_brightness = saved_load_factor.lcd_brightness;
108 cpu_load_freq_history[cnt].suspend_count = saved_load_factor.suspend_count;
110 #if defined(CONFIG_SLP_CHECK_BUS_LOAD)
111 cpu_load_freq_history[cnt].nr_run_avg
112 = saved_load_factor.nr_running_task;
114 cpu_load_freq_history[cnt].mif_bus_freq
115 = saved_load_factor.mif_bus_freq;
116 cpu_load_freq_history[cnt].int_bus_freq
117 = saved_load_factor.int_bus_freq;
118 cpu_load_freq_history[cnt].mif_bus_load
119 = saved_load_factor.mif_bus_load;
120 cpu_load_freq_history[cnt].mif_bus_load
121 = saved_load_factor.mif_bus_load;
123 cpu_load_freq_history[cnt].gpu_freq
125 cpu_load_freq_history[cnt].gpu_utilization
126 = mali_dvfs_utilization;
129 #if defined(CONFIG_SLP_CHECK_RESOURCE)
130 cpu_load_freq_history[cnt].bt_tx_bytes
131 = saved_load_factor.bt_tx_bytes;
132 saved_load_factor.bt_tx_bytes = 0;
134 cpu_load_freq_history[cnt].bt_rx_bytes
135 = saved_load_factor.bt_rx_bytes;
136 saved_load_factor.bt_rx_bytes = 0;
138 cpu_load_freq_history[cnt].bt_enabled
139 = saved_load_factor.bt_enabled;
141 cpu_load_freq_history[cnt].wifi_tx_bytes
142 = saved_load_factor.wifi_tx_bytes;
143 saved_load_factor.wifi_tx_bytes = 0;
145 cpu_load_freq_history[cnt].wifi_rx_bytes
146 = saved_load_factor.wifi_rx_bytes;
147 saved_load_factor.wifi_rx_bytes = 0;
149 cpu_load_freq_history[cnt].wifi_enabled
150 = saved_load_factor.wifi_enabled;
154 cpu_load_freq_history[cnt].pid = saved_load_factor.active_app_pid;
155 cpu_load_freq_history[cnt].battery_soc = saved_load_factor.battery_soc;
158 cpu_busy_level = check_load_level(cnt);
159 if (cpu_busy_level != cpu_busy_level_before) {
160 pr_info("cpu_busy_level=%d->%d", cpu_busy_level_before, cpu_busy_level);
161 cpu_busy_level_before = cpu_busy_level;
162 update_cpu_busy_level();
165 #if defined(CONFIG_SLP_BUS_CLK_CHECK_LOAD)
167 unsigned int pm_domains;
168 unsigned int clk_gates[CLK_GATES_NUM];
169 clk_mon_power_domain(&pm_domains);
170 clk_mon_clock_gate(clk_gates);
172 cpu_load_freq_history[cnt].power_domains[0] = pm_domains;
173 memcpy(cpu_load_freq_history[cnt].clk_gates
174 , clk_gates, CLK_GATES_NUM*sizeof(unsigned int));
178 #if defined(CONFIG_SLP_CURRENT_MONITOR)
179 if (current_monitor_en == 1)
180 current_monitor_manager(cnt);
185 char cpu_load_freq_menu[] ="=======================================" \
186 "===============================================\n" \
187 " TIME CPU_FREQ F_LOCK O_LOCK [INDEX] " \
188 "CPU0 CPU1 ONLINE NR_RUN\n";
190 unsigned int show_cpu_load_freq_sub(int cnt, int show_cnt, char *buf, unsigned int buf_size, int ret)
194 if ((cnt - show_cnt) < 0) {
195 delta = cnt - show_cnt;
196 cnt = cpu_load_history_num + delta;
200 if ((cnt+1 >= cpu_load_history_num)
201 || (cpu_load_freq_history_view[cnt+1].time == 0))
206 for (j = 0; j < show_cnt; j++) {
207 if (cnt > cpu_load_history_num-1)
209 ret += snprintf(buf + ret, PAGE_SIZE - ret
210 , "%10s\t%d.%d %d.%d/%d.%d %d/%d [%5d] %3d %3d "
212 , cpu_load_freq_history_view[cnt].time
213 , cpu_load_freq_history_view[cnt].cpufreq[0]/1000000
214 , (cpu_load_freq_history_view[cnt].cpufreq[0]/100000) % 10
215 , cpu_load_freq_history_view[cnt].cpu_min_locked_freq/1000000
216 , (cpu_load_freq_history_view[cnt].cpu_min_locked_freq/100000) % 10
217 , cpu_load_freq_history_view[cnt].cpu_max_locked_freq/1000000
218 , (cpu_load_freq_history_view[cnt].cpu_max_locked_freq/100000) %10
219 , cpu_load_freq_history_view[cnt].cpu_min_locked_online
220 , cpu_load_freq_history_view[cnt].cpu_max_locked_online
222 , cpu_load_freq_history_view[cnt].cpu_load[0]
223 , cpu_load_freq_history_view[cnt].cpu_load[1]
224 , cpu_load_freq_history_view[cnt].nr_onlinecpu
225 , cpu_load_freq_history_view[cnt].nr_run_avg/100
226 , cpu_load_freq_history_view[cnt].nr_run_avg%100);
234 #if defined(CONFIG_SLP_CHECK_BUS_LOAD)
236 char cpu_bus_load_freq_menu[] ="==============================" \
237 "===========================================" \
238 "============================================" \
239 "===========================================\n" \
240 " TIME STA CPU_F F_LOCK O_LOCK [INDEX] " \
241 "CPU0 ( C1/ C2/ C3) CPU1 ONLINE NR_RUN MIF_F MIF_L INT_F INT_L" \
242 " GPU_F GPU_UTIL INPUT\n";
245 unsigned int show_cpu_bus_load_freq_sub(int cnt, int show_cnt
246 , char *buf, unsigned int buf_size, int ret)
250 if ((cnt - show_cnt) < 0) {
251 delta = cnt - show_cnt;
252 cnt = cpu_load_history_num + delta;
256 if ((cnt+1 >= cpu_load_history_num)
257 || (cpu_load_freq_history_view[cnt+1].time == 0))
262 for (j = 0; j < show_cnt; j++) {
263 if (cnt > cpu_load_history_num-1)
266 ret += snprintf(buf + ret, buf_size - ret
267 , "%8s %c %d.%d %d.%d/%d.%d %d/%d [%5d] %3d (%3d/%3d/%3d) %3d "
268 "%3d %3d.%02d %3d %3d %3d %3d %3d %3d"
270 , cpu_load_freq_history_view[cnt].time
271 , cpu_load_freq_history_view[cnt].status
272 , cpu_load_freq_history_view[cnt].cpufreq[0]/1000000
273 , (cpu_load_freq_history_view[cnt].cpufreq[0]/100000) % 10
274 , cpu_load_freq_history_view[cnt].cpu_min_locked_freq/1000000
275 , (cpu_load_freq_history_view[cnt].cpu_min_locked_freq/100000) % 10
276 , cpu_load_freq_history_view[cnt].cpu_max_locked_freq/1000000
277 , (cpu_load_freq_history_view[cnt].cpu_max_locked_freq/100000) %10
278 , cpu_load_freq_history_view[cnt].cpu_min_locked_online
279 , cpu_load_freq_history_view[cnt].cpu_max_locked_online
281 , cpu_load_freq_history_view[cnt].cpu_load[0]
282 , cpu_load_freq_history_view[cnt].cpu_idle_time[0]/10
283 , cpu_load_freq_history_view[cnt].cpu_idle_time[1]/10
284 , cpu_load_freq_history_view[cnt].cpu_idle_time[2]/10
285 , cpu_load_freq_history_view[cnt].cpu_load[1]
286 , cpu_load_freq_history_view[cnt].nr_onlinecpu
287 , cpu_load_freq_history_view[cnt].nr_run_avg/100
288 , cpu_load_freq_history_view[cnt].nr_run_avg%100
289 , cpu_load_freq_history_view[cnt].mif_bus_freq/1000
290 , cpu_load_freq_history_view[cnt].mif_bus_load
291 , cpu_load_freq_history_view[cnt].int_bus_freq/1000
292 , cpu_load_freq_history_view[cnt].int_bus_load
293 , cpu_load_freq_history_view[cnt].gpu_freq
294 , cpu_load_freq_history_view[cnt].gpu_utilization
295 , cpu_load_freq_history_view[cnt].input_rec_history_cnt);
304 #if defined(CONFIG_SLP_BUS_CLK_CHECK_LOAD)
305 char cpu_bus_clk_load_freq_menu[] ="============================" \
306 "============================================" \
307 "============================================" \
308 "============================================" \
309 "============================================\n" \
310 " TIME STA CPU_F F_LOCK O_LOCK [INDEX] " \
311 "CPU0 ( C1/ C2/ C3) CPU1 ONLINE NR_RUN MIF_F MIF_L INT_F INT_L" \
312 " GPU_F GPU_UTIL INPUT" \
313 " PD CLK1 CLK2 CLK3 CLK4\n";
316 unsigned int show_cpu_bus_clk_load_freq_sub(int cnt
317 , int show_cnt, char *buf, int ret)
321 if ((cnt - show_cnt) < 0) {
322 delta = cnt - show_cnt;
323 cnt = cpu_load_history_num + delta;
327 if ((cnt+1 >= cpu_load_history_num)
328 || (cpu_load_freq_history_view[cnt+1].time == 0))
333 for (j = 0; j < show_cnt; j++) {
335 if (cnt > cpu_load_history_num-1)
338 if (ret < PAGE_SIZE - 1) {
339 ret += snprintf(buf + ret, PAGE_SIZE - ret
340 , "%8s %c %d.%d %d.%d/%d.%d %d/%d [%5d] %3d (%3d/%3d/%3d) %3d "
341 "%3d %3d.%02d %3d %3d %3d %3d %3d %3d"
342 " %5d %4X %8X %8X %8X %8X\n"
343 , cpu_load_freq_history_view[cnt].time
344 , cpu_load_freq_history_view[cnt].status
345 , cpu_load_freq_history_view[cnt].cpufreq[0]/1000000
346 , (cpu_load_freq_history_view[cnt].cpufreq[0]/100000) % 10
347 , cpu_load_freq_history_view[cnt].cpu_min_locked_freq/1000000
348 , (cpu_load_freq_history_view[cnt].cpu_min_locked_freq/100000) % 10
349 , cpu_load_freq_history_view[cnt].cpu_max_locked_freq/1000000
350 , (cpu_load_freq_history_view[cnt].cpu_max_locked_freq/100000) %10
351 , cpu_load_freq_history_view[cnt].cpu_min_locked_online
352 , cpu_load_freq_history_view[cnt].cpu_max_locked_online
354 , cpu_load_freq_history_view[cnt].cpu_load[0]
355 , cpu_load_freq_history_view[cnt].cpu_idle_time[0]/10
356 , cpu_load_freq_history_view[cnt].cpu_idle_time[1]/10
357 , cpu_load_freq_history_view[cnt].cpu_idle_time[2]/10
358 , cpu_load_freq_history_view[cnt].cpu_load[1]
359 , cpu_load_freq_history_view[cnt].nr_onlinecpu
360 , cpu_load_freq_history_view[cnt].nr_run_avg/100
361 , cpu_load_freq_history_view[cnt].nr_run_avg%100
362 , cpu_load_freq_history_view[cnt].mif_bus_freq/1000
363 , cpu_load_freq_history_view[cnt].mif_bus_load
364 , cpu_load_freq_history_view[cnt].int_bus_freq/1000
365 , cpu_load_freq_history_view[cnt].int_bus_load
366 , cpu_load_freq_history_view[cnt].gpu_freq
367 , cpu_load_freq_history_view[cnt].gpu_utilization
368 , cpu_load_freq_history_view[cnt].input_rec_history_cnt
369 , cpu_load_freq_history_view[cnt].power_domains[0]
370 , cpu_load_freq_history_view[cnt].clk_gates[0]
371 , cpu_load_freq_history_view[cnt].clk_gates[1]
372 , cpu_load_freq_history_view[cnt].clk_gates[2]
373 , cpu_load_freq_history_view[cnt].clk_gates[3]
385 #if defined(CONFIG_CHECK_NOT_CPUIDLE_CAUSE)
386 static int not_lpa_cause_check_sub(char *buf, int buf_size)
390 ret += snprintf(buf + ret, buf_size - ret, "%s\n", get_not_w_aftr_cause());
396 #if defined(CONFIG_SLP_CURRENT_MONITOR)
397 unsigned int show_current_monitor_read_sub(int cnt, int show_cnt
398 , char *buf, unsigned int buf_size, int ret)
402 if ((cnt - show_cnt) < 0) {
403 delta = cnt - show_cnt;
404 cnt = cpu_load_history_num + delta;
408 if ((cnt+1 >= cpu_load_history_num)
409 || (cpu_load_freq_history[cnt+1].time[0] == '\0'))
414 for (j = 0; j < show_cnt; j++) {
415 char task_name[TASK_COMM_LEN]={0,};
417 if (cnt > cpu_load_history_num-1)
420 get_name_from_pid(task_name, cpu_load_freq_history[cnt].pid);
422 ret += snprintf(buf + ret, PAGE_SIZE - ret
423 , "%10s %16s %5d %1c %3d %d.%d %d.%d %d.%d %d %3d %3d %3d %3d %3d"
424 " %3d.%02d %3d %3d %3d %3d %3d %3d %3d"
425 " %d %5d %5d %d %5d %5d\n"
426 , cpu_load_freq_history[cnt].time
428 , cpu_load_freq_history[cnt].suspend_count
429 , cpu_load_freq_history[cnt].status
430 , cpu_load_freq_history[cnt].battery_soc
431 , cpu_load_freq_history[cnt].cpufreq[0]/1000000
432 , (cpu_load_freq_history[cnt].cpufreq[0]/100000) % 10
433 , cpu_load_freq_history[cnt].cpu_min_locked_freq/1000000
434 , (cpu_load_freq_history[cnt].cpu_min_locked_freq/100000) % 10
435 , cpu_load_freq_history[cnt].cpu_max_locked_freq/1000000
436 , (cpu_load_freq_history[cnt].cpu_max_locked_freq/100000) %10
437 , cpu_load_freq_history[cnt].nr_onlinecpu
438 , cpu_load_freq_history[cnt].cpu_load[0]
439 , cpu_load_freq_history[cnt].cpu_idle_time[0]/10
440 , cpu_load_freq_history[cnt].cpu_idle_time[1]/10
441 , cpu_load_freq_history[cnt].cpu_idle_time[2]/10
442 , cpu_load_freq_history[cnt].cpu_load[1]
443 , cpu_load_freq_history[cnt].nr_run_avg/100
444 , cpu_load_freq_history[cnt].nr_run_avg%100
445 , cpu_load_freq_history[cnt].mif_bus_freq/1000
446 , cpu_load_freq_history[cnt].mif_bus_load
447 , cpu_load_freq_history[cnt].int_bus_freq/1000
448 , cpu_load_freq_history[cnt].int_bus_load
449 , cpu_load_freq_history[cnt].gpu_freq
450 , cpu_load_freq_history[cnt].gpu_utilization
451 , cpu_load_freq_history[cnt].lcd_brightness
452 , cpu_load_freq_history[cnt].bt_enabled
453 , cpu_load_freq_history[cnt].bt_tx_bytes
454 , cpu_load_freq_history[cnt].bt_rx_bytes
455 , cpu_load_freq_history[cnt].wifi_enabled
456 , cpu_load_freq_history[cnt].wifi_tx_bytes
457 , cpu_load_freq_history[cnt].wifi_rx_bytes);
468 #if defined (CONFIG_SLP_CPU_TESTER)
490 struct cpu_test_list_tag cpu_idletest_list[] = {
491 {CPU_IDLE_TEST, CPUIDLE_C1, 1000},
496 struct cpu_test_list_tag cpu_freqtest_list[] = {
497 {CPU_FREQ_TEST, CPUFREQ_1200M, 1000},
498 {CPU_FREQ_TEST, CPUFREQ_1100M, 1000},
499 {CPU_FREQ_TEST, CPUFREQ_1000M, 1000},
500 {CPU_FREQ_TEST, CPUFREQ_800M, 1000},
501 {CPU_FREQ_TEST, CPUFREQ_533M, 1000},
502 {CPU_FREQ_TEST, CPUFREQ_400M, 1000},
503 {CPU_FREQ_TEST, CPUFREQ_200M, 1000},
508 struct cpu_test_freq_table_tag cpu_test_freq_table[] = {
518 struct cpu_test_idle_table_tag cpu_test_idle_table[] ={
524 void set_cpufreq_force_state(int cpufreq_enum)
526 switch(cpufreq_enum) {
528 cpufreq_force_state = 1190400;
531 cpufreq_force_state = 1094400;
534 cpufreq_force_state = 998400;
537 cpufreq_force_state = 800000;
540 cpufreq_force_state = 533333;
543 cpufreq_force_state = 400000;
546 cpufreq_force_state = 200000;
554 int cpu_freq_to_enum(int cpufreq)
556 int cpufreq_enum = -1;
560 cpufreq_enum = CPUFREQ_1200M;
563 cpufreq_enum = CPUFREQ_1100M;
566 cpufreq_enum = CPUFREQ_1000M;
569 cpufreq_enum = CPUFREQ_800M;
572 cpufreq_enum = CPUFREQ_533M;
575 cpufreq_enum = CPUFREQ_400M;
578 cpufreq_enum = CPUFREQ_200M;
587 void cpu_tester_enum_to_str(char *str, int type, int enum_value)
589 if (type == CPU_FREQ_TEST) {
590 switch (enum_value) {
592 strcpy(str, "1.2Ghz");
595 strcpy(str, "1.1Ghz");
598 strcpy(str, "1.0Ghz");
601 strcpy(str, "800Mhz");
604 strcpy(str, "533Mhz");
607 strcpy(str, "400Mhz");
610 strcpy(str, "200Mhz");
613 strcpy(str, "RANDOM");
616 }else if (type == CPU_IDLE_TEST) {
617 switch (enum_value) {
628 strcpy(str, "RANDOM");
638 static int cpu_busy_gpu_usage = 200;
639 int gpu_load_checking(unsigned int cnt)
643 if ((cpu_load_freq_history[cnt].gpu_freq >= (133 * 1000000))
644 && (cpu_load_freq_history[cnt].gpu_utilization >= cpu_busy_gpu_usage)) {
651 int cpu_load_checking(unsigned int cnt)
653 int ret = NOT_BUSY_LOAD;
654 unsigned int high_cpufreq, high_usage;
656 high_cpufreq = cpu_load_freq_history[cnt].cpufreq[0];
657 high_usage = max(cpu_load_freq_history[cnt].cpu_load[0], cpu_load_freq_history[cnt].cpu_load[1]);
659 if ((high_cpufreq >= 1000000)
660 && (high_usage >= 90)) {
662 } else if (high_usage >= 99) {