BACKPORT: sched/fair: Fix cpu_util_wake() for 'execl' type workloads

A ~10% regression has been reported for UnixBench's execl throughput
test by Aaron Lu and Ye Xiaolong:

That test is pretty simple, it does a "recursive" execve() syscall on the
same binary. Starting from the syscall, this sequence is possible:

           select_task_rq_fair()          <==| Task already enqueued
                 capacity_spare_wake()    <==| Functions not called from
		   cpu_util_wake()           | the wakeup path

which means we can end up calling cpu_util_wake() not only from the
"wakeup path", as its name would suggest. Indeed, the task doing an
execve() syscall is already enqueued on the CPU we want to get the
cpu_util_wake() for.

The estimated utilization for a CPU computed in cpu_util_wake() was
written under the assumption that function can be called only from the
wakeup path. If instead the task is already enqueued, we end up with a
utilization which does not remove the current task's contribution from
the estimated utilization of the CPU.
This will wrongly assume a reduced spare capacity on the current CPU and
increase the chances to migrate the task on execve.

The regression is tracked down to:

 commit d519329f72a6 ("sched/fair: Update util_est only on util_avg updates")

because in that patch we turn on by default the UTIL_EST sched feature.
However, the real issue is introduced by:

 commit f9be3e5961c5 ("sched/fair: Use util_est in LB and WU paths")

Let's fix this by ensuring to always discount the task estimated
utilization from the CPU's estimated utilization when the task is also
the current one. The same benchmark of the bug report, executed on a
dual socket 40 CPUs Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz machine,
reports these "Execl Throughput" figures (higher the better):

   mainline     : 48136.5 lps
   mainline+fix : 55376.5 lps

which correspond to a 15% speedup.

Moreover, since {cpu_util,capacity_spare}_wake() are not really only
used from the wakeup path, let's remove this ambiguity by using a better
matching name: {cpu_util,capacity_spare}_without().

Since we are at that, let's also improve the existing documentation.

Change-Id: I6dca1ed09cb34b7b8d9d75c33088a402aa3b7b24
Reported-by: Aaron Lu <>
Reported-by: Ye Xiaolong <>
Tested-by: Aaron Lu <>
Signed-off-by: Patrick Bellasi <>
Signed-off-by: Peter Zijlstra (Intel) <>
Cc: Dietmar Eggemann <>
Cc: Juri Lelli <>
Cc: Linus Torvalds <>
Cc: Morten Rasmussen <>
Cc: Peter Zijlstra <>
Cc: Quentin Perret <>
Cc: Steve Muckle <>
Cc: Suren Baghdasaryan <>
Cc: Thomas Gleixner <>
Cc: Todd Kjos <>
Cc: Vincent Guittot <>
Fixes: f9be3e5961c5 (sched/fair: Use util_est in LB and WU paths)
Signed-off-by: Ingo Molnar <>
 backported to android-4.19 from c469933e772132 in tip/sched/urgent
 propagated renaming of cpu_util_wake() into find_best_target()
 the only other callsite we have in the android kernel.
Signed-off-by: Patrick Bellasi <>
1 file changed