};
struct cpu_sched {
- struct coreset fg;
+ struct coreset *fg;
GSList *apps;
bool is_initalized;
};
return r;
}
}
- return cpu_sched_init_cgroup_set(&cs->fg);
+
+ return cs->fg ? cpu_sched_init_cgroup_set(cs->fg) : 0;
}
/* create single core struct representation */
static int load_config(struct parse_result *result, void *user_data)
{
- int r;
struct cpu_sched *data = (struct cpu_sched *)user_data;
assert(data);
- if (strcmp(result->name, CPU_SCHED_FG_NAME)) { /* not a 'foreground' group */
- struct coreset *c = (struct coreset *)calloc(1, sizeof *c);
- if (NULL == c)
- return RESOURCED_ERROR_OUT_OF_MEMORY;
-
- c->name = strdup(result->name);
-
- r = cpu_sched_parse_cpuset(c, result->value);
-
- if (RESOURCED_ERROR_NONE == r)
- data->apps = g_slist_append(data->apps, c);
- } else {
- data->fg.name = strdup(CPU_SCHED_FG_NAME);
- r = cpu_sched_parse_cpuset(&data->fg, result->value);
- }
+ struct coreset *c = (struct coreset *)calloc(1, sizeof *c);
+ if (NULL == c)
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ int r = cpu_sched_parse_cpuset(c, result->value);
if (r < 0) {
- _E("cpu-sched parse fg coreset: could not parse");
+ _E("cpu-sched parse %s coreset: could not parse", result->name);
return RESOURCED_ERROR_FAIL;
}
- return RESOURCED_ERROR_NONE;
+ if (strcmp(result->name, CPU_SCHED_FG_NAME)) { /* not a 'foreground' group */
+ c->name = strdup(result->name);
+ data->apps = g_slist_append(data->apps, c);
+ } else {
+ c->name = strdup(CPU_SCHED_FG_NAME);
+ data->fg = c;
+ }
+
+ return c->name ? RESOURCED_ERROR_NONE : RESOURCED_ERROR_OUT_OF_MEMORY;
}
static int cpu_sched_parse_config(struct cpu_sched *data)
assert(set);
-
r = snprintf(path, sizeof path, "%s/%s", CPUSET_CGROUP, set->name);
if (r < 0) {
_E("cpu-sched: failed to setup path for cpuset (%s)", set->name);
gslist_for_each_item(i, cs.apps) {
cpu_sched_cpu_on_for_coreset((struct coreset *)i->data, id);
}
- cpu_sched_cpu_on_for_coreset(&cs.fg, id);
+ if (cs.fg)
+ cpu_sched_cpu_on_for_coreset(cs.fg, id);
return RESOURCED_ERROR_NONE;
}
cpu_sched_cpu_off_for_coreset((struct coreset *)i->data, id);
}
- cpu_sched_cpu_off_for_coreset(&cs.fg, id);
+ if (cs.fg)
+ cpu_sched_cpu_off_for_coreset(cs.fg, id);
return RESOURCED_ERROR_NONE;
}
static int cpu_sched_app_foreground(void *data)
{
+ assert(cs.fg);
+
struct proc_status *ps = (struct proc_status *)data;
assert(ps);
_D("cpu-sched: app %s moved to foreground; pid=%d", ps->pai->appid, ps->pid);
- return cpu_sched_add_pid_to_cpuset(&cs.fg, ps->pid, true);
+ return cpu_sched_add_pid_to_cpuset(cs.fg, ps->pid, true);
}
-
static int cpu_sched_app_launch(void *data)
{
struct proc_status *ps = (struct proc_status *)data;
static void register_notifiers()
{
- register_notifier(RESOURCED_NOTIFIER_APP_RESUME, cpu_sched_app_foreground);
- register_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, cpu_sched_app_foreground);
- register_notifier(RESOURCED_NOTIFIER_WIDGET_FOREGRD, cpu_sched_app_foreground);
+ if (cs.fg) {
+ register_notifier(RESOURCED_NOTIFIER_APP_RESUME, cpu_sched_app_foreground);
+ register_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, cpu_sched_app_foreground);
+ register_notifier(RESOURCED_NOTIFIER_WIDGET_FOREGRD, cpu_sched_app_foreground);
+ }
register_notifier(RESOURCED_NOTIFIER_CPU_ON, cpu_sched_cpu_on);
register_notifier(RESOURCED_NOTIFIER_CPU_OFF, cpu_sched_cpu_off);
static void unregister_notifiers()
{
- unregister_notifier(RESOURCED_NOTIFIER_APP_RESUME, cpu_sched_app_foreground);
- unregister_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, cpu_sched_app_foreground);
- unregister_notifier(RESOURCED_NOTIFIER_WIDGET_FOREGRD, cpu_sched_app_foreground);
+ if (cs.fg) {
+ unregister_notifier(RESOURCED_NOTIFIER_APP_RESUME, cpu_sched_app_foreground);
+ unregister_notifier(RESOURCED_NOTIFIER_APP_FOREGRD, cpu_sched_app_foreground);
+ unregister_notifier(RESOURCED_NOTIFIER_WIDGET_FOREGRD, cpu_sched_app_foreground);
+ }
unregister_notifier(RESOURCED_NOTIFIER_CPU_ON, cpu_sched_cpu_on);
unregister_notifier(RESOURCED_NOTIFIER_CPU_OFF, cpu_sched_cpu_off);
static void cpu_sched_free_cpusets()
{
g_slist_free_full(g_steal_pointer(&cs.apps), cpu_sched_free_cpuset_full);
- cpu_sched_free_cpuset(&cs.fg);
+ if (cs.fg) {
+ cpu_sched_free_cpuset(cs.fg);
+ free(cs.fg);
+ cs.fg = NULL;
+ }
}
static void cpu_sched_check_apps()
continue;
}
- if (pai->state == PROC_STATE_FOREGROUND)
- cpu_sched_add_pid_to_cpuset(&cs.fg, pai->main_pid, true);
+ if (cs.fg && pai->state == PROC_STATE_FOREGROUND)
+ cpu_sched_add_pid_to_cpuset(cs.fg, pai->main_pid);
}
}