Skip to content

Commit 5db9154

Browse files
AboorvaDevarajanPeter Zijlstra
authored andcommitted
sched: Pass correct scheduling policy to __setscheduler_class
Commit 98442f0 ("sched: Fix delayed_dequeue vs switched_from_fair()") overlooked that __setscheduler_prio(), now __setscheduler_class() relies on p->policy for task_should_scx(), and moved the call before __setscheduler_params() updates it, causing it to be using the old p->policy value. Resolve this by changing task_should_scx() to take the policy itself instead of a task pointer, such that __sched_setscheduler() can pass in the updated policy. Fixes: 98442f0 ("sched: Fix delayed_dequeue vs switched_from_fair()") Signed-off-by: Aboorva Devarajan <aboorvad@linux.ibm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Tejun Heo <tj@kernel.org>
1 parent 9c70b2a commit 5db9154

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

kernel/sched/core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4711,7 +4711,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
47114711
if (rt_prio(p->prio)) {
47124712
p->sched_class = &rt_sched_class;
47134713
#ifdef CONFIG_SCHED_CLASS_EXT
4714-
} else if (task_should_scx(p)) {
4714+
} else if (task_should_scx(p->policy)) {
47154715
p->sched_class = &ext_sched_class;
47164716
#endif
47174717
} else {
@@ -7025,7 +7025,7 @@ int default_wake_function(wait_queue_entry_t *curr, unsigned mode, int wake_flag
70257025
}
70267026
EXPORT_SYMBOL(default_wake_function);
70277027

7028-
const struct sched_class *__setscheduler_class(struct task_struct *p, int prio)
7028+
const struct sched_class *__setscheduler_class(int policy, int prio)
70297029
{
70307030
if (dl_prio(prio))
70317031
return &dl_sched_class;
@@ -7034,7 +7034,7 @@ const struct sched_class *__setscheduler_class(struct task_struct *p, int prio)
70347034
return &rt_sched_class;
70357035

70367036
#ifdef CONFIG_SCHED_CLASS_EXT
7037-
if (task_should_scx(p))
7037+
if (task_should_scx(policy))
70387038
return &ext_sched_class;
70397039
#endif
70407040

@@ -7142,7 +7142,7 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
71427142
queue_flag &= ~DEQUEUE_MOVE;
71437143

71447144
prev_class = p->sched_class;
7145-
next_class = __setscheduler_class(p, prio);
7145+
next_class = __setscheduler_class(p->policy, prio);
71467146

71477147
if (prev_class != next_class && p->se.sched_delayed)
71487148
dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);

kernel/sched/ext.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,14 +4256,14 @@ static const struct kset_uevent_ops scx_uevent_ops = {
42564256
* Used by sched_fork() and __setscheduler_prio() to pick the matching
42574257
* sched_class. dl/rt are already handled.
42584258
*/
4259-
bool task_should_scx(struct task_struct *p)
4259+
bool task_should_scx(int policy)
42604260
{
42614261
if (!scx_enabled() ||
42624262
unlikely(scx_ops_enable_state() == SCX_OPS_DISABLING))
42634263
return false;
42644264
if (READ_ONCE(scx_switching_all))
42654265
return true;
4266-
return p->policy == SCHED_EXT;
4266+
return policy == SCHED_EXT;
42674267
}
42684268

42694269
/**
@@ -4493,7 +4493,7 @@ static void scx_ops_disable_workfn(struct kthread_work *work)
44934493

44944494
sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
44954495

4496-
p->sched_class = __setscheduler_class(p, p->prio);
4496+
p->sched_class = __setscheduler_class(p->policy, p->prio);
44974497
check_class_changing(task_rq(p), p, old_class);
44984498

44994499
sched_enq_and_set_task(&ctx);
@@ -5204,7 +5204,7 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
52045204
sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
52055205

52065206
p->scx.slice = SCX_SLICE_DFL;
5207-
p->sched_class = __setscheduler_class(p, p->prio);
5207+
p->sched_class = __setscheduler_class(p->policy, p->prio);
52085208
check_class_changing(task_rq(p), p, old_class);
52095209

52105210
sched_enq_and_set_task(&ctx);

kernel/sched/ext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool scx_can_stop_tick(struct rq *rq);
1818
void scx_rq_activate(struct rq *rq);
1919
void scx_rq_deactivate(struct rq *rq);
2020
int scx_check_setscheduler(struct task_struct *p, int policy);
21-
bool task_should_scx(struct task_struct *p);
21+
bool task_should_scx(int policy);
2222
void init_sched_ext_class(void);
2323

2424
static inline u32 scx_cpuperf_target(s32 cpu)

kernel/sched/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3830,7 +3830,7 @@ static inline int rt_effective_prio(struct task_struct *p, int prio)
38303830

38313831
extern int __sched_setscheduler(struct task_struct *p, const struct sched_attr *attr, bool user, bool pi);
38323832
extern int __sched_setaffinity(struct task_struct *p, struct affinity_context *ctx);
3833-
extern const struct sched_class *__setscheduler_class(struct task_struct *p, int prio);
3833+
extern const struct sched_class *__setscheduler_class(int policy, int prio);
38343834
extern void set_load_weight(struct task_struct *p, bool update_load);
38353835
extern void enqueue_task(struct rq *rq, struct task_struct *p, int flags);
38363836
extern bool dequeue_task(struct rq *rq, struct task_struct *p, int flags);

kernel/sched/syscalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ int __sched_setscheduler(struct task_struct *p,
707707
}
708708

709709
prev_class = p->sched_class;
710-
next_class = __setscheduler_class(p, newprio);
710+
next_class = __setscheduler_class(policy, newprio);
711711

712712
if (prev_class != next_class && p->se.sched_delayed)
713713
dequeue_task(rq, p, DEQUEUE_SLEEP | DEQUEUE_DELAYED | DEQUEUE_NOCLOCK);

0 commit comments

Comments
 (0)