rcutorture: Refactor to enable non-x86 architectures
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Fri, 4 Oct 2013 20:15:55 +0000 (13:15 -0700)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Tue, 3 Dec 2013 18:11:15 +0000 (10:11 -0800)
This commit expands the checks for what architecture is running to generate
additional qemu-system- commands, then uses the resulting qemu-system-
command name to choose different qemu arguments as needed for different
architectures.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
tools/testing/selftests/rcutorture/bin/functions.sh
tools/testing/selftests/rcutorture/bin/kvm-test-1-rcu.sh
tools/testing/selftests/rcutorture/bin/kvm.sh

index c974414ef7a5bd121aa1bf54d3ba7d8d9fe5e2d3..d0d19ebd2a945b648d114c4a0ac14a2d44611f48 100644 (file)
@@ -78,3 +78,81 @@ identify_qemu () {
                exit 1
        fi
 }
+
+# identify_qemu_append qemu-cmd
+#
+# Output arguments for the qemu "-append" string based on CPU type
+# and the RCU_QEMU_INTERACTIVE environment variable.
+identify_qemu_append () {
+       case "$1" in
+       qemu-system-x86_64|qemu-system-i386)
+               echo noapic selinux=0 initcall_debug debug
+               ;;
+       esac
+       if test -n "$RCU_QEMU_INTERACTIVE"
+       then
+               echo root=/dev/sda
+       else
+               echo console=ttyS0
+       fi
+}
+
+# identify_qemu_args qemu-cmd serial-file
+#
+# Output arguments for qemu arguments based on the RCU_QEMU_MAC
+# and RCU_QEMU_INTERACTIVE environment variables.
+identify_qemu_args () {
+       case "$1" in
+       qemu-system-x86_64|qemu-system-i386)
+               ;;
+       qemu-system-ppc64)
+               echo -enable-kvm -M pseries -cpu POWER7 -nodefaults
+               echo -device spapr-vscsi
+               if test -n "$RCU_QEMU_INTERACTIVE" -a -n "$RCU_QEMU_MAC"
+               then
+                       echo -device spapr-vlan,netdev=net0,mac=$RCU_QEMU_MAC
+                       echo -netdev bridge,br=br0,id=net0
+               elif test -n "$RCU_QEMU_INTERACTIVE"
+               then
+                       echo -net nic -net user
+               fi
+               ;;
+       esac
+       if test -n "$RCU_QEMU_INTERACTIVE"
+       then
+               echo -monitor stdio -serial pty -S
+       else
+               echo -serial file:$2
+       fi
+}
+
+# identify_qemu_vcpus
+#
+# Returns the number of virtual CPUs available to the aggregate of the
+# guest OSes.
+identify_qemu_vcpus () {
+       lscpu | grep '^CPU(s):' | sed -e 's/CPU(s)://'
+}
+
+# specify_qemu_cpus qemu-cmd qemu-args #cpus
+#
+# Appends a string containing "-smp XXX" to qemu-args, unless the incoming
+# qemu-args already contains "-smp".
+specify_qemu_cpus () {
+       local nt;
+
+       if echo $2 | grep -q -e -smp
+       then
+               echo $2
+       else
+               case "$1" in
+               qemu-system-x86_64|qemu-system-i386)
+                       echo $2 -smp $3
+                       ;;
+               qemu-system-ppc64)
+                       nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`"
+                       echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt
+                       ;;
+               esac
+       fi
+}
index 5e2e79b5eaba1e1769a00031b1c33eedde541c9c..9fd546ccb075e4a25049b8ceebc6c75157baf25d 100755 (executable)
@@ -115,20 +115,21 @@ QEMU="`identify_qemu $builddir/vmlinux.o`"
 
 # Generate -smp qemu argument.
 cpu_count=`configNR_CPUS.sh $config_template`
-ncpus=`grep '^processor' /proc/cpuinfo | wc -l`
-if test $cpu_count -gt $ncpus
+vcpus=`identify_qemu_vcpus`
+if test $cpu_count -gt $vcpus
 then
-       echo CPU count limited from $cpu_count to $ncpus
+       echo CPU count limited from $cpu_count to $vcpus
        touch $resdir/Warnings
-       echo CPU count limited from $cpu_count to $ncpus >> $resdir/Warnings
-       cpu_count=$ncpus
-fi
-if echo $qemu_args | grep -q -e -smp
-then
-       echo CPU count specified by caller
-else
-       qemu_args="$qemu_args -smp $cpu_count"
+       echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
+       cpu_count=$vcpus
 fi
+qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
+
+# Generate architecture-specific and interaction-specific qemu arguments
+qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$builddir/console.log"`"
+
+# Generate qemu -append arguments
+qemu_append="`identify_qemu_append "$QEMU"`"
 
 # Generate CPU-hotplug boot parameters
 boot_args="`rcutorture_param_onoff "$boot_args" $builddir/.config`"
@@ -137,8 +138,8 @@ boot_args="`rcutorture_param_n_barrier_cbs "$boot_args"`"
 # Pull in Kconfig-fragment boot parameters
 boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
 
-echo $QEMU -serial file:$builddir/console.log $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append \"noapic selinux=0 console=ttyS0 initcall_debug debug rcutorture.stat_interval=15 rcutorture.shutdown_secs=$seconds rcutorture.rcutorture_runnable=1 $boot_args\" > $resdir/qemu-cmd
-$QEMU -name rcu-test -serial file:$builddir/console.log $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append "noapic selinux=0 console=ttyS0 initcall_debug debug rcutorture.stat_interval=15 rcutorture.shutdown_secs=$seconds rcutorture.rcutorture_runnable=1 $boot_args" &
+echo $QEMU $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append \"$qemu_append rcutorture.stat_interval=15 rcutorture.shutdown_secs=$seconds rcutorture.rcutorture_runnable=1 $boot_args\" > $resdir/qemu-cmd
+$QEMU $qemu_args -m 512 -kernel $builddir/arch/x86/boot/bzImage -append "$qemu_append rcutorture.stat_interval=15 rcutorture.shutdown_secs=$seconds rcutorture.rcutorture_runnable=1 $boot_args" &
 qemu_pid=$!
 commandcompleted=0
 echo Monitoring qemu job at pid $qemu_pid
index 2af549491f2388903ae736a46da106b45f663bc0..979c3413463465eb203622185d3e8f9ff017525f 100644 (file)
@@ -44,7 +44,9 @@ usage () {
        echo "       --configs \"config-file list\""
        echo "       --datestamp string"
        echo "       --duration minutes"
+       echo "       --interactive"
        echo "       --kversion vN.NN"
+       echo "       --mac nn:nn:nn:nn:nn:nn"
        echo "       --qemu-cmd qemu-system-..."
        echo "       --results absolute-pathname"
        echo "       --relbuilddir relative-pathname"
@@ -96,11 +98,19 @@ do
                dur=$2
                shift
                ;;
+       --interactive)
+               RCU_QEMU_INTERACTIVE=1; export RCU_QEMU_INTERACTIVE
+               ;;
        --kversion)
                checkarg --kversion "(kernel version)" $# "$2" '^v[0-9.]*$' error
                kversion=$2
                shift
                ;;
+       --mac)
+               checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
+               RCU_QEMU_MAC=$2; export RCU_QEMU_MAC
+               shift
+               ;;
        --qemu-cmd)
                checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
                RCU_QEMU_CMD="$2"; export RCU_QEMU_CMD