[PATCH v2 0/3] sched: Simplify ifdeffery around CONFIG_SCHED_SMT

Shrikanth Hegde posted 3 patches 1 month ago
include/linux/sched/smt.h |  4 ----
include/linux/topology.h  | 15 +++++++++++++-
kernel/sched/core.c       |  6 ------
kernel/sched/ext_idle.c   |  6 ------
kernel/sched/fair.c       | 41 +++++----------------------------------
kernel/sched/sched.h      |  6 ------
kernel/sched/topology.c   |  2 --
kernel/stop_machine.c     |  5 +++++
kernel/workqueue.c        |  4 ----
9 files changed, 24 insertions(+), 65 deletions(-)
[PATCH v2 0/3] sched: Simplify ifdeffery around CONFIG_SCHED_SMT
Posted by Shrikanth Hegde 1 month ago
Semantics
=========
- For CONFIG_SCHED_SMT=y:
    No functional change.
- For CONFIG_SCHED_SMT=n:
    - cpu_smt_mask(cpu) becomes cpumask_of(cpu), effectively making it
      per CPU with no siblings.
    - sched_smt_present remains defined, but never becomes active:
    	 Since cpumask_weight(cpumask_of(cpu)) == 1

Performance impact
==================
- CONFIG_SCHED_SMT=y:
    No change in generated code.
- CONFIG_SCHED_SMT=n:
    - Small increase in text size (~0.01%) due to removal of compile-time
      stubs. Most paths remain effectively dead due to static keys.
    - Fast paths are protected using IS_ENABLED(CONFIG_SCHED_SMT).

With that, cpu_smt_mask() to be used unconditionally and reduces
CONFIG_SCHED_SMT-specific code paths, improving readability and
maintainability.

This leaves the remaining use of CONFIG_SCHED_SMT mainly for topology
handling bits.

Since v1[1]:
- Dropped changes for stop_core_cpuslocked. intel_ifs is the only
  user and it gets compiled with SCHED_SMT always. Added comments
  around it why ifdefs are still being kept.
- Decided not to add sched_smt_active checks for sched_core_cpu_deactivate
  and sched_core_cpu_starting, they bail out if weight(smt_mask) == 1.
  Hence core_lock won't be held for long. It is not fastpath either.
- Thanks to Valentin Schneider and Tejun Heo for checking out the series
  and the feedback.

Shrikanth Hegde (3):
  topology: Introduce cpu_smt_mask for CONFIG_SCHED_SMT=n
  sched: Simplify ifdeffery around cpu_smt_mask
  sched/fair: Add compile time check in fastpaths for CONFIG_SCHED_SMT=n

 include/linux/sched/smt.h |  4 ----
 include/linux/topology.h  | 15 +++++++++++++-
 kernel/sched/core.c       |  6 ------
 kernel/sched/ext_idle.c   |  6 ------
 kernel/sched/fair.c       | 41 +++++----------------------------------
 kernel/sched/sched.h      |  6 ------
 kernel/sched/topology.c   |  2 --
 kernel/stop_machine.c     |  5 +++++
 kernel/workqueue.c        |  4 ----
 9 files changed, 24 insertions(+), 65 deletions(-)

-- 
2.47.3
Re: [PATCH v2 0/3] sched: Simplify ifdeffery around CONFIG_SCHED_SMT
Posted by K Prateek Nayak 1 month ago
Hello Shrikanth,

On 5/12/2026 8:51 PM, Shrikanth Hegde wrote:
> Semantics
> =========
> - For CONFIG_SCHED_SMT=y:
>     No functional change.
> - For CONFIG_SCHED_SMT=n:
>     - cpu_smt_mask(cpu) becomes cpumask_of(cpu), effectively making it
>       per CPU with no siblings.
>     - sched_smt_present remains defined, but never becomes active:
>     	 Since cpumask_weight(cpumask_of(cpu)) == 1
> 
> Performance impact
> ==================
> - CONFIG_SCHED_SMT=y:
>     No change in generated code.
> - CONFIG_SCHED_SMT=n:
>     - Small increase in text size (~0.01%) due to removal of compile-time
>       stubs. Most paths remain effectively dead due to static keys.
>     - Fast paths are protected using IS_ENABLED(CONFIG_SCHED_SMT).
> 
> With that, cpu_smt_mask() to be used unconditionally and reduces
> CONFIG_SCHED_SMT-specific code paths, improving readability and
> maintainability.
> 
> This leaves the remaining use of CONFIG_SCHED_SMT mainly for topology
> handling bits.

Thank you again cleaning this up! Feel free to include:

Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>

I also tested removing the "select SCHED_SMT" dependency for x86 after
guarding SDTL_INIT(..., SMT) behind CONFIG_SCHED_SMT and the system is
up fine; performance is terrible as expected :-)

-- 
Thanks and Regards,
Prateek
Re: [PATCH v2 0/3] sched: Simplify ifdeffery around CONFIG_SCHED_SMT
Posted by Valentin Schneider 1 month ago
On 12/05/26 20:51, Shrikanth Hegde wrote:
> Semantics
> =========
> - For CONFIG_SCHED_SMT=y:
>     No functional change.
> - For CONFIG_SCHED_SMT=n:
>     - cpu_smt_mask(cpu) becomes cpumask_of(cpu), effectively making it
>       per CPU with no siblings.
>     - sched_smt_present remains defined, but never becomes active:
>        Since cpumask_weight(cpumask_of(cpu)) == 1
>
> Performance impact
> ==================
> - CONFIG_SCHED_SMT=y:
>     No change in generated code.
> - CONFIG_SCHED_SMT=n:
>     - Small increase in text size (~0.01%) due to removal of compile-time
>       stubs. Most paths remain effectively dead due to static keys.
>     - Fast paths are protected using IS_ENABLED(CONFIG_SCHED_SMT).
>
> With that, cpu_smt_mask() to be used unconditionally and reduces
> CONFIG_SCHED_SMT-specific code paths, improving readability and
> maintainability.
>
> This leaves the remaining use of CONFIG_SCHED_SMT mainly for topology
> handling bits.
>

Reviewed-by: Valentin Schneider <vschneid@redhat.com>