4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
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.
20 #ifndef __CONFIG_PARSER_H__
21 #define __CONFIG_PARSER_H__
28 #endif /* __cplusplus */
31 #define CONF_FILE_SUFFIX ".conf"
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"
39 #define VIP_CONF_DIR RD_CONFIG_PATH"/vip-process.d"
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"
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"
66 /* configuration name */
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 #define MEMORY_LMK_THRESHOLD_LEAVE_NAME_CONF "LmkThresholdLeave"
93 /* CPU specific configuration name */
94 #define CPU_SCHED_NAME_CONF "CpuSched"
95 #define CPU_NICE_NAME_CONF "CpuNice"
96 #define CPU_SHARE_NAME_CONF "CpuShare"
97 #define CPU_RT_PRIORITY_NAME_CONF "CpuRTPriority"
98 #define CPU_SCHED_FEATURE_NAME_CONF "CpuSchedFeature"
99 #define CPU_RT_RUN_TIME_NAME_CONF "CpuRTRuntime"
100 #define CPU_RT_PERIOD_NAME_CONF "CpuRTPeriod"
101 #define CPU_CFS_RUN_TIME_NAME_CONF "CpuCFSRuntime"
102 #define CPU_CFS_PERIOD_NAME_CONF "CpuCFSPeriod"
103 #define CPU_BOOSTING_LEVEL_NAME_CONF "CpuBoostingLevel"
104 #define MEMORY_BACKGROUND_LRU_NAME_CONF "MemoryBackgroundLru"
105 #define CPU_THROTTLING_NAME_CONF "CpuThrottling"
108 #define SWAP_ENABLE_NAME_CONF "SwapEnable"
109 #define RECLAIM_AT_BOOT_NAME_CONF "ReclaimAtBoot"
110 #define SWAP_TYPE_NAME_CONF "SwapType"
111 #define BACKGROUND_LRU_SWAPPINESS_NAME_CONF "BackgroundLruSwappiness"
112 #define COMP_ALGORITHM_NAME_CONF "CompAlgorithm"
113 #define ZRAM_RATIO_NAME_CONF "ZramRatio"
114 #define POOL_RATIO_NAME_CONF "PoolRatio"
115 #define POOL_TYPE_NAME_CONF "PoolType"
116 #define DEDUP_ENABLE_NAME_CONF "DedupEnable"
117 #define DEDUP_AT_BOOT_NAME_CONF "DedupAtBoot"
118 #define SCAN_ON_LOWMEM_NAME_CONF "ScanOnLowmem"
119 #define KSM_MODE_NAME_CONF "KsmMode"
120 #define PAGES_TO_SCAN_NAME_CONF "PagesToScan"
121 #define PAGES_TO_SCAN_WITH_BOOST_NAME_CONF "PagesToScanWithBoost"
122 #define COMPACTION_ENABLE_NAME_CONF "CompactionEnable"
123 #define FRAG_LEVEL_NAME_CONF "FragLevel"
124 #define AFTER_SCREEN_DIM_CONF "AfterScreenDim"
125 #define FOREGROUND_APPS_NAME_CONF "ForegroundApps"
126 #define CPU_AFFINITY_NAME_CONF "CpuAffinity"
128 /* configuration value */
129 #define CGROUP_LOW_VALUE_CONF "lowest"
130 #define ACTION_BROADCAST_VALUE_CONF "broadcast"
131 #define ACTION_RECLAIM_VALUE_CONF "reclaim"
132 #define ACTION_KILL_VALUE_CONF "kill"
133 #define ACTION_REBOOT_VALUE_CONF "reboot"
134 #define ACTION_IGNORE_VALUE_CONF "ignore"
136 /* Memory specific configuration name */
137 #define MEMORY_LIMIT_TRIGGER_OOM_VALUE_CONF "oom"
138 #define MEMORY_LIMIT_TRIGGER_THRESHOLD_VALUE_CONF "threshold"
140 /* CPU specific configuration name */
141 #define RT_RUNTIME_SHARE_VALUE_CONF "rt_runtime_share"
142 #define NO_RT_RUNTIME_SHARE_VALUE_CONF "no_rt_runtime_share"
143 #define CPU_SCHED_DEADLINE_VALUE_CONF "deadline"
144 #define CPU_SCHED_FIFO_VALUE_CONF "fifo"
145 #define CPU_SCHED_RR_VALUE_CONF "rr"
146 #define CPU_SCHED_OTHER_VALUE_CONF "other"
147 #define CPU_SCHED_IDLE_VALUE_CONF "idle"
148 #define CPU_SCHED_BATCH_VALUE_CONF "batch"
149 #define CPU_BOOSTING_LEVEL_STRONG_VALUE_CONF "strong"
150 #define CPU_BOOSTING_LEVEL_MEDIUM_VALUE_CONF "medium"
151 #define CPU_BOOSTING_LEVEL_WEAK_VALUE_CONF "weak"
153 #define MATCH(a, b) (!strncmp(a, b, strlen(a) + 1) ? 1 : 0)
154 #define SET_CONF(a, b) (a = (b > 0.0 ? b : a))
161 VIP_CONFIG, /* old style */
164 struct parse_result {
171 * @brief Parse config file and call callback\n
172 * @param[in] file_name conf file.
173 * @param[in] cb cb is called when conf file is parsed line by line.
174 * @param[in] user_data user data is passed to cb.
175 * @return 0 on success, negative if failed
177 int config_parse(const char *file_name, int cb(struct parse_result *result,
178 void *user_data), void *user_data);
180 /* Prototype for a parser for a specific configuration setting */
181 typedef int (*ConfigParserCallback)(
182 const char *filename,
190 typedef int (*ConfigParseFunc)(const char *path, void *data);
192 /* Wraps information for parsing a specific configuration variable, to
193 * be stored in a simple array */
194 typedef struct ConfigTableItem {
195 const char *section; /* Section */
196 const char *lvalue; /* Name of the variable */
197 ConfigParserCallback cb; /* Function that is called to
198 * parse the variable's
200 int ltype; /* Distinguish different
201 * variables passed to the
203 void *data; /* Where to store the
207 void remove_app_conf_info_list(void);
208 void remove_service_conf_info_list(void);
209 GSList *get_app_conf_info_list(void);
210 GSList *get_service_conf_info_list(void);
211 void resourced_parse_vendor_configs(void);
212 void resourced_free_vendor_configs(void);
213 int cpu_sched_parse_cpuset(void *data, char *value);
216 #endif /* __cplusplus */