From 224980fd5760c75abb4b3e791fa3020a90f1cb4a Mon Sep 17 00:00:00 2001 From: Chen Hui Date: Fri, 25 Nov 2022 11:56:13 +0800 Subject: [PATCH] sched: programmable: Add a tag for the task hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I5KUFB CVE: NA -------------------------------- Add a tag for the task, useful to identify the special task. User can use the file system interface to mark different tags for specific workloads. The kernel subsystems can use the set_* helpers to mark it too. The bpf prog obtains the tags to detect different workloads. Signed-off-by: Chen Hui Signed-off-by: Ren Zhijie Signed-off-by: Hui Tang --- include/linux/sched.h | 5 +++++ init/init_task.c | 3 +++ kernel/sched/core.c | 3 +++ 3 files changed, 11 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 888e5cc2fb6a..fbd0f947643c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1416,7 +1416,12 @@ struct task_struct { KABI_RESERVE(4) KABI_RESERVE(5) #endif +#ifdef CONFIG_BPF_SCHED + /* Used to pad the tag of a task */ + KABI_USE(6, long tag) +#else KABI_RESERVE(6) +#endif KABI_RESERVE(7) KABI_RESERVE(8) KABI_RESERVE(9) diff --git a/init/init_task.c b/init/init_task.c index 891007de2eef..49418809de26 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -216,6 +216,9 @@ struct task_struct init_task #endif #ifdef CONFIG_SECCOMP_FILTER .seccomp = { .filter_count = ATOMIC_INIT(0) }, +#endif +#ifdef CONFIG_BPF_SCHED + .tag = 0, #endif ._resvd = &init_task_struct_resvd, }; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 61b89cf69976..2c30aceed1e9 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3477,6 +3477,9 @@ static void __sched_fork(unsigned long clone_flags, struct task_struct *p) #ifdef CONFIG_SMP p->wake_entry.u_flags = CSD_TYPE_TTWU; #endif +#ifdef CONFIG_BPF_SCHED + p->tag = 0; +#endif } DEFINE_STATIC_KEY_FALSE(sched_numa_balancing); -- GitLab