Skip to content

Commit

Permalink
sched/tune: Introduce SchedTune Assist[v3]
Browse files Browse the repository at this point in the history
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 <return.of.octobot@gmail.com>
Co-authored-by: Yaroslav Furman <yaro330@gmail.com>
  • Loading branch information
YaroST12 authored and acuicultor committed Feb 12, 2021
1 parent 7ff6d6b commit 5a9c607
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 6 deletions.
10 changes: 10 additions & 0 deletions init/Kconfig
Expand Up @@ -1257,6 +1257,16 @@ config CPUSET_TOP_APP

endif

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 SYSFS_DEPRECATED
bool "Enable deprecated sysfs features to support old userspace tools"
depends on SYSFS
Expand Down
94 changes: 88 additions & 6 deletions kernel/sched/tune.c
Expand Up @@ -716,28 +716,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 */
};
Expand All @@ -761,6 +809,37 @@ schedtune_boostgroup_init(struct schedtune *st, int idx)
st->idx = idx;
}

#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)
{
Expand All @@ -776,10 +855,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);
Expand Down

0 comments on commit 5a9c607

Please sign in to comment.