sched/core: Adjusting the order of scanning CPU
authorHao Jia <jiahao.os@bytedance.com>
Fri, 16 Dec 2022 06:24:06 +0000 (14:24 +0800)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 27 Dec 2022 11:52:17 +0000 (12:52 +0100)
When select_idle_capacity() starts scanning for an idle CPU, it starts
with target CPU that has already been checked in select_idle_sibling().
So we start checking from the next CPU and try the target CPU at the end.
Similarly for task_numa_assign(), we have just checked numa_migrate_on
of dst_cpu, so start from the next CPU. This also works for
steal_cookie_task(), the first scan must fail and start directly
from the next one.

Signed-off-by: Hao Jia <jiahao.os@bytedance.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Link: https://lore.kernel.org/r/20221216062406.7812-3-jiahao.os@bytedance.com
kernel/sched/core.c
kernel/sched/fair.c

index 1f3259c5f1c2b12e411f64200b8535cafe7adf15..048ec2417990aae23b82b9a357e6939b179948c0 100644 (file)
@@ -6209,7 +6209,7 @@ static bool steal_cookie_task(int cpu, struct sched_domain *sd)
 {
        int i;
 
-       for_each_cpu_wrap(i, sched_domain_span(sd), cpu) {
+       for_each_cpu_wrap(i, sched_domain_span(sd), cpu + 1) {
                if (i == cpu)
                        continue;
 
index aaff2092ffdf7fbf873e320251059d3786e7082f..e9d906a9bba9cfbc4ca63eda8ec32d06aa5fa9b7 100644 (file)
@@ -1836,7 +1836,7 @@ static void task_numa_assign(struct task_numa_env *env,
                int start = env->dst_cpu;
 
                /* Find alternative idle CPU. */
-               for_each_cpu_wrap(cpu, cpumask_of_node(env->dst_nid), start) {
+               for_each_cpu_wrap(cpu, cpumask_of_node(env->dst_nid), start + 1) {
                        if (cpu == env->best_cpu || !idle_cpu(cpu) ||
                            !cpumask_test_cpu(cpu, env->p->cpus_ptr)) {
                                continue;
@@ -6935,7 +6935,7 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
        util_min = uclamp_eff_value(p, UCLAMP_MIN);
        util_max = uclamp_eff_value(p, UCLAMP_MAX);
 
-       for_each_cpu_wrap(cpu, cpus, target) {
+       for_each_cpu_wrap(cpu, cpus, target + 1) {
                unsigned long cpu_cap = capacity_of(cpu);
 
                if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu))