util: kernel: Add check whether taskstats is supported
[platform/core/system/pass.git] / include / util / kernel.h
1 /*
2  * PASS
3  *
4  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifndef __KERNEL_H__
20 #define __KERNEL_H__
21
22 #include <glib.h>
23 #include <linux/taskstats.h>
24 #include "common.h"
25
26 struct cpu_stat {
27         char name[10];
28         unsigned int cpu;
29         int64_t user;
30         int64_t system;
31         int64_t nice;
32         int64_t idle;
33         int64_t wait;
34         int64_t hard_irq;
35         int64_t soft_irq;
36 };
37
38 struct proc_map_info {
39         uint32_t rss;
40         uint32_t pss;
41         uint32_t swap;
42         uint32_t swap_pss;
43         uint32_t gpu_mem;
44 };
45
46 enum {
47         PROCESS_STAT_FIELD_PID,
48         PROCESS_STAT_FIELD_COMM,
49         PROCESS_STAT_FIELD_STATE,
50         PROCESS_STAT_FIELD_PPID,
51         PROCESS_STAT_FIELD_PGID,
52         PROCESS_STAT_FIELD_MAX,
53 };
54
55 int kernel_get_online_cpu_num(void);
56 int kernel_get_possible_cpu_num(void);
57
58 int kernel_get_total_cpu_stat(struct cpu_stat *total);
59 int kernel_get_per_cpu_stat(struct cpu_stat *cpus, int num_possible_cpus,
60                             int *num_online_cpus);
61
62 int kernel_get_memory_info(const char *key, u_int64_t *val);
63 int kernel_get_memory_total(u_int64_t *val);
64
65 int kernel_get_process_stat_fields(pid_t pid, char *buffer, int buf_len,
66                                    char *stat_fields[PROCESS_STAT_FIELD_MAX]);
67 int kernel_get_process_taskstats(struct taskstats *stats, int cmd_type, pid_t pid);
68 int kernel_get_thread_group_taskstats(struct taskstats *stats, pid_t tgid, bool get_proc_info);
69 int
70 kernel_get_thread_group_map_info(struct proc_map_info *map_info, pid_t tgid, bool include_gpu_mem);
71 bool kernel_check_gpu_support(void);
72 bool kernel_check_taskstat_support(void);
73 #endif