From nobody Mon May 25 00:09:51 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE21D3C278A; Wed, 20 May 2026 08:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266056; cv=none; b=l/qFtGRtKYPfi6DbDcOkkOWp6sLZpwCGDHfL9eEpyJgOpY0RAxeiLiCVM3HZY1LlHTmQFGwUJDHRdY+fbFc4sCf3ll+aapYdtUjZdKf1UCGT2Fh+EM72RPzMv+5tuR8aRBWubtKGIvhrgfNVUG4AqGSDUMnfrF2B1/RSwl8lp8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266056; c=relaxed/simple; bh=xzi0aeKJWPisVRhSvU+bIh1wl5JPFeNj+9cWRiqxau4=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=azuHrC7Wfi4XZXCWdA5x3VMA6hOkiZlEF8GHYpM6kGBtAiHWxgf96V6EosWi7A29gJZB6YeaHcNb6Z4V1i4yn5AwC7+hnIKXVNBSTI/8qEds8ZzwwWB3LbqgV24yQ9fcfaRmh70//s2WCtqu5lnQYU+frBfdkjLdbdMllTkRttU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IFdgsR2t; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pDExV8RA; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IFdgsR2t"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pDExV8RA" Date: Wed, 20 May 2026 08:34:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779266051; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/O43BMtuc6+Dlx9XW5hTbdX+MrZI7PCXfOs6GjwDIzI=; b=IFdgsR2tiFCD2Cc/pxh8CCRK0pAOYbV6Zv13jP/wf1Bajl1g6hBXwyUECcthq8EeY6p8TF q7w1u3FRtW9HItiMrZA+wt87IfMa8j42n+QHdjtmFfQhciWfpm8iaIgoGUKvuNSpUSQPML N4393cl9+ftar9atYjBXq0ocEAmJYKEzAOroZou3q6pq8mFsq47j9K9Vx6vnsCeNtP0CMB V9TCooUxFy2vAXCE/P4xC9E6TfKa/Yx71ktfgmPRDl6X3DbBtwqR0SgpdbVwJ+w9RCvEjN QP2/EhWOFZoLgA/zWUQUsm9Y+GncUbbBP1/sHrVXQMeW/A7NFTjZ3Ub3nMxo3A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779266051; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/O43BMtuc6+Dlx9XW5hTbdX+MrZI7PCXfOs6GjwDIzI=; b=pDExV8RApSnLjSaPBPvCVsPYJxcWhRDFWB+reO/ZyIXRtkEKcRcWeULNgQ1AB7C40qOrLR LhJMzcW+I3Do2aDw== From: "tip-bot2 for Shrikanth Hegde" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched: Simplify ifdeffery around cpu_smt_mask Cc: Shrikanth Hegde , "Peter Zijlstra (Intel)" , Phil Auld , Valentin Schneider , Tejun Heo , K Prateek Nayak , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260515172456.542799-3-sshegde@linux.ibm.com> References: <20260515172456.542799-3-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177926605001.711.12033195724646041814.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: 5bc6ab2d42e545f816def21cfcdb4ba35cc74bf6 Gitweb: https://git.kernel.org/tip/5bc6ab2d42e545f816def21cfcdb4ba35= cc74bf6 Author: Shrikanth Hegde AuthorDate: Fri, 15 May 2026 22:54:54 +05:30 Committer: Peter Zijlstra CommitterDate: Tue, 19 May 2026 12:17:37 +02:00 sched: Simplify ifdeffery around cpu_smt_mask Now, that cpu_smt_mask is defined as cpumask_of(cpu) for CONFIG_SCHED_SMT=3Dn, it is possible to get rid of the ifdeffery. Effectively, - This makes sched_smt_present is defined always - cpumask_weight(cpumask_of(cpu)) =3D=3D 1. So sched_smt_present_inc/dec will never enable the sched_smt_present. Which is expected. - Paths that were compile-time eliminated become runtime guarded using static keys. - Defines set_idle_cores, test_idle_cores, etc which could likely benefit the CONFIG_SCHED_SMT=3Dn systems to use the same optimizations within the LLC at wakeups. - This will expose sched_smt_present symbol for CONFIG_SCHED_SMT=3Dn. Likely not a concern. - There is a bloat of code CONFIG_SCHED_SMT=3Dn. (NR_CPUS=3D2048) add/remove: 24/18 grow/shrink: 26/28 up/down: 6396/-3188 (3208) Total: Before=3D30629880, After=3D30633088, chg +0.01% - No code bloat for CONFIG_SCHED_SMT=3Dy, which is expected. - Add comments around stop_core_cpuslocked on why ifdefs are not removed. - This leaves the remaining uses of CONFIG_SCHED_SMT mainly for topology building bits which has a policy based decision. Signed-off-by: Shrikanth Hegde Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Phil Auld Reviewed-by: Valentin Schneider Acked-by: Tejun Heo Tested-by: K Prateek Nayak Link: https://patch.msgid.link/20260515172456.542799-3-sshegde@linux.ibm.com --- include/linux/sched/smt.h | 4 ---- kernel/sched/core.c | 6 ------ kernel/sched/ext_idle.c | 6 ------ kernel/sched/fair.c | 35 ----------------------------------- kernel/sched/sched.h | 6 ------ kernel/sched/topology.c | 2 -- kernel/stop_machine.c | 5 +++++ kernel/workqueue.c | 4 ---- 8 files changed, 5 insertions(+), 63 deletions(-) diff --git a/include/linux/sched/smt.h b/include/linux/sched/smt.h index 166b19a..cde6679 100644 --- a/include/linux/sched/smt.h +++ b/include/linux/sched/smt.h @@ -4,16 +4,12 @@ =20 #include =20 -#ifdef CONFIG_SCHED_SMT extern struct static_key_false sched_smt_present; =20 static __always_inline bool sched_smt_active(void) { return static_branch_likely(&sched_smt_present); } -#else -static __always_inline bool sched_smt_active(void) { return false; } -#endif =20 void arch_smt_update(void); =20 diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b905805..3ae5f19 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8612,18 +8612,14 @@ static void cpuset_cpu_inactive(unsigned int cpu) =20 static inline void sched_smt_present_inc(int cpu) { -#ifdef CONFIG_SCHED_SMT if (cpumask_weight(cpu_smt_mask(cpu)) =3D=3D 2) static_branch_inc_cpuslocked(&sched_smt_present); -#endif } =20 static inline void sched_smt_present_dec(int cpu) { -#ifdef CONFIG_SCHED_SMT if (cpumask_weight(cpu_smt_mask(cpu)) =3D=3D 2) static_branch_dec_cpuslocked(&sched_smt_present); -#endif } =20 int sched_cpu_activate(unsigned int cpu) @@ -8711,9 +8707,7 @@ int sched_cpu_deactivate(unsigned int cpu) */ sched_smt_present_dec(cpu); =20 -#ifdef CONFIG_SCHED_SMT sched_core_cpu_deactivate(cpu); -#endif =20 if (!sched_smp_initialized) return 0; diff --git a/kernel/sched/ext_idle.c b/kernel/sched/ext_idle.c index 7468560..2bcf58e 100644 --- a/kernel/sched/ext_idle.c +++ b/kernel/sched/ext_idle.c @@ -79,7 +79,6 @@ static bool scx_idle_test_and_clear_cpu(int cpu) int node =3D scx_cpu_node_if_enabled(cpu); struct cpumask *idle_cpus =3D idle_cpumask(node)->cpu; =20 -#ifdef CONFIG_SCHED_SMT /* * SMT mask should be cleared whether we can claim @cpu or not. The SMT * cluster is not wholly idle either way. This also prevents @@ -104,7 +103,6 @@ static bool scx_idle_test_and_clear_cpu(int cpu) else if (cpumask_test_cpu(cpu, idle_smts)) __cpumask_clear_cpu(cpu, idle_smts); } -#endif =20 return cpumask_test_and_clear_cpu(cpu, idle_cpus); } @@ -622,7 +620,6 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_= cpu, u64 wake_flags, goto out_unlock; } =20 -#ifdef CONFIG_SCHED_SMT /* * Use @prev_cpu's sibling if it's idle. */ @@ -634,7 +631,6 @@ s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_= cpu, u64 wake_flags, goto out_unlock; } } -#endif =20 /* * Search for any idle CPU in the same LLC domain. @@ -714,7 +710,6 @@ static void update_builtin_idle(int cpu, bool idle) =20 assign_cpu(cpu, idle_cpus, idle); =20 -#ifdef CONFIG_SCHED_SMT if (sched_smt_active()) { const struct cpumask *smt =3D cpu_smt_mask(cpu); struct cpumask *idle_smts =3D idle_cpumask(node)->smt; @@ -731,7 +726,6 @@ static void update_builtin_idle(int cpu, bool idle) cpumask_andnot(idle_smts, idle_smts, smt); } } -#endif } =20 /* diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 09d3acd..233bd2e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1555,7 +1555,6 @@ update_stats_curr_start(struct cfs_rq *cfs_rq, struct= sched_entity *se) =20 static inline bool is_core_idle(int cpu) { -#ifdef CONFIG_SCHED_SMT int sibling; =20 for_each_cpu(sibling, cpu_smt_mask(cpu)) { @@ -1565,7 +1564,6 @@ static inline bool is_core_idle(int cpu) if (!idle_cpu(sibling)) return false; } -#endif =20 return true; } @@ -2248,7 +2246,6 @@ numa_type numa_classify(unsigned int imbalance_pct, return node_fully_busy; } =20 -#ifdef CONFIG_SCHED_SMT /* Forward declarations of select_idle_sibling helpers */ static inline bool test_idle_cores(int cpu); static inline int numa_idle_core(int idle_core, int cpu) @@ -2266,12 +2263,6 @@ static inline int numa_idle_core(int idle_core, int = cpu) =20 return idle_core; } -#else /* !CONFIG_SCHED_SMT: */ -static inline int numa_idle_core(int idle_core, int cpu) -{ - return idle_core; -} -#endif /* !CONFIG_SCHED_SMT */ =20 /* * Gather all necessary information to make NUMA balancing placement @@ -7778,7 +7769,6 @@ static inline int __select_idle_cpu(int cpu, struct t= ask_struct *p) return -1; } =20 -#ifdef CONFIG_SCHED_SMT DEFINE_STATIC_KEY_FALSE(sched_smt_present); EXPORT_SYMBOL_GPL(sched_smt_present); =20 @@ -7888,29 +7878,6 @@ static int select_idle_smt(struct task_struct *p, st= ruct sched_domain *sd, int t return -1; } =20 -#else /* !CONFIG_SCHED_SMT: */ - -static inline void set_idle_cores(int cpu, int val) -{ -} - -static inline bool test_idle_cores(int cpu) -{ - return false; -} - -static inline int select_idle_core(struct task_struct *p, int core, struct= cpumask *cpus, int *idle_cpu) -{ - return __select_idle_cpu(core, p); -} - -static inline int select_idle_smt(struct task_struct *p, struct sched_doma= in *sd, int target) -{ - return -1; -} - -#endif /* !CONFIG_SCHED_SMT */ - /* * Scan the LLC domain for idle CPUs; this is dynamically regulated by * comparing the average scan cost (tracked in sd->avg_scan_cost) against = the @@ -12002,9 +11969,7 @@ static int should_we_balance(struct lb_env *env) * idle has been found, then its not needed to check other * SMT siblings for idleness: */ -#ifdef CONFIG_SCHED_SMT cpumask_andnot(swb_cpus, swb_cpus, cpu_smt_mask(cpu)); -#endif continue; } =20 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 9f63b15..e476623 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1667,7 +1667,6 @@ do { \ flags =3D _raw_spin_rq_lock_irqsave(rq); \ } while (0) =20 -#ifdef CONFIG_SCHED_SMT extern void __update_idle_core(struct rq *rq); =20 static inline void update_idle_core(struct rq *rq) @@ -1676,12 +1675,7 @@ static inline void update_idle_core(struct rq *rq) __update_idle_core(rq); } =20 -#else /* !CONFIG_SCHED_SMT: */ -static inline void update_idle_core(struct rq *rq) { } -#endif /* !CONFIG_SCHED_SMT */ - #ifdef CONFIG_FAIR_GROUP_SCHED - static inline struct task_struct *task_of(struct sched_entity *se) { WARN_ON_ONCE(!entity_is_task(se)); diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 5847b83..a1f46e3 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -1310,9 +1310,7 @@ static void init_sched_groups_capacity(int cpu, struc= t sched_domain *sd) cpumask_copy(mask, sched_group_span(sg)); for_each_cpu(cpu, mask) { cores++; -#ifdef CONFIG_SCHED_SMT cpumask_andnot(mask, mask, cpu_smt_mask(cpu)); -#endif } sg->cores =3D cores; =20 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c index 3fe6b0c..773d8e9 100644 --- a/kernel/stop_machine.c +++ b/kernel/stop_machine.c @@ -633,6 +633,11 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const s= truct cpumask *cpus) EXPORT_SYMBOL_GPL(stop_machine); =20 #ifdef CONFIG_SCHED_SMT +/* + * INTEL_IFS is the only user of this API. That selftest can + * only be compiled if SMP=3Dy. On x86 it selects SCHED_SMT. + * Keep the ifdefs for now. + */ int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data) { const struct cpumask *smt_mask =3D cpu_smt_mask(cpu); diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 5f747f2..99ef412 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -8187,11 +8187,7 @@ static bool __init cpus_dont_share(int cpu0, int cpu= 1) =20 static bool __init cpus_share_smt(int cpu0, int cpu1) { -#ifdef CONFIG_SCHED_SMT return cpumask_test_cpu(cpu0, cpu_smt_mask(cpu1)); -#else - return false; -#endif } =20 static bool __init cpus_share_numa(int cpu0, int cpu1)