Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1590437 > unrolled thread

Re: [PATCH] sched: Optimize pick_next_task for idle_sched_class too

Started bySteven Rostedt <rostedt@goodmis.org>
First post2017-03-01 17:00 +0100
Last post2017-03-01 17:50 +0100
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] sched: Optimize pick_next_task for idle_sched_class too Steven Rostedt <rostedt@goodmis.org> - 2017-03-01 17:00 +0100
    Re: [PATCH] sched: Optimize pick_next_task for idle_sched_class too Steven Rostedt <rostedt@goodmis.org> - 2017-03-01 17:30 +0100
      Re: [PATCH] sched: Optimize pick_next_task for idle_sched_class too Peter Zijlstra <peterz@infradead.org> - 2017-03-01 17:50 +0100
    Re: [PATCH] sched: Optimize pick_next_task for idle_sched_class too Peter Zijlstra <peterz@infradead.org> - 2017-03-01 17:50 +0100

#1590437 — Re: [PATCH] sched: Optimize pick_next_task for idle_sched_class too

FromSteven Rostedt <rostedt@goodmis.org>
Date2017-03-01 17:00 +0100
SubjectRe: [PATCH] sched: Optimize pick_next_task for idle_sched_class too
Message-ID<tgePw-5b2-5@gated-at.bofh.it>
On Thu, 23 Feb 2017 20:45:06 +0530
Pavan Kondeti <pkondeti@codeaurora.org> wrote:

> Hi Peter,
> 
> On Thu, Feb 23, 2017 at 7:24 PM, Peter Zijlstra <peterz@infradead.org> wrote:
> > On Thu, Feb 23, 2017 at 04:04:22PM +0530, Pavan Kondeti wrote:  
> >> Hi Peter,
> >>  
> >> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> >> > index 49ce1cb..51ca21e 100644
> >> > --- a/kernel/sched/core.c
> >> > +++ b/kernel/sched/core.c
> >> > @@ -3321,15 +3321,14 @@ static inline void schedule_debug(struct task_struct *prev)
> >> >  static inline struct task_struct *
> >> >  pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
> >> >  {
> >> > -       const struct sched_class *class = &fair_sched_class;
> >> > +       const struct sched_class *class;
> >> >         struct task_struct *p;
> >> >
> >> >         /*
> >> >          * Optimization: we know that if all tasks are in
> >> >          * the fair class we can call that function directly:
> >> >          */
> >> > -       if (likely(prev->sched_class == class &&
> >> > -                  rq->nr_running == rq->cfs.h_nr_running)) {
> >> > +       if (likely(rq->nr_running == rq->cfs.h_nr_running)) {
> >> >                 p = fair_sched_class.pick_next_task(rq, prev, rf);
> >> >                 if (unlikely(p == RETRY_TASK))
> >> >                         goto again;  
> >>
> >> Would this delay pulling RT tasks from other CPUs? Lets say this CPU
> >> has 2 fair tasks and 1 RT task. The RT task is sleeping now. Earlier,
> >> we attempt to pull RT tasks from other CPUs in pick_next_task_rt(),
> >> which is not done anymore.  
> >
> > It should not; the two places of interrests are when we leave the RT
> > class to run anything lower (fair,idle), at which point we'll pull,
> > or when an RT tasks wakes up, at which point it'll push.  
> 
> Can you kindly show me where we are pulling when a RT task goes to
> sleep? Apart from class/prio change, I see pull happening only from
> pick_next_task_rt().

Thanks for pointing this out. I was just doing some tests with my
migrate program and it was failing dramatically. Then looking at why,
it appeared to be missing pushes. Putting back in my old patch, fixed
it up.

Peter, do we have a solution for this yet? Are you going to add the one
with the linker magic?

-- Steve

[toc] | [next] | [standalone]


#1590486

FromSteven Rostedt <rostedt@goodmis.org>
Date2017-03-01 17:30 +0100
Message-ID<tgfix-5AK-1@gated-at.bofh.it>
In reply to#1590437
On Wed, 1 Mar 2017 17:03:52 +0100
Peter Zijlstra <peterz@infradead.org> wrote:

> On Wed, Mar 01, 2017 at 10:53:03AM -0500, Steven Rostedt wrote:
> > Peter, do we have a solution for this yet? Are you going to add the one
> > with the linker magic?  
> 
> I queued the below earlier today.

Isn't this pretty much identical to the patch I sent you a month ago?

  http://lkml.kernel.org/r/20170119101703.2abeaeb6@gandalf.local.home

-- Steve

> 
> ---
> Subject: sched: Fix pick_next_task() for RT,DL
> From: Peter Zijlstra <peterz@infradead.org>
> Date: Wed Mar  1 10:51:47 CET 2017
> 
> Pavan noticed that commit 49ee576809d8 ("sched/core: Optimize
> pick_next_task() for idle_sched_class") broke RT,DL balancing by
> robbing them of the opportinty to do new-'idle' balancing when their
> last runnable task (on that runqueue) goes away.
> 
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Reported-by: Pavan Kondeti <pkondeti@codeaurora.org>
> Fixes: 49ee576809d8 ("sched/core: Optimize pick_next_task() for idle_sched_class")
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -3273,10 +3273,15 @@ pick_next_task(struct rq *rq, struct tas
>  	struct task_struct *p;
>  
>  	/*
> -	 * Optimization: we know that if all tasks are in
> -	 * the fair class we can call that function directly:
> +	 * Optimization: we know that if all tasks are in the fair class we can
> +	 * call that function directly, but only if the @pref task wasn't of a
> +	 * higher scheduling class, because otherwise those loose the
> +	 * opportunity to pull in more work from other CPUs.
>  	 */
> -	if (likely(rq->nr_running == rq->cfs.h_nr_running)) {
> +	if (likely((prev->sched_class == &idle_sched_class ||
> +		    prev->sched_class == &fair_sched_class) &&
> +		   rq->nr_running == rq->cfs.h_nr_running)) {
> +
>  		p = fair_sched_class.pick_next_task(rq, prev, rf);
>  		if (unlikely(p == RETRY_TASK))
>  			goto again;

[toc] | [prev] | [next] | [standalone]


#1590504

FromPeter Zijlstra <peterz@infradead.org>
Date2017-03-01 17:50 +0100
Message-ID<tgfBT-5HN-9@gated-at.bofh.it>
In reply to#1590486
On Wed, Mar 01, 2017 at 11:19:22AM -0500, Steven Rostedt wrote:
> On Wed, 1 Mar 2017 17:03:52 +0100
> Peter Zijlstra <peterz@infradead.org> wrote:
> 
> > On Wed, Mar 01, 2017 at 10:53:03AM -0500, Steven Rostedt wrote:
> > > Peter, do we have a solution for this yet? Are you going to add the one
> > > with the linker magic?  
> > 
> > I queued the below earlier today.
> 
> Isn't this pretty much identical to the patch I sent you a month ago?
> 
>   http://lkml.kernel.org/r/20170119101703.2abeaeb6@gandalf.local.home

Yes, except this one has a comment explaining why we care about
prev->sched_class.

[toc] | [prev] | [next] | [standalone]


#1590507

FromPeter Zijlstra <peterz@infradead.org>
Date2017-03-01 17:50 +0100
Message-ID<tgfix-5AK-3@gated-at.bofh.it>
In reply to#1590437
On Wed, Mar 01, 2017 at 10:53:03AM -0500, Steven Rostedt wrote:
> Peter, do we have a solution for this yet? Are you going to add the one
> with the linker magic?

I queued the below earlier today.

---
Subject: sched: Fix pick_next_task() for RT,DL
From: Peter Zijlstra <peterz@infradead.org>
Date: Wed Mar  1 10:51:47 CET 2017

Pavan noticed that commit 49ee576809d8 ("sched/core: Optimize
pick_next_task() for idle_sched_class") broke RT,DL balancing by
robbing them of the opportinty to do new-'idle' balancing when their
last runnable task (on that runqueue) goes away.

Cc: Steven Rostedt <rostedt@goodmis.org>
Reported-by: Pavan Kondeti <pkondeti@codeaurora.org>
Fixes: 49ee576809d8 ("sched/core: Optimize pick_next_task() for idle_sched_class")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3273,10 +3273,15 @@ pick_next_task(struct rq *rq, struct tas
 	struct task_struct *p;
 
 	/*
-	 * Optimization: we know that if all tasks are in
-	 * the fair class we can call that function directly:
+	 * Optimization: we know that if all tasks are in the fair class we can
+	 * call that function directly, but only if the @pref task wasn't of a
+	 * higher scheduling class, because otherwise those loose the
+	 * opportunity to pull in more work from other CPUs.
 	 */
-	if (likely(rq->nr_running == rq->cfs.h_nr_running)) {
+	if (likely((prev->sched_class == &idle_sched_class ||
+		    prev->sched_class == &fair_sched_class) &&
+		   rq->nr_running == rq->cfs.h_nr_running)) {
+
 		p = fair_sched_class.pick_next_task(rq, prev, rf);
 		if (unlikely(p == RETRY_TASK))
 			goto again;

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web