Update from product codes
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / include / linux / load_analyzer.h
1
2 #ifndef _LINUX_SYSTEM_LOAD_ANALYZER_H
3 #define _LINUX_SYSTEM_LOAD_ANALYZER_H
4
5 #define CPU_NUM NR_CPUS
6
7
8 /*** FUNCTION OPTION ***/
9 #if defined(CONFIG_SLP_KERNEL_ENG)
10 #define CPU_LOAD_HISTORY_NUM    2000
11 #define CPU_TASK_HISTORY_NUM    30000
12 #else
13 #define CPU_LOAD_HISTORY_NUM    300
14 #define CPU_TASK_HISTORY_NUM    30
15 #endif
16
17
18 #define CONFIG_SLP_CHECK_BUS_LOAD       1
19 //#define CONFIG_SLP_CHECK_BUSY_LEVEL   1
20 //#define CONFIG_SLP_BUS_CLK_CHECK_LOAD 1
21 #define CONFIG_SLP_MINI_TRACER          1
22
23
24 #define CONFIG_SLP_CPU_TESTER           1
25
26 #define CONFIG_SLP_CHECK_RESOURCE       1
27
28 /*******************************************************/
29 #define CONFIG_CHECK_WORK_HISTORY       1
30 #if defined(CONFIG_SLP_KERNEL_ENG)
31 #define CPU_WORK_HISTORY_NUM    1000
32 #else
33 #define CPU_WORK_HISTORY_NUM    30
34 #endif
35 /********************************************************/
36
37 #if defined(CONFIG_SLP_KERNEL_ENG)
38 #define CONFIG_SLP_CURRENT_MONITOR      1
39 #endif
40 #define CONFIG_SLP_CHECK_PHY_ADDR       1
41 //#define CONFIG_CHECK_NOT_CPUIDLE_CAUSE        1
42 //#define CONFIG_CHECK_ENTER_AFTR               1
43 #define CONFIG_LOAD_ANALYZER_PMQOS      1
44 #define CONFIG_SLP_INPUT_REC            1
45 #define CONFIG_SLP_BUSY_LEVEL   1
46
47
48 /* You should choose one of them */
49 //#define CONFIG_SLP_MSM_BUS    1
50 #define CONFIG_SLP_EXYNOS_BUS   1
51
52
53 #if defined(CONFIG_SLP_EXYNOS_BUS)
54 #define PWR_DOMAINS_NUM 1
55 #define CLK_GATES_NUM           4
56 #elif defined(CONFIG_SLP_MSM_BUS)
57 #define PWR_DOMAINS_NUM 3
58 #define CLK_GATES_NUM           5
59 #else
60 #define PWR_DOMAINS_NUM 3
61 #define CLK_GATES_NUM           5
62 #endif
63
64
65 enum {
66         NR_RUNNING_TASK,
67         MIF_BUS_FREQ,
68         MIF_BUS_LOAD,
69         INT_BUS_FREQ,
70         INT_BUS_LOAD,
71         GPU_FREQ,
72         GPU_UTILIZATION,
73         BATTERY_SOC,
74         LCD_BRIGHTNESS,
75         ACTIVE_APP_PID,
76         SUSPEND_STATE,
77         SUSPEND_COUNT,
78 #ifdef CONFIG_SLP_CHECK_RESOURCE
79         CONN_BT_ENABLED,
80         CONN_BT_TX,
81         CONN_BT_RX,
82         CONN_WIFI_ENABLED,
83         CONN_WIFI_TX,
84         CONN_WIFI_RX,
85 #endif
86 };
87
88 struct saved_load_factor_tag {
89         unsigned int nr_running_task;
90         unsigned int mif_bus_freq;
91         unsigned int mif_bus_load;
92         unsigned int int_bus_freq;
93         unsigned int int_bus_load;
94         unsigned int gpu_freq;
95         unsigned int gpu_utilization;
96         unsigned int active_app_pid;
97         unsigned int battery_soc;
98         unsigned int lcd_brightness;
99         unsigned int suspend_state;
100         unsigned int suspend_count;
101 #ifdef CONFIG_SLP_CHECK_RESOURCE
102         unsigned int bt_tx_bytes;
103         unsigned int bt_rx_bytes;
104         unsigned int bt_enabled;
105         unsigned int wifi_tx_bytes;
106         unsigned int wifi_rx_bytes;
107         unsigned int wifi_enabled;
108 #endif
109 };
110
111 extern struct saved_load_factor_tag     saved_load_factor;
112
113 extern bool cpu_task_history_onoff;
114
115 extern int value_for_debug;
116
117 extern int current_monitor_en;
118
119 extern struct cpuidle_device *cpu_idle_dev;
120
121 extern int kernel_mini_tracer_i2c_log_on;
122
123 void cpu_print_buf_to_klog(char *buffer);
124
125 void store_external_load_factor(int type, unsigned int data);
126
127 void store_cpu_load(unsigned int cpufreq[], unsigned int cpu_load[]);
128
129 void cpu_load_touch_event(unsigned int event);
130
131 void __slp_store_task_history(unsigned int cpu, struct task_struct *task);
132
133 static inline void slp_store_task_history(unsigned int cpu
134                                         , struct task_struct *task)
135 {
136         __slp_store_task_history(cpu, task);
137 }
138
139 u64  get_load_analyzer_time(void);
140
141 void __slp_store_work_history(struct work_struct *work, work_func_t func
142                                                 , u64 start_time, u64 end_time);
143
144 void __slp_store_input_history(void *dev,
145                                unsigned int type, unsigned int code, int value);
146
147 void store_killed_task(struct task_struct *tsk);
148 int search_killed_task(unsigned int pid, char *task_name);
149
150 void cpu_last_load_freq(unsigned int range, int max_list_num);
151
152
153
154
155
156
157 #if defined(CONFIG_LOAD_ANALYZER_INTERNAL)
158
159 struct cpu_process_runtime_tag {
160         struct list_head list;
161         unsigned long long runtime;
162         struct task_struct *task;
163         unsigned int pid;
164         unsigned int cnt;
165         unsigned int usage;
166 };
167
168 #if defined (CONFIG_CHECK_WORK_HISTORY)
169 struct cpu_work_runtime_tag {
170         struct list_head list;
171         u64 start_time;
172         u64 end_time;
173         u64 occup_time;
174
175         struct task_struct *task;
176         unsigned int pid;
177         unsigned int cnt;
178
179         struct work_struct *work;
180         work_func_t func;
181 };
182 #endif
183
184 struct cpu_load_freq_history_tag {
185         char time[16];
186         unsigned long long time_stamp;
187         unsigned int cpufreq[CPU_NUM];
188         int cpu_max_locked_freq;
189         int cpu_min_locked_freq;
190         int cpu_max_locked_online;
191         int cpu_min_locked_online;
192
193         unsigned int cpu_load[CPU_NUM];
194         unsigned int cpu_idle_time[3];
195
196         unsigned int touch_event;
197         unsigned int nr_onlinecpu;
198         unsigned int nr_run_avg;
199         unsigned int task_history_cnt[CPU_NUM];
200         unsigned int gpu_freq;
201         unsigned int gpu_utilization;
202
203         char status;
204         unsigned int suspend_count;
205         unsigned int pid;
206         unsigned int battery_soc;
207         unsigned int lcd_brightness;
208 #if defined (CONFIG_CHECK_WORK_HISTORY)
209         unsigned int work_history_cnt[CPU_NUM];
210 #endif
211
212 //#if defined (CONFIG_SLP_INPUT_REC)
213         unsigned int input_rec_history_cnt;
214 //#endif
215
216 #if defined(CONFIG_SLP_CHECK_BUS_LOAD)
217
218 #if defined(CONFIG_SLP_EXYNOS_BUS)
219         unsigned int mif_bus_freq;
220         unsigned int mif_bus_load;
221         unsigned int int_bus_freq;
222         unsigned int int_bus_load;
223 #elif defined(CONFIG_SLP_MSM_BUS)
224         unsigned int bimc_clk;
225         unsigned int cnoc_clk;
226         unsigned int pnoc_clk;
227         unsigned int snoc_clk;
228 #endif
229 #endif
230
231 #if defined(CONFIG_SLP_BUS_CLK_CHECK_LOAD)
232         unsigned int power_domains[PWR_DOMAINS_NUM];
233         unsigned int clk_gates[CLK_GATES_NUM];
234 #endif
235 #if defined(CONFIG_SLP_CHECK_RESOURCE)
236         unsigned int bt_tx_bytes;
237         unsigned int bt_rx_bytes;
238         unsigned int bt_enabled;
239
240         unsigned int wifi_tx_bytes;
241         unsigned int wifi_rx_bytes;
242         unsigned int wifi_enabled;
243
244 /* for the 3G Models
245         unsigned int modem_tx_bytes;
246         unsigned int modem_rx_bytes;
247 */
248 #endif
249 };
250
251 struct cpu_task_history_tag {
252         unsigned long long time;
253         struct task_struct *task;
254         unsigned int pid;
255 };
256 static struct cpu_task_history_tag (*cpu_task_history)[CPU_NUM];
257 static struct cpu_task_history_tag       (*cpu_task_history_view)[CPU_NUM];
258 #define CPU_TASK_HISTORY_SIZE   (sizeof(struct cpu_task_history_tag) \
259                                         * cpu_task_history_num * CPU_NUM)
260
261
262 unsigned int show_cpu_load_freq_sub(int cnt, int show_cnt, char *buf, unsigned int buf_size, int ret);
263
264 extern char cpu_load_freq_menu[];
265
266 #if defined(CONFIG_SLP_CHECK_BUS_LOAD)
267 extern char cpu_bus_load_freq_menu[];
268 unsigned int show_cpu_bus_load_freq_sub(int cnt, int show_cnt
269                                         , char *buf, unsigned int buf_size, int ret);
270 #endif
271
272 #if defined(CONFIG_SLP_BUS_CLK_CHECK_LOAD)
273 extern char cpu_bus_clk_load_freq_menu[];
274 unsigned int show_cpu_bus_clk_load_freq_sub(int cnt
275                                         , int show_cnt, char *buf, int ret);
276 #endif
277
278
279
280 /******** +CONFIG_SLP_CURRENT_MONITOR+  ********/
281
282 #if defined (CONFIG_SLP_CURRENT_MONITOR)
283 void current_monitor_manager(int cnt);
284 unsigned int show_current_monitor_read_sub(int cnt, int show_cnt
285                                         , char *buf, unsigned int buf_size, int ret);
286 #endif
287 /******** -CONFIG_SLP_CURRENT_MONITOR- ********/
288
289
290
291
292 /******** +CONFIG_CHECK_NOT_CPUIDLE_CAUSE+  ********/
293 #if defined(CONFIG_CHECK_NOT_CPUIDLE_CAUSE)
294 static ssize_t not_lpa_cause_check(struct file *file,
295                         char __user *buffer, size_t count, loff_t *ppos);
296 static int not_lpa_cause_check_sub(char *buf, int buf_size);
297 #endif
298 /******** -CONFIG_CHECK_NOT_CPUIDLE_CAUSE- ********/
299
300
301
302
303 /******** +CONFIG_CHECK_WORK_HISTORY+  ********/
304 #if defined (CONFIG_CHECK_WORK_HISTORY)
305 struct cpu_work_history_tag {
306         u64 start_time;
307         u64 end_time;
308 //      u64 occup_time;
309
310         struct task_struct *task;
311         unsigned int pid;
312         struct work_struct *work;
313         work_func_t     func;
314 };
315
316 #define CPU_WORK_HISTORY_SIZE   (sizeof(struct cpu_work_history_tag) \
317                                         * cpu_work_history_num * CPU_NUM)
318
319 static unsigned int  cpu_work_history_cnt[CPU_NUM];
320 static struct cpu_work_history_tag (*cpu_work_history)[CPU_NUM];
321 static struct cpu_work_history_tag       (*cpu_work_history_view)[CPU_NUM];
322 unsigned int cpu_work_history_num = CPU_WORK_HISTORY_NUM;
323 static unsigned int  cpu_work_history_show_start_cnt;
324 static unsigned int  cpu_work_history_show_end_cnt;
325 static  int  cpu_work_history_show_select_cpu;
326
327 static struct list_head work_headlist;
328
329 bool cpu_work_history_onoff;
330 #endif
331 /******** -CONFIG_CHECK_WORK_HISTORY- ********/
332
333
334 /******** +CONFIG_SLP_INPUT_REC+  ********/
335 #if defined (CONFIG_SLP_INPUT_REC)
336 #if defined(CONFIG_SLP_KERNEL_ENG)
337 #define INPUT_REC_HISTORY_NUM   20000
338 #else
339 #define INPUT_REC_HISTORY_NUM   20
340 #endif
341 #define MAX_INPUT_DEVICES       256
342
343 struct input_rec_history_tag {
344         u64 time;
345         struct input_dev *dev;
346         unsigned int type;
347         unsigned int code;
348         int value;
349 };
350
351 #define MAX_INPUT_DEV_NAME_LEN  64
352 struct input_dev_info_tag {
353         struct input_dev *dev;
354         char name[MAX_INPUT_DEV_NAME_LEN];
355 };
356
357
358 unsigned int input_rec_history_num = INPUT_REC_HISTORY_NUM;
359 #define INPUT_REC_HISTORY_SIZE  (sizeof(struct input_rec_history_tag) \
360                                         * input_rec_history_num)
361
362 static unsigned int  input_rec_history_cnt;
363 static struct input_rec_history_tag (*input_rec_history);
364 static struct input_rec_history_tag (*input_rec_history_view);
365 static unsigned int  input_rec_history_show_start_cnt;
366 static unsigned int  input_rec_history_show_end_cnt;
367 static  int  input_rec_history_show_select_cpu;
368 bool input_rec_history_onoff;
369 int b_input_load_data;
370 int input_dev_info_current_num;
371 unsigned int input_dev_info_saved_num;
372 struct input_dev_info_tag input_dev_info_current[MAX_INPUT_DEVICES];
373 struct input_dev_info_tag input_dev_info_saved[MAX_INPUT_DEVICES];
374
375 struct input_dev * input_rec_change_dev(struct input_dev *old_dev);
376 #endif
377 /******** -CONFIG_SLP_INPUT_REC- ********/
378
379
380 #endif /* end of CONFIG_LOAD_ANALYZER_INTERNAL */
381
382
383 /******** +CONFIG_SLP_MINI_TRACER+  ********/
384 #if defined(CONFIG_SLP_MINI_TRACER)
385
386 #define TIME_ON         (1 << 0)
387 #define FLUSH_CACHE     (1 << 1)
388
389 void kernel_mini_tracer(char *input_string, int option);
390 void kernel_mini_tracer_smp(char *input_string);
391 #define mini_trace_log {  \
392         char str[64];   \
393         sprintf(str, "%s %d\n", __FUNCTION__, __LINE__); \
394         kernel_mini_tracer(str, TIME_ON | FLUSH_CACHE); \
395 }
396 #else
397 #define mini_trace_log
398 #endif
399 /******** -CONFIG_SLP_MINI_TRACER- ********/
400
401
402 /******** +CONFIG_SLP_CPU_TESTER+ ********/
403 #if defined (CONFIG_SLP_CPU_TESTER)
404 #define CPU_TEST_START_TIME     50 /* 50 sec after boot */
405
406
407 enum {
408         CPU_IDLE_TEST,
409         CPU_FREQ_TEST,
410         END_OF_LIST,
411 };
412
413 struct cpu_test_list_tag {
414         int test_item;
415         int setting_value;
416         int test_time;   /* ms */
417         unsigned int test_cnt;
418 };
419
420
421 struct cpu_test_freq_table_tag {
422         int cpufreq;
423         int enter_count;
424         int exit_count;
425 };
426
427 struct cpu_test_idle_table_tag {
428         int cpuidle;
429         int enter_count;
430         int exit_count;
431 };
432
433 extern struct cpu_test_freq_table_tag cpu_test_freq_table[];
434 extern struct cpu_test_idle_table_tag cpu_test_idle_table[];
435
436 extern int cpu_tester_en;
437 extern int cpufreq_tester_en;
438 extern int cpuidle_tester_en;
439
440 extern int cpu_idle_trace_en;
441 extern int cpufreq_force_state;
442
443 int cpu_freq_to_enum(int cpufreq);
444 int cpuidle_force_set(int *force_state, int next_state);
445 int cpufreq_force_set(int *force_state, int target_freq);
446 void set_cpufreq_force_state(int cpufreq_enum);
447 #endif
448
449
450 /******** +CONFIG_SLP_BUSY_LEVEL+ ********/
451 #if defined (CONFIG_SLP_BUSY_LEVEL)
452 enum {
453         BUSY_LOAD,
454         NOT_BUSY_LOAD,
455         GPU_VERY_BUSY_LOAD,
456 };
457
458 extern int cpu_busy_level;
459 int la_get_cpu_busy_level(void);
460 void la_set_cpu_busy_level(int set_cpu_busy_level);
461 int check_load_level(unsigned int current_cnt);
462 #endif
463
464
465 #endif