162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2022 Huawei Technologies Co., Ltd. All rights reserved.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef DFX_HUNGTASK_BASE_H
762306a36Sopenharmony_ci#define DFX_HUNGTASK_BASE_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/list.h>
1062306a36Sopenharmony_ci#include <linux/sched.h>
1162306a36Sopenharmony_ci#include <linux/types.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#define ENABLE_SHOW_LEN 8
1462306a36Sopenharmony_ci#define WHITELIST_STORE_LEN 400
1562306a36Sopenharmony_ci#define WHITELIST_LEN 61
1662306a36Sopenharmony_ci#define WHITE_LIST 1
1762306a36Sopenharmony_ci#define BLACK_LIST 2
1862306a36Sopenharmony_ci#define HT_ENABLE 1
1962306a36Sopenharmony_ci#define HT_DISABLE 0
2062306a36Sopenharmony_ci#define HEARTBEAT_TIME 3
2162306a36Sopenharmony_ci#define MAX_LOOP_NUM (CONFIG_DEFAULT_HUNG_TASK_TIMEOUT / HEARTBEAT_TIME)
2262306a36Sopenharmony_ci#define ONE_MINUTE (60 / HEARTBEAT_TIME)
2362306a36Sopenharmony_ci#define ONE_AND_HALF_MINUTE (90 / HEARTBEAT_TIME)
2462306a36Sopenharmony_ci#define TWO_MINUTES (120 / HEARTBEAT_TIME)
2562306a36Sopenharmony_ci#define THREE_MINUTES (180 / HEARTBEAT_TIME)
2662306a36Sopenharmony_ci#define TWENTY_SECONDS (21 / HEARTBEAT_TIME)
2762306a36Sopenharmony_ci#define THIRTY_SECONDS (30 / HEARTBEAT_TIME)
2862306a36Sopenharmony_ci#define HUNG_ONE_HOUR (3600 / HEARTBEAT_TIME)
2962306a36Sopenharmony_ci#define HUNG_TEN_MINUTES (600 / HEARTBEAT_TIME)
3062306a36Sopenharmony_ci#define HUNGTASK_REPORT_TIMECOST TWENTY_SECONDS
3162306a36Sopenharmony_ci#define HT_DUMP_IN_PANIC_LOOSE 5
3262306a36Sopenharmony_ci#define HT_DUMP_IN_PANIC_STRICT 2
3362306a36Sopenharmony_ci#define REFRESH_INTERVAL THREE_MINUTES
3462306a36Sopenharmony_ci#define FLAG_DUMP_WHITE (1 << 0)
3562306a36Sopenharmony_ci#define FLAG_DUMP_APP (1 << 1)
3662306a36Sopenharmony_ci#define FLAG_DUMP_NOSCHEDULE (1 << 2)
3762306a36Sopenharmony_ci#define FLAG_DUMP_JANK (1 << 3)
3862306a36Sopenharmony_ci#define FLAG_PANIC (1 << 4)
3962306a36Sopenharmony_ci#define FLAG_PF_FROZEN (1 << 6)
4062306a36Sopenharmony_ci#define TASK_TYPE_IGNORE 0
4162306a36Sopenharmony_ci#define TASK_TYPE_WHITE (1 << 0)
4262306a36Sopenharmony_ci#define TASK_TYPE_APP (1 << 1)
4362306a36Sopenharmony_ci#define TASK_TYPE_JANK (1 << 2)
4462306a36Sopenharmony_ci#define TASK_TYPE_KERNEL (1 << 3)
4562306a36Sopenharmony_ci#define TASK_TYPE_NATIVE (1 << 4)
4662306a36Sopenharmony_ci#define TASK_TYPE_FROZEN (1 << 6)
4762306a36Sopenharmony_ci#define PID_INIT 1
4862306a36Sopenharmony_ci#define PID_KTHREAD 2
4962306a36Sopenharmony_ci#define DEFAULT_WHITE_DUMP_CNT MAX_LOOP_NUM
5062306a36Sopenharmony_ci#define DEFAULT_WHITE_PANIC_CNT MAX_LOOP_NUM
5162306a36Sopenharmony_ci#define HUNG_TASK_UPLOAD_ONCE 1
5262306a36Sopenharmony_ci#define FROZEN_BUF_LEN 1024
5362306a36Sopenharmony_ci#define MAX_REMOVE_LIST_NUM 200
5462306a36Sopenharmony_ci#define HUNGTASK_DOMAIN "KERNEL_VENDOR"
5562306a36Sopenharmony_ci#define HUNGTASK_NAME "HUNGTASK"
5662306a36Sopenharmony_ci#define INIT_FREEZE_NAME "INIT_FREEZE"
5762306a36Sopenharmony_ci#define HUNG_TASK_BATCHING 1024
5862306a36Sopenharmony_ci#define TIME_REFRESH_PIDS 20
5962306a36Sopenharmony_ci#define PID_ERROR (-1)
6062306a36Sopenharmony_ci#define HUNGTASK_EVENT_WHITELIST 1
6162306a36Sopenharmony_ci#define REPORT_MSGLENGTH 200
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cistruct task_item {
6462306a36Sopenharmony_ci	struct rb_node node;
6562306a36Sopenharmony_ci	pid_t pid;
6662306a36Sopenharmony_ci	pid_t tgid;
6762306a36Sopenharmony_ci	char name[TASK_COMM_LEN + 1];
6862306a36Sopenharmony_ci	unsigned long switch_count;
6962306a36Sopenharmony_ci	unsigned int task_type;
7062306a36Sopenharmony_ci	int dump_wa;
7162306a36Sopenharmony_ci	int panic_wa;
7262306a36Sopenharmony_ci	int dump_jank;
7362306a36Sopenharmony_ci	int d_state_time;
7462306a36Sopenharmony_ci	bool isdone_wa;
7562306a36Sopenharmony_ci};
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistruct hashlist_node {
7862306a36Sopenharmony_ci	pid_t pid;
7962306a36Sopenharmony_ci	struct hlist_node list;
8062306a36Sopenharmony_ci};
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cistruct whitelist_item {
8362306a36Sopenharmony_ci	pid_t pid;
8462306a36Sopenharmony_ci	char name[TASK_COMM_LEN + 1];
8562306a36Sopenharmony_ci};
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_cistruct task_hung_upload {
8862306a36Sopenharmony_ci	char name[TASK_COMM_LEN + 1];
8962306a36Sopenharmony_ci	pid_t pid;
9062306a36Sopenharmony_ci	pid_t tgid;
9162306a36Sopenharmony_ci	unsigned int flag;
9262306a36Sopenharmony_ci	int duration;
9362306a36Sopenharmony_ci};
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciextern unsigned long sysctl_hung_task_timeout_secs;
9662306a36Sopenharmony_ciextern unsigned int sysctl_hung_task_panic;
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_civoid do_dump_task(struct task_struct *task);
9962306a36Sopenharmony_ciint dump_task_wa(struct task_item *item, int dump_cnt,
10062306a36Sopenharmony_ci		 struct task_struct *task, unsigned int flag);
10162306a36Sopenharmony_civoid do_show_task(struct task_struct *task, unsigned int flag, int d_state_time);
10262306a36Sopenharmony_civoid hungtask_show_state_filter(unsigned long state_filter);
10362306a36Sopenharmony_ciint htbase_create_sysfs(void);
10462306a36Sopenharmony_civoid htbase_set_panic(int new_did_panic);
10562306a36Sopenharmony_civoid htbase_set_timeout_secs(unsigned long new_hungtask_timeout_secs);
10662306a36Sopenharmony_civoid htbase_check_tasks(unsigned long timeout);
10762306a36Sopenharmony_cibool hashlist_find(struct hlist_head *head, int count, pid_t tgid);
10862306a36Sopenharmony_civoid hashlist_clear(struct hlist_head *head, int count);
10962306a36Sopenharmony_cibool hashlist_insert(struct hlist_head *head, int count, pid_t tgid);
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci#endif /* DFX_HUNGTASK_BASE_H */
112