The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: Valentin Schneider <vschneid@redhat.com>
Cc: kprateek.nayak@amd.com, juri.lelli@redhat.com,
	dietmar.eggemann@arm.com, tj@kernel.org, rostedt@goodmis.org,
	tglx@kernel.org, mgorman@suse.de, bsegall@google.com,
	arighi@nvidia.com, linux-kernel@vger.kernel.org,
	mingo@kernel.org, peterz@infradead.org,
	vincent.guittot@linaro.org
Subject: Re: [PATCH 2/3] sched: Simplify ifdeffery around cpu_smt_mask
Date: Mon, 11 May 2026 20:07:23 +0530	[thread overview]
Message-ID: <09edb32d-774a-4780-bb05-cb227f6cddb7@linux.ibm.com> (raw)
In-Reply-To: <xhsmhpl322jl2.mognet@vschneid-thinkpadt14sgen2i.remote.csb>

Hi Valentin, Thanks for the reviewing this patchset.

On 5/11/26 6:23 PM, Valentin Schneider wrote:
> On 06/05/26 16:30, Shrikanth Hegde wrote:
>> Now, that cpu_smt_mask is defined as cpumask_of(cpu) for
>> CONFIG_SCHED_SMT=n, it is possible to get rid of the ifdeffery.
>>
>> Effectively,
>> - This makes sched_smt_present is defined always
>>
>> - cpumask_weight(cpumask_of(cpu)) == 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=n systems to use the same optimizations within the
>>    LLC at wakeups.
>>
>> - This will expose sched_smt_present,stop_core_cpuslocked symbol for
>>    CONFIG_SCHED_SMT=n. Likely not a concern.
>>
>> - There a bloat of code CONFIG_SCHED_SMT=n. (NR_CPUS=2048)
>>    add/remove: 25/18 grow/shrink: 26/19 up/down: 6696/-3064 (3632)
>>    Total: Before=30771823, After=30775455, chg +0.01%
>>
>> - No code bloat for CONFIG_SCHED_SMT=y, which is expected.
>>
> 
> Some nitpicks below, otherwise this LGTM except the sched_ext bits which
> I'm not familiar enough with.

sched_ext just added the ifdefs for the masks i think.
It has sched_smt_active() already.

> 
>> @@ -8703,9 +8699,7 @@ int sched_cpu_deactivate(unsigned int cpu)
>>         */
>>        sched_smt_present_dec(cpu);
>>
>> -#ifdef CONFIG_SCHED_SMT
>>        sched_core_cpu_deactivate(cpu);
>> -#endif
> 
> That ends up grabbing @core_lock, arguably this is during hotplug but still
> seems a bit wasteful when, with CONFIG_SCHED_SMT=1, we know the mask weight
> will never exceed 1. Probably worth adding a sched_smt_active() check
> within the callee.
> 

Ok. Fair enough. Even cpu bringup path too could use the same opt.
Something like below?
---

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 084ec3987d7c..add0fcc8ba90 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6494,6 +6494,10 @@ static void sched_core_cpu_starting(unsigned int cpu)
         struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
         int t;
  
+       /* No point in doing anything further if SMT is not active */
+       if (!sched_smt_active())
+               return;
+
         guard(core_lock)(&cpu);
  
         WARN_ON_ONCE(rq->core != rq);
@@ -6533,6 +6537,10 @@ static void sched_core_cpu_deactivate(unsigned int cpu)
         struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
         int t;
  
+       /* No point in doing anything further if SMT is not active */
+       if (!sched_smt_active())
+               return;
+
         guard(core_lock)(&cpu);
  
         /* if we're the last man standing, nothing to do */


> 
>> @@ -632,7 +632,6 @@ int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
>>   }
>>   EXPORT_SYMBOL_GPL(stop_machine);
>>
>> -#ifdef CONFIG_SCHED_SMT
>>   int stop_core_cpuslocked(unsigned int cpu, cpu_stop_fn_t fn, void *data)
> 
> That seems to be only used by the INTEL_IFS selftest stuff which does some
> wait_for_sibling_cpu() loop; at a quick glance it seems to do the right
> thing for weight := 1 but IMO worth a proper look. That or have the IFS
> code not run that when there is no SMT.
> 

Right. intel_ifs is the only user.
INTEL_IFS depends on SMP. SMP select CONFIG_SMT on x86.

Symbol: INTEL_IFS [=n]
Depends on: X86_PLATFORM_DEVICES [=y] && X86 [=y] && CPU_SUP_INTEL [=y] && 64BIT [=y] && SMP [=y]

So, maybe leave this as is, to avoid the code bloat for CONFIG_SCHED_SMT=n as there is no user?
Maybe i will add a comment about it.

from ./bloat-o-meter. it adds about 260
stop_core_cpuslocked                           -     260    +260

Does that make sense?

  reply	other threads:[~2026-05-11 14:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06 11:00 [PATCH 0/3] sched: Simplify ifdeffery around CONFIG_SCHED_SMT Shrikanth Hegde
2026-05-06 11:00 ` [PATCH 1/3] topology: Introduce cpu_smt_mask for CONFIG_SCHED_SMT=n Shrikanth Hegde
2026-05-06 11:00 ` [PATCH 2/3] sched: Simplify ifdeffery around cpu_smt_mask Shrikanth Hegde
2026-05-11 12:53   ` Valentin Schneider
2026-05-11 14:37     ` Shrikanth Hegde [this message]
2026-05-11 18:46       ` Tejun Heo
2026-05-06 11:00 ` [PATCH 3/3] sched/fair: Add compile time check in fastpaths for CONFIG_SCHED_SMT=n Shrikanth Hegde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=09edb32d-774a-4780-bb05-cb227f6cddb7@linux.ibm.com \
    --to=sshegde@linux.ibm.com \
    --cc=arighi@nvidia.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox