hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8OIT1
--------------------------------
Add hook of sched type in can_migrate_task(), as follows: 'cfs_can_migrate_task' Decide whether the task can be migrated to dst_cpu.
Signed-off-by: Guan Jing guanjing6@huawei.com --- include/linux/sched.h | 7 +++++++ include/linux/sched_hook_defs.h | 2 ++ kernel/sched/fair.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h index 569d055518cc..dfa4c5a22130 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2492,6 +2492,13 @@ struct sched_migrate_ctx { int sd_flag; int new_cpu; }; + +struct sched_migrate_node { + int src_cpu; + int src_node; + int dst_cpu; + int dst_node; +}; #endif
#ifdef CONFIG_SCHED_CORE diff --git a/include/linux/sched_hook_defs.h b/include/linux/sched_hook_defs.h index 0e91209826a1..c43297cc6049 100644 --- a/include/linux/sched_hook_defs.h +++ b/include/linux/sched_hook_defs.h @@ -1,2 +1,4 @@ /* SPDX-License-Identifier: GPL-2.0 */ BPF_SCHED_HOOK(int, -1, cfs_select_rq, struct sched_migrate_ctx *ctx) +BPF_SCHED_HOOK(int, -1, cfs_can_migrate_task, struct task_struct *p, + struct sched_migrate_node *migrate_node) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index fc17a3af11b1..b0f65c68f6bb 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9907,9 +9907,26 @@ static int can_migrate_task(struct task_struct *p, struct lb_env *env) { int tsk_cache_hot; +#ifdef CONFIG_BPF_SCHED + struct sched_migrate_node migrate_node; + int ret; +#endif
lockdep_assert_rq_held(env->src_rq);
+#ifdef CONFIG_BPF_SCHED + if (bpf_sched_enabled()) { + migrate_node.src_cpu = env->src_cpu; + migrate_node.src_node = cpu_to_node(env->src_cpu); + migrate_node.dst_cpu = env->dst_cpu; + migrate_node.dst_node = cpu_to_node(env->dst_cpu); + + ret = bpf_sched_cfs_can_migrate_task(p, &migrate_node); + if (!ret) + return ret; + } +#endif + /* * We do not migrate tasks that are: * 1) throttled_lb_pair, or