[tip: sched/core] sched/fair: Add sched_smt_active check for fastpaths

tip-bot2 for Shrikanth Hegde posted 1 patch 4 days, 14 hours ago
kernel/sched/fair.c |  9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
[tip: sched/core] sched/fair: Add sched_smt_active check for fastpaths
Posted by tip-bot2 for Shrikanth Hegde 4 days, 14 hours ago
The following commit has been merged into the sched/core branch of tip:

Commit-ID:     3dbb362f90f3a8300ed9209d3278e30f8dbfb780
Gitweb:        https://git.kernel.org/tip/3dbb362f90f3a8300ed9209d3278e30f8dbfb780
Author:        Shrikanth Hegde <sshegde@linux.ibm.com>
AuthorDate:    Fri, 15 May 2026 22:54:55 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Tue, 19 May 2026 12:17:37 +02:00

sched/fair: Add sched_smt_active check for fastpaths

For fastpaths such as wakeup and load balance even minimal code additions
can add up. is_core_idle is accessed during load balance.

Other callsites of is_core_idle make sched_smt_active() check first.
Make the same check in should_we_balance.

Rest of access to cpu_smt_mask isn't in fastpath.

Note: Remove the stale comment above is_core_idle. Enqueue methods
of fair aren't close to it anymore.

Suggested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Link: https://patch.msgid.link/20260515172456.542799-4-sshegde@linux.ibm.com
---
 kernel/sched/fair.c |  9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 233bd2e..14bd31b 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1549,10 +1549,7 @@ update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
 	se->exec_start = rq_clock_task(rq_of(cfs_rq));
 }
 
-/**************************************************
- * Scheduling class queueing methods:
- */
-
+/* Check sched_smt_active before calling this to avoid overheads in fastpaths */
 static inline bool is_core_idle(int cpu)
 {
 	int sibling;
@@ -11961,7 +11958,9 @@ static int should_we_balance(struct lb_env *env)
 		 * balancing cores, but remember the first idle SMT CPU for
 		 * later consideration.  Find CPU on an idle core first.
 		 */
-		if (!(env->sd->flags & SD_SHARE_CPUCAPACITY) && !is_core_idle(cpu)) {
+		if (sched_smt_active() &&
+		    !(env->sd->flags & SD_SHARE_CPUCAPACITY) &&
+		    !is_core_idle(cpu)) {
 			if (idle_smt == -1)
 				idle_smt = cpu;
 			/*