Skip to content

Commit

Permalink
kernel: Restore schedtune compatibility
Browse files Browse the repository at this point in the history
When SCHED_TUNE is disabled, certain elements in userspace, like
libperfmgr, may throw errors when it doesn't detect SCHEDTUNE-related nodes.
So, create a few dummy nodes to satisfy said userspace elements.

Change-Id: I24df608349551c94d4b50d0764548bd669e5a770
Signed-off-by: darkhz <[email protected]>
Signed-off-by: Panchajanya1999 <[email protected]>
  • Loading branch information
darkhz authored and saikiran2001-v2 committed Apr 14, 2023
1 parent e6f4b71 commit 7b0b07a
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/linux/cgroup_subsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SUBSYS(cpu)
SUBSYS(cpuacct)
#endif

#if IS_ENABLED(CONFIG_SCHED_TUNE)
#if IS_ENABLED(CONFIG_SCHED_TUNE) || IS_ENABLED(CONFIG_SCHED_TUNE_DUMMY)
SUBSYS(schedtune)
#endif

Expand Down
7 changes: 7 additions & 0 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,13 @@ config SCHED_TUNE

If unsure, say N.

config SCHED_TUNE_DUMMY
bool "Create dummy SCHEDTUNE nodes"
depends on SMP
depends on !SCHED_TUNE
help
Create dummy SCHEDTUNE nodes.

config DEFAULT_USE_ENERGY_AWARE
bool "Default to enabling the Energy Aware Scheduler feature"
default n
Expand Down
1 change: 1 addition & 0 deletions kernel/sched/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ obj-$(CONFIG_SCHED_AUTOGROUP) += autogroup.o
obj-$(CONFIG_SCHEDSTATS) += stats.o
obj-$(CONFIG_SCHED_DEBUG) += debug.o
obj-$(CONFIG_SCHED_TUNE) += tune.o
obj-$(CONFIG_SCHED_TUNE_DUMMY) += tune_dummy.o
obj-$(CONFIG_CGROUP_CPUACCT) += cpuacct.o
obj-$(CONFIG_CPU_FREQ) += cpufreq.o
obj-$(CONFIG_CPU_FREQ_GOV_SCHEDUTIL) += cpufreq_schedutil.o
Expand Down
122 changes: 122 additions & 0 deletions kernel/sched/tune_dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include <linux/cgroup.h>
#include "sched.h"

#define BOOSTGROUPS_COUNT 5

struct schedtune {
/* SchedTune CGroup subsystem */
struct cgroup_subsys_state css;

/* Boost value for tasks on that SchedTune CGroup */
int boost;

/* Hint to bias scheduling of tasks on that SchedTune CGroup
* towards idle CPUs */
int prefer_idle;
};

static struct schedtune
root_schedtune = {
.boost = 0,
.prefer_idle = 0,
};

static struct schedtune *allocated_group[BOOSTGROUPS_COUNT] = {
&root_schedtune,
NULL,
};

static inline struct schedtune *css_st(struct cgroup_subsys_state *css)
{
return container_of(css, struct schedtune, css);
}

static u64
prefer_idle_read(struct cgroup_subsys_state *css, struct cftype *cft)
{
return 0;
}

static int
prefer_idle_write(struct cgroup_subsys_state *css, struct cftype *cft,
u64 prefer_idle)
{
return 0;
}

static s64
boost_read(struct cgroup_subsys_state *css, struct cftype *cft)
{
return 0;
}

static int
boost_write(struct cgroup_subsys_state *css, struct cftype *cft,
s64 boost)
{
return 0;
}

static struct cftype files[] = {
{
.name = "boost",
.read_s64 = boost_read,
.write_s64 = boost_write,
},
{
.name = "prefer_idle",
.read_u64 = prefer_idle_read,
.write_u64 = prefer_idle_write,
},
{ } /* terminate */
};

static struct cgroup_subsys_state *
schedtune_css_alloc(struct cgroup_subsys_state *parent_css)
{
struct schedtune *st;
int idx;

if (!parent_css)
return &root_schedtune.css;

/* Allow only single level hierachies */
if (parent_css != &root_schedtune.css) {
pr_err("Nested SchedTune boosting groups not allowed\n");
return ERR_PTR(-ENOMEM);
}

/* Allow only a limited number of boosting groups */
for (idx = 1; idx < BOOSTGROUPS_COUNT; ++idx)
if (!allocated_group[idx])
break;
if (idx == BOOSTGROUPS_COUNT) {
pr_err("Trying to create more than %d SchedTune boosting groups\n",
BOOSTGROUPS_COUNT);
return ERR_PTR(-ENOSPC);
}

st = kzalloc(sizeof(*st), GFP_KERNEL);
if (!st)
goto out;

return &st->css;

out:
return ERR_PTR(-ENOMEM);
}

static void
schedtune_css_free(struct cgroup_subsys_state *css)
{
struct schedtune *st = css_st(css);

kfree(st);
}

struct cgroup_subsys schedtune_cgrp_subsys = {
.css_alloc = schedtune_css_alloc,
.css_free = schedtune_css_free,
.legacy_cftypes = files,
.early_init = 1,
};

0 comments on commit 7b0b07a

Please sign in to comment.