Skip to contentSkip to conversation

Replace MAX_SMP probe loop

PATCH Superseded Colton Lewis 3 participants 7 messages Jan 11, 2023 – Jan 31, 2023

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Replace MAX_SMP probe loop

v2:

Instead of deleting the probe loop, replace it with reading QEMU error output.

v1:

https://lore.kernel.org/kvm/[email protected]/

Colton Lewis (1):
arm: Replace MAX_SMP probe loop in favor of reading directly

 scripts/runtime.bash | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

--
2.39.0.314.g84b9a713c41-goog

#1 lore raw

PATCH v2 1/1 arm: Replace MAX_SMP probe loop in favor of reading directly

Replace the MAX_SMP probe loop in favor of reading a number directly from the QEMU error message. This is equally safe as the existing code because the error message has had the same format as long as it has existed, since QEMU v2.10. The final number before the end of the error message line indicates the max QEMU supports. A short awk program is used to extract the number, which becomes the new MAX_SMP value.

This loop logic is broken for machines with a number of CPUs that isn't a power of two. A machine with 8 CPUs will test with MAX_SMP=8 but a machine with 12 CPUs will test with MAX_SMP=6 because 12 >> 2 ==
6. This can, in rare circumstances, lead to different test results depending only on the number of CPUs the machine has.

A previous comment explains the loop should only apply to kernels <=v4.3 on arm and suggests deletion when it becomes tiresome to maintian. However, it is always theoretically possible to test on a machine that has more CPUs than QEMU supports, so it makes sense to leave some check in place.

---
 scripts/runtime.bash | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
scripts/runtime.bash +7 -9
index f8794e9..4377e75 100644
@@ -188,12 +188,10 @@ function run()
 # Probe for MAX_SMP, in case it's less than the number of host cpus.
 #
 # This probing currently only works for ARM, as x86 bails on another
-# error first. Also, this probing isn't necessary for any ARM hosts
-# running kernels later than v4.3, i.e. those including ef748917b52
-# "arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'". So, at some
-# point when maintaining the while loop gets too tiresome, we can
-# just remove it...
-while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
-		|& grep -qi 'exceeds max CPUs'; do
-	MAX_SMP=$((MAX_SMP >> 1))
-done
+# error first. The awk program takes the last number from the QEMU
+# error message, which gives the allowable MAX_SMP.
+if $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+      |& grep -qi 'exceeds max CPUs'; then
+	GET_LAST_NUM='/exceeds max CPUs/ {match($0, /[[:digit:]]+)$/); print substr($0, RSTART, RLENGTH-1)}'
+	MAX_SMP=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& awk "$GET_LAST_NUM")
+fi
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#2 lore raw

Re: [kvm-unit-tests PATCH v2 1/1] arm: Replace MAX_SMP probe loop in favor of reading directly

Quoted 11 lines · Colton Lewis

Replace the MAX_SMP probe loop in favor of reading a number directly from the QEMU error message. This is equally safe as the existing code because the error message has had the same format as long as it has existed, since QEMU v2.10. The final number before the end of the error message line indicates the max QEMU supports. A short awk program is used to extract the number, which becomes the new MAX_SMP value.

This loop logic is broken for machines with a number of CPUs that isn't a power of two. A machine with 8 CPUs will test with MAX_SMP=8 but a machine with 12 CPUs will test with MAX_SMP=6 because 12 >> 2 ==

                                                                    ^ 1
Quoted 2 lines

6. This can, in rare circumstances, lead to different test results depending only on the number of CPUs the machine has.

I guess that problem doesn't go away if we don't set the number of CPUs to be the same, regardless of machine, i.e. we're still picking a machine-specific value when we pick MAX_SMP. I think I know what you mean though. For gicv2 tests on machines that support non-power-of-2 CPUs greater than 8 it's possible to end up with less than 8 for MAX_SMP, which is surprising. Maybe while fixing the shift above you can change the text to be more in line with that?

Quoted 23 lines

A previous comment explains the loop should only apply to kernels <=v4.3 on arm and suggests deletion when it becomes tiresome to maintian. However, it is always theoretically possible to test on a machine that has more CPUs than QEMU supports, so it makes sense to leave some check in place.

---
 scripts/runtime.bash | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
scripts/runtime.bash +0 -3
index f8794e9..4377e75 100644
@@ -188,12 +188,10 @@ function run()
 # Probe for MAX_SMP, in case it's less than the number of host cpus.
 #
 # This probing currently only works for ARM, as x86 bails on another
-# error first. Also, this probing isn't necessary for any ARM hosts
-# running kernels later than v4.3, i.e. those including ef748917b52
-# "arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'". So, at some

scripts/runtime.bash function run() · line 194

Quoted 10 lines
scripts/runtime.bash +4 -6
-# point when maintaining the while loop gets too tiresome, we can
-# just remove it...
-while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
-		|& grep -qi 'exceeds max CPUs'; do
-	MAX_SMP=$((MAX_SMP >> 1))
-done
+# error first. The awk program takes the last number from the QEMU
+# error message, which gives the allowable MAX_SMP.
+if $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+      |& grep -qi 'exceeds max CPUs'; then

If the message has always been the same then the -i on grep shouldn't be necessary.

scripts/runtime.bash function run() · line 196

Quoted 2 lines
scripts/runtime.bash +2 -0
+	GET_LAST_NUM='/exceeds max CPUs/ {match($0, /[[:digit:]]+)$/); print substr($0, RSTART, RLENGTH-1)}'
+	MAX_SMP=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& awk "$GET_LAST_NUM")

We should restructure this so we only have to invoke QEMU once and I think we can do it with just bash and grep. Something like

if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'exceeds max CPUs'); then

     smp=${smp##*\(}
     MAX_SMP=${smp:0:-1}

fi

Thanks,
drew

#3 lore raw

Re: [kvm-unit-tests PATCH v2 1/1] arm: Replace MAX_SMP probe loop in favor of reading directly

Sorry I missed this email earlier.

Quoted 17 lines · Andrew Jones
Quoted 11 lines · Colton Lewis

Replace the MAX_SMP probe loop in favor of reading a number directly from the QEMU error message. This is equally safe as the existing code because the error message has had the same format as long as it has existed, since QEMU v2.10. The final number before the end of the error message line indicates the max QEMU supports. A short awk program is used to extract the number, which becomes the new MAX_SMP value.

This loop logic is broken for machines with a number of CPUs that isn't a power of two. A machine with 8 CPUs will test with MAX_SMP=8 but a machine with 12 CPUs will test with MAX_SMP=6 because 12 >> 2 ==

                                                                     ^ 1
Quoted 2 lines

6. This can, in rare circumstances, lead to different test results depending only on the number of CPUs the machine has.

Quoted 7 lines

I guess that problem doesn't go away if we don't set the number of CPUs to be the same, regardless of machine, i.e. we're still picking a machine-specific value when we pick MAX_SMP. I think I know what you mean though. For gicv2 tests on machines that support non-power-of-2 CPUs greater than 8 it's possible to end up with less than 8 for MAX_SMP, which is surprising. Maybe while fixing the shift above you can change the text to be more in line with that?

I will rephrase the message and fix the shift.

Quoted 27 lines
Quoted 27 lines

A previous comment explains the loop should only apply to kernels <=v4.3 on arm and suggests deletion when it becomes tiresome to maintian. However, it is always theoretically possible to test on a machine that has more CPUs than QEMU supports, so it makes sense to leave some check in place.

---
  scripts/runtime.bash | 16 +++++++---------
  1 file changed, 7 insertions(+), 9 deletions(-)
scripts/runtime.bash +0 -8
index f8794e9..4377e75 100644
@@ -188,12 +188,10 @@ function run()
  # Probe for MAX_SMP, in case it's less than the number of host cpus.
  #
  # This probing currently only works for ARM, as x86 bails on another
-# error first. Also, this probing isn't necessary for any ARM hosts
-# running kernels later than v4.3, i.e. those including ef748917b52
-# "arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'". So, at some
-# point when maintaining the while loop gets too tiresome, we can
-# just remove it...
-while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
-		|& grep -qi 'exceeds max CPUs'; do
-	MAX_SMP=$((MAX_SMP >> 1))
Quoted 8 lines

scripts/runtime.bash function run() · line 194

Quoted 5 lines
scripts/runtime.bash +4 -1
-done
+# error first. The awk program takes the last number from the QEMU
+# error message, which gives the allowable MAX_SMP.
+if $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+      |& grep -qi 'exceeds max CPUs'; then

If the message has always been the same then the -i on grep shouldn't be necessary.

True. I was only copying the grep command that was there.

Quoted 8 lines
Quoted 4 lines
scripts/runtime.bash +1 -0
+	GET_LAST_NUM='/exceeds max CPUs/ {match($0, /[[:digit:]]+)$/); print  

substr($0, RSTART, RLENGTH-1)}'

scripts/runtime.bash +1 -0
+	MAX_SMP=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |&  

awk "$GET_LAST_NUM")

We should restructure this so we only have to invoke QEMU once and I think we can do it with just bash and grep. Something like

Quoted 5 lines

if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |&
grep 'exceeds max CPUs'); then

      smp=${smp##*\(}
      MAX_SMP=${smp:0:-1}

fi

Good idea.

#4 lore raw

Re: [kvm-unit-tests PATCH v2 1/1] arm: Replace MAX_SMP probe loop in favor of reading directly

In reply to Colton Lewis
Quoted 39 lines · Colton Lewis

Replace the MAX_SMP probe loop in favor of reading a number directly from the QEMU error message. This is equally safe as the existing code because the error message has had the same format as long as it has existed, since QEMU v2.10. The final number before the end of the error message line indicates the max QEMU supports. A short awk program is used to extract the number, which becomes the new MAX_SMP value.

This loop logic is broken for machines with a number of CPUs that isn't a power of two. A machine with 8 CPUs will test with MAX_SMP=8 but a machine with 12 CPUs will test with MAX_SMP=6 because 12 >> 2 ==
6. This can, in rare circumstances, lead to different test results depending only on the number of CPUs the machine has.

A previous comment explains the loop should only apply to kernels <=v4.3 on arm and suggests deletion when it becomes tiresome to maintian. However, it is always theoretically possible to test on a machine that has more CPUs than QEMU supports, so it makes sense to leave some check in place.

---
  scripts/runtime.bash | 16 +++++++---------
  1 file changed, 7 insertions(+), 9 deletions(-)
scripts/runtime.bash +0 -6
index f8794e9..4377e75 100644
@@ -188,12 +188,10 @@ function run()
  # Probe for MAX_SMP, in case it's less than the number of host cpus.
  #
  # This probing currently only works for ARM, as x86 bails on another
-# error first. Also, this probing isn't necessary for any ARM hosts
-# running kernels later than v4.3, i.e. those including ef748917b52
-# "arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'". So, at some
-# point when maintaining the while loop gets too tiresome, we can
-# just remove it...
-while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \

scripts/runtime.bash function run() · line 197

Quoted 10 lines
scripts/runtime.bash +7 -3
-		|& grep -qi 'exceeds max CPUs'; do
-	MAX_SMP=$((MAX_SMP >> 1))
-done
+# error first. The awk program takes the last number from the QEMU
+# error message, which gives the allowable MAX_SMP.
+if $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+      |& grep -qi 'exceeds max CPUs'; then
+	GET_LAST_NUM='/exceeds max CPUs/ {match($0, /[[:digit:]]+)$/); print substr($0, RSTART, RLENGTH-1)}'
+	MAX_SMP=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& awk "$GET_LAST_NUM")
+fi

Is that string with "exceeds" really still the recent error message of the latest QEMU versions? When I'm running

qemu-system-aarch64 -machine virt -smp 1024

I'm getting:

qemu-system-aarch64: Invalid SMP CPUs 1024. The max CPUs supported by machine 'virt-8.0' is 512

... thus no "exceeds" in here? What do I miss? Maybe it's better to just grep for "max CPUs" ?

Thomas

#5 lore raw

Re: [kvm-unit-tests PATCH v2 1/1] arm: Replace MAX_SMP probe loop in favor of reading directly

Quoted 58 lines · Thomas Huth
Quoted 49 lines · Colton Lewis

Replace the MAX_SMP probe loop in favor of reading a number directly from the QEMU error message. This is equally safe as the existing code because the error message has had the same format as long as it has existed, since QEMU v2.10. The final number before the end of the error message line indicates the max QEMU supports. A short awk program is used to extract the number, which becomes the new MAX_SMP value.

This loop logic is broken for machines with a number of CPUs that isn't a power of two. A machine with 8 CPUs will test with MAX_SMP=8 but a machine with 12 CPUs will test with MAX_SMP=6 because 12 >> 2 ==
6. This can, in rare circumstances, lead to different test results depending only on the number of CPUs the machine has.

A previous comment explains the loop should only apply to kernels <=v4.3 on arm and suggests deletion when it becomes tiresome to maintian. However, it is always theoretically possible to test on a machine that has more CPUs than QEMU supports, so it makes sense to leave some check in place.

---
   scripts/runtime.bash | 16 +++++++---------
   1 file changed, 7 insertions(+), 9 deletions(-)
scripts/runtime.bash +5 -9
index f8794e9..4377e75 100644
@@ -188,12 +188,10 @@ function run()
   # Probe for MAX_SMP, in case it's less than the number of host cpus.
   #
   # This probing currently only works for ARM, as x86 bails on another
-# error first. Also, this probing isn't necessary for any ARM hosts
-# running kernels later than v4.3, i.e. those including ef748917b52
-# "arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'". So, at some
-# point when maintaining the while loop gets too tiresome, we can
-# just remove it...
-while $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
-		|& grep -qi 'exceeds max CPUs'; do
-	MAX_SMP=$((MAX_SMP >> 1))
-done
+# error first. The awk program takes the last number from the QEMU
+# error message, which gives the allowable MAX_SMP.
+if $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+      |& grep -qi 'exceeds max CPUs'; then
+	GET_LAST_NUM='/exceeds max CPUs/ {match($0, /[[:digit:]]+)$/); print  

substr($0, RSTART, RLENGTH-1)}'

scripts/runtime.bash +1 -0
+	MAX_SMP=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |&  
Quoted 2 lines

awk "$GET_LAST_NUM")
+fi

Is that string with "exceeds" really still the recent error message of the latest QEMU versions? When I'm running

qemu-system-aarch64 -machine virt -smp 1024

Quoted 7 lines

I'm getting:

qemu-system-aarch64: Invalid SMP CPUs 1024. The max CPUs supported by machine 'virt-8.0' is 512

... thus no "exceeds" in here? What do I miss? Maybe it's better to just grep for "max CPUs" ?

The full qemu command run by the test is much more complicated. It takes a different code path and results in different errors, including the "exceeds" one. All my testing has been done with QEMU v7.0, released 2022.

#6 lore raw

Re: [kvm-unit-tests PATCH v2 1/1] arm: Replace MAX_SMP probe loop in favor of reading directly

Quoted 25 lines · Colton Lewis
Quoted 23 lines · Thomas Huth
Quoted 22 lines · Colton Lewis

Replace the MAX_SMP probe loop in favor of reading a number directly from the QEMU error message. This is equally safe as the existing code because the error message has had the same format as long as it has existed, since QEMU v2.10. The final number before the end of the error message line indicates the max QEMU supports. A short awk program is used to extract the number, which becomes the new MAX_SMP value.

This loop logic is broken for machines with a number of CPUs that isn't a power of two. A machine with 8 CPUs will test with MAX_SMP=8 but a machine with 12 CPUs will test with MAX_SMP=6 because 12 >> 2 ==
6. This can, in rare circumstances, lead to different test results depending only on the number of CPUs the machine has.

A previous comment explains the loop should only apply to kernels <=v4.3 on arm and suggests deletion when it becomes tiresome to maintian. However, it is always theoretically possible to test on a machine that has more CPUs than QEMU supports, so it makes sense to leave some check in place.

---

...

Quoted 18 lines
Quoted 17 lines
Quoted 7 lines

+if $RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP \
+      |& grep -qi 'exceeds max CPUs'; then
+    GET_LAST_NUM='/exceeds max CPUs/ {match($0, /[[:digit:]]+)$/); print substr($0, RSTART, RLENGTH-1)}'
+    MAX_SMP=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& awk "$GET_LAST_NUM")
+fi

Is that string with "exceeds" really still the recent error message of the latest QEMU versions? When I'm running

   qemu-system-aarch64 -machine virt -smp 1024

I'm getting:

   qemu-system-aarch64: Invalid SMP CPUs 1024. The max CPUs supported by machine 'virt-8.0' is 512

Quoted 7 lines
Quoted 2 lines

... thus no "exceeds" in here? What do I miss? Maybe it's better to just grep for "max CPUs" ?

The full qemu command run by the test is much more complicated. It takes a different code path and results in different errors, including the "exceeds" one. All my testing has been done with QEMU v7.0, released 2022.

Could you please provide such a command line? I haven't been able to reproduce this with the current development version of QEMU (using TCG) - either I (likely) did something wrong, or the behavior of QEMU changed in the past months...

Thanks,
Thomas