linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] cpumask: limit visibility of FORCE_NR_CPUS
@ 2022-10-19 22:59 Yury Norov
  2022-11-04 17:43 ` Valentin Schneider
  0 siblings, 1 reply; 6+ messages in thread
From: Yury Norov @ 2022-10-19 22:59 UTC (permalink / raw)
  To: linux-kernel, Geert Uytterhoeven, Linus Torvalds,
	Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Stephen Rothwell, Peter Zijlstra, Thomas Gleixner,
	Paul E . McKenney, Vlastimil Babka, Dmitry Vyukov,
	Valentin Schneider, Sander Vanheule, Alexey Klimov, Eric Biggers
  Cc: Yury Norov

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
+	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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] cpumask: limit visibility of FORCE_NR_CPUS
  2022-10-19 22:59 [PATCH v2] cpumask: limit visibility of FORCE_NR_CPUS Yury Norov
@ 2022-11-04 17:43 ` Valentin Schneider
  2022-11-04 22:36   ` Yury Norov
  0 siblings, 1 reply; 6+ messages in thread
From: Valentin Schneider @ 2022-11-04 17:43 UTC (permalink / raw)
  To: Yury Norov, linux-kernel, Geert Uytterhoeven, Linus Torvalds,
	Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Stephen Rothwell, Peter Zijlstra, Thomas Gleixner,
	Paul E . McKenney, Vlastimil Babka, Dmitry Vyukov,
	Sander Vanheule, Alexey Klimov, Eric Biggers
  Cc: Yury Norov

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] cpumask: limit visibility of FORCE_NR_CPUS
  2022-11-04 17:43 ` Valentin Schneider
@ 2022-11-04 22:36   ` Yury Norov
  2022-11-07 12:45     ` Valentin Schneider
  0 siblings, 1 reply; 6+ messages in thread
From: Yury Norov @ 2022-11-04 22:36 UTC (permalink / raw)
  To: Valentin Schneider
  Cc: linux-kernel, Geert Uytterhoeven, Linus Torvalds,
	Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Stephen Rothwell, Peter Zijlstra, Thomas Gleixner,
	Paul E . McKenney, Vlastimil Babka, Dmitry Vyukov,
	Sander Vanheule, Alexey Klimov, Eric Biggers

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] cpumask: limit visibility of FORCE_NR_CPUS
  2022-11-04 22:36   ` Yury Norov
@ 2022-11-07 12:45     ` Valentin Schneider
  2022-11-07 17:55       ` Linus Torvalds
  0 siblings, 1 reply; 6+ messages in thread
From: Valentin Schneider @ 2022-11-07 12:45 UTC (permalink / raw)
  To: Yury Norov
  Cc: linux-kernel, Geert Uytterhoeven, Linus Torvalds,
	Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Stephen Rothwell, Peter Zijlstra, Thomas Gleixner,
	Paul E . McKenney, Vlastimil Babka, Dmitry Vyukov,
	Sander Vanheule, Alexey Klimov, Eric Biggers

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>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] cpumask: limit visibility of FORCE_NR_CPUS
  2022-11-07 12:45     ` Valentin Schneider
@ 2022-11-07 17:55       ` Linus Torvalds
  2022-11-07 18:20         ` Yury Norov
  0 siblings, 1 reply; 6+ messages in thread
From: Linus Torvalds @ 2022-11-07 17:55 UTC (permalink / raw)
  To: Valentin Schneider
  Cc: Yury Norov, linux-kernel, Geert Uytterhoeven, Andy Shevchenko,
	Rasmus Villemoes, Andrew Morton, Stephen Rothwell,
	Peter Zijlstra, Thomas Gleixner, Paul E . McKenney,
	Vlastimil Babka, Dmitry Vyukov, Sander Vanheule, Alexey Klimov,
	Eric Biggers

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] cpumask: limit visibility of FORCE_NR_CPUS
  2022-11-07 17:55       ` Linus Torvalds
@ 2022-11-07 18:20         ` Yury Norov
  0 siblings, 0 replies; 6+ messages in thread
From: Yury Norov @ 2022-11-07 18:20 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Valentin Schneider, linux-kernel, Geert Uytterhoeven,
	Andy Shevchenko, Rasmus Villemoes, Andrew Morton,
	Stephen Rothwell, Peter Zijlstra, Thomas Gleixner,
	Paul E . McKenney, Vlastimil Babka, Dmitry Vyukov,
	Sander Vanheule, Alexey Klimov, Eric Biggers

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-07 18:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 22:59 [PATCH v2] cpumask: limit visibility of FORCE_NR_CPUS Yury Norov
2022-11-04 17:43 ` Valentin Schneider
2022-11-04 22:36   ` Yury Norov
2022-11-07 12:45     ` Valentin Schneider
2022-11-07 17:55       ` Linus Torvalds
2022-11-07 18:20         ` Yury Norov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).