Skip to contentSkip to conversation

configure: Support CONFIG_* extension

PATCH In review Andrew Jones 2 participants 5 messages Sep 3, 2024 – Sep 11, 2024

Subsystems (5)
KVM RISC-V s390 KVM arm64 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

cover configure: Support CONFIG_* extension

riscv already wants to change NR_CPUS sometimes, so a CONFIG_NR_CPUS, which can be changed at compile time, would be helpful. We could just provide support for that with the configure command line, but other configurations will eventually come along (there are already two more in another riscv branch). Add support for extending config.h with a manually provided config.h-type file and also add support for using it for CONFIG_NR_CPUS for riscv.

Andrew Jones (2):
configure: Introduce add-config
riscv: Make NR_CPUS configurable

 configure             | 17 ++++++++++++++++-
 lib/riscv/asm/setup.h |  3 ++-
 2 files changed, 18 insertions(+), 2 deletions(-)
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/2 configure: Introduce add-config

Allow users to add additional CONFIG_* and override defaults by concatenating a given file with #define's and #undef's to lib/config.h

---
 configure | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
configure +14 -0
index 27ae9cc89657..7a1317d0650d 100755
@@ -64,6 +64,8 @@ usage() {
 	                           no environ is provided by the user (enabled by default)
 	    --erratatxt=FILE       specify a file to use instead of errata.txt. Use
 	                           '--erratatxt=' to ensure no file is used.
+	    --add-config=FILE      specify a file containing configs (CONFIG_*) to add on to the
+	                           generated lib/config.h. Use #undef to override default configs.
 	    --host-key-document=HOST_KEY_DOCUMENT
 	                           Specify the machine-specific host-key document for creating
 	                           a PVM image with 'genprotimg' (s390x only)
@@ -153,6 +155,10 @@ while [[ "$1" = -* ]]; do
 	    erratatxt=
 	    [ "$arg" ] && erratatxt=$(eval realpath "$arg")
 	    ;;
+	--add-config)
+	    add_config=
+	    [ "$arg" ] && add_config=$(eval realpath "$arg")
+	    ;;
 	--host-key-document)
 	    host_key_document="$arg"
 	    ;;
@@ -213,6 +219,10 @@ if [ "$erratatxt" ] && [ ! -f "$erratatxt" ]; then
     echo "erratatxt: $erratatxt does not exist or is not a regular file"
     exit 1
 fi
+if [ "$add_config" ] && [ ! -f "$add_config" ]; then
+    echo "add-config: $add_config does not exist or is not a regular file"
+    exit 1
+fi
 
 arch_name=$arch
 [ "$arch" = "aarch64" ] && arch="arm64"
@@ -502,4 +512,8 @@ cat <<EOF >> lib/config.h
 
 EOF
 fi
+if [ "$add_config" ]; then
+    echo "/* Additional configs from $add_config */" >> lib/config.h
+    cat "$add_config" >> lib/config.h
+fi
 echo "#endif" >> lib/config.h
Signature · 1 line
2.46.0
#4 lore raw

PATCH 2/2 riscv: Make NR_CPUS configurable

In reply to Andrew Jones

Unit tests would like to go nuts with the number of harts in order to help shake out issues with hart number assumptions. Rather than set a huge number that will only be used when a platform supports a huge number or when QEMU is told to exceed the recommended number of vcpus, make the number configurable. However, we do bump the default from 16 to 2*xlen since we would like to always force kvm-unit-tests to use cpumasks with more than one word in order to ensure that code stays maintained.

To override the default for NR_CPUS to, e.g. 256, testers should use --add-config. For example,

  $ cat <<EOF > 256.config
  #undef CONFIG_NR_CPUS
  #define CONFIG_NR_CPUS 256
  EOF
  $ ./configure --arch=riscv64 --cross-prefix=riscv64-linux-gnu- --add-config=256.config
---
 configure             | 3 ++-
 lib/riscv/asm/setup.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
configure +2 -1
index 7a1317d0650d..5ed0c28fcaea 100755
@@ -508,7 +508,8 @@ EOF
 elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
 cat <<EOF >> lib/config.h
 
-#define CONFIG_UART_EARLY_BASE 0x10000000
+#define CONFIG_NR_CPUS			(__riscv_xlen * 2)
+#define CONFIG_UART_EARLY_BASE		0x10000000
 
 EOF
 fi
lib/riscv/asm/setup.h +2 -1
index a13159bfe395..43b63c56d96f 100644
@@ -2,9 +2,10 @@
 #ifndef _ASMRISCV_SETUP_H_
 #define _ASMRISCV_SETUP_H_
 #include <libcflat.h>
+#include <config.h>
 #include <asm/processor.h>
 
-#define NR_CPUS 16
+#define NR_CPUS CONFIG_NR_CPUS
 extern struct thread_info cpus[NR_CPUS];
 extern int nr_cpus;
 extern uint64_t timebase_frequency;
Signature · 1 line
2.46.0
#2 lore raw

Re: [kvm-unit-tests PATCH 1/2] configure: Introduce add-config

In reply to Andrew Jones
Quoted 3 lines · Andrew Jones

Allow users to add additional CONFIG_* and override defaults by concatenating a given file with #define's and #undef's to lib/config.h

That's a horrible config format lol, but probbaly the simplest way to get something working. What if you included the user config first, then make the generated config test ifndef before defining the default?

Is it better to have a config file than to just add more --options to configure? If we had thousands of options maybe, but so far we are getting by with configure options. I think I prefer that for now unless we wholesale moved everything to a .config style.

Thanks,
Nick

Quoted 50 lines
---
 configure | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
configure +14 -0
index 27ae9cc89657..7a1317d0650d 100755
@@ -64,6 +64,8 @@ usage() {
 	                           no environ is provided by the user (enabled by default)
 	    --erratatxt=FILE       specify a file to use instead of errata.txt. Use
 	                           '--erratatxt=' to ensure no file is used.
+	    --add-config=FILE      specify a file containing configs (CONFIG_*) to add on to the
+	                           generated lib/config.h. Use #undef to override default configs.
 	    --host-key-document=HOST_KEY_DOCUMENT
 	                           Specify the machine-specific host-key document for creating
 	                           a PVM image with 'genprotimg' (s390x only)
@@ -153,6 +155,10 @@ while [[ "$1" = -* ]]; do
 	    erratatxt=
 	    [ "$arg" ] && erratatxt=$(eval realpath "$arg")
 	    ;;
+	--add-config)
+	    add_config=
+	    [ "$arg" ] && add_config=$(eval realpath "$arg")
+	    ;;
 	--host-key-document)
 	    host_key_document="$arg"
 	    ;;
@@ -213,6 +219,10 @@ if [ "$erratatxt" ] && [ ! -f "$erratatxt" ]; then
     echo "erratatxt: $erratatxt does not exist or is not a regular file"
     exit 1
 fi
+if [ "$add_config" ] && [ ! -f "$add_config" ]; then
+    echo "add-config: $add_config does not exist or is not a regular file"
+    exit 1
+fi
 
 arch_name=$arch
 [ "$arch" = "aarch64" ] && arch="arm64"
@@ -502,4 +512,8 @@ cat <<EOF >> lib/config.h
 
 EOF
 fi
+if [ "$add_config" ]; then
+    echo "/* Additional configs from $add_config */" >> lib/config.h
+    cat "$add_config" >> lib/config.h
+fi
 echo "#endif" >> lib/config.h
#3 lore raw

Re: [kvm-unit-tests PATCH 1/2] configure: Introduce add-config

Quoted 8 lines · Nicholas Piggin
Quoted 3 lines · Andrew Jones

Allow users to add additional CONFIG_* and override defaults by concatenating a given file with #define's and #undef's to lib/config.h

That's a horrible config format lol, but probbaly the simplest way to get something working. What if you included the user config first, then make the generated config test ifndef before defining the default?

User config first and then #ifndef would indeed be better.

Quoted 4 lines

Is it better to have a config file than to just add more --options to configure? If we had thousands of options maybe, but so far we are getting by with configure options.

I have some unposted patches where I introduce two more configs, which is what inspired me to stop adding configure command line options.

Quoted 2 lines

I think I prefer that for now
unless we wholesale moved everything to a .config style.

Moving to .config would be good, and importing and applying Kconfiglib doesn't look too daunting either. We can put this --add-config idea on hold until we've had a chance to experiment.

Thanks,
drew