Skip to contentSkip to conversation

sched/fair: consider sched-idle CPU when selecting idle core

PATCH In review Jiang Biao 4 participants 7 messages Jul 24, 2020 Scheduler

lore
Share & tools
lore

Jiang Biao

author
#0 lore raw

PATCH 1/1 sched/fair: consider sched-idle CPU when selecting idle core

From: Jiang Biao <[email protected]>

Sched-idle CPU has been considered in select_idle_cpu and select_idle_smt, it also needs to be considered in select_idle_core to be consistent and keep the same *idle* policy.

---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -2
index 04fa8dbcfa4d..f430a9820d08 100644
@@ -6014,7 +6014,7 @@ void __update_idle_core(struct rq *rq)
 		if (cpu == core)
 			continue;
 
-		if (!available_idle_cpu(cpu))
+		if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu))
 			goto unlock;
 	}
 
@@ -6045,7 +6045,7 @@ static int select_idle_core(struct task_struct *p, struct sched_domain *sd, int
 		bool idle = true;
 
 		for_each_cpu(cpu, cpu_smt_mask(core)) {
-			if (!available_idle_cpu(cpu)) {
+			if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu)) {
 				idle = false;
 				break;
 			}
Signature · 1 line
2.21.0
maintainer
#1 lore raw
Quoted 6 lines · Jiang Biao

From: Jiang Biao <[email protected]>

Sched-idle CPU has been considered in select_idle_cpu and select_idle_smt, it also needs to be considered in select_idle_core to be consistent and keep the same *idle* policy.

In the case of select_idle_core, we are looking for a core that is fully idle but if one CPU of the core is running a sched_idle task, the core will not be idle and we might end up having the wakeup task on a CPU and a sched_idle task on another CPU of the core which is not what we want

Quoted 32 lines
---
 kernel/sched/fair.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/fair.c +2 -3
index 04fa8dbcfa4d..f430a9820d08 100644
@@ -6014,7 +6014,7 @@ void __update_idle_core(struct rq *rq)
                if (cpu == core)
                        continue;
 
-               if (!available_idle_cpu(cpu))
+               if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu))
                        goto unlock;
        }
 
@@ -6045,7 +6045,7 @@ static int select_idle_core(struct task_struct *p, struct sched_domain *sd, int
                bool idle = true;
 
                for_each_cpu(cpu, cpu_smt_mask(core)) {
-                       if (!available_idle_cpu(cpu)) {
+                       if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu)) {
                                idle = false;
                                break;
                        }
--

2.21.0

#2 lore raw
Quoted 9 lines · Vincent Guittot
Quoted 6 lines · Jiang Biao

From: Jiang Biao <[email protected]>

Sched-idle CPU has been considered in select_idle_cpu and select_idle_smt, it also needs to be considered in select_idle_core to be consistent and keep the same *idle* policy.

Quoted 5 lines

In the case of select_idle_core, we are looking for a core that is fully idle but if one CPU of the core is running a sched_idle task, the core will not be idle and we might end up having the wakeup task on a CPU and a sched_idle task on another CPU of the core which is not what we want

Got it. sched_idle task may interfere its sibling, which brings me another question,
If there's a core with smt1 running sched_idle task and smt2 idle, selecting smt1
rather than smt2 should be more helpful for wakee task, because wakee task could suppress the sched_idle task without neighbour interfering. And there seems to be no consideration about that currently. Is it worth improving that?

Thanks a lot.

Regards,
Jiang

maintainer
#3 lore raw
Quoted 17 lines · Jiang Biao
Quoted 9 lines · Vincent Guittot
Quoted 6 lines · Jiang Biao

From: Jiang Biao <[email protected]>

Sched-idle CPU has been considered in select_idle_cpu and select_idle_smt, it also needs to be considered in select_idle_core to be consistent and keep the same *idle* policy.

Quoted 5 lines

In the case of select_idle_core, we are looking for a core that is fully idle but if one CPU of the core is running a sched_idle task, the core will not be idle and we might end up having the wakeup task on a CPU and a sched_idle task on another CPU of the core which is not what we want

Quoted 6 lines

Got it. sched_idle task may interfere its sibling, which brings me another question,
If there's a core with smt1 running sched_idle task and smt2 idle, selecting smt1
rather than smt2 should be more helpful for wakee task, because wakee task could suppress the sched_idle task without neighbour interfering.

But the sched_idle will then probably quickly move on the idle smt2

Quoted 2 lines

And there seems to be no consideration about that currently. Is it worth improving that?

This will complexify and extend the duration of the search loop and as mentioned above, it will most probably be a nop at the end because of sched_idle task moving on smt2

Quoted 5 lines

Thanks a lot.

Regards,
Jiang

#4 lore raw
Quoted 26 lines · Vincent Guittot
Quoted 17 lines · Jiang Biao
Quoted 9 lines · Vincent Guittot
Quoted 6 lines · Jiang Biao

From: Jiang Biao <[email protected]>

Sched-idle CPU has been considered in select_idle_cpu and select_idle_smt, it also needs to be considered in select_idle_core to be consistent and keep the same *idle* policy.

Quoted 5 lines

In the case of select_idle_core, we are looking for a core that is fully idle but if one CPU of the core is running a sched_idle task, the core will not be idle and we might end up having the wakeup task on a CPU and a sched_idle task on another CPU of the core which is not what we want

Quoted 6 lines

Got it. sched_idle task may interfere its sibling, which brings me another question,
If there's a core with smt1 running sched_idle task and smt2 idle, selecting smt1
rather than smt2 should be more helpful for wakee task, because wakee task could suppress the sched_idle task without neighbour interfering.

Quoted 8 lines

But the sched_idle will then probably quickly move on the idle smt2

Quoted 2 lines

And there seems to be no consideration about that currently. Is it worth improving that?

This will complexify and extend the duration of the search loop and as mentioned above, it will most probably be a nop at the end because of sched_idle task moving on smt2

Indeed, the complexity is not worth.
Thanks for the explanation.

Regards,
Jiang

Quoted 6 lines
Quoted 6 lines

Thanks a lot.

Regards,
Jiang

#5 lore raw
Quoted 30 lines · Jiang Biao
Quoted 28 lines · Vincent Guittot
Quoted 17 lines · Jiang Biao
Quoted 9 lines · Vincent Guittot
Quoted 6 lines · Jiang Biao

From: Jiang Biao <[email protected]>

Sched-idle CPU has been considered in select_idle_cpu and select_idle_smt, it also needs to be considered in select_idle_core to be consistent and keep the same *idle* policy.

Quoted 5 lines

In the case of select_idle_core, we are looking for a core that is fully idle but if one CPU of the core is running a sched_idle task, the core will not be idle and we might end up having the wakeup task on a CPU and a sched_idle task on another CPU of the core which is not what we want

Quoted 6 lines

Got it. sched_idle task may interfere its sibling, which brings me another question,
If there's a core with smt1 running sched_idle task and smt2 idle, selecting smt1
rather than smt2 should be more helpful for wakee task, because wakee task could suppress the sched_idle task without neighbour interfering.

But the sched_idle will then probably quickly move on the idle smt2

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

And there seems to be no consideration about that currently. Is it worth improving that?

This will complexify and extend the duration of the search loop and as mentioned above, it will most probably be a nop at the end because of sched_idle task moving on smt2

Indeed, the complexity is not worth.
Thanks for the explanation.

BTW., if you disagree then you could add a bit of debug instrumentation to measure to what extent it's a nop at the end of the search loop, to turn the "most probably" statement into a specific number.

Thanks,

Ingo

#6 lore raw
Quoted 43 lines · Ingo Molnar
Quoted 30 lines · Jiang Biao
Quoted 28 lines · Vincent Guittot
Quoted 17 lines · Jiang Biao
Quoted 9 lines · Vincent Guittot
Quoted 6 lines · Jiang Biao

From: Jiang Biao <[email protected]>

Sched-idle CPU has been considered in select_idle_cpu and select_idle_smt, it also needs to be considered in select_idle_core to be consistent and keep the same *idle* policy.

Quoted 5 lines

In the case of select_idle_core, we are looking for a core that is fully idle but if one CPU of the core is running a sched_idle task, the core will not be idle and we might end up having the wakeup task on a CPU and a sched_idle task on another CPU of the core which is not what we want

Quoted 6 lines

Got it. sched_idle task may interfere its sibling, which brings me another question,
If there's a core with smt1 running sched_idle task and smt2 idle, selecting smt1
rather than smt2 should be more helpful for wakee task, because wakee task could suppress the sched_idle task without neighbour interfering.

But the sched_idle will then probably quickly move on the idle smt2

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

And there seems to be no consideration about that currently. Is it worth improving that?

This will complexify and extend the duration of the search loop and as mentioned above, it will most probably be a nop at the end because of sched_idle task moving on smt2

Indeed, the complexity is not worth.
Thanks for the explanation.

Quoted 8 lines

BTW., if you disagree then you could add a bit of debug instrumentation to measure to what extent it's a nop at the end of the search loop, to turn the "most probably" statement into a specific number.

Thanks,

Ingo

Ok, I'll try.
Thanks for your reply.

Regards,
Jiang