linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Resend][PATCH] sched/fair: micro-optimize pick_next_entity()
@ 2021-08-25  6:27 Li RongQing
  2021-08-31 14:09 ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Li RongQing @ 2021-08-25  6:27 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, linux-kernel, lirongqing

Only check the skip buddy when next buddy and last buddy
are not picked up, this can save the cycles of checking
the skip buddy and computation of the second buddy, when
next and last buddy will be picked up
for example, yield_to_task_fair() set both next and skip
buddy

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 kernel/sched/fair.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 44c452072a1b..9c6569ddf3eb 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4503,11 +4503,22 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
 
 	se = left; /* ideally we run the leftmost entity */
 
-	/*
-	 * Avoid running the skip buddy, if running something else can
-	 * be done without getting too unfair.
-	 */
-	if (cfs_rq->skip && cfs_rq->skip == se) {
+
+	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;
+	} else if (cfs_rq->skip && cfs_rq->skip == se) {
+		/*
+		 * Avoid running the skip buddy, if running something else can
+		 * be done without getting too unfair.
+		 */
 		struct sched_entity *second;
 
 		if (se == curr) {
@@ -4522,18 +4533,6 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
 			se = second;
 	}
 
-	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;
-	}
-
 	return se;
 }
 
-- 
2.33.0.69.gc420321.dirty


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

* Re: [Resend][PATCH] sched/fair: micro-optimize pick_next_entity()
  2021-08-25  6:27 [Resend][PATCH] sched/fair: micro-optimize pick_next_entity() Li RongQing
@ 2021-08-31 14:09 ` Peter Zijlstra
  2021-09-01  7:19   ` 答复: " Li,Rongqing
  2021-09-03  3:59   ` Li,Rongqing
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Zijlstra @ 2021-08-31 14:09 UTC (permalink / raw)
  To: Li RongQing
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, linux-kernel

On Wed, Aug 25, 2021 at 02:27:49PM +0800, Li RongQing wrote:
> Only check the skip buddy when next buddy and last buddy
> are not picked up, this can save the cycles of checking
> the skip buddy and computation of the second buddy, when
> next and last buddy will be picked up
> for example, yield_to_task_fair() set both next and skip
> buddy

Is that actually measurable?

But looking at it, should we not, instead, move the whole ->skip thing to
the bottom, so we unconditionally check it vs the result of
->next/->last ?

Imagine ->next == ->skip, then we want to avoid running it and not have
->next win.


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

* 答复: [Resend][PATCH] sched/fair: micro-optimize pick_next_entity()
  2021-08-31 14:09 ` Peter Zijlstra
@ 2021-09-01  7:19   ` Li,Rongqing
  2021-09-03  3:59   ` Li,Rongqing
  1 sibling, 0 replies; 4+ messages in thread
From: Li,Rongqing @ 2021-09-01  7:19 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, linux-kernel



> -----邮件原件-----
> 发件人: Peter Zijlstra <peterz@infradead.org>
> 发送时间: 2021年8月31日 22:10
> 收件人: Li,Rongqing <lirongqing@baidu.com>
> 抄送: mingo@redhat.com; juri.lelli@redhat.com; vincent.guittot@linaro.org;
> dietmar.eggemann@arm.com; rostedt@goodmis.org; bsegall@google.com;
> mgorman@suse.de; bristot@redhat.com; linux-kernel@vger.kernel.org
> 主题: Re: [Resend][PATCH] sched/fair: micro-optimize pick_next_entity()
> 
> On Wed, Aug 25, 2021 at 02:27:49PM +0800, Li RongQing wrote:
> > Only check the skip buddy when next buddy and last buddy are not
> > picked up, this can save the cycles of checking the skip buddy and
> > computation of the second buddy, when next and last buddy will be
> > picked up for example, yield_to_task_fair() set both next and skip
> > buddy
> 
> Is that actually measurable?
> 
No measurable


> But looking at it, should we not, instead, move the whole ->skip thing to the
> bottom, so we unconditionally check it vs the result of
> ->next/->last ?
> 
> Imagine ->next == ->skip, then we want to avoid running it and not have
> ->next win.

True, next/last may be equal to skip  

-Li


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

* 答复: [Resend][PATCH] sched/fair: micro-optimize pick_next_entity()
  2021-08-31 14:09 ` Peter Zijlstra
  2021-09-01  7:19   ` 答复: " Li,Rongqing
@ 2021-09-03  3:59   ` Li,Rongqing
  1 sibling, 0 replies; 4+ messages in thread
From: Li,Rongqing @ 2021-09-03  3:59 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, bristot, linux-kernel



> -----邮件原件-----
> 发件人: Peter Zijlstra <peterz@infradead.org>
> 发送时间: 2021年8月31日 22:10
> 收件人: Li,Rongqing <lirongqing@baidu.com>
> 抄送: mingo@redhat.com; juri.lelli@redhat.com; vincent.guittot@linaro.org;
> dietmar.eggemann@arm.com; rostedt@goodmis.org; bsegall@google.com;
> mgorman@suse.de; bristot@redhat.com; linux-kernel@vger.kernel.org
> 主题: Re: [Resend][PATCH] sched/fair: micro-optimize pick_next_entity()
> 
> On Wed, Aug 25, 2021 at 02:27:49PM +0800, Li RongQing wrote:
> > Only check the skip buddy when next buddy and last buddy are not
> > picked up, this can save the cycles of checking the skip buddy and
> > computation of the second buddy, when next and last buddy will be
> > picked up for example, yield_to_task_fair() set both next and skip
> > buddy
> 
> Is that actually measurable?
> 
> But looking at it, should we not, instead, move the whole ->skip thing to the
> bottom, so we unconditionally check it vs the result of
> ->next/->last ?
> 
> Imagine ->next == ->skip, then we want to avoid running it and not have
> ->next win.

skip means this task is running on cpu, next is the blocked task and will be running.

I donot know how they can be same.

-Li

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

end of thread, other threads:[~2021-09-03  3:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25  6:27 [Resend][PATCH] sched/fair: micro-optimize pick_next_entity() Li RongQing
2021-08-31 14:09 ` Peter Zijlstra
2021-09-01  7:19   ` 答复: " Li,Rongqing
2021-09-03  3:59   ` Li,Rongqing

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).