Skip to content

Commit

Permalink
sched/tune: Add initial support for Dynamic SchedTune Boost
Browse files Browse the repository at this point in the history
Provide functions to activate and reset SchedTune boost:

int do_stune_boost(char *st_name, int boost);
int reset_stune_boost(char *st_name);

Signed-off-by: joshuous <joshuous@gmail.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
  • Loading branch information
joshchoo authored and khusika committed Jun 15, 2018
1 parent 15612b8 commit 51e85c0
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/linux/sched.h
Expand Up @@ -3283,4 +3283,9 @@ struct cpu_cycle_counter_cb {
};
int register_cpu_cycle_counter_cb(struct cpu_cycle_counter_cb *cb);

#ifdef CONFIG_DYNAMIC_STUNE_BOOST
int do_stune_boost(char *st_name, int boost);
int reset_stune_boost(char *st_name);
#endif /* CONFIG_DYNAMIC_STUNE_BOOST */

#endif
9 changes: 9 additions & 0 deletions init/Kconfig
Expand Up @@ -1020,6 +1020,15 @@ config CGROUP_SCHEDTUNE

Say N if unsure.

config DYNAMIC_STUNE_BOOST
bool "Dynamic SchedTune boosting support"
depends on SCHED_TUNE
help
This option extends the SchedTune framework and provides APIs to
activate and reset SchedTune boosting from anywhere in the kernel.

If unsure, say N.

config MEMCG
bool "Memory Resource Controller for Control Groups"
depends on RESOURCE_COUNTERS
Expand Down
91 changes: 91 additions & 0 deletions kernel/sched/tune.c
Expand Up @@ -19,6 +19,12 @@ int sysctl_sched_cfs_boost __read_mostly;

extern struct target_nrg schedtune_target_nrg;

#ifdef CONFIG_DYNAMIC_STUNE_BOOST
static DEFINE_MUTEX(stune_boost_mutex);
static struct schedtune *getSchedtune(char *st_name);
static int dynamic_boost_write(struct schedtune *st, int boost);
#endif /* CONFIG_DYNAMIC_STUNE_BOOST */

/* Performance Boost region (B) threshold params */
static int perf_boost_idx;

Expand Down Expand Up @@ -129,6 +135,14 @@ struct schedtune {
/* Hint to bias scheduling of tasks on that SchedTune CGroup
* towards idle CPUs */
int prefer_idle;

#ifdef CONFIG_DYNAMIC_STUNE_BOOST
/*
* This tracks the default boost value and is used to restore
* the value when Dynamic SchedTune Boost is reset.
*/
int boost_default;
#endif /* CONFIG_DYNAMIC_STUNE_BOOST */
};

static inline struct schedtune *css_st(struct cgroup_subsys_state *css)
Expand Down Expand Up @@ -161,6 +175,9 @@ root_schedtune = {
.perf_boost_idx = 0,
.perf_constrain_idx = 0,
.prefer_idle = 0,
#ifdef CONFIG_DYNAMIC_STUNE_BOOST
.boost_default = 0,
#endif /* CONFIG_DYNAMIC_STUNE_BOOST */
};

int
Expand Down Expand Up @@ -598,6 +615,9 @@ boost_write(struct cgroup_subsys_state *css, struct cftype *cft,
st->perf_constrain_idx = threshold_idx;

st->boost = boost;
#ifdef CONFIG_DYNAMIC_STUNE_BOOST
st->boost_default = boost;
#endif /* CONFIG_DYNAMIC_STUNE_BOOST */
if (css == &root_schedtune.css) {
sysctl_sched_cfs_boost = boost;
perf_boost_idx = threshold_idx;
Expand Down Expand Up @@ -738,6 +758,77 @@ schedtune_init_cgroups(void)
schedtune_initialized = true;
}

#ifdef CONFIG_DYNAMIC_STUNE_BOOST
static struct schedtune *getSchedtune(char *st_name)
{
int idx;

for (idx = 1; idx < BOOSTGROUPS_COUNT; ++idx) {
char name_buf[NAME_MAX + 1];
struct schedtune *st = allocated_group[idx];

if (!st) {
pr_warn("SCHEDTUNE: Could not find %s\n", st_name);
break;
}

cgroup_name(st->css.cgroup, name_buf, sizeof(name_buf));
if (strncmp(name_buf, st_name, strlen(st_name)) == 0)
return st;
}

return NULL;
}

static int dynamic_boost_write(struct schedtune *st, int boost)
{
int ret;
/* Backup boost_default */
int boost_default_backup = st->boost_default;

ret = boost_write(&st->css, NULL, boost);

/* Restore boost_default */
st->boost_default = boost_default_backup;

return ret;
}

int do_stune_boost(char *st_name, int boost)
{
int ret = 0;
struct schedtune *st = getSchedtune(st_name);

if (!st)
return -EINVAL;

mutex_lock(&stune_boost_mutex);

/* Boost if new value is greater than current */
if (boost > st->boost)
ret = dynamic_boost_write(st, boost);

mutex_unlock(&stune_boost_mutex);

return ret;
}

int reset_stune_boost(char *st_name)
{
int ret = 0;
struct schedtune *st = getSchedtune(st_name);

if (!st)
return -EINVAL;

mutex_lock(&stune_boost_mutex);
ret = dynamic_boost_write(st, st->boost_default);
mutex_unlock(&stune_boost_mutex);

return ret;
}
#endif /* CONFIG_DYNAMIC_STUNE_BOOST */

#else /* CONFIG_CGROUP_SCHEDTUNE */

int
Expand Down

0 comments on commit 51e85c0

Please sign in to comment.