sched: set loop_max after rq lock is taken

While doing a load balance there is a race in setting
loop_max variable since nr_running can be changed causing
incorect iteration loops.

As a result we may skip some candidates or check the same
tasks again.

Change-Id: I2f58f8fe96c14bd70674e600bc33caeb8aa960c6
Signed-off-by: Uladzislau 2 Rezki <uladzislau2.rezki@sonymobile.com>
Signed-off-by: Artem Labazov <123321artyom@gmail.com>
This commit is contained in:
Uladzislau 2 Rezki 2017-02-08 09:43:27 +01:00 committed by Timi
parent 3e419e234e
commit 510802be8f

View file

@ -10540,7 +10540,6 @@ redo:
* correctly treated as an imbalance. * correctly treated as an imbalance.
*/ */
env.flags |= LBF_ALL_PINNED; env.flags |= LBF_ALL_PINNED;
env.loop_max = min(sysctl_sched_nr_migrate, busiest->nr_running);
more_balance: more_balance:
raw_spin_lock_irqsave(&busiest->lock, flags); raw_spin_lock_irqsave(&busiest->lock, flags);
@ -10553,6 +10552,12 @@ more_balance:
goto no_move; goto no_move;
} }
/*
* Set loop_max when rq's lock is taken to prevent a race.
*/
env.loop_max = min(sysctl_sched_nr_migrate,
busiest->nr_running);
/* /*
* cur_ld_moved - load moved in current iteration * cur_ld_moved - load moved in current iteration
* ld_moved - cumulative load moved across iterations * ld_moved - cumulative load moved across iterations