[PATCH 4/4] sched/rt: Better distribute tasks that wakeup simultaneously

From: Qais Yousef
Date: Tue Apr 14 2020 - 11:15:54 EST


If multiple RT tasks of the same priority wakeup simultaneously,
select_task_rt_rt() will always return the same CPU for all tasks
because find_lowest_rq() always returns the first cpu in the
lowest_mask.

Use cpumask_any_and() to randomize the selection, hence better
distribute the tasks.

This helps alleviate the thundering herd issue described here when
multiple tasks of the same priority wake up simultaneously:

https://lore.kernel.org/lkml/20200219140243.wfljmupcrwm2jelo@e107158-lin/

Signed-off-by: Qais Yousef <qais.yousef@xxxxxxx>
CC: Juri Lelli <juri.lelli@xxxxxxxxxx>
CC: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
CC: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
CC: Steven Rostedt <rostedt@xxxxxxxxxxx>
CC: Ben Segall <bsegall@xxxxxxxxxx>
CC: Mel Gorman <mgorman@xxxxxxx>
CC: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CC: Yury Norov <yury.norov@xxxxxxxxx>
CC: Paul Turner <pjt@xxxxxxxxxx>
CC: Alexey Dobriyan <adobriyan@xxxxxxxxx>
CC: Josh Don <joshdon@xxxxxxxxxx>
CC: Pavan Kondeti <pkondeti@xxxxxxxxxxxxxx>
CC: linux-kernel@xxxxxxxxxxxxxxx
---
kernel/sched/rt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index df11d88c9895..16c7eede370a 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1750,8 +1750,8 @@ static int find_lowest_rq(struct task_struct *task)
return this_cpu;
}

- best_cpu = cpumask_first_and(lowest_mask,
- sched_domain_span(sd));
+ best_cpu = cpumask_any_and(lowest_mask,
+ sched_domain_span(sd));
if (best_cpu < nr_cpu_ids) {
rcu_read_unlock();
return best_cpu;
--
2.17.1