[v2] cpumask: limit visibility of FORCE_NR_CPUS

Message ID 20221019225939.1646349-1-yury.norov@gmail.com
State New
Headers
Series [v2] cpumask: limit visibility of FORCE_NR_CPUS |

Commit Message

Yury Norov Oct. 19, 2022, 10:59 p.m. UTC
  In current form, FORCE_NR_CPUS is visible to all users building their
kernels, even not experts. It is also set in allmodconfig or allyesconfig,
which is not a correct behavior.

The 'choice' and unused config UNFORCE_NR_CPUS are used to ensure that
auto-generated configs that try to enable as much options as possible,
like allmodconfig, don't enable FORCE_NR_CPUS.

Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
v2: extend commit message with an explanation for what we need 'choice'.

 lib/Kconfig | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
  

Comments

Valentin Schneider Nov. 4, 2022, 5:43 p.m. UTC | #1
On 19/10/22 15:59, Yury Norov wrote:
> In current form, FORCE_NR_CPUS is visible to all users building their
> kernels, even not experts. It is also set in allmodconfig or allyesconfig,
> which is not a correct behavior.
>
> The 'choice' and unused config UNFORCE_NR_CPUS are used to ensure that
> auto-generated configs that try to enable as much options as possible,
> like allmodconfig, don't enable FORCE_NR_CPUS.
>
> Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> ---
> v2: extend commit message with an explanation for what we need 'choice'.
>
>  lib/Kconfig | 31 ++++++++++++++++++++++++-------
>  1 file changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/lib/Kconfig b/lib/Kconfig
> index 9bbf8a4b2108..1ada12f5dda6 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -528,14 +528,31 @@ config CPUMASK_OFFSTACK
>         them on the stack.  This is a bit more expensive, but avoids
>         stack overflow.
>
> +choice
> +	prompt "Number of CPUs detection method"
> +	default UNFORCE_NR_CPUS
> +	depends on SMP && EXPERT

What about moving the 'depends on EXPERT' onto FORCE_NR_CPUS? I find it
makes it easier to figure out the requirements for that option, and is
similar to how e.g. CONFIG_PREEMPT_RT is handled.

> +	help
> +	  Select between boot-time and compile-time detection of number
> +	  of CPUs. If it's possible to provide exact number of CPUs at
> +	  compile-time, kernel code may be optimized better.
> +	  For general-purpose kernel, choose "boot time" option.
> +
> +config UNFORCE_NR_CPUS
> +	bool "Set number of CPUs at boot time"
> +	help
> +	  Choose it if you build general-purpose kernel and want to rely
> +	  on kernel to detect actual number of CPUs.
> +
>  config FORCE_NR_CPUS
> -       bool "NR_CPUS is set to an actual number of CPUs"
> -       depends on SMP
> -       help
> -         Say Yes if you have NR_CPUS set to an actual number of possible
> -         CPUs in your system, not to a default value. This forces the core
> -         code to rely on compile-time value and optimize kernel routines
> -         better.
> +	bool "Set number of CPUs at compile time"
> +	help
> +	  Choose it if NR_CPUS corresponds to an actual number of
> +	  possible CPUs in your system. This forces the core code
> +	  to rely on compile-time value and optimize kernel routines
> +	  better.
> +
> +endchoice
>
>  config CPU_RMAP
>       bool
> --
> 2.34.1
  
Yury Norov Nov. 4, 2022, 10:36 p.m. UTC | #2
On Fri, Nov 04, 2022 at 05:43:53PM +0000, Valentin Schneider wrote:
> On 19/10/22 15:59, Yury Norov wrote:
> > In current form, FORCE_NR_CPUS is visible to all users building their
> > kernels, even not experts. It is also set in allmodconfig or allyesconfig,
> > which is not a correct behavior.
> >
> > The 'choice' and unused config UNFORCE_NR_CPUS are used to ensure that
> > auto-generated configs that try to enable as much options as possible,
> > like allmodconfig, don't enable FORCE_NR_CPUS.
> >
> > Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Signed-off-by: Yury Norov <yury.norov@gmail.com>
> > ---
> > v2: extend commit message with an explanation for what we need 'choice'.
> >
> >  lib/Kconfig | 31 ++++++++++++++++++++++++-------
> >  1 file changed, 24 insertions(+), 7 deletions(-)
> >
> > diff --git a/lib/Kconfig b/lib/Kconfig
> > index 9bbf8a4b2108..1ada12f5dda6 100644
> > --- a/lib/Kconfig
> > +++ b/lib/Kconfig
> > @@ -528,14 +528,31 @@ config CPUMASK_OFFSTACK
> >         them on the stack.  This is a bit more expensive, but avoids
> >         stack overflow.
> >
> > +choice
> > +	prompt "Number of CPUs detection method"
> > +	default UNFORCE_NR_CPUS
> > +	depends on SMP && EXPERT
> 
> What about moving the 'depends on EXPERT' onto FORCE_NR_CPUS? I find it
> makes it easier to figure out the requirements for that option, and is
> similar to how e.g. CONFIG_PREEMPT_RT is handled.

In case of PREEMPT_RT, there are some other options to choose. In case of
FORCE_NR_CPUS there will be a choice with a single option, and it would be
weird that the option is never used.

I'd prefer to hide this choice for non-experts entirely.
  
Valentin Schneider Nov. 7, 2022, 12:45 p.m. UTC | #3
On 04/11/22 15:36, Yury Norov wrote:
> On Fri, Nov 04, 2022 at 05:43:53PM +0000, Valentin Schneider wrote:
>> On 19/10/22 15:59, Yury Norov wrote:
>> > +choice
>> > +	prompt "Number of CPUs detection method"
>> > +	default UNFORCE_NR_CPUS
>> > +	depends on SMP && EXPERT
>>
>> What about moving the 'depends on EXPERT' onto FORCE_NR_CPUS? I find it
>> makes it easier to figure out the requirements for that option, and is
>> similar to how e.g. CONFIG_PREEMPT_RT is handled.
>
> In case of PREEMPT_RT, there are some other options to choose. In case of
> FORCE_NR_CPUS there will be a choice with a single option, and it would be
> weird that the option is never used.
>

True, this would have been neater as a single config, but AIUI it's a
required "trick" for allyesconfig. I would have expected other configs to
have hit similar issues in the past, but didn't find any.

> I'd prefer to hide this choice for non-experts entirely.

Sure.

Reviewed-by: Valentin Schneider <vschneid@redhat.com>
  
Linus Torvalds Nov. 7, 2022, 5:55 p.m. UTC | #4
On Mon, Nov 7, 2022 at 4:45 AM Valentin Schneider <vschneid@redhat.com> wrote:
>
> True, this would have been neater as a single config, but AIUI it's a
> required "trick" for allyesconfig. I would have expected other configs to
> have hit similar issues in the past, but didn't find any.

Actually, the standard trick for allmodconfig and allyesconfig is to
use the "COMPILE_TEST" config variable.

It's basically a variable for "I'm not going to *run* the result, but
I want to make sure to get build coverage".

And both allmodconfig and allyesconfig set that config option.

In most cases, the "COMPILE_TEST" config variable is used to enable
things that wouldn't make sense on the chosen hardware platform, so
you have things like

        depends on ARCH_DAVINCI || COMPILE_TEST

because some driver only makes sense on ARCH_DAVINCI, but people still
want the build coverage.

But sometimes it's used the other way around, so fro example on x86 we have

     config X86_DECODER_SELFTEST

which explicitly depends on COMPILE_TEST *not* being set, because it's
a test that takes forever to run (particularly for huge kernels), and
so it's actually disabled for the  common all{yes,mod}config cases.

Same goes for things like LTO_CLANG_FULL. It's just expensive for big
build tests, plus causes too many issues for now.

End result: if some option actually *reduces* test coverage, or has
some other reason why it makes no sense for build tests, use that

        depends on !COMPILE_TEST

to not have allmodconfig and allyesconfig pick it.

                    Linus
  
Yury Norov Nov. 7, 2022, 6:20 p.m. UTC | #5
On Mon, Nov 07, 2022 at 09:55:34AM -0800, Linus Torvalds wrote:
> On Mon, Nov 7, 2022 at 4:45 AM Valentin Schneider <vschneid@redhat.com> wrote:
> >
> > True, this would have been neater as a single config, but AIUI it's a
> > required "trick" for allyesconfig. I would have expected other configs to
> > have hit similar issues in the past, but didn't find any.
> 
> Actually, the standard trick for allmodconfig and allyesconfig is to
> use the "COMPILE_TEST" config variable.
> 
> It's basically a variable for "I'm not going to *run* the result, but
> I want to make sure to get build coverage".
> 
> And both allmodconfig and allyesconfig set that config option.
> 
> In most cases, the "COMPILE_TEST" config variable is used to enable
> things that wouldn't make sense on the chosen hardware platform, so
> you have things like
> 
>         depends on ARCH_DAVINCI || COMPILE_TEST
> 
> because some driver only makes sense on ARCH_DAVINCI, but people still
> want the build coverage.
> 
> But sometimes it's used the other way around, so fro example on x86 we have
> 
>      config X86_DECODER_SELFTEST
> 
> which explicitly depends on COMPILE_TEST *not* being set, because it's
> a test that takes forever to run (particularly for huge kernels), and
> so it's actually disabled for the  common all{yes,mod}config cases.
> 
> Same goes for things like LTO_CLANG_FULL. It's just expensive for big
> build tests, plus causes too many issues for now.
> 
> End result: if some option actually *reduces* test coverage, or has
> some other reason why it makes no sense for build tests, use that
> 
>         depends on !COMPILE_TEST
> 
> to not have allmodconfig and allyesconfig pick it.

Thanks, I'll send v3 than.

Thanks,
Yury
  

Patch

diff --git a/lib/Kconfig b/lib/Kconfig
index 9bbf8a4b2108..1ada12f5dda6 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -528,14 +528,31 @@  config CPUMASK_OFFSTACK
 	  them on the stack.  This is a bit more expensive, but avoids
 	  stack overflow.
 
+choice
+	prompt "Number of CPUs detection method"
+	default UNFORCE_NR_CPUS
+	depends on SMP && EXPERT
+	help
+	  Select between boot-time and compile-time detection of number
+	  of CPUs. If it's possible to provide exact number of CPUs at
+	  compile-time, kernel code may be optimized better.
+	  For general-purpose kernel, choose "boot time" option.
+
+config UNFORCE_NR_CPUS
+	bool "Set number of CPUs at boot time"
+	help
+	  Choose it if you build general-purpose kernel and want to rely
+	  on kernel to detect actual number of CPUs.
+
 config FORCE_NR_CPUS
-       bool "NR_CPUS is set to an actual number of CPUs"
-       depends on SMP
-       help
-         Say Yes if you have NR_CPUS set to an actual number of possible
-         CPUs in your system, not to a default value. This forces the core
-         code to rely on compile-time value and optimize kernel routines
-         better.
+	bool "Set number of CPUs at compile time"
+	help
+	  Choose it if NR_CPUS corresponds to an actual number of
+	  possible CPUs in your system. This forces the core code
+	  to rely on compile-time value and optimize kernel routines
+	  better.
+
+endchoice
 
 config CPU_RMAP
 	bool