linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/fair: tweak pick_next_entity
@ 2020-09-30 17:35 Peter Oskolkov
  2020-10-01  7:17 ` Vincent Guittot
  2020-10-05  7:43 ` [tip: sched/core] sched/fair: Tweak pick_next_entity() tip-bot2 for Peter Oskolkov
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Oskolkov @ 2020-09-30 17:35 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Vincent Guittot, Dietmar Eggemann,
	linux-kernel
  Cc: Peter Oskolkov, Peter Oskolkov

Currently, pick_next_entity(...) has the following structure
(simplified):

[...]
if (last_buddy_ok())
  result = last_buddy;
if (next_buddy_ok())
  result = next_buddy;
[...]

The intended behavior is to prefer next buddy over last buddy;
the current code somewhat obfuscates this, and also wastes
cycles checking the last buddy when eventually the next buddy is
picked up.

So this patch refactors two 'ifs' above into

[...]
if (next_buddy_ok())
    result = next_buddy;
else if (last_buddy_ok())
    result = last_buddy;
[...]

Signed-off-by: Peter Oskolkov <posk@google.com>
---
 kernel/sched/fair.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index fc3410b8b990..cec6cf9b2bb3 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4465,17 +4465,17 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
 			se = second;
 	}
 
-	/*
-	 * Prefer last buddy, try to return the CPU to a preempted task.
-	 */
-	if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1)
-		se = cfs_rq->last;
-
-	/*
-	 * Someone really wants this to run. If it's not unfair, run it.
-	 */
-	if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1)
+	if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) {
+		/*
+		 * Someone really wants this to run. If it's not unfair, run it.
+		 */
 		se = cfs_rq->next;
+	} else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) {
+		/*
+		 * Prefer last buddy, try to return the CPU to a preempted task.
+		 */
+		se = cfs_rq->last;
+	}
 
 	clear_buddies(cfs_rq, se);
 
-- 
2.28.0.709.gb0816b6eb0-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched/fair: tweak pick_next_entity
  2020-09-30 17:35 [PATCH] sched/fair: tweak pick_next_entity Peter Oskolkov
@ 2020-10-01  7:17 ` Vincent Guittot
  2020-10-01  7:33   ` Peter Zijlstra
  2020-10-05  7:43 ` [tip: sched/core] sched/fair: Tweak pick_next_entity() tip-bot2 for Peter Oskolkov
  1 sibling, 1 reply; 4+ messages in thread
From: Vincent Guittot @ 2020-10-01  7:17 UTC (permalink / raw)
  To: Peter Oskolkov
  Cc: Ingo Molnar, Peter Zijlstra, Dietmar Eggemann, linux-kernel,
	Peter Oskolkov

On Wed, 30 Sep 2020 at 19:35, Peter Oskolkov <posk@google.com> wrote:
>
> Currently, pick_next_entity(...) has the following structure
> (simplified):
>
> [...]
> if (last_buddy_ok())
>   result = last_buddy;
> if (next_buddy_ok())
>   result = next_buddy;
> [...]
>
> The intended behavior is to prefer next buddy over last buddy;
> the current code somewhat obfuscates this, and also wastes
> cycles checking the last buddy when eventually the next buddy is
> picked up.
>
> So this patch refactors two 'ifs' above into
>
> [...]
> if (next_buddy_ok())
>     result = next_buddy;
> else if (last_buddy_ok())
>     result = last_buddy;
> [...]
>
> Signed-off-by: Peter Oskolkov <posk@google.com>

Reviewed-by: Vincent Guittot <vincent.guitttot@linaro.org>

> ---
>  kernel/sched/fair.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index fc3410b8b990..cec6cf9b2bb3 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -4465,17 +4465,17 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
>                         se = second;
>         }
>
> -       /*
> -        * Prefer last buddy, try to return the CPU to a preempted task.
> -        */
> -       if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1)
> -               se = cfs_rq->last;
> -
> -       /*
> -        * Someone really wants this to run. If it's not unfair, run it.
> -        */
> -       if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1)
> +       if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) {
> +               /*
> +                * Someone really wants this to run. If it's not unfair, run it.
> +                */
>                 se = cfs_rq->next;
> +       } else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) {
> +               /*
> +                * Prefer last buddy, try to return the CPU to a preempted task.
> +                */
> +               se = cfs_rq->last;
> +       }
>
>         clear_buddies(cfs_rq, se);
>
> --
> 2.28.0.709.gb0816b6eb0-goog
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched/fair: tweak pick_next_entity
  2020-10-01  7:17 ` Vincent Guittot
@ 2020-10-01  7:33   ` Peter Zijlstra
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2020-10-01  7:33 UTC (permalink / raw)
  To: Vincent Guittot
  Cc: Peter Oskolkov, Ingo Molnar, Dietmar Eggemann, linux-kernel,
	Peter Oskolkov

On Thu, Oct 01, 2020 at 09:17:43AM +0200, Vincent Guittot wrote:
> On Wed, 30 Sep 2020 at 19:35, Peter Oskolkov <posk@google.com> wrote:
> >
> > Currently, pick_next_entity(...) has the following structure
> > (simplified):
> >
> > [...]
> > if (last_buddy_ok())
> >   result = last_buddy;
> > if (next_buddy_ok())
> >   result = next_buddy;
> > [...]
> >
> > The intended behavior is to prefer next buddy over last buddy;
> > the current code somewhat obfuscates this, and also wastes
> > cycles checking the last buddy when eventually the next buddy is
> > picked up.
> >
> > So this patch refactors two 'ifs' above into
> >
> > [...]
> > if (next_buddy_ok())
> >     result = next_buddy;
> > else if (last_buddy_ok())
> >     result = last_buddy;
> > [...]
> >
> > Signed-off-by: Peter Oskolkov <posk@google.com>
> 
> Reviewed-by: Vincent Guittot <vincent.guitttot@linaro.org>

Thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: sched/core] sched/fair: Tweak pick_next_entity()
  2020-09-30 17:35 [PATCH] sched/fair: tweak pick_next_entity Peter Oskolkov
  2020-10-01  7:17 ` Vincent Guittot
@ 2020-10-05  7:43 ` tip-bot2 for Peter Oskolkov
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Peter Oskolkov @ 2020-10-05  7:43 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Peter Oskolkov, Peter Zijlstra (Intel), Vincent Guittot, x86, LKML

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     9abb897345ce1d41257567f571a78137c961c405
Gitweb:        https://git.kernel.org/tip/9abb897345ce1d41257567f571a78137c961c405
Author:        Peter Oskolkov <posk@google.com>
AuthorDate:    Wed, 30 Sep 2020 10:35:32 -07:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Sat, 03 Oct 2020 16:30:52 +02:00

sched/fair: Tweak pick_next_entity()

Currently, pick_next_entity(...) has the following structure
(simplified):

  [...]
  if (last_buddy_ok())
    result = last_buddy;
  if (next_buddy_ok())
    result = next_buddy;
  [...]

The intended behavior is to prefer next buddy over last buddy;
the current code somewhat obfuscates this, and also wastes
cycles checking the last buddy when eventually the next buddy is
picked up.

So this patch refactors two 'ifs' above into

  [...]
  if (next_buddy_ok())
      result = next_buddy;
  else if (last_buddy_ok())
      result = last_buddy;
  [...]

Signed-off-by: Peter Oskolkov <posk@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Vincent Guittot <vincent.guitttot@linaro.org>
Link: https://lkml.kernel.org/r/20200930173532.1069092-1-posk@google.com
---
 kernel/sched/fair.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index fc3410b..cec6cf9 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4465,17 +4465,17 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
 			se = second;
 	}
 
-	/*
-	 * Prefer last buddy, try to return the CPU to a preempted task.
-	 */
-	if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1)
-		se = cfs_rq->last;
-
-	/*
-	 * Someone really wants this to run. If it's not unfair, run it.
-	 */
-	if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1)
+	if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) {
+		/*
+		 * Someone really wants this to run. If it's not unfair, run it.
+		 */
 		se = cfs_rq->next;
+	} else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) {
+		/*
+		 * Prefer last buddy, try to return the CPU to a preempted task.
+		 */
+		se = cfs_rq->last;
+	}
 
 	clear_buddies(cfs_rq, se);
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-05  7:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 17:35 [PATCH] sched/fair: tweak pick_next_entity Peter Oskolkov
2020-10-01  7:17 ` Vincent Guittot
2020-10-01  7:33   ` Peter Zijlstra
2020-10-05  7:43 ` [tip: sched/core] sched/fair: Tweak pick_next_entity() tip-bot2 for Peter Oskolkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).