pci->cpu_boosting_level = config_parse_boosting_level(result->value);
}
+ else if (!strncmp(result->name, CPU_AFFINITY_NAME_CONF, strlen(CPU_AFFINITY_NAME_CONF) + 1)
+ && *config_type == OPTIMIZER_CONFIG) {
+ if (!pci) {
+ _E("process configuration information pointer should not be NULL");
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ if (cpu_sched_parse_cpuset(&pci->cpuset_info, result->value) < 0) {
+ _E("invalid cpu affinity value (%s)", result->value);
+
+ if (pci->cpuset_info.cpu_info != NULL)
+ g_slist_free_full(pci->cpuset_info.cpu_info, free);
+ pci->cpuset_info.cpu_info = NULL;
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+ }
+ }
/* else if (!strncmp(result->name, CPU_RT_RUN_TIME_NAME_CONF,
strlen(CPU_RT_RUN_TIME_NAME_CONF)+1) &&
*config_type == OPTIMIZER_CONFIG) {
#define GLOBAL_RT_PERIOD_US_PATH "/proc/sys/kernel/sched_rt_period_us"
#define GLOBAL_RT_RUNTIME_US_PATH "/proc/sys/kernel/sched_rt_runtime_us"
#define CPU_SCHED_FEATURE_PATH "/sys/kernel/debug/sched_features"
+#define ONLINE_CPU_PATH "/sys/devices/system/cpu/online"
struct cpu_sched {
struct cpuset_info *fg;
static struct cpu_sched cs;
+static int cpu_sched_cpu_on(void *data);
+
struct cpuset_info *cpu_sched_find_coreset(const char *name)
{
GSList *i;
int r;
char buf[512];
- assert(set);
+ if (set == NULL)
+ return 0;
+
assert(set->name);
r = cgroup_make_subdir(CPUSET_CGROUP, set->name, NULL);
return 0;
}
+static int cpu_sched_init_cpu_online_info(void)
+{
+ int ret;
+ GSList *item;
+ struct cpuset_info cpuset_info = {0, };
+ _cleanup_free_ char *buf = NULL;
+
+ buf = calloc(1, PATH_MAX);
+ if (!buf)
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+
+ /* Read the current online cpus */
+ ret = fread_str(ONLINE_CPU_PATH, &buf);
+ if (ret < 0) {
+ _E("[CPU-SCHED] failed to read online cpu");
+ return ret;
+ }
+
+ if (cpu_sched_parse_cpuset(&cpuset_info, buf) < 0) {
+ _E("invalid cpu affinity value (%s)", buf);
+
+ if (cpuset_info.cpu_info != NULL)
+ g_slist_free_full(cpuset_info.cpu_info, free);
+
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ /* Pin cpu affinity */
+ gslist_for_each_item(item, cpuset_info.cpu_info) {
+ struct cpu_info *cpu_info = (struct cpu_info *)item->data;
+ if (cpu_info == NULL)
+ continue;
+
+ cpu_sched_cpu_on(&cpu_info->cpu_id);
+ }
+
+ return RESOURCED_ERROR_NONE;
+}
+
/* init cpuset's cgroups */
static int cpu_sched_init_cgroup(struct cpu_sched *cs)
{
}
}
- return cs->fg ? cpu_sched_init_cgroup_set(cs->fg) : 0;
+ r = cpu_sched_init_cgroup_set(cs->fg);
+ if (r < 0) {
+ _E("cpu-set: error setting up cpuset (%s)", cs->fg->name);
+ return r;
+ }
+
+ return cpu_sched_init_cpu_online_info();
}
/* free memory allocated in cpuset_info structure */
static int load_cpu_affinity_config(struct cpu_sched *data)
{
char *name;
- bool is_fg;
+ gpointer app_name;
+ gpointer proc_conf_ptr;
+ GHashTableIter app_list_iter;
assert(data);
- if (!get_cpu_affinity_conf_name())
- return RESOURCED_ERROR_NONE;
+ if (get_cpu_affinity_conf_name() == NULL)
+ goto cpu_affinity_set_for_fixed_app;
name = strdup(get_cpu_affinity_conf_name());
- is_fg = !strcmp(name, FOREGROUND_APPS_NAME_CONF);
+ if (!name || strcmp(name, FOREGROUND_APPS_NAME_CONF)) {
+ _E("[CPU-SCHED] Failed to allocate memory during making a duplicate name or wrong name (%s)",
+ get_cpu_affinity_conf_name());
+ goto cpu_affinity_set_for_fixed_app;
+ }
struct cpuset_info *cpuset_info = (struct cpuset_info *)calloc(1, sizeof *cpuset_info);
if (cpuset_info == NULL) {
free(name);
- return RESOURCED_ERROR_OUT_OF_MEMORY;
+ _E("[CPU_SCHED] Failed to allocate memory");
+ goto cpu_affinity_set_for_fixed_app;
}
cpuset_info->name = name;
- if (cpu_sched_parse_cpuset(cpuset_info, get_cpu_affinity_conf_value()) < 0) {
+ if (!get_cpu_affinity_conf_value() ||
+ cpu_sched_parse_cpuset(cpuset_info, get_cpu_affinity_conf_value()) < 0) {
cpu_sched_free_cpuset(&cpuset_info);
- return RESOURCED_ERROR_FAIL;
+ goto cpu_affinity_set_for_fixed_app;
}
- if (is_fg)
- data->fg = cpuset_info;
- else
- data->apps = g_slist_append(data->apps, cpuset_info);
+ data->fg = cpuset_info;
+cpu_affinity_set_for_fixed_app:
+ /* Free memory if previously allocated memory for 'ForegroundApps' exists */
free_cpu_affinity_conf();
+
+ /* Register static fixed cpu affinity apps */
+ g_hash_table_iter_init(&app_list_iter, fixed_app_list_get());
+ while (g_hash_table_iter_next(&app_list_iter, &app_name, &proc_conf_ptr)) {
+ struct proc_conf_info *pci = (struct proc_conf_info *)proc_conf_ptr;
+
+ if (!pci) {
+ _W("[CPU-SCHED] Process configuration information is NULL");
+ continue;
+ }
+
+ if (pci->cpuset_info.cpu_info) {
+ pci->cpuset_info.name = pci->name;
+ data->apps = g_slist_append(data->apps, &pci->cpuset_info);
+ }
+ }
+
return RESOURCED_ERROR_NONE;
}