Re: sched: tweak select_idle_sibling to look for idle threads

From: Peter Zijlstra
Date: Wed May 04 2016 - 11:31:52 EST


On Wed, May 04, 2016 at 12:37:01PM +0200, Peter Zijlstra wrote:

> +static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int target)
> +{
> + struct sched_domain *this_sd = rcu_dereference(*this_cpu_ptr(&sd_llc));
> + u64 time, cost;
> + s64 delta;
> + int cpu, wrap;
> +
> + if (sched_feat(AVG_CPU)) {
> + u64 avg_idle = this_rq()->avg_idle;
> + u64 avg_cost = this_sd->avg_scan_cost;
> +
> + if (sched_feat(PRINT_AVG))
> + trace_printk("idle: %Ld cost: %Ld\n", avg_idle, avg_cost);
> +
> + if (avg_idle / 32 < avg_cost)

s/32/512/ + IDLE_SMT fixes a hackbench regression

hackbench, like tbench, doesn't like IDLE_CPU to trigger, but apparently
needs IDLE_SMT.

Bah, I could sort of explain 32 away, but 512 is firmly in the magic
value range :/

> + return -1;
> + }
> +
> + time = local_clock();
> +
> + for_each_cpu_wrap(cpu, sched_domain_span(sd), target, wrap) {
> + if (!cpumask_test_cpu(cpu, tsk_cpus_allowed(p)))
> + continue;
> + if (idle_cpu(cpu))
> + break;
> + }
> +
> + time = local_clock() - time;
> + cost = this_sd->avg_scan_cost;
> + delta = (s64)(time - cost) / 8;
> + /* trace_printk("time: %Ld cost: %Ld delta: %Ld\n", time, cost, delta); */
> + this_sd->avg_scan_cost += delta;
> +
> + return cpu;
> +}