#include "swap-common.h"
#include "dedup-common.h"
#include "compact-common.h"
+#include "cpu-sched-common.h"
#define MAX_SECTION 64
#define CPU_INIT_PRIO 100
+static int config_parse_swap_types(
+ const char *rvalue,
+ void *data)
+{
+ enum swap_type *type = data;
+ char *word, *state;
+ size_t l;
+
+ if (is_empty(rvalue))
+ return 0;
+
+ *type = 0;
+
+ FOREACH_WORD_SEPARATOR(word, l, rvalue, "+|", state) {
+ if (strneq(word, "zram", l))
+ *type |= SWAP_TYPE_ZRAM;
+ else if (strneq(word, "file", l))
+ *type |= SWAP_TYPE_FILE;
+ else if (strneq(word, "zswap", l))
+ *type |= SWAP_TYPE_ZSWAP;
+ else
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int config_parse_cpu_sched_features(const char *value)
+{
+ int cpu_sched_type = CPU_SCHED_UNINITIALIZED;
+ char *word, *state;
+ size_t l;
+
+ if (is_empty(value))
+ return cpu_sched_type;
+
+ FOREACH_WORD_SEPARATOR(word, l, value, ",", state) {
+ if (strneq(word, RT_RUNTIME_SHARE, l))
+ cpu_sched_type |= CPU_SCHED_RUNTIME_SHARE;
+ else if (strneq(word, NO_RT_RUNTIME_SHARE, l))
+ cpu_sched_type |= CPU_SCHED_NO_RUNTIME_SHARE;
+ else if (strneq(word, RT_RUNTIME_GREED, l))
+ cpu_sched_type |= CPU_SCHED_RUNTIME_GREED;
+ else
+ return CPU_SCHED_UNINITIALIZED;
+ }
+
+ return cpu_sched_type;
+}
+
+static int config_parse_time_us(const char *value)
+{
+ char size;
+ char *ptr = strchr(value, 's');
+ if (ptr == NULL) {
+ _E("[DEBUG] Cannot find 's' in the string (%s)", value);
+ return 0;
+ }
+
+ if (value > (ptr - 1)) {
+ _E("[DEBUG] Size of string should be larger than 1");
+ return 0;
+ }
+
+ size = *(ptr - 1);
+ *(ptr - 1) = '\0';
+
+ if (size == ' ') {
+ return atoi(value) * 1000 * 1000;
+ }
+ else if (size == 'm') {
+ return atoi(value) * 1000;
+ }
+ else if (size == 'u') {
+ return atoi(value);
+ }
+ else {
+ _E("[DEBUG] Unknown unit of time");
+ return 0;
+ }
+}
+
static int optimizer_config(struct parse_result *result, void *user_data)
{
if (!result)
return RESOURCED_ERROR_FAIL;
}
+ struct cpu_sched_conf *cpu_sched_conf = get_cpu_sched_conf();
+ if (cpu_sched_conf == NULL) {
+ _E("[DEBUG] cpu_sched configuration is NULL");
+ return RESOURCED_ERROR_FAIL;
+ }
+
if (!strncmp(result->section, SWAP_SECTION, strlen(SWAP_SECTION)+1)) {
if (!strncmp(result->name, SWAP_ENABLE_CONF, strlen(SWAP_ENABLE_CONF)+1)) {
if (!strncmp(result->value, "yes", 4) ||
}
else if (!strncmp(result->name, SWAP_TYPE_CONF,
strlen(SWAP_TYPE_CONF)+1)) {
- if (strlen(result->value) + 1 > sizeof(swap_conf->type)) {
+ if (config_parse_swap_types(result->value, &swap_conf->swap_type) < 0) {
+ _E("[DEBUG] Failed to parse type of swap, so use default zram type");
+ swap_conf->swap_type = SWAP_TYPE_ZRAM;
+ }
+/* if (strlen(result->value) + 1 > sizeof(swap_conf->type)) {
_E("Size of swap_conf->type is not enough");
return RESOURCED_ERROR_OUT_OF_MEMORY;
}
- strncpy(swap_conf->type, result->value, sizeof(swap_conf->type) - 1);
+ strncpy(swap_conf->type, result->value, sizeof(swap_conf->type) - 1);*/
}
else if (!strncmp(result->name, VIP_GROUP_SWAPPINESS_CONF,
strlen(VIP_GROUP_SWAPPINESS_CONF)+1)) {
result->name, result->value, result->section);
}
}
+ else if (!strncmp(result->section, CPU_SCHED_SECTION,
+ strlen(CPU_SCHED_SECTION)+1)) {
+ if (!strncmp(result->name, CPU_SCHED_FEATURE_CONF,
+ strlen(CPU_SCHED_FEATURE_CONF) + 1)) {
+ cpu_sched_conf->cpu_sched_flag = config_parse_cpu_sched_features(result->value);
+ }
+ else if (!strncmp(result->name, CPU_RT_RUN_TIME_CONF,
+ strlen(CPU_RT_RUN_TIME_CONF) + 1)) {
+ cpu_sched_conf->rt_runtime_us = config_parse_time_us(result->value);
+ }
+ else if (!strncmp(result->name, CPU_RT_PERIOD_CONF,
+ strlen(CPU_RT_PERIOD_CONF) + 1)) {
+ cpu_sched_conf->rt_period_us = config_parse_time_us(result->value);
+ }
+ else {
+ _E("[DEBUG] Unknown configuration name (%s) and value (%s) on section (%s)",
+ result->name, result->value, result->section);
+ }
+ }
else if (!strncmp(result->section, CPU_AFFINITY_SECTION,
strlen(CPU_AFFINITY_SECTION)+1)) {
int error = RESOURCED_ERROR_NONE;
config_type = LIMITER_CONFIG;
load_per_vendor_configs(LIMITER_CONF_DIR, vendor_config, &config_type);
- /* Load configurations in optimizer.conf */
+ /* Load configurations in optimizer.conf and optimizer.conf.d */
config_parse(OPTIMIZER_CONF_FILE, optimizer_config, NULL);
+ config_type = OPTIMIZER_CONFIG;
+ load_per_vendor_configs(OPTIMIZER_CONF_DIR, vendor_config, &config_type);
+ /* Load configuration in process.conf */
config_type = PROCESS_CONFIG;
load_per_vendor_configs(PROC_CONF_DIR, vendor_config, &config_type);
}