cpuset: Refactor cpuset assist code

- Fix invalid memory manipulation and potential buffer undersizing
 - Improve overall code style
 - Revise Kconfig description
 - Use task_is_booster helper instead of hard-coding an "init"
   comparison

Signed-off-by: Danny Lin <danny@kdrag0n.dev>
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
This commit is contained in:
Danny Lin
2019-08-04 04:28:17 +00:00
committed by UtsavBalar1231
parent c45e65572c
commit 04eada3a89
2 changed files with 35 additions and 28 deletions

View File

@@ -1116,12 +1116,11 @@ config SCHED_TUNE
If unsure, say N.
config CPUSETS_ASSIST
bool "Cpusets configuration helper"
bool "Cpuset configuration helper"
depends on CPUSETS
depends on ANDROID
help
This option enables the configuration of default cpusets
parameters from kernel.
This option enables in-kernel overrides for cpuset values.
If unsure, say N.

View File

@@ -57,6 +57,7 @@
#include <linux/backing-dev.h>
#include <linux/sort.h>
#include <linux/oom.h>
#include <linux/binfmts.h>
#include <linux/uaccess.h>
#include <linux/atomic.h>
@@ -137,6 +138,13 @@ struct cpuset {
int relax_domain_level;
};
#ifdef CONFIG_CPUSETS_ASSIST
struct cs_target {
const char *name;
char *cpus;
};
#endif
static inline struct cpuset *css_cs(struct cgroup_subsys_state *css)
{
return css ? container_of(css, struct cpuset, css) : NULL;
@@ -1712,11 +1720,6 @@ static ssize_t cpuset_write_resmask(struct kernfs_open_file *of,
struct cpuset *trialcs;
int retval = -ENODEV;
#ifndef CONFIG_CPUSETS_ASSIST
/* Don't call strstrip here because buf is read-only */
buf = strstrip(buf);
#endif
/*
* CPU or memory hotunplug may leave @cs w/o any execution
* resources, in which case the hotplug code asynchronously updates
@@ -1771,32 +1774,37 @@ out_unlock:
return retval ?: nbytes;
}
static ssize_t cpuset_write_resmask_assist(struct kernfs_open_file *of,
struct cs_target tgt, size_t nbytes,
loff_t off)
{
pr_info("cpuset_assist: setting %s to %s\n", tgt.name, tgt.cpus);
return cpuset_write_resmask(of, tgt.cpus, nbytes, off);
}
static ssize_t cpuset_write_resmask_wrapper(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off)
{
#ifdef CONFIG_CPUSETS_ASSIST
int i;
struct cpuset *cs = css_cs(of_css(of));
struct c_data {
char *c_name;
char *c_cpus;
static struct cs_target cs_targets[] = {
/* Little-only cpusets go first */
{ "foreground", "0-5" },
{ "background", "0-2" },
{ "system-background", "0-3" },
{ "restricted", "0-5" },
{ "top-app", "0-7" },
{ "camera-daemon", "0-3,6-7" },
};
struct c_data c_targets[6] = {
/* Silver only cpusets go first */
{ "foreground", "0-5"},//0-2,4-7
{ "background", "0-2"},//0-1
{ "system-background", "0-3"},//0-2
{ "restricted", "0-5"},//0-7
{ "top-app", "0-7"},//0-7
{ "camera-daemon", "0-3,6-7"}};//0-7
struct cpuset *cs = css_cs(of_css(of));
int i;
if (!strcmp(current->comm, "init")) {
for (i = 0; i < ARRAY_SIZE(c_targets); i++) {
if (!strcmp(cs->css.cgroup->kn->name, c_targets[i].c_name)) {
strcpy(buf, c_targets[i].c_cpus);
pr_info("%s: setting to %s\n", c_targets[i].c_name, buf);
break;
}
if (task_is_booster(current)) {
for (i = 0; i < ARRAY_SIZE(cs_targets); i++) {
struct cs_target tgt = cs_targets[i];
if (!strcmp(cs->css.cgroup->kn->name, tgt.name))
return cpuset_write_resmask_assist(of, tgt,
nbytes, off);
}
}
#endif