[PATCH OLK-6.6 V1 0/2] sched-ebpf-add-for-exec-init

sched-ebpf-add-for-exec-init Cheng Yu (2): sched/ebpf: Add bpf_sched_cfs_exec_set_cpumask hook sched/ebpf: Add kfunc to set the preferred NUMA node for the task fs/exec.c | 7 +++++++ include/linux/sched_hook_defs.h | 1 + kernel/sched/bpf_sched.c | 34 ++++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 11 deletions(-) -- 2.25.1

hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ICFKYV -------------------------------- Add bpf_sched_cfs_exec_set_cpumask hook in exec_binprm, which allows setting cpumask for the process. Signed-off-by: Cheng Yu <serein.chengyu@huawei.com> --- fs/exec.c | 7 +++++++ include/linux/sched_hook_defs.h | 1 + 2 files changed, 8 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 2ac3ef80628f..3dd371dfa89c 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -75,6 +75,7 @@ #include "internal.h" #include <trace/events/sched.h> +#include <linux/bpf_sched.h> static int bprm_creds_from_file(struct linux_binprm *bprm); @@ -1846,6 +1847,12 @@ static int exec_binprm(struct linux_binprm *bprm) trace_sched_process_exec(current, old_pid, bprm); ptrace_event(PTRACE_EVENT_EXEC, old_vpid); proc_exec_connector(current); + +#ifdef CONFIG_BPF_SCHED + if (bpf_sched_enabled()) + bpf_sched_cfs_exec_init(current); +#endif + return 0; } diff --git a/include/linux/sched_hook_defs.h b/include/linux/sched_hook_defs.h index 57b7f61d515c..ef3feef2fee3 100644 --- a/include/linux/sched_hook_defs.h +++ b/include/linux/sched_hook_defs.h @@ -6,3 +6,4 @@ BPF_SCHED_HOOK(int, -1, cfs_tag_entity_eligible, struct sched_entity *se) BPF_SCHED_HOOK(int, -1, cfs_tag_pick_next_entity, const struct sched_entity *curr, const struct sched_entity *next) +BPF_SCHED_HOOK(void, (void) 0, cfs_exec_init, struct task_struct *tsk) -- 2.25.1

hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ICFKYV -------------------------------- The kfunc allows setting preferred NUMA node for the task, and rename the kfunc set. Signed-off-by: Cheng Yu <serein.chengyu@huawei.com> --- kernel/sched/bpf_sched.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/kernel/sched/bpf_sched.c b/kernel/sched/bpf_sched.c index 1973cfacc079..6849a58439b2 100644 --- a/kernel/sched/bpf_sched.c +++ b/kernel/sched/bpf_sched.c @@ -210,18 +210,30 @@ __bpf_kfunc long bpf_sched_tag_of_entity(struct sched_entity *se) return group_cfs_rq(se)->tg->tag; } -BTF_SET8_START(sched_entity_kfunc_btf_ids) +__bpf_kfunc int bpf_sched_set_task_prefer_nid(struct task_struct *task, int nid) +{ + if (!task) + return -EINVAL; + + if ((unsigned int)nid >= nr_node_ids) + return -EINVAL; + + return set_prefer_cpus_ptr(task, cpumask_of_node(nid)); +} + +BTF_SET8_START(sched_task_kfunc_btf_ids) BTF_ID_FLAGS(func, bpf_sched_entity_is_task) BTF_ID_FLAGS(func, bpf_sched_entity_to_task) BTF_ID_FLAGS(func, bpf_sched_tag_of_entity) -BTF_SET8_END(sched_entity_kfunc_btf_ids) +BTF_ID_FLAGS(func, bpf_sched_set_task_prefer_nid) +BTF_SET8_END(sched_task_kfunc_btf_ids) -static const struct btf_kfunc_id_set sched_entity_kfunc_set = { +static const struct btf_kfunc_id_set sched_task_kfunc_set = { .owner = THIS_MODULE, - .set = &sched_entity_kfunc_btf_ids, + .set = &sched_task_kfunc_btf_ids, }; -BTF_ID_LIST(sched_entity_dtor_ids) +BTF_ID_LIST(sched_task_dtor_ids) static int __init bpf_kfunc_init(void) { @@ -232,10 +244,10 @@ static int __init bpf_kfunc_init(void) .kfunc_btf_id = cpustats_dtor_ids[1] }, }; - const struct btf_id_dtor_kfunc sched_entity_dtors[] = { + const struct btf_id_dtor_kfunc sched_task_dtors[] = { { - .btf_id = sched_entity_dtor_ids[0], - .kfunc_btf_id = sched_entity_dtor_ids[1] + .btf_id = sched_task_dtor_ids[0], + .kfunc_btf_id = sched_task_dtor_ids[1] }, }; @@ -245,9 +257,9 @@ static int __init bpf_kfunc_init(void) ret = ret ?: register_btf_id_dtor_kfuncs(cpustats_dtors, ARRAY_SIZE(cpustats_dtors), THIS_MODULE); - ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED, &sched_entity_kfunc_set); - return ret ?: register_btf_id_dtor_kfuncs(sched_entity_dtors, - ARRAY_SIZE(sched_entity_dtors), + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED, &sched_task_kfunc_set); + return ret ?: register_btf_id_dtor_kfuncs(sched_task_dtors, + ARRAY_SIZE(sched_task_dtors), THIS_MODULE); } late_initcall(bpf_kfunc_init); -- 2.25.1

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/17511 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/NYV... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/17511 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/NYV...
participants (2)
-
Cheng Yu
-
patchwork bot