[PATCH v7 5/8] sched/topology: Unify tl_smt_mask() across core and all arch

K Prateek Nayak posted 8 patches 1 month, 1 week ago
[PATCH v7 5/8] sched/topology: Unify tl_smt_mask() across core and all arch
Posted by K Prateek Nayak 1 month, 1 week ago
Unify the tl_smt_mask() wrapper around cpu_smt_mask() across core, x86,
ppc, and s390.

On s390, include/linux/topology.c defines an explicit cpu_smt_mask()
wrapper around topology_sibling_cpumask() when cpu_smt_mask() is not
defined by the arch/ bits and topology_sibling_cpumask() on s390 returns
&cpu_topology[cpu].thread_mask.

No functional changes intended.

Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
---
 arch/powerpc/kernel/smp.c      | 5 -----
 arch/s390/kernel/topology.c    | 8 +-------
 arch/x86/kernel/smpboot.c      | 5 -----
 include/linux/sched/topology.h | 8 +++++++-
 kernel/sched/topology.c        | 7 -------
 5 files changed, 8 insertions(+), 25 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 7f79b853b221..c58ddf84fe63 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -1038,11 +1038,6 @@ static const struct cpumask *smallcore_smt_mask(struct sched_domain_topology_lev
 {
 	return cpu_smallcore_mask(cpu);
 }
-
-static const struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
-{
-	return cpu_smt_mask(cpu);
-}
 #endif
 
 static struct cpumask *cpu_corgrp_mask(int cpu)
diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
index 5129e3ffa7f5..c88eda847309 100644
--- a/arch/s390/kernel/topology.c
+++ b/arch/s390/kernel/topology.c
@@ -509,12 +509,6 @@ int topology_cpu_init(struct cpu *cpu)
 	return rc;
 }
 
-static const struct cpumask *cpu_thread_mask(struct sched_domain_topology_level *tl, int cpu)
-{
-	return &cpu_topology[cpu].thread_mask;
-}
-
-
 const struct cpumask *cpu_coregroup_mask(int cpu)
 {
 	return &cpu_topology[cpu].core_mask;
@@ -541,7 +535,7 @@ static const struct cpumask *cpu_pkg_mask(struct sched_domain_topology_level *tl
 }
 
 static struct sched_domain_topology_level s390_topology[] = {
-	SDTL_INIT(cpu_thread_mask, cpu_smt_flags, SMT),
+	SDTL_INIT(tl_smt_mask, cpu_smt_flags, SMT),
 	SDTL_INIT(cpu_mc_mask, cpu_core_flags, MC),
 	SDTL_INIT(cpu_book_mask, NULL, BOOK),
 	SDTL_INIT(cpu_drawer_mask, NULL, DRAWER),
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 4cd3d69741cf..03ff6270966a 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -463,11 +463,6 @@ static int x86_core_flags(void)
 {
 	return cpu_core_flags() | x86_sched_itmt_flags();
 }
-
-static const struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
-{
-	return cpu_smt_mask(cpu);
-}
 #endif
 
 #ifdef CONFIG_SCHED_CLUSTER
diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
index 602508130c8a..d75fbb7d9667 100644
--- a/include/linux/sched/topology.h
+++ b/include/linux/sched/topology.h
@@ -37,7 +37,13 @@ static inline int cpu_smt_flags(void)
 {
 	return SD_SHARE_CPUCAPACITY | SD_SHARE_LLC;
 }
-#endif
+
+static const __maybe_unused
+struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
+{
+	return cpu_smt_mask(cpu);
+}
+#endif /* CONFIG_SCHED_SMT */
 
 #ifdef CONFIG_SCHED_CLUSTER
 static inline int cpu_cluster_flags(void)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index dfc754e0668c..92165fe56a2d 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -1724,13 +1724,6 @@ sd_init(struct sched_domain_topology_level *tl,
 	return sd;
 }
 
-#ifdef CONFIG_SCHED_SMT
-static const struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
-{
-	return cpu_smt_mask(cpu);
-}
-#endif
-
 #ifdef CONFIG_SCHED_CLUSTER
 static const struct cpumask *tl_cls_mask(struct sched_domain_topology_level *tl, int cpu)
 {
-- 
2.34.1
Re: [PATCH v7 5/8] sched/topology: Unify tl_smt_mask() across core and all arch
Posted by Peter Zijlstra 1 month, 1 week ago
> diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
> index 602508130c8a..d75fbb7d9667 100644
> --- a/include/linux/sched/topology.h
> +++ b/include/linux/sched/topology.h
> @@ -37,7 +37,13 @@ static inline int cpu_smt_flags(void)
>  {
>  	return SD_SHARE_CPUCAPACITY | SD_SHARE_LLC;
>  }
> -#endif
> +
> +static const __maybe_unused
> +struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
> +{
> +	return cpu_smt_mask(cpu);
> +}
> +#endif /* CONFIG_SCHED_SMT */

Problem with that __maybe_unused is that you forgot inline.

static inline const
struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
{
	return cpu_smt_mask(cpu);
}

seems to make it happy.
Re: [PATCH v7 5/8] sched/topology: Unify tl_smt_mask() across core and all arch
Posted by Christophe Leroy 1 month, 1 week ago

Le 26/08/2025 à 10:01, Peter Zijlstra a écrit :
>> diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
>> index 602508130c8a..d75fbb7d9667 100644
>> --- a/include/linux/sched/topology.h
>> +++ b/include/linux/sched/topology.h
>> @@ -37,7 +37,13 @@ static inline int cpu_smt_flags(void)
>>   {
>>   	return SD_SHARE_CPUCAPACITY | SD_SHARE_LLC;
>>   }
>> -#endif
>> +
>> +static const __maybe_unused
>> +struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
>> +{
>> +	return cpu_smt_mask(cpu);
>> +}
>> +#endif /* CONFIG_SCHED_SMT */
> 
> Problem with that __maybe_unused is that you forgot inline.
> 
> static inline const
> struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
> {
> 	return cpu_smt_mask(cpu);
> }
> 
> seems to make it happy.
> 

But the function is referenced by SDTL_INIT() macro so there is no real 
point in declaring it inline. Would be cleaner to have it defined in a C 
file.

Christophe
Re: [PATCH v7 5/8] sched/topology: Unify tl_smt_mask() across core and all arch
Posted by Peter Zijlstra 1 month, 1 week ago
On Tue, Aug 26, 2025 at 10:11:40AM +0200, Christophe Leroy wrote:
> 
> 
> Le 26/08/2025 à 10:01, Peter Zijlstra a écrit :
> > > diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
> > > index 602508130c8a..d75fbb7d9667 100644
> > > --- a/include/linux/sched/topology.h
> > > +++ b/include/linux/sched/topology.h
> > > @@ -37,7 +37,13 @@ static inline int cpu_smt_flags(void)
> > >   {
> > >   	return SD_SHARE_CPUCAPACITY | SD_SHARE_LLC;
> > >   }
> > > -#endif
> > > +
> > > +static const __maybe_unused
> > > +struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
> > > +{
> > > +	return cpu_smt_mask(cpu);
> > > +}
> > > +#endif /* CONFIG_SCHED_SMT */
> > 
> > Problem with that __maybe_unused is that you forgot inline.
> > 
> > static inline const
> > struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
> > {
> > 	return cpu_smt_mask(cpu);
> > }
> > 
> > seems to make it happy.
> > 
> 
> But the function is referenced by SDTL_INIT() macro so there is no real
> point in declaring it inline. Would be cleaner to have it defined in a C
> file.

Ah, that's what you mean. I was more focussed on getting rid of that
horrible __maybe_unused and then either works. But yes, perhaps just
having them in a .c file is best.
Re: [PATCH v7 5/8] sched/topology: Unify tl_smt_mask() across core and all arch
Posted by Christophe Leroy 1 month, 1 week ago

Le 26/08/2025 à 06:13, K Prateek Nayak a écrit :
> Unify the tl_smt_mask() wrapper around cpu_smt_mask() across core, x86,
> ppc, and s390.
> 
> On s390, include/linux/topology.c defines an explicit cpu_smt_mask()
> wrapper around topology_sibling_cpumask() when cpu_smt_mask() is not
> defined by the arch/ bits and topology_sibling_cpumask() on s390 returns
> &cpu_topology[cpu].thread_mask.
> 
> No functional changes intended.
> 
> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com>
> ---
>   arch/powerpc/kernel/smp.c      | 5 -----
>   arch/s390/kernel/topology.c    | 8 +-------
>   arch/x86/kernel/smpboot.c      | 5 -----
>   include/linux/sched/topology.h | 8 +++++++-
>   kernel/sched/topology.c        | 7 -------
>   5 files changed, 8 insertions(+), 25 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
> index 7f79b853b221..c58ddf84fe63 100644
> --- a/arch/powerpc/kernel/smp.c
> +++ b/arch/powerpc/kernel/smp.c
> @@ -1038,11 +1038,6 @@ static const struct cpumask *smallcore_smt_mask(struct sched_domain_topology_lev
>   {
>   	return cpu_smallcore_mask(cpu);
>   }
> -
> -static const struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
> -{
> -	return cpu_smt_mask(cpu);
> -}
>   #endif
>   
>   static struct cpumask *cpu_corgrp_mask(int cpu)
> diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
> index 5129e3ffa7f5..c88eda847309 100644
> --- a/arch/s390/kernel/topology.c
> +++ b/arch/s390/kernel/topology.c
> @@ -509,12 +509,6 @@ int topology_cpu_init(struct cpu *cpu)
>   	return rc;
>   }
>   
> -static const struct cpumask *cpu_thread_mask(struct sched_domain_topology_level *tl, int cpu)
> -{
> -	return &cpu_topology[cpu].thread_mask;
> -}
> -
> -
>   const struct cpumask *cpu_coregroup_mask(int cpu)
>   {
>   	return &cpu_topology[cpu].core_mask;
> @@ -541,7 +535,7 @@ static const struct cpumask *cpu_pkg_mask(struct sched_domain_topology_level *tl
>   }
>   
>   static struct sched_domain_topology_level s390_topology[] = {
> -	SDTL_INIT(cpu_thread_mask, cpu_smt_flags, SMT),
> +	SDTL_INIT(tl_smt_mask, cpu_smt_flags, SMT),
>   	SDTL_INIT(cpu_mc_mask, cpu_core_flags, MC),
>   	SDTL_INIT(cpu_book_mask, NULL, BOOK),
>   	SDTL_INIT(cpu_drawer_mask, NULL, DRAWER),
> diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
> index 4cd3d69741cf..03ff6270966a 100644
> --- a/arch/x86/kernel/smpboot.c
> +++ b/arch/x86/kernel/smpboot.c
> @@ -463,11 +463,6 @@ static int x86_core_flags(void)
>   {
>   	return cpu_core_flags() | x86_sched_itmt_flags();
>   }
> -
> -static const struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
> -{
> -	return cpu_smt_mask(cpu);
> -}
>   #endif
>   
>   #ifdef CONFIG_SCHED_CLUSTER
> diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
> index 602508130c8a..d75fbb7d9667 100644
> --- a/include/linux/sched/topology.h
> +++ b/include/linux/sched/topology.h
> @@ -37,7 +37,13 @@ static inline int cpu_smt_flags(void)
>   {
>   	return SD_SHARE_CPUCAPACITY | SD_SHARE_LLC;
>   }
> -#endif
> +
> +static const __maybe_unused
> +struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)

__maybe_unused hides the dust under the carpet.

Leave the function in kernel/sched/topology.c and make it non-static 
with a prototype in linux/sched/topology.h

> +{
> +	return cpu_smt_mask(cpu);
> +}
> +#endif /* CONFIG_SCHED_SMT */
>   
>   #ifdef CONFIG_SCHED_CLUSTER
>   static inline int cpu_cluster_flags(void)
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index dfc754e0668c..92165fe56a2d 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -1724,13 +1724,6 @@ sd_init(struct sched_domain_topology_level *tl,
>   	return sd;
>   }
>   
> -#ifdef CONFIG_SCHED_SMT
> -static const struct cpumask *tl_smt_mask(struct sched_domain_topology_level *tl, int cpu)
> -{
> -	return cpu_smt_mask(cpu);
> -}
> -#endif
> -
>   #ifdef CONFIG_SCHED_CLUSTER
>   static const struct cpumask *tl_cls_mask(struct sched_domain_topology_level *tl, int cpu)
>   {