
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/ICA1GK -------------------------------- Which is to get the cpuset cgroup that a task lies in. Signed-off-by: GONG Ruiqi <gongruiqi1@huawei.com> --- kernel/bpf-rvi/Kconfig | 1 + kernel/cgroup/cpuset.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/kernel/bpf-rvi/Kconfig b/kernel/bpf-rvi/Kconfig index a23cf696f021..0e356ae6fc85 100644 --- a/kernel/bpf-rvi/Kconfig +++ b/kernel/bpf-rvi/Kconfig @@ -6,6 +6,7 @@ config BPF_RVI depends on BPF_EVENTS depends on BPF_SYSCALL depends on BPF_JIT + depends on CPUSETS default n help A resource view is a bundle of interfaces under /proc and /sys diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 26d3a17e8806..992433114ed2 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -46,6 +46,12 @@ #include <linux/wait.h> #include <linux/kabi.h> +#ifdef CONFIG_BPF_RVI +#include <linux/bpf.h> +#include <linux/btf.h> +#include <linux/btf_ids.h> +#endif + DEFINE_STATIC_KEY_FALSE(cpusets_pre_enable_key); DEFINE_STATIC_KEY_FALSE(cpusets_enabled_key); @@ -5200,3 +5206,28 @@ void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task) seq_printf(m, "Mems_allowed_list:\t%*pbl\n", nodemask_pr_args(&task->mems_allowed)); } + +#ifdef CONFIG_BPF_RVI +__bpf_kfunc struct cpuset *bpf_cpuset_from_task(struct task_struct *task) +{ + if (!task) + return NULL; + return task_cs(task); +} + +BTF_SET8_START(bpf_cpuset_kfunc_ids) +BTF_ID_FLAGS(func, bpf_cpuset_from_task, KF_RET_NULL | KF_RCU) +BTF_SET8_END(bpf_cpuset_kfunc_ids) + +static const struct btf_kfunc_id_set bpf_cpuset_kfunc_set = { + .owner = THIS_MODULE, + .set = &bpf_cpuset_kfunc_ids, +}; + +static int __init bpf_cpuset_kfunc_init(void) +{ + return register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, + &bpf_cpuset_kfunc_set); +} +late_initcall(bpf_cpuset_kfunc_init); +#endif -- 2.25.1