Skip to contentSkip to conversation

cpumask: limit visibility of FORCE_NR_CPUS

PATCH Applied Yury Norov 3 participants 6 messages Oct 19, 2022 – Nov 7, 2022 Library code

v2 of 3 Applied 1/1 Latest is v3 →

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

PATCH v2 1/1 cpumask: limit visibility of FORCE_NR_CPUS

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.

---
v2: extend commit message with an explanation for what we need 'choice'.

 lib/Kconfig | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
lib/Kconfig +24 -7
index 9bbf8a4b2108..1ada12f5dda6 100644
@@ -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
Signature · 1 line
2.34.1
#1 lore raw
Quoted 22 lines · 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.

---
v2: extend commit message with an explanation for what we need 'choice'.

 lib/Kconfig | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
lib/Kconfig +0 -0
index 9bbf8a4b2108..1ada12f5dda6 100644

lib/Kconfig config CPUMASK_OFFSTACK · line 534

Quoted 7 lines
lib/Kconfig +4 -0
@@ -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.

Quoted 33 lines
lib/Kconfig +20 -8
+	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

author
#2 lore raw
Quoted 26 lines · Valentin Schneider
Quoted 25 lines · 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.

---
v2: extend commit message with an explanation for what we need 'choice'.

 lib/Kconfig | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
lib/Kconfig +0 -0
index 9bbf8a4b2108..1ada12f5dda6 100644
@@ -528,14 +528,31 @@ config CPUMASK_OFFSTACK
        them on the stack.  This is a bit more expensive, but avoids
        stack overflow.
 
Quoted 8 lines

lib/Kconfig config CPUMASK_OFFSTACK · line 534

Quoted 4 lines
lib/Kconfig +4 -0
+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.

Reviewed-by
#3 lore raw
Quoted 11 lines · Yury Norov
Quoted 9 lines · Valentin Schneider

lib/Kconfig config CPUMASK_OFFSTACK · line 534

Quoted 4 lines · Yury Norov
lib/Kconfig +4 -0
+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.

Quoted 4 lines

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.

Quoted 1 line

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

Sure.

#4 lore raw
Quoted 4 lines · Valentin Schneider

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

author
#5 lore raw
Quoted 34 lines · Linus Torvalds
Quoted 4 lines · Valentin Schneider

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.

Quoted 6 lines

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