plugin-api: resourced: Add window info into 'task_info' for LMK governor
[platform/core/system/libsyscommon.git] / src / plugin-api / resourced / include / syscommon-plugin-resourced-memory-lmk.h
1 /**
2  * MIT License
3  *
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is furnished
11  * to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24
25 #ifndef __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__
26 #define __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__
27
28 #include <glib.h>
29 #include <stdbool.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 struct task_info {
36         /*
37          * Mostly, there are not multiple processes with the same pgid.
38          * So, for the frequent case, we use pid variable to avoid
39          * allocating arrays.
40          */
41         pid_t pid;
42         GArray *pids;
43         pid_t pgid;
44         /* oom_score_adj is smae as /proc/<pid>/oom_score_adj */
45         int oom_score_adj;
46         /*
47          * oom_score_lru is same as oom_score_adj or adjusted by
48          * proc_app_info lru_state for apps that are marked as favourite.
49          *
50          * oom_score_lru is the main value used in comparison for LMK.
51          */
52         int oom_score_lru;
53         int size;
54         /**
55          * proc_app_info_oom_killed and proc_app_info_flags
56          * are not used if task is not an app.
57          * Especially, proc_app_info_oom_killed is NULL when this task
58          * is not an app.
59          */
60         bool *proc_app_info_oom_killed;
61         int proc_app_info_flags;
62
63         /**
64          * TODO: A process can have more than one window,
65          * and an app can have more than one process. Therefore,
66          * a task_info can have more than one window.
67          */
68         int window_pid;
69         int x;
70         int y;
71         int z;
72         int w;
73         int h;
74         int layer;
75         int opaque;
76         int visibility;
77         bool is_transformed;
78         bool alpha;
79         bool is_focused;
80         bool is_mapped;
81 };
82
83 /**
84  * @brief Get the backend data of resourced-memory-lmk module
85  * @return @c 0 on success, otherwise a negative error value
86  */
87 int syscommon_plugin_resourced_memory_lmk_get_backend(void);
88
89 /**
90  * @brief Put the backend data of resourced-memory-lmk module
91  * @return @c 0 on success, otherwise a negative error value
92  */
93 int syscommon_plugin_resourced_memory_lmk_put_backend(void);
94
95 /**
96  * @brief Call the get_kill_candidates function of resourced-memory-lmk module
97  * @param[in] candidates is an an GArray to return kill candidates
98  * @param[in] task_info_app_array is a GArray that contains app info
99  * @param[in] task_info_proc_array is a GArray that contains process info
100  * @param[in] totalram_kb is the total amount of memory in kibibytes
101  * @return @c the number of kill candidates on success,
102  *            otherwise a negative error value
103  */
104 int syscommon_plugin_resourced_memory_lmk_get_kill_candidates(
105                                                 GArray *candidates,
106                                                 GArray *task_info_app_array,
107                                                 GArray *task_info_proc_array,
108                                                 unsigned long totalram_kb);
109
110 #ifdef __cplusplus
111 }
112 #endif
113
114 #endif /* __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__ */