From c45e65572c57b290cb62a6217a7afef76cbe74df Mon Sep 17 00:00:00 2001 From: Yaroslav Furman Date: Tue, 11 Jun 2019 23:03:11 +0300 Subject: [PATCH] kernel: introduce CPUSets Assist Same concept as in stune assist: A kernel-side helper to write default cpusets values and forbid init from adjusting them. Default values are set for Snapdragon 675 (6+2) Signed-off-by: Yaroslav Furman [kdrag0n: Fixed typo in commit message] Signed-off-by: Danny Lin Signed-off-by: UtsavBalar1231 --- init/Kconfig | 10 ++++++++++ kernel/cgroup/cpuset.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/init/Kconfig b/init/Kconfig index f635e7bc67c8..2be6106f0d52 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1115,6 +1115,16 @@ config SCHED_TUNE If unsure, say N. +config CPUSETS_ASSIST + bool "Cpusets configuration helper" + depends on CPUSETS + depends on ANDROID + help + This option enables the configuration of default cpusets + parameters from kernel. + + If unsure, say N. + config DEFAULT_USE_ENERGY_AWARE bool "Default to enabling the Energy Aware Scheduler feature" default n diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 2b1ff29bd2c1..7a2138690059 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1712,7 +1712,10 @@ 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 @@ -1768,6 +1771,41 @@ out_unlock: return retval ?: nbytes; } +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; + }; + 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 + + 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; + } + } + } +#endif + + buf = strstrip(buf); + + return cpuset_write_resmask(of, buf, nbytes, off); +} + /* * These ascii lists should be read in a single call, by using a user * buffer large enough to hold the entire map. If read in smaller @@ -1860,7 +1898,7 @@ static struct cftype files[] = { { .name = "cpus", .seq_show = cpuset_common_seq_show, - .write = cpuset_write_resmask, + .write = cpuset_write_resmask_wrapper, .max_write_len = (100U + 6 * NR_CPUS), .private = FILE_CPULIST, },