
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ICB7K1 -------------------------------- Addd a command-line "sched_soft_domain" switch for the soft domain feature; this switch is enabled by default. Signed-off-by: Zhang Qiao <zhangqiao22@huawei.com> --- kernel/sched/core.c | 9 ++++++++ kernel/sched/soft_domain.c | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e23a81913984..07101f6b10a4 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9998,6 +9998,9 @@ static s64 cpu_soft_domain_read_s64(struct cgroup_subsys_state *css, { struct task_group *tg = css_tg(css); + if (!tg->sf_ctx) + return 0; + return (s64)tg->sf_ctx->policy; } @@ -10017,6 +10020,9 @@ static u64 cpu_soft_domain_quota_read_u64(struct cgroup_subsys_state *css, { struct task_group *tg = css_tg(css); + if (!tg->sf_ctx) + return 0; + return (u64)tg->sf_ctx->nr_cpus; } @@ -10024,6 +10030,9 @@ static int soft_domain_cpu_list_seq_show(struct seq_file *sf, void *v) { struct task_group *tg = css_tg(seq_css(sf)); + if (!tg->sf_ctx) + return 0; + seq_printf(sf, "%*pbl\n", cpumask_pr_args(to_cpumask(tg->sf_ctx->span))); return 0; diff --git a/kernel/sched/soft_domain.c b/kernel/sched/soft_domain.c index f20ff3b54fdc..b8bbfef42b23 100644 --- a/kernel/sched/soft_domain.c +++ b/kernel/sched/soft_domain.c @@ -18,6 +18,30 @@ #include "sched.h" #include <linux/sort.h> +static DEFINE_STATIC_KEY_TRUE(__soft_domain_switch); + +static int __init soft_domain_switch_setup(char *str) +{ + int val = 0; + + if (kstrtoint(str, 0, &val)) + pr_warn("sched_soft_domain parameter is error: %s\n", str); + else { + if (val == 1) + static_branch_enable(&__soft_domain_switch); + else if (val == 0) + static_branch_disable(&__soft_domain_switch); + } + + return 1; +} +__setup("sched_soft_domain=", soft_domain_switch_setup); + +static bool soft_domain_enabled(void) +{ + return static_branch_likely(&__soft_domain_switch); +} + static DEFINE_PER_CPU(struct soft_domain *, g_sf_d); static void free_sub_soft_domain(struct soft_domain *sf_d); @@ -87,6 +111,8 @@ static void free_soft_domain(void) if (sf_d) free_sub_soft_domain(sf_d); } + + static_branch_disable(&__soft_domain_switch); } void build_soft_domain(void) @@ -95,6 +121,9 @@ void build_soft_domain(void) static struct cpumask cpus; int i, ret; + if (!soft_domain_enabled()) + return; + cpumask_copy(&cpus, cpu_active_mask); rcu_read_lock(); for_each_cpu(i, &cpus) { @@ -358,6 +387,9 @@ int sched_group_set_soft_domain(struct task_group *tg, long val) { int ret = 0; + if (!soft_domain_enabled()) + return -EPERM; + if (val < -1 || val > nr_node_ids) return -EINVAL; @@ -385,6 +417,9 @@ int sched_group_set_soft_domain_quota(struct task_group *tg, long val) { int ret = 0; + if (!soft_domain_enabled()) + return -EPERM; + mutex_lock(&soft_domain_mutex); if (tg->sf_ctx->policy != 0) { ret = -EINVAL; @@ -403,6 +438,9 @@ int init_soft_domain(struct task_group *tg, struct task_group *parent) struct soft_domain_ctx *sf_ctx = NULL; struct soft_domain_ctx *psf_ctx = NULL; + if (!soft_domain_enabled()) + return 0; + sf_ctx = kzalloc(sizeof(*sf_ctx) + cpumask_size(), GFP_KERNEL); if (!sf_ctx) return -ENOMEM; @@ -426,6 +464,9 @@ void offline_soft_domain(struct task_group *tg) struct soft_domain_ctx *sf_ctx = NULL; struct soft_domain_ctx *psf_ctx = NULL; + if (!soft_domain_enabled()) + return; + sf_ctx = tg->sf_ctx; psf_ctx = tg->parent->sf_ctx; @@ -446,6 +487,9 @@ void offline_soft_domain(struct task_group *tg) int destroy_soft_domain(struct task_group *tg) { + if (!soft_domain_enabled()) + return 0; + kfree(tg->sf_ctx); return 0; -- 2.18.0.huawei.25