Skip to content

Commit bec2860

Browse files
srikardIngo Molnar
authored andcommitted
sched/fair: Optimize select_idle_core()
Currently we loop through all threads of a core to evaluate if the core is idle or not. This is unnecessary. If a thread of a core is not idle, skip evaluating other threads of a core. Also while clearing the cpumask, bits of all CPUs of a core can be cleared in one-shot. Collecting ticks on a Power 9 SMT 8 system around select_idle_core while running schbench shows us (units are in ticks, hence lesser is better) Without patch N Min Max Median Avg Stddev x 130 151 1083 284 322.72308 144.41494 With patch N Min Max Median Avg Stddev Improvement x 164 88 610 201 225.79268 106.78943 30.03% Signed-off-by: Srikar Dronamraju <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Reviewed-by: Vincent Guittot <[email protected]> Acked-by: Mel Gorman <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 918229c commit bec2860

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

kernel/sched/fair.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5787,10 +5787,12 @@ static int select_idle_core(struct task_struct *p, struct sched_domain *sd, int
57875787
bool idle = true;
57885788

57895789
for_each_cpu(cpu, cpu_smt_mask(core)) {
5790-
__cpumask_clear_cpu(cpu, cpus);
5791-
if (!available_idle_cpu(cpu))
5790+
if (!available_idle_cpu(cpu)) {
57925791
idle = false;
5792+
break;
5793+
}
57935794
}
5795+
cpumask_andnot(cpus, cpus, cpu_smt_mask(core));
57945796

57955797
if (idle)
57965798
return core;

0 commit comments

Comments
 (0)