Re: sched: tweak select_idle_sibling to look for idle threads

From: Peter Zijlstra
Date: Mon May 02 2016 - 11:02:21 EST


On Mon, May 02, 2016 at 04:50:04PM +0200, Mike Galbraith wrote:
> On Mon, 2016-05-02 at 10:46 +0200, Peter Zijlstra wrote:
> 5226 /*
> 5227 * If there are idle cores to be had, go find one.
> 5228 */
> 5229 if (sched_feat(IDLE_CORE) && test_idle_cores(target)) {
> 5230 i = select_idle_core(p, target);
> 5231 if ((unsigned)i < nr_cpumask_bits)
> 5232 return i;
> 5233
> 5234 /*
> 5235 * Failed to find an idle core; stop looking for one.
> 5236 */
> 5237 clear_idle_cores(target);
> 5238 }
> 5239 #if 1
> 5240 for_each_cpu(i, cpu_smt_mask(target)) {
> 5241 if (idle_cpu(i))
> 5242 return i;
> 5243 }
> 5244
> 5245 return target;
> 5246 #endif

And yes, I have a variant of that, that does indeed work way better than
scanning the whole LLC domain for idle threads.

If you want a laugh, modify select_idle_core() to remember the last idle
thread it encounters and have it return that when it fails to find an
idle core.. I'm still stumped to explain why it behaves the way it does.