Messages in this thread Patch in this message | | | From | Barry Song <> | Subject | [PATCH v2] sched/fair: Remove the cost of a redundant cpumask_next_wrap in select_idle_cpu | Date | Wed, 24 Nov 2021 17:15:46 +0800 |
| |
From: Barry Song <song.bao.hua@hisilicon.com>
This patch keeps the same scanning amount, but drops a redundant loop of cpumask_next_wrap. The original code did for_each_cpu_wrap(cpu, cpus, target + 1), then checked --nr; this patch does --nr before doing the next loop, thus, it can remove a cpumask_next_wrap() which costs a little bit.
Signed-off-by: Barry Song <song.bao.hua@hisilicon.com> --- -v2: make code clearer with respect to Peter's comment
kernel/sched/fair.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6e476f6..8cd23f1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6278,6 +6278,7 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool time = cpu_clock(this); } + --nr; for_each_cpu_wrap(cpu, cpus, target + 1) { if (has_idle_core) { i = select_idle_core(p, cpu, cpus, &idle_cpu); @@ -6285,11 +6286,11 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool return i; } else { - if (!--nr) - return -1; idle_cpu = __select_idle_cpu(cpu, p); if ((unsigned int)idle_cpu < nr_cpumask_bits) break; + if (!--nr) + return -1; } } -- 1.8.3.1
| |