From: Tejun Heo <tj@kernel.org> mainline inclusion from mainline-v6.12-rc1 commit 2c8d046d5d51691550da023976815e7a64151636 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IDC9YK Reference: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commi... -------------------------------- A new BPF extensible sched_class will need to dynamically change how a task picks its sched_class. For example, if the loaded BPF scheduler progs fail, the tasks will be forced back on CFS even if the task's policy is set to the new sched_class. To support such mapping, add normal_policy() which wraps testing for %SCHED_NORMAL. This doesn't cause any behavior changes. v2: Update the description with more details on the expected use. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: David Vernet <dvernet@meta.com> Acked-by: Josh Don <joshdon@google.com> Acked-by: Hao Luo <haoluo@google.com> Acked-by: Barret Rhoden <brho@google.com> Conflicts: kernel/sched/fair.c kernel/sched/sched.h [Only pick the part modified by this mainline commit, and ignore the conflict part caused by higher version.] Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- kernel/sched/fair.c | 2 +- kernel/sched/sched.h | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 3e316c5cdbd0..8db61776907e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9607,7 +9607,7 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_ /* * BATCH and IDLE tasks do not preempt others. */ - if (unlikely(p->policy != SCHED_NORMAL)) + if (unlikely(!normal_policy(p->policy))) return; cfs_rq = cfs_rq_of(se); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index cba4b475be99..e0c6880d7b9e 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -188,9 +188,15 @@ static inline int idle_policy(int policy) { return policy == SCHED_IDLE; } + +static inline int normal_policy(int policy) +{ + return policy == SCHED_NORMAL; +} + static inline int fair_policy(int policy) { - return policy == SCHED_NORMAL || policy == SCHED_BATCH; + return normal_policy(policy) || policy == SCHED_BATCH; } static inline int rt_policy(int policy) -- 2.34.1