1a1af00b5ff201a13188e07516a2d73ced08d2ae
[platform/core/system/resourced.git] / src / common / conf / config-parser.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2013 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
20 #ifndef __CONFIG_PARSER_H__
21 #define __CONFIG_PARSER_H__
22
23 #include <stdio.h>
24 #include <stdbool.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29
30
31 #define CONF_FILE_SUFFIX                    ".conf"
32
33 #define LIMITER_CONF_FILE                   RD_CONFIG_FILE(limiter)
34 #define OPTIMIZER_CONF_FILE                 RD_CONFIG_FILE(optimizer)
35 #define LIMITER_CONF_DIR                    RD_CONFIG_PATH"/limiter.conf.d"
36 #define OPTIMIZER_CONF_DIR                  RD_CONFIG_PATH"/optimizer.conf.d"
37 #define PROC_CONF_DIR                       RD_CONFIG_PATH"/process.conf.d"
38 /* old style */
39 #define VIP_CONF_DIR                        RD_CONFIG_PATH"/vip-process.d"
40
41 /* section name */
42 /* limiter.conf */
43 #define PRIVATE_SECTION                     "Private"
44 #define MEMORY_LEVEL_THRESHOLD_SECTION      "MemoryLevelThreshold"
45 #define MEMORY_APP_TYPE_LIMIT_SECTION       "MemoryAppTypeLimit"
46 #define MEMORY_APP_STATUS_LIMIT_SECTION     "MemoryAppStatusLimit"
47 #define MEMORY_BACKGROUND_LRU_SECTION       "MemoryBackgroundLru"
48 #define CPU_THROTTLING_SECTION              "CpuThrottling"
49 #define MEMORY_LIMIT_TRIGGER_SECTION        "MemoryLimitTrigger"
50 #define OLD_VIP_GROUP_SECTION               "VIP_GROUP"
51
52 /* optimizer.conf */
53 #define SWAP_SECTION                        "MemorySwap"
54 #define ZRAM_SECTION                        "MemoryZram"
55 #define ZSWAP_SECTION                       "MemoryZswap"
56 #define DEDUP_SECTION                       "MemoryDedup"
57 #define KSM_SECTION                         "MemoryKsm"
58 #define COMPACTION_SECTION                  "MemoryCompaction"
59 #define BACKGROUND_RECLAIM_SECTION          "MemoryBackgroundReclaim"
60 #define CPU_SCHED_SECTION                   "CpuSched"
61 #define CPU_AFFINITY_SECTION                "CpuAffinity"
62 #define CPU_BOOSTING_LEVEL_STRONG_SECTION   "CpuBoostingLevelStrong"
63 #define CPU_BOOSTING_LEVEL_MEDIUM_SECTION   "CpuBoostingLevelMedium"
64 #define CPU_BOOSTING_LEVEL_WEAK_SECTION     "CpuBoostingLevelWeak"
65
66 /* configuration name */
67 /* limiter.conf */
68 #define APP_NAME_CONF                                "App"
69 #define SERVICE_NAME_CONF                            "Service"
70 #define OLD_SERVICE_NAME_CONF                        "SERVICE"  /* old style */
71 #define PROCESS_NAME_CONF                            "Process"
72 #define OLD_PROCESS_NAME_CONF                        "PROCESS"  /* old style */
73 #define MEM_CGROUP_NAME_CONF                         "MemGroup"
74 #define MEM_LIMIT_ACTION_NAME_CONF                   "MemLimitAction"
75 #define ACTION_ON_FAILURE_NAME_CONF                  "ActionOnFailure"
76 #define OLD_ACTION_ON_FAILURE_NAME_CONF              "ACTION_ON_FAILURE"
77 #define WATCHDOG_ACTION_NAME_CONF                    "WatchdogAction"
78 #define OOM_SCORE_NAME_CONF                          "OomScore"
79 #define BACKGROUND_LRU_LIMIT_NAME_CONF               "BackgroundLruLimit"
80 #define MEDIUM_LEVEL_NAME_CONF                       "MediumLevel"
81 #define LOW_LEVEL_NAME_CONF                          "LowLevel"
82 #define CRITICAL_LEVEL_NAME_CONF                     "CriticalLevel"
83 #define OOM_LEVEL_NAME_CONF                          "OomLevel"
84 #define OOM_POPUP_NAME_CONF                          "OomPopup"
85 #define SERVICE_PER_APP_LIMIT_ACTION_NAME_CONF       "ServicePerAppLimitAction"
86 #define WIDGET_PER_APP_LIMIT_ACTION_NAME_CONF        "WidgetPerAppLimitAction"
87 #define GUI_PER_APP_LIMIT_ACTION_NAME_CONF           "GUIPerAppLimitAction"
88 #define BACKGROUND_PER_APP_LIMIT_ACTION_NAME_CONF    "BackgroundPerAppLimitAction"
89 #define MEMORY_LIMIT_TRIGGER_NAME_CONF               "MemoryLimitTrigger"
90 #define MEMORY_LMK_KILL_EXCEPTION_NAME_CONF          "LmkKillException"
91
92 /* CPU specific configuration name */
93 #define CPU_SCHED_NAME_CONF                          "CpuSched"
94 #define CPU_NICE_NAME_CONF                           "CpuNice"
95 #define CPU_SHARE_NAME_CONF                          "CpuShare"
96 #define CPU_RT_PRIORITY_NAME_CONF                    "CpuRTPriority"
97 #define CPU_SCHED_FEATURE_NAME_CONF                  "CpuSchedFeature"
98 #define CPU_RT_RUN_TIME_NAME_CONF                    "CpuRTRuntime"
99 #define CPU_RT_PERIOD_NAME_CONF                      "CpuRTPeriod"
100 #define CPU_CFS_RUN_TIME_NAME_CONF                   "CpuCFSRuntime"
101 #define CPU_CFS_PERIOD_NAME_CONF                     "CpuCFSPeriod"
102 #define CPU_BOOSTING_LEVEL_NAME_CONF                 "CpuBoostingLevel"
103 #define MEMORY_BACKGROUND_LRU_NAME_CONF              "MemoryBackgroundLru"
104 #define CPU_THROTTLING_NAME_CONF                     "CpuThrottling"
105
106 /* optimizer.conf */
107 #define SWAP_ENABLE_NAME_CONF                        "SwapEnable"
108 #define RECLAIM_AT_BOOT_NAME_CONF                    "ReclaimAtBoot"
109 #define SWAP_TYPE_NAME_CONF                          "SwapType"
110 #define BACKGROUND_LRU_SWAPPINESS_NAME_CONF          "BackgroundLruSwappiness"
111 #define COMP_ALGORITHM_NAME_CONF                     "CompAlgorithm"
112 #define ZRAM_RATIO_NAME_CONF                         "ZramRatio"
113 #define POOL_RATIO_NAME_CONF                         "PoolRatio"
114 #define POOL_TYPE_NAME_CONF                          "PoolType"
115 #define DEDUP_ENABLE_NAME_CONF                       "DedupEnable"
116 #define DEDUP_AT_BOOT_NAME_CONF                      "DedupAtBoot"
117 #define SCAN_ON_LOWMEM_NAME_CONF                     "ScanOnLowmem"
118 #define KSM_MODE_NAME_CONF                           "KsmMode"
119 #define PAGES_TO_SCAN_NAME_CONF                      "PagesToScan"
120 #define PAGES_TO_SCAN_WITH_BOOST_NAME_CONF           "PagesToScanWithBoost"
121 #define COMPACTION_ENABLE_NAME_CONF                  "CompactionEnable"
122 #define FRAG_LEVEL_NAME_CONF                         "FragLevel"
123 #define AFTER_SCREEN_DIM_CONF                        "AfterScreenDim"
124 #define FOREGROUND_APPS_NAME_CONF                    "ForegroundApps"
125 #define CPU_AFFINITY_NAME_CONF                       "CpuAffinity"
126
127 /* configuration value */
128 #define CGROUP_LOW_VALUE_CONF                        "lowest"
129 #define ACTION_BROADCAST_VALUE_CONF                  "broadcast"
130 #define ACTION_RECLAIM_VALUE_CONF                    "reclaim"
131 #define ACTION_KILL_VALUE_CONF                       "kill"
132 #define ACTION_REBOOT_VALUE_CONF                     "reboot"
133 #define ACTION_IGNORE_VALUE_CONF                     "ignore"
134
135 /* Memory specific configuration name */
136 #define MEMORY_LIMIT_TRIGGER_OOM_VALUE_CONF          "oom"
137 #define MEMORY_LIMIT_TRIGGER_THRESHOLD_VALUE_CONF    "threshold"
138
139 /* CPU specific configuration name */
140 #define RT_RUNTIME_SHARE_VALUE_CONF                  "rt_runtime_share"
141 #define NO_RT_RUNTIME_SHARE_VALUE_CONF               "no_rt_runtime_share"
142 #define CPU_SCHED_DEADLINE_VALUE_CONF                "deadline"
143 #define CPU_SCHED_FIFO_VALUE_CONF                    "fifo"
144 #define CPU_SCHED_RR_VALUE_CONF                      "rr"
145 #define CPU_SCHED_OTHER_VALUE_CONF                   "other"
146 #define CPU_SCHED_IDLE_VALUE_CONF                    "idle"
147 #define CPU_SCHED_BATCH_VALUE_CONF                   "batch"
148 #define CPU_BOOSTING_LEVEL_STRONG_VALUE_CONF         "strong"
149 #define CPU_BOOSTING_LEVEL_MEDIUM_VALUE_CONF         "medium"
150 #define CPU_BOOSTING_LEVEL_WEAK_VALUE_CONF           "weak"
151
152 #define MATCH(a, b)     (!strncmp(a, b, strlen(a) + 1) ? 1 : 0)
153 #define SET_CONF(a, b)  (a = (b > 0.0 ? b : a))
154
155 enum config_type {
156         LIMITER_CONFIG,
157         OPTIMIZER_CONFIG,
158         MONITOR_CONFIG,
159         PROCESS_CONFIG,
160         VIP_CONFIG, /* old style */
161 };
162
163 struct parse_result {
164         char *section;
165         char *name;
166         char *value;
167 };
168
169 /**
170  * @brief Parse config file and call callback\n
171  * @param[in] file_name conf file.
172  * @param[in] cb cb is called when conf file is parsed line by line.
173  * @param[in] user_data user data is passed to cb.
174  * @return 0 on success, negative if failed
175  */
176 int config_parse(const char *file_name, int cb(struct parse_result *result,
177                         void *user_data), void *user_data);
178
179 /* Prototype for a parser for a specific configuration setting */
180 typedef int (*ConfigParserCallback)(
181                 const char *filename,
182                 unsigned line,
183                 const char *section,
184                 const char *lvalue,
185                 int ltype,
186                 const char *rvalue,
187                 void *data);
188
189 typedef int (*ConfigParseFunc)(const char *path, void *data);
190
191 /* Wraps information for parsing a specific configuration variable, to
192  * be stored in a simple array */
193 typedef struct ConfigTableItem {
194         const char *section;            /* Section */
195         const char *lvalue;             /* Name of the variable */
196         ConfigParserCallback cb;        /* Function that is called to
197                                          * parse the variable's
198                                          * value */
199         int ltype;                      /* Distinguish different
200                                          * variables passed to the
201                                          * same callback */
202         void *data;                     /* Where to store the
203                                          * variable's data */
204 } ConfigTableItem;
205
206 void remove_app_conf_info_list(void);
207 void remove_service_conf_info_list(void);
208 GSList *get_app_conf_info_list(void);
209 GSList *get_service_conf_info_list(void);
210 void resourced_parse_vendor_configs(void);
211 void resourced_free_vendor_configs(void);
212 int cpu_sched_parse_cpuset(void *data, char *value);
213 #ifdef __cplusplus
214 }
215 #endif /* __cplusplus */
216
217 #endif