From edbcb6146e7ac034a822b176430869333e6b33cc Mon Sep 17 00:00:00 2001 From: Yaroslav Furman Date: Wed, 8 May 2019 15:09:37 -0400 Subject: [PATCH] sched/tune: Introduce SchedTune Assist[v3] This implements a mechanism by which default SchedTune parameters can be configured in-kernel, circumventing userspace, and mitigating reliance on ramdisk modification in the context of custom kernels. [2.5V]: This version adds proper protection from userspace (mainly init) trying to write lame boost values and gives full control to developer and user (sh is not blocked). [V3.0]: Use a struct to store all the values. [0ctobot: Update for msm-4.9 and improve coding style] [YaroST12: Update for msm-4.14] Co-authored-by: Adam W. Willis Co-authored-by: Yaroslav Furman Signed-off-by: Yaroslav Furman Change-Id: I70b676014d580b7df0f2962a989579376e261d49 --- init/Kconfig | 10 +++++ kernel/sched/tune.c | 94 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index c9e782fde611..9e0be90b764f 100755 --- a/init/Kconfig +++ b/init/Kconfig @@ -1146,6 +1146,16 @@ config SCHED_TUNE If unsure, say N. +config STUNE_ASSIST + bool "SchedTune configuration helper" + depends on SCHED_TUNE + depends on ANDROID + help + This option enables the configuration of default SchedTune + 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/sched/tune.c b/kernel/sched/tune.c index 212165944f56..64c6d2e5eecd 100755 --- a/kernel/sched/tune.c +++ b/kernel/sched/tune.c @@ -653,28 +653,76 @@ boost_write(struct cgroup_subsys_state *css, struct cftype *cft, return 0; } +#ifdef CONFIG_STUNE_ASSIST +#ifdef CONFIG_SCHED_WALT +static int sched_boost_override_write_wrapper(struct cgroup_subsys_state *css, + struct cftype *cft, u64 override) +{ + if (!strcmp(current->comm, "init")) + return 0; + + sched_boost_override_write(css, NULL, override); + + return 0; +} + +static int sched_colocate_write_wrapper(struct cgroup_subsys_state *css, + struct cftype *cft, u64 colocate) +{ + if (!strcmp(current->comm, "init")) + return 0; + + sched_colocate_write(css, NULL, colocate); + + return 0; +} +#endif + +static int boost_write_wrapper(struct cgroup_subsys_state *css, + struct cftype *cft, s64 boost) +{ + if (!strcmp(current->comm, "init")) + return 0; + + boost_write(css, NULL, boost); + + return 0; +} + +static int prefer_idle_write_wrapper(struct cgroup_subsys_state *css, + struct cftype *cft, u64 prefer_idle) +{ + if (!strcmp(current->comm, "init")) + return 0; + + prefer_idle_write(css, NULL, prefer_idle); + + return 0; +} +#endif + static struct cftype files[] = { #ifdef CONFIG_SCHED_WALT { .name = "sched_boost_no_override", .read_u64 = sched_boost_override_read, - .write_u64 = sched_boost_override_write, + .write_u64 = sched_boost_override_write_wrapper, }, { .name = "colocate", .read_u64 = sched_colocate_read, - .write_u64 = sched_colocate_write, + .write_u64 = sched_colocate_write_wrapper, }, #endif { .name = "boost", .read_s64 = boost_read, - .write_s64 = boost_write, + .write_s64 = boost_write_wrapper, }, { .name = "prefer_idle", .read_u64 = prefer_idle_read, - .write_u64 = prefer_idle_write, + .write_u64 = prefer_idle_write_wrapper, }, { } /* terminate */ }; @@ -699,6 +747,37 @@ schedtune_boostgroup_init(struct schedtune *st) return 0; } +#ifdef CONFIG_STUNE_ASSIST +static void write_default_values(struct cgroup_subsys_state *css) +{ + u8 i; + struct groups_data { + char *name; + int boost; + bool prefer_idle; + bool colocate; + bool no_override; + }; + struct groups_data groups[3] = { + { "top-app", 5, 1, 0, 1 }, + { "foreground", 1, 1, 0, 1 }, + { "background", 0, 0, 1, 0 }}; + + for (i = 0; i < ARRAY_SIZE(groups); i++) { + if (!strcmp(css->cgroup->kn->name, groups[i].name)) { + pr_info("%s: %i - %i - %i - %i\n", groups[i].name, + groups[i].boost, groups[i].prefer_idle, + groups[i].colocate, + groups[i].no_override); + boost_write(css, NULL, groups[i].boost); + prefer_idle_write(css, NULL, groups[i].prefer_idle); + sched_colocate_write(css, NULL, groups[i].colocate); + sched_boost_override_write(css, NULL, groups[i].no_override); + } + } +} +#endif + static struct cgroup_subsys_state * schedtune_css_alloc(struct cgroup_subsys_state *parent_css) { @@ -714,10 +793,13 @@ schedtune_css_alloc(struct cgroup_subsys_state *parent_css) return ERR_PTR(-ENOMEM); } - /* Allow only a limited number of boosting groups */ - for (idx = 1; idx < BOOSTGROUPS_COUNT; ++idx) + for (idx = 1; idx < BOOSTGROUPS_COUNT; ++idx) { if (!allocated_group[idx]) break; +#ifdef CONFIG_STUNE_ASSIST + write_default_values(&allocated_group[idx]->css); +#endif + } if (idx == BOOSTGROUPS_COUNT) { pr_err("Trying to create more than %d SchedTune boosting groups\n", BOOSTGROUPS_COUNT);