1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2022 Huawei Technologies Co., Ltd. All rights reserved.
4  */
5 
6 #ifndef DFX_HUNGTASK_BASE_H
7 #define DFX_HUNGTASK_BASE_H
8 
9 #include <linux/list.h>
10 #include <linux/sched.h>
11 #include <linux/types.h>
12 
13 #define ENABLE_SHOW_LEN 8
14 #define WHITELIST_STORE_LEN 400
15 #define WHITELIST_LEN 61
16 #define WHITE_LIST 1
17 #define BLACK_LIST 2
18 #define HT_ENABLE 1
19 #define HT_DISABLE 0
20 #define HEARTBEAT_TIME 3
21 #define MAX_LOOP_NUM (CONFIG_DEFAULT_HUNG_TASK_TIMEOUT / HEARTBEAT_TIME)
22 #define ONE_MINUTE (60 / HEARTBEAT_TIME)
23 #define ONE_AND_HALF_MINUTE (90 / HEARTBEAT_TIME)
24 #define TWO_MINUTES (120 / HEARTBEAT_TIME)
25 #define THREE_MINUTES (180 / HEARTBEAT_TIME)
26 #define TWENTY_SECONDS (21 / HEARTBEAT_TIME)
27 #define THIRTY_SECONDS (30 / HEARTBEAT_TIME)
28 #define HUNG_ONE_HOUR (3600 / HEARTBEAT_TIME)
29 #define HUNG_TEN_MINUTES (600 / HEARTBEAT_TIME)
30 #define HUNGTASK_REPORT_TIMECOST TWENTY_SECONDS
31 #define HT_DUMP_IN_PANIC_LOOSE 5
32 #define HT_DUMP_IN_PANIC_STRICT 2
33 #define REFRESH_INTERVAL THREE_MINUTES
34 #define FLAG_DUMP_WHITE (1 << 0)
35 #define FLAG_DUMP_APP (1 << 1)
36 #define FLAG_DUMP_NOSCHEDULE (1 << 2)
37 #define FLAG_DUMP_JANK (1 << 3)
38 #define FLAG_PANIC (1 << 4)
39 #define FLAG_PF_FROZEN (1 << 6)
40 #define TASK_TYPE_IGNORE 0
41 #define TASK_TYPE_WHITE (1 << 0)
42 #define TASK_TYPE_APP (1 << 1)
43 #define TASK_TYPE_JANK (1 << 2)
44 #define TASK_TYPE_KERNEL (1 << 3)
45 #define TASK_TYPE_NATIVE (1 << 4)
46 #define TASK_TYPE_FROZEN (1 << 6)
47 #define PID_INIT 1
48 #define PID_KTHREAD 2
49 #define DEFAULT_WHITE_DUMP_CNT MAX_LOOP_NUM
50 #define DEFAULT_WHITE_PANIC_CNT MAX_LOOP_NUM
51 #define HUNG_TASK_UPLOAD_ONCE 1
52 #define FROZEN_BUF_LEN 1024
53 #define MAX_REMOVE_LIST_NUM 200
54 #define HUNGTASK_DOMAIN "KERNEL_VENDOR"
55 #define HUNGTASK_NAME "HUNGTASK"
56 #define INIT_FREEZE_NAME "INIT_FREEZE"
57 #define HUNG_TASK_BATCHING 1024
58 #define TIME_REFRESH_PIDS 20
59 #define PID_ERROR (-1)
60 #define HUNGTASK_EVENT_WHITELIST 1
61 #define REPORT_MSGLENGTH 200
62 
63 struct task_item {
64 	struct rb_node node;
65 	pid_t pid;
66 	pid_t tgid;
67 	char name[TASK_COMM_LEN + 1];
68 	unsigned long switch_count;
69 	unsigned int task_type;
70 	int dump_wa;
71 	int panic_wa;
72 	int dump_jank;
73 	int d_state_time;
74 	bool isdone_wa;
75 };
76 
77 struct hashlist_node {
78 	pid_t pid;
79 	struct hlist_node list;
80 };
81 
82 struct whitelist_item {
83 	pid_t pid;
84 	char name[TASK_COMM_LEN + 1];
85 };
86 
87 struct task_hung_upload {
88 	char name[TASK_COMM_LEN + 1];
89 	pid_t pid;
90 	pid_t tgid;
91 	unsigned int flag;
92 	int duration;
93 };
94 
95 extern unsigned long sysctl_hung_task_timeout_secs;
96 extern unsigned int sysctl_hung_task_panic;
97 
98 void do_dump_task(struct task_struct *task);
99 int dump_task_wa(struct task_item *item, int dump_cnt,
100 		 struct task_struct *task, unsigned int flag);
101 void do_show_task(struct task_struct *task, unsigned int flag, int d_state_time);
102 void hungtask_show_state_filter(unsigned long state_filter);
103 int htbase_create_sysfs(void);
104 void htbase_set_panic(int new_did_panic);
105 void htbase_set_timeout_secs(unsigned long new_hungtask_timeout_secs);
106 void htbase_check_tasks(unsigned long timeout);
107 bool hashlist_find(struct hlist_head *head, int count, pid_t tgid);
108 void hashlist_clear(struct hlist_head *head, int count);
109 bool hashlist_insert(struct hlist_head *head, int count, pid_t tgid);
110 
111 #endif /* DFX_HUNGTASK_BASE_H */
112