4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @desc proc common process
25 #ifndef __PROC_COMMON_H__
26 #define __PROC_COMMON_H__
32 #include "resourced.h"
34 #include "memory-cgroup.h"
35 #include "cpu-sched-common.h"
39 #endif /* __cplusplus */
41 #define RUNTIME_APP_INFO_DIR RUNTIME_RESOURCED_DIR"/appinfo"
43 #define GPOINTER_TO_PID(x) (pid_t)GPOINTER_TO_INT((x))
44 #define PID_TO_GPOINTER(x) GINT_TO_POINTER((pid_t)(x))
46 typedef GSList *pid_list;
50 PROC_ACTION_RECLAIM = 2,
51 PROC_ACTION_BROADCAST = 4,
53 PROC_ACTION_IGNORE = 8,
55 PROC_ACTION_REBOOT = 16,
63 struct proc_conf_info {
64 char name[MAX_NAME_LENGTH];
65 enum cgroup_type mem_type; /* fixed memory cgroup */
66 enum cgroup_type cpu_type; /* fixed cpu cgroup */
67 enum proc_action watchdog_action; /* watchdog action */
68 enum proc_action fail_action; /* release action */
69 struct mem_action mem_action;
70 struct cpu_sched_info cpu_sched_info;
74 enum application_type {
87 PROC_STATE_FOREGROUND,
88 PROC_STATE_BACKGROUND,
89 PROC_STATE_SUSPEND_READY,
96 struct proc_app_info *pai;
97 struct proc_conf_info *pci;
101 struct proc_limit_status {
102 struct proc_status ps;
103 unsigned long limit_bytes;
104 enum proc_action action;
107 enum proc_exclude_type {
117 enum proc_prelaunch_flags {
119 PROC_LARGEMEMORY = 0x01u, /* for mark large memory */
120 PROC_SIGTERM = 0x02u, /* for make killer kill victim by SIGTERM */
121 PROC_WEBAPP = 0x04u, /* for checking webapp */
122 PROC_DOWNLOADAPP = 0x08u, /* for monitoring disk usage about downloadable app */
123 PROC_SERVICEAPP = 0x10u, /* for distinguishing service app and ui app */
124 PROC_CGROUP_HIGH_ATTRIBUTE = 0x20u, /* for providing High level about MDM app */
125 PROC_BGALLOW = 0x100u, /* for allowing background application */
126 PROC_BGCTRL_PLATFORM = 0x200u, /* for controlling background application by appfw */
127 PROC_BGCTRL_APP = 0x400u, /* for checking old version application */
131 * BG categories in TIZEN 2.4
132 * Media : Playing audio, recoding, and streaming video in background
133 * Download : Downloading data with the Tizen download-manager API
134 * Background network : Processing general network operation
135 * in background (Sync-manager, IM / VOIP)
136 * Location: Processing location data in background
137 * Sensor : Processing context data from the sensors
138 * such as gesture, health (product)
139 * IOT communition & connectivity : Communicating between external
140 * devices in background such as WIFI, BT, SAP (only product)
141 * System : hidden category for system applications like home
143 enum proc_background_category {
146 PROC_BG_DOWNLOAD = 0x2,
147 PROC_BG_NETWORK = 0x4,
148 PROC_BG_LOCATION = 0x8,
149 PROC_BG_SENSOR = 0x10,
151 PROC_BG_SYSTEM = 0x40,
154 enum proc_lru_state {
155 PROC_FOREGROUND = -1,
160 PROC_FAVORITE_LRU_MAX = 35,
164 enum cgroup_cmd_type { /** cgroup command type **/
165 PROC_CGROUP_SET_FOREGRD,
166 PROC_CGROUP_SET_ACTIVE,
167 PROC_CGROUP_SET_BACKGRD,
168 PROC_CGROUP_SET_INACTIVE,
169 PROC_CGROUP_SET_LAUNCH_REQUEST,
170 PROC_CGROUP_SET_RESUME_REQUEST,
171 PROC_CGROUP_SET_TERMINATE_REQUEST,
172 PROC_CGROUP_SET_SERVICE_REQUEST,
173 PROC_CGROUP_SET_NOTI_REQUEST,
174 PROC_CGROUP_SET_PROC_EXCLUDE_REQUEST,
175 PROC_CGROUP_GET_MEMSWEEP,
176 PROC_CGROUP_SET_TERMINATED,
177 PROC_CGROUP_SET_SYSTEM_SERVICE,
178 PROC_CGROUP_GET_CMDLINE,
180 PROC_CGROUP_GET_STAT,
181 PROC_CGROUP_GET_STATUS,
182 PROC_CGROUP_GET_OOMSCORE,
183 PROC_CGROUP_GET_PGID_CMDLINE,
186 struct proc_exclude {
188 enum proc_exclude_type type;
191 struct proc_program_info {
197 struct proc_memory_state {
198 struct memcg_info *memcg_info;
203 bool memlimit_update_exclude;
206 struct proc_app_info {
210 bool app_watchdog_exclude;
211 bool app_memcg_update_exclude;
212 bool app_cpucg_update_exclude;
213 bool app_cpu_nice_update_exclude;
218 enum proc_state state;
219 enum application_type type;
220 struct resourced_appinfo *ai;
221 struct proc_program_info *program;
222 struct proc_memory_state memory;
223 unsigned long starttime;
225 unsigned long last_thaw_time; // in seconds since boot
229 //int proc_priority_set_fixed(void *data);
230 int proc_get_freezer_status(void);
232 struct proc_app_info *find_app_info(const pid_t pid);
233 struct proc_app_info *find_app_info_by_appid(const char *appid);
235 int proc_get_id_info(struct proc_status *ps, char **app_name, char **pkg_name);
238 * @desc set memory field in proc_app_info sturcture of selected pai, the data
239 * are used by lowmem module.
242 void proc_set_process_memory_state(struct proc_app_info *pai,
243 int memcg_idx, struct memcg_info *memcg_info, int oom_score_adj);
245 int proc_get_appflag(const pid_t pid);
247 static inline int equal_name_info(const char *id_a, const char *id_b)
249 return !strncmp(id_a, id_b, strlen(id_b)+1);
252 int proc_get_svc_state(struct proc_program_info *ppi);
254 bool proc_check_lru_suspend(int val, int lru);
256 enum proc_state proc_check_suspend_state(struct proc_app_info *pai);
258 GSList *proc_app_list_open(void);
259 void proc_app_list_close(void);
261 #define PAL_INIT_VALUE (GSList*)-1
263 static inline void cleanup_proc_app_list_close_func(GSList **l)
265 if (*l != PAL_INIT_VALUE)
266 proc_app_list_close();
269 #define _cleanup_app_list_close_ __attribute__((cleanup(cleanup_proc_app_list_close_func)))
272 * @desc Check whether this process is OOM-fixed app or not
273 * @param[in] pid Process ID
274 * @return 1 if it is OOM-fixed app. Else, 0
276 //int proc_priority_is_oom_fixed_process(int pid);
279 * @desc Check whether this process is cpu cgroup fixed app or not
280 * @param[in] pid Process ID
281 * @return 1 if it is cpu cgroup fixed app. Else, 0
283 //int proc_priority_is_cpu_cgroup_fixed_process(int pid);
285 void fixed_app_and_service_list_init(void);
286 void fixed_app_and_service_list_exit(void);
287 void fixed_app_list_insert(struct proc_conf_info *pci);
288 void fixed_service_list_insert(struct proc_conf_info *pci);
289 void fixed_limit_pid_list_insert(pid_t pid, void *value);
290 void fixed_limit_pid_list_remove(pid_t pid);
291 GHashTable* fixed_app_list_get(void);
292 GHashTable * fixed_service_list_get(void);
293 struct proc_conf_info* fixed_app_and_service_exist_check(const char *name, enum proc_type proc_type);
294 enum proc_action fixed_app_and_service_watchdog_action(const char *name, enum proc_type proc_type);
298 #endif /* __cplusplus */
300 #endif /* __PROC_COMMON_H__ */