[PATCH 1/6] sched/ext: Fix scx vs sched_delayed

Peter Zijlstra posted 6 patches 3 weeks, 4 days ago
[PATCH 1/6] sched/ext: Fix scx vs sched_delayed
Posted by Peter Zijlstra 3 weeks, 4 days ago
Commit 98442f0ccd82 ("sched: Fix delayed_dequeue vs
switched_from_fair()") forgot about scx :/

Fixes: 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()")
Reported-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20241030104934.GK14555@noisy.programming.kicks-ass.net
---
 kernel/sched/ext.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4489,11 +4489,16 @@ static void scx_ops_disable_workfn(struc
 	scx_task_iter_start(&sti);
 	while ((p = scx_task_iter_next_locked(&sti))) {
 		const struct sched_class *old_class = p->sched_class;
+		const struct sched_class *new_class =
+			__setscheduler_class(p->policy, p->prio);
 		struct sched_enq_and_set_ctx ctx;
 
+		if (old_class != new_class && p->se.sched_delayed)
+			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
+
 		sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
 
-		p->sched_class = __setscheduler_class(p->policy, p->prio);
+		p->sched_class = new_class;
 		check_class_changing(task_rq(p), p, old_class);
 
 		sched_enq_and_set_task(&ctx);
@@ -5199,12 +5204,17 @@ static int scx_ops_enable(struct sched_e
 	scx_task_iter_start(&sti);
 	while ((p = scx_task_iter_next_locked(&sti))) {
 		const struct sched_class *old_class = p->sched_class;
+		const struct sched_class *new_class =
+			__setscheduler_class(p->policy, p->prio);
 		struct sched_enq_and_set_ctx ctx;
 
+		if (old_class != new_class && p->se.sched_delayed)
+			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEE_DELAYED);
+
 		sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
 
 		p->scx.slice = SCX_SLICE_DFL;
-		p->sched_class = __setscheduler_class(p->policy, p->prio);
+		p->sched_class = new_class;
 		check_class_changing(task_rq(p), p, old_class);
 
 		sched_enq_and_set_task(&ctx);
Re: [PATCH 1/6] sched/ext: Fix scx vs sched_delayed
Posted by Tejun Heo 3 weeks, 4 days ago
On Wed, Oct 30, 2024 at 04:12:56PM +0100, Peter Zijlstra wrote:
> Commit 98442f0ccd82 ("sched: Fix delayed_dequeue vs
> switched_from_fair()") forgot about scx :/
> 
> Fixes: 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()")
> Reported-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Link: https://lkml.kernel.org/r/20241030104934.GK14555@noisy.programming.kicks-ass.net

Sans the compile issue:

 Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun
Re: [PATCH 1/6] sched/ext: Fix scx vs sched_delayed
Posted by Christian Loehle 3 weeks, 4 days ago
On 10/30/24 15:12, Peter Zijlstra wrote:
> Commit 98442f0ccd82 ("sched: Fix delayed_dequeue vs
> switched_from_fair()") forgot about scx :/
> 
> Fixes: 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()")
> Reported-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Link: https://lkml.kernel.org/r/20241030104934.GK14555@noisy.programming.kicks-ass.net
> ---
>  kernel/sched/ext.c |   14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -4489,11 +4489,16 @@ static void scx_ops_disable_workfn(struc
>  	scx_task_iter_start(&sti);
>  	while ((p = scx_task_iter_next_locked(&sti))) {
>  		const struct sched_class *old_class = p->sched_class;
> +		const struct sched_class *new_class =
> +			__setscheduler_class(p->policy, p->prio);
>  		struct sched_enq_and_set_ctx ctx;
>  
> +		if (old_class != new_class && p->se.sched_delayed)
> +			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
> +
>  		sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
>  
> -		p->sched_class = __setscheduler_class(p->policy, p->prio);
> +		p->sched_class = new_class;
>  		check_class_changing(task_rq(p), p, old_class);
>  
>  		sched_enq_and_set_task(&ctx);
> @@ -5199,12 +5204,17 @@ static int scx_ops_enable(struct sched_e
>  	scx_task_iter_start(&sti);
>  	while ((p = scx_task_iter_next_locked(&sti))) {
>  		const struct sched_class *old_class = p->sched_class;
> +		const struct sched_class *new_class =
> +			__setscheduler_class(p->policy, p->prio);
>  		struct sched_enq_and_set_ctx ctx;
>  
> +		if (old_class != new_class && p->se.sched_delayed)
> +			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEE_DELAYED);
> +

s/DEQUEE_DELAYED/DEQUEUE_DELAYED
Anyway, no luck for me applying the series onto sched/core scx's for-next or rc5.
Any hint or do you mind supplying a branch?
Re: [PATCH 1/6] sched/ext: Fix scx vs sched_delayed
Posted by Peter Zijlstra 3 weeks, 4 days ago
On Wed, Oct 30, 2024 at 03:50:05PM +0000, Christian Loehle wrote:
> On 10/30/24 15:12, Peter Zijlstra wrote:
> > Commit 98442f0ccd82 ("sched: Fix delayed_dequeue vs
> > switched_from_fair()") forgot about scx :/
> > 
> > Fixes: 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()")
> > Reported-by: Tejun Heo <tj@kernel.org>
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > Link: https://lkml.kernel.org/r/20241030104934.GK14555@noisy.programming.kicks-ass.net
> > ---
> >  kernel/sched/ext.c |   14 ++++++++++++--
> >  1 file changed, 12 insertions(+), 2 deletions(-)
> > 
> > --- a/kernel/sched/ext.c
> > +++ b/kernel/sched/ext.c
> > @@ -4489,11 +4489,16 @@ static void scx_ops_disable_workfn(struc
> >  	scx_task_iter_start(&sti);
> >  	while ((p = scx_task_iter_next_locked(&sti))) {
> >  		const struct sched_class *old_class = p->sched_class;
> > +		const struct sched_class *new_class =
> > +			__setscheduler_class(p->policy, p->prio);
> >  		struct sched_enq_and_set_ctx ctx;
> >  
> > +		if (old_class != new_class && p->se.sched_delayed)
> > +			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
> > +
> >  		sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
> >  
> > -		p->sched_class = __setscheduler_class(p->policy, p->prio);
> > +		p->sched_class = new_class;
> >  		check_class_changing(task_rq(p), p, old_class);
> >  
> >  		sched_enq_and_set_task(&ctx);
> > @@ -5199,12 +5204,17 @@ static int scx_ops_enable(struct sched_e
> >  	scx_task_iter_start(&sti);
> >  	while ((p = scx_task_iter_next_locked(&sti))) {
> >  		const struct sched_class *old_class = p->sched_class;
> > +		const struct sched_class *new_class =
> > +			__setscheduler_class(p->policy, p->prio);
> >  		struct sched_enq_and_set_ctx ctx;
> >  
> > +		if (old_class != new_class && p->se.sched_delayed)
> > +			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEE_DELAYED);
> > +
> 
> s/DEQUEE_DELAYED/DEQUEUE_DELAYED

Bah, typing so hard..

> Anyway, no luck for me applying the series onto sched/core scx's for-next or rc5.
> Any hint or do you mind supplying a branch?

I think I did it on top of tip/master..
Re: [PATCH 1/6] sched/ext: Fix scx vs sched_delayed
Posted by Christian Loehle 3 weeks, 4 days ago
On 10/30/24 15:54, Peter Zijlstra wrote:
> On Wed, Oct 30, 2024 at 03:50:05PM +0000, Christian Loehle wrote:
>> On 10/30/24 15:12, Peter Zijlstra wrote:
>>> Commit 98442f0ccd82 ("sched: Fix delayed_dequeue vs
>>> switched_from_fair()") forgot about scx :/
>>>
>>> Fixes: 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()")
>>> Reported-by: Tejun Heo <tj@kernel.org>
>>> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
>>> Link: https://lkml.kernel.org/r/20241030104934.GK14555@noisy.programming.kicks-ass.net
>>> ---
>>>  kernel/sched/ext.c |   14 ++++++++++++--
>>>  1 file changed, 12 insertions(+), 2 deletions(-)
>>>
>>> --- a/kernel/sched/ext.c
>>> +++ b/kernel/sched/ext.c
>>> @@ -4489,11 +4489,16 @@ static void scx_ops_disable_workfn(struc
>>>  	scx_task_iter_start(&sti);
>>>  	while ((p = scx_task_iter_next_locked(&sti))) {
>>>  		const struct sched_class *old_class = p->sched_class;
>>> +		const struct sched_class *new_class =
>>> +			__setscheduler_class(p->policy, p->prio);
>>>  		struct sched_enq_and_set_ctx ctx;
>>>  
>>> +		if (old_class != new_class && p->se.sched_delayed)
>>> +			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
>>> +
>>>  		sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
>>>  
>>> -		p->sched_class = __setscheduler_class(p->policy, p->prio);
>>> +		p->sched_class = new_class;
>>>  		check_class_changing(task_rq(p), p, old_class);
>>>  
>>>  		sched_enq_and_set_task(&ctx);
>>> @@ -5199,12 +5204,17 @@ static int scx_ops_enable(struct sched_e
>>>  	scx_task_iter_start(&sti);
>>>  	while ((p = scx_task_iter_next_locked(&sti))) {
>>>  		const struct sched_class *old_class = p->sched_class;
>>> +		const struct sched_class *new_class =
>>> +			__setscheduler_class(p->policy, p->prio);
>>>  		struct sched_enq_and_set_ctx ctx;
>>>  
>>> +		if (old_class != new_class && p->se.sched_delayed)
>>> +			dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEE_DELAYED);
>>> +
>>
>> s/DEQUEE_DELAYED/DEQUEUE_DELAYED
> 
> Bah, typing so hard..
> 
>> Anyway, no luck for me applying the series onto sched/core scx's for-next or rc5.
>> Any hint or do you mind supplying a branch?
> 
> I think I did it on top of tip/master..

0b9c113ad1c2 (tip/master) Merge branch into tip/master: 'x86/sev'
results in the following diff for me (line number mismatch by 5), stops applying from 2/6:
-- 

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 65334c13ffa5..2b5f1742299a 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -4494,11 +4494,16 @@ static void scx_ops_disable_workfn(struct kthread_work *work)
        scx_task_iter_start(&sti);
        while ((p = scx_task_iter_next_locked(&sti))) {
                const struct sched_class *old_class = p->sched_class;
+               const struct sched_class *new_class =
+                       __setscheduler_class(p->policy, p->prio);
                struct sched_enq_and_set_ctx ctx;
 
+               if (old_class != new_class && p->se.sched_delayed)
+                       dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
+
                sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
 
-               p->sched_class = __setscheduler_class(p->policy, p->prio);
+               p->sched_class = new_class;
                check_class_changing(task_rq(p), p, old_class);
 
                sched_enq_and_set_task(&ctx);