From: Aboorva Devarajan <aboorvad@linux.ibm.com> hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IDC9YK -------------------------------- This commit comes from mainline 5db91545ef81 ("sched: Pass correct scheduling policy to __setscheduler_class"), which was to adapt the commit 98442f0ccd82 ("sched: Fix delayed_dequque vs switched_from_fair()"). However, this version does not has thea feature delayed queue, so only pick the necessary code for sched_ext. For now, this current hulk patch does not change any code logic, only to make less conflicts later for the comming sched_ext patches. Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com> Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- kernel/sched/core.c | 18 ++++++++++++------ kernel/sched/ext.c | 12 ++++++++---- kernel/sched/ext.h | 2 +- kernel/sched/sched.h | 3 ++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index d852cf17b2c4..b9b36f77942f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4684,7 +4684,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p) if (rt_prio(p->prio)) { p->sched_class = &rt_sched_class; #ifdef CONFIG_SCHED_CLASS_EXT - } else if (task_should_scx(p)) { + } else if (task_should_scx(p->policy)) { p->sched_class = &ext_sched_class; #endif } else { @@ -6980,7 +6980,7 @@ void __setscheduler_prio(struct task_struct *p, int prio) else if (rt_prio(prio)) p->sched_class = &rt_sched_class; #ifdef CONFIG_SCHED_CLASS_EXT - else if (task_should_scx(p)) + else if (task_should_scx(p->policy)) p->sched_class = &ext_sched_class; #endif else @@ -6991,10 +6991,16 @@ void __setscheduler_prio(struct task_struct *p, int prio) /* * Currently, __setscheduler_class is mainly picked for sched_ext, - * but in mainline it is for delayed_dequeue in EEVDF, the commit is - * 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()") + * but the original patch comes from mainline, the commits are: + * + * 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()"): + * it is for delayed_dequeue in EEVDF + * + * 5db91545ef81 + * ("sched: Pass correct scheduling policy to __setscheduler_class"): + * it is to adopt __setscheduler_class() in sched_ext. */ -const struct sched_class *__setscheduler_class(struct task_struct *p, int prio) +const struct sched_class *__setscheduler_class(int policy, int prio) { if (dl_prio(prio)) return &dl_sched_class; @@ -7003,7 +7009,7 @@ const struct sched_class *__setscheduler_class(struct task_struct *p, int prio) return &rt_sched_class; #ifdef CONFIG_SCHED_CLASS_EXT - if (task_should_scx(p)) + if (task_should_scx(policy)) return &ext_sched_class; #endif diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 868f6e5a385e..c9670f54984b 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -4264,14 +4264,14 @@ static const struct kset_uevent_ops scx_uevent_ops = { * Used by sched_fork() and __setscheduler_prio() to pick the matching * sched_class. dl/rt are already handled. */ -bool task_should_scx(struct task_struct *p) +bool task_should_scx(int policy) { if (!scx_enabled() || unlikely(scx_ops_enable_state() == SCX_OPS_DISABLING)) return false; if (READ_ONCE(scx_switching_all)) return true; - return p->policy == SCHED_EXT; + return policy == SCHED_EXT; } /** @@ -4504,8 +4504,10 @@ static void scx_ops_disable_workfn(struct kthread_work *work) /* * pick from mainline * 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()") + * 5db91545ef81 ("sched: Pass correct scheduling policy to + * __setscheduler_class") */ - p->sched_class = __setscheduler_class(p, p->prio); + p->sched_class = __setscheduler_class(p->policy, p->prio); check_class_changing(task_rq(p), p, old_class); sched_enq_and_set_task(&ctx); @@ -5220,8 +5222,10 @@ static int scx_ops_enable(struct sched_ext_ops *ops) /* * pick from mainline * 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()") + * 5db91545ef81 ("sched: Pass correct scheduling policy to + * __setscheduler_class") */ - p->sched_class = __setscheduler_class(p, p->prio); + p->sched_class = __setscheduler_class(p->policy, p->prio); check_class_changing(task_rq(p), p, old_class); sched_enq_and_set_task(&ctx); diff --git a/kernel/sched/ext.h b/kernel/sched/ext.h index 246019519231..b1675bb59fc4 100644 --- a/kernel/sched/ext.h +++ b/kernel/sched/ext.h @@ -18,7 +18,7 @@ bool scx_can_stop_tick(struct rq *rq); void scx_rq_activate(struct rq *rq); void scx_rq_deactivate(struct rq *rq); int scx_check_setscheduler(struct task_struct *p, int policy); -bool task_should_scx(struct task_struct *p); +bool task_should_scx(int policy); void init_sched_ext_class(void); static inline u32 scx_cpuperf_target(s32 cpu) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 3ea70281aab6..4360b7e2814a 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -4055,8 +4055,9 @@ extern void __setscheduler_params(struct task_struct *p, const struct sched_attr /* * pick from mainline * 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()") + * 5db91545ef81 ("sched: Pass correct scheduling policy to __setscheduler_class") */ -extern const struct sched_class *__setscheduler_class(struct task_struct *p, int prio); +extern const struct sched_class *__setscheduler_class(int policy, int prio); extern void set_load_weight(struct task_struct *p, bool update_load); extern void enqueue_task(struct rq *rq, struct task_struct *p, int flags); extern bool dequeue_task(struct rq *rq, struct task_struct *p, int flags); -- 2.34.1