[RFC PATCH v4 04/28] sched: Avoid calculating the cpumask if the system is overloaded

From: Chen Yu
Date: Sat Aug 09 2025 - 01:08:23 EST


From: K Prateek Nayak <kprateek.nayak@xxxxxxx>

If SIS_UTIL terminates the search for idle CPUs, the result of
cpumask_and() becomes irrelevant. Given that select_idle_cpu()
may now be invoked twice per wake-up within select_idle_sibling()
due to cache-aware wake-ups, this overhead can be observed in
benchmarks such as hackbench.

To conserve additional cycles-particularly in scenarios where
the LLC is frequently targeted and the search aborts because
the LLC is busy - calculate the cpumask only when the system is
not overloaded.

Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
---
kernel/sched/fair.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 00bd0d25bc91..a7be5c5ecba3 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7940,8 +7940,6 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
int i, cpu, idle_cpu = -1, nr = INT_MAX;
struct sched_domain_shared *sd_share;

- cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr);
-
if (sched_feat(SIS_UTIL)) {
sd_share = rcu_dereference(per_cpu(sd_llc_shared, target));
if (sd_share) {
@@ -7953,6 +7951,8 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
}
}

+ cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr);
+
if (static_branch_unlikely(&sched_cluster_active)) {
struct sched_group *sg = sd->groups;

--
2.25.1