• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Decription: cmdmonitor function declaration
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  */
14 #ifndef CMD_MONITOR_H
15 #define CMD_MONITOR_H
16 
17 #include "tzdebug.h"
18 #include "teek_ns_client.h"
19 #include "smc_smp.h"
20 #include <linux/version.h>
21 
22 #if (KERNEL_VERSION(4, 14, 0) > LINUX_VERSION_CODE)
23 #define TASK_COMM_LEN 16
24 #endif
25 
26 enum {
27 	TYPE_CRASH_TEE = 1,
28 	TYPE_CRASH_TA = 2,
29 	TYPE_KILLED_TA = 3,
30 };
31 
32 /*
33  * when cmd execute more than 25s in tee,
34  * it will be terminated when CA is killed
35  */
36 #define CMD_MAX_EXECUTE_TIME 10U
37 #define S_TO_MS 1000
38 #define S_TO_US 1000000
39 
40 struct time_spec {
41 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0))
42 	struct timespec ts;
43 #else
44 	struct timespec64 ts;
45 #endif
46 };
47 
48 struct cmd_monitor {
49 	struct list_head list;
50 	struct time_spec sendtime;
51 	struct time_spec lasttime;
52 	int32_t timer_index;
53 	int count;
54 	bool returned;
55 	bool is_reported;
56 	pid_t pid;
57 	pid_t tid;
58 	char pname[TASK_COMM_LEN];
59 	char tname[TASK_COMM_LEN];
60 	unsigned int lastcmdid;
61 	long long timetotal;
62 	int agent_call_count;
63 };
64 
65 struct cmd_monitor *cmd_monitor_log(const struct tc_ns_smc_cmd *cmd);
66 void cmd_monitor_reset_context(void);
67 void cmd_monitor_logend(struct cmd_monitor *item);
68 void init_cmd_monitor(void);
69 void free_cmd_monitor(void);
70 void do_cmd_need_archivelog(void);
71 bool is_thread_reported(pid_t tid);
72 void tzdebug_archivelog(void);
73 void cmd_monitor_ta_crash(int32_t type, const uint8_t *ta_uuid, uint32_t uuid_len);
74 void tzdebug_memstat(void);
75 void get_time_spec(struct time_spec *time);
76 #endif
77