return CPU_BOOSTING_LEVEL_NONE;
}
+/* Create a single cpu_info struct representation */
+static int cpu_sched_new_cpu_info(struct cpuset_info *set, int cpu_id)
+{
+ struct cpu_info *cpu_info;
+
+ assert(set);
+
+ if (cpu_id < 0)
+ return RESOURCED_ERROR_FAIL;
+
+ cpu_info = (struct cpu_info *)calloc(1, sizeof *cpu_info);
+ if (cpu_info == NULL) {
+ _E("cpu-sched: could not allocate memory for cpu_info struct");
+ return RESOURCED_ERROR_FAIL;
+ }
+ cpu_info->cpu_id = cpu_id;
+ cpu_info->online = false;
+
+ set->cpu_info = g_slist_append(set->cpu_info, cpu_info);
+ return RESOURCED_ERROR_NONE;
+}
+
+static int cpu_sched_new_cpu_info_range(struct cpuset_info *set, int min_cpu, int max_cpu)
+{
+ assert(set);
+
+ if (min_cpu < 0 || max_cpu < 0 || min_cpu >= max_cpu) {
+ _E("cpu range (%d - %d) is wrong", min_cpu, max_cpu);
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+ }
+
+ for (int cpu = min_cpu; cpu <= max_cpu; cpu++) {
+ if (cpu_sched_new_cpu_info(set, cpu) != RESOURCED_ERROR_NONE)
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ return RESOURCED_ERROR_NONE;
+}
+
+/* Parse config for specific cpuset_info line */
+int cpu_sched_parse_cpuset(void *data, char *value)
+{
+ int count;
+ int min, max;
+ struct cpuset_info *set = (struct cpuset_info *)data;
+ char *ptr, *saveptr;
+
+ assert(set);
+ assert(value);
+ assert(!set->cpu_info);
+
+ ptr = strtok_r(value, ",", &saveptr);
+ while (ptr) {
+ /* single value */
+ if (strstr(ptr, "-") == NULL) {
+ count = sscanf(ptr, "%d", &min);
+ if (count != 1)
+ goto parse_cpuset_fail;
+
+ if (cpu_sched_new_cpu_info(set, min) != RESOURCED_ERROR_NONE)
+ goto parse_cpuset_fail;
+ /* range */
+ } else {
+ count = sscanf(ptr, "%d-%d", &min, &max);
+ if (count != 2)
+ goto parse_cpuset_fail;
+
+ if (cpu_sched_new_cpu_info_range(set, min, max) != RESOURCED_ERROR_NONE)
+ goto parse_cpuset_fail;
+ }
+
+ ptr = strtok_r(NULL, ",", &saveptr);
+ }
+
+ return RESOURCED_ERROR_NONE;
+
+parse_cpuset_fail:
+ _E("cpu-sched: error parsing cpuset (%s)", ptr);
+ return RESOURCED_ERROR_FAIL;
+}
+
static int optimizer_config(struct parse_result *result, void *user_data)
{
if (!result)
#define GLOBAL_RT_RUNTIME_US_PATH "/proc/sys/kernel/sched_rt_runtime_us"
#define CPU_SCHED_FEATURE_PATH "/sys/kernel/debug/sched_features"
-struct core {
- int id;
- bool on;
-};
-
-struct coreset {
- GSList *cores;
- char *name;
- bool disclaimer_shown;
-};
-
struct cpu_sched {
- struct coreset *fg;
+ struct cpuset_info *fg;
GSList *apps;
bool is_initialized;
};
static struct cpu_sched cs;
-struct coreset *cpu_sched_find_coreset(const char *name)
+struct cpuset_info *cpu_sched_find_coreset(const char *name)
{
GSList *i;
- struct coreset *c;
+ struct cpuset_info *cpuset_info;
gslist_for_each_item(i, cs.apps) {
- c = (struct coreset *)i->data;
- if (!strcmp(name, c->name))
- return c;
+ cpuset_info = (struct cpuset_info *)i->data;
+ if (!strcmp(name, cpuset_info->name))
+ return cpuset_info;
}
return NULL;
}
return ret;
}
-static int cpu_sched_init_cgroup_set(const struct coreset *set)
+static int cpu_sched_init_cgroup_set(const struct cpuset_info *set)
{
int r;
char buf[512];
{
int r;
GSList *i;
- struct coreset *c;
+ struct cpuset_info *cpuset_info;
if (cpu_sched_is_cpuset_mounted() == false) {
r = cgroup_make_subdir(CGROUP_PATH, "cpuset", NULL);
}
gslist_for_each_item(i, cs->apps) {
- c = (struct coreset *)i->data;
- r = cpu_sched_init_cgroup_set(c);
+ cpuset_info = (struct cpuset_info *)i->data;
+ r = cpu_sched_init_cgroup_set(cpuset_info);
if (r < 0) {
- _E("cpu-set: error setting up cpuset (%s)", c->name);
+ _E("cpu-set: error setting up cpuset (%s)", cpuset_info->name);
return r;
}
}
return cs->fg ? cpu_sched_init_cgroup_set(cs->fg) : 0;
}
-/* create single core struct representation */
-static int cpu_sched_new_core(struct coreset *set, int core_id)
+/* free memory allocated in cpuset_info structure */
+static void cpu_sched_free_cpuset(struct cpuset_info **cpuset_info)
{
- struct core *c;
+ struct cpuset_info *set = *cpuset_info;
- assert(set);
- assert(core_id >= 0);
-
- c = (struct core *)calloc(1, sizeof *c);
- if (c == NULL) {
- _E("cpu-sched: could not allocate memory for core struct");
- return RESOURCED_ERROR_FAIL;
- }
- c->id = core_id;
- c->on = false;
-
- set->cores = g_slist_append(set->cores, c);
- return RESOURCED_ERROR_NONE;
-}
-
-/* free memory allocated in coreset structure */
-static void cpu_sched_free_cpuset(struct coreset **c)
-{
- struct coreset *set = *c;
-
- if (set->cores != NULL)
- g_slist_free_full(set->cores, free);
- set->cores = NULL;
+ if (set->cpu_info != NULL)
+ g_slist_free_full(set->cpu_info, free);
+ set->cpu_info = NULL;
free(set->name);
set->name = NULL;
free(set);
- *c = NULL;
+ *cpuset_info = NULL;
}
-/* free memory allocated in coreset structure and the structure */
+/* free memory allocated in cpuset_info structure and the structure */
static void cpu_sched_free_cpuset_full(void *data)
{
- struct coreset *set = (struct coreset *)data;
+ struct cpuset_info *set = (struct cpuset_info *)data;
assert(set);
cpu_sched_free_cpuset(&set);
}
-/* parse config for specific coreset line */
-static int cpu_sched_parse_cpuset(struct coreset *set, char *value)
-{
- char *ptr, *saveptr;
- int min, max;
- int r;
-
- assert(set);
- assert(value);
- assert(!set->cores);
-
- ptr = strtok_r(value, ",", &saveptr);
- while (ptr) {
- if (strstr(ptr, "-") == NULL) { /* single value */
- r = sscanf(ptr, "%d", &min);
- if (r == 1 && min >= 0) {
- if (cpu_sched_new_core(set, min) != RESOURCED_ERROR_NONE)
- goto parse_cpuset_fail;
- } else {
- _E("cpu-sched: error parsing cpuset (%s)", ptr);
- goto parse_cpuset_fail;
- }
- } else { /* range */
- r = sscanf(ptr, "%d-%d", &min, &max);
- if (r == 2 && min >= 0 && max >= 0 && max > min) {
- for (int i = min; i <= max; i++) {
- if (cpu_sched_new_core(set, i) != RESOURCED_ERROR_NONE)
- goto parse_cpuset_fail;
- }
- } else {
- _E("cpu-sched: error parsing cpuset (%s)", ptr);
- goto parse_cpuset_fail;
- }
-
- }
-
- ptr = strtok_r(NULL, ",", &saveptr);
- }
- return RESOURCED_ERROR_NONE;
-parse_cpuset_fail:
- cpu_sched_free_cpuset(&set);
- return RESOURCED_ERROR_FAIL;
-}
static int load_cpu_affinity_config(struct cpu_sched *data)
{
name = strdup(get_cpu_affinity_conf_name());
is_fg = !strcmp(name, FOREGROUND_APPS_NAME_CONF);
- struct coreset *c = (struct coreset *)calloc(1, sizeof *c);
- if (c == NULL) {
+ 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;
}
- c->name = name;
+ cpuset_info->name = name;
- if (cpu_sched_parse_cpuset(c, get_cpu_affinity_conf_value()) < 0) {
+ if (cpu_sched_parse_cpuset(cpuset_info, get_cpu_affinity_conf_value()) < 0) {
+ cpu_sched_free_cpuset(&cpuset_info);
return RESOURCED_ERROR_FAIL;
}
if (is_fg)
- data->fg = c;
+ data->fg = cpuset_info;
else
- data->apps = g_slist_append(data->apps, c);
+ data->apps = g_slist_append(data->apps, cpuset_info);
free_cpu_affinity_conf();
return RESOURCED_ERROR_NONE;
return RESOURCED_ERROR_NONE;
}
-static int cpu_sched_write_coreset(struct coreset *set)
+static int cpu_sched_write_coreset(struct cpuset_info *set)
{
GSList *i;
- struct core *c;
+ struct cpu_info *cpu_info;
char path[128], coreset[128];
int r;
}
r = 0;
- gslist_for_each_item(i, set->cores) {
- c = (struct core *)i->data;
- if (c == NULL || c->on == false)
+ gslist_for_each_item(i, set->cpu_info) {
+ cpu_info = (struct cpu_info *)i->data;
+ if (cpu_info == NULL || cpu_info->online == false)
continue;
- r += snprintf(coreset + r, sizeof coreset - r, "%d,", c->id);
+ r += snprintf(coreset + r, sizeof coreset - r, "%d,", cpu_info->cpu_id);
}
if (r > 0)
return cgroup_write_node_str(path, "cpuset.cpus", coreset);
}
-static int cpu_sched_cpu_on_for_coreset(struct coreset *set, int core_id)
+static int cpu_sched_cpu_on_for_coreset(struct cpuset_info *set, int core_id)
{
GSList *i;
- struct core *c;
+ struct cpu_info *cpu_info;
bool refresh = false;
assert(set);
assert(core_id >= 0);
- if (set->cores == NULL)
+ if (set->cpu_info == NULL)
return 0;
- gslist_for_each_item(i, set->cores) {
- c = (struct core *)i->data;
- if (c == NULL || c->id != core_id)
+ gslist_for_each_item(i, set->cpu_info) {
+ cpu_info = (struct cpu_info *)i->data;
+ if (cpu_info == NULL || cpu_info->cpu_id != core_id)
continue;
- _D("cpu-sched: core %d on for coreset %s", core_id, set->name);
- c->on = true;
+ _D("cpu-sched: core %d on for cpuset_info %s", core_id, set->name);
+ cpu_info->online = true;
refresh = true;
break;
}
return cpu_sched_write_coreset(set);
}
-static int cpu_sched_cpu_off_for_coreset(struct coreset *set, int core_id)
+static int cpu_sched_cpu_off_for_coreset(struct cpuset_info *set, int core_id)
{
GSList *i;
- struct core *c;
+ struct cpu_info *cpu_info;
bool refresh = false;
assert(set);
assert(core_id >= 0);
- if (set->cores == NULL)
+ if (set->cpu_info == NULL)
return 0;
- gslist_for_each_item(i, set->cores) {
- c = (struct core *)i->data;
- if (c == NULL || c->id != core_id)
+ gslist_for_each_item(i, set->cpu_info) {
+ cpu_info = (struct cpu_info *)i->data;
+ if (cpu_info == NULL || cpu_info->cpu_id != core_id)
continue;
- _D("cpu-sched: core %d off for coreset %s", core_id, set->name);
- c->on = false;
+ _D("cpu-sched: core %d off for cpuset_info %s", core_id, set->name);
+ cpu_info->online = false;
refresh = true;
break;
}
_D("cpu-sched: core %d plugged in", id);
gslist_for_each_item(i, cs.apps) {
- cpu_sched_cpu_on_for_coreset((struct coreset *)i->data, id);
+ cpu_sched_cpu_on_for_coreset((struct cpuset_info *)i->data, id);
}
if (cs.fg)
cpu_sched_cpu_on_for_coreset(cs.fg, id);
_D("cpu-sched: core %d plugged out", id);
gslist_for_each_item(i, cs.apps) {
- cpu_sched_cpu_off_for_coreset((struct coreset *)i->data, id);
+ cpu_sched_cpu_off_for_coreset((struct cpuset_info *)i->data, id);
}
if (cs.fg)
return RESOURCED_ERROR_NONE;
}
-static int cpu_sched_add_pid_to_cpuset(struct coreset *set, pid_t pid)
+static int cpu_sched_add_pid_to_cpuset(struct cpuset_info *set, pid_t pid)
{
assert(set);
return RESOURCED_ERROR_NONE;
}
-static int cpu_sched_remove_pid_from_cpuset(struct coreset *set, pid_t pid)
+static int cpu_sched_remove_pid_from_cpuset(struct cpuset_info *set, pid_t pid)
{
assert(set);
return RESOURCED_ERROR_NONE;
}
-/* if app is subject to static coreset config its coreset should not be changed */
+/* if app is subject to static cpuset_info config its cpuset_info should not be changed */
static bool cpu_sched_is_static_app(const char *appid)
{
assert (appid);
- struct coreset *c = cpu_sched_find_coreset(appid);
- if (!c)
+ struct cpuset_info *cpuset_info = cpu_sched_find_coreset(appid);
+ if (!cpuset_info)
return false;
- if (c->disclaimer_shown == false) {
+ if (cpuset_info->disclaimer_shown == false) {
_D("cpu-sched: appid %s is statically configured - not subject to cpuset change", appid);
- c->disclaimer_shown = true;
+ cpuset_info->disclaimer_shown = true;
}
return true;
static int cpu_sched_app_launch(void *data)
{
struct proc_status *ps = (struct proc_status *)data;
- struct coreset *c;
+ struct cpuset_info *cpuset_info;
assert(ps);
assert(ps->pai);
_D("cpu-sched: app launch: %s", ps->pai->appid);
- c = cpu_sched_find_coreset(ps->pai->appid);
- if (c == NULL)
+ cpuset_info = cpu_sched_find_coreset(ps->pai->appid);
+ if (cpuset_info == NULL)
return 0;
- return cpu_sched_add_pid_to_cpuset(c, ps->pid);
+ return cpu_sched_add_pid_to_cpuset(cpuset_info, ps->pid);
}
/*static int cpu_sched_rt_scheduler(void *data)
_cleanup_app_list_close_ GSList *proc_app_list = PAL_INIT_VALUE;
GSList *giter;
struct proc_app_info *pai;
- struct coreset *c;
+ struct cpuset_info *cpuset_info;
proc_app_list = proc_app_list_open();
gslist_for_each_item(giter, proc_app_list) {
if (!pai || !pai->main_pid)
continue;
- c = cpu_sched_find_coreset(pai->appid);
- if (c != NULL) {
- cpu_sched_add_pid_to_cpuset(c, pai->main_pid);
+ cpuset_info = cpu_sched_find_coreset(pai->appid);
+ if (cpuset_info != NULL) {
+ cpu_sched_add_pid_to_cpuset(cpuset_info, pai->main_pid);
continue;
}