2 # SPDX-License-Identifier: GPL-2.0+
4 # Run a series of tests under KVM. By default, this series is specified
5 # by the relevant CFLIST file, but can be overridden by the --configs
6 # command-line argument.
8 # Usage: kvm.sh [ options ]
10 # Copyright (C) IBM Corporation, 2011
12 # Authors: Paul E. McKenney <paulmck@linux.ibm.com>
17 T
=${TMPDIR-/tmp}/kvm.sh.$$
21 cd `dirname $scriptname`/..
/..
/..
/..
/..
/
25 KVM
="`pwd`/tools/testing/selftests/rcutorture"; export KVM
26 PATH
=${KVM}/bin
:$PATH; export PATH
29 TORTURE_ALLOTED_CPUS
="`identify_qemu_vcpus`"
30 TORTURE_DEFCONFIG
=defconfig
32 TORTURE_INITRD
="$KVM/initrd"; export TORTURE_INITRD
33 TORTURE_KCONFIG_ARG
=""
36 TORTURE_SHUTDOWN_GRACE
=180
42 ds
=`date +%Y.%m.%d-%H:%M:%S`
46 echo "Usage: $scriptname optional arguments:"
47 echo " --bootargs kernel-boot-arguments"
48 echo " --bootimage relative-path-to-kernel-boot-image"
50 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
52 echo " --datestamp string"
53 echo " --defconfig string"
54 echo " --dryrun sched|script"
55 echo " --duration minutes"
57 echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
58 echo " --kconfig Kconfig-options"
59 echo " --kmake-arg kernel-make-arguments"
60 echo " --mac nn:nn:nn:nn:nn:nn"
61 echo " --memory megabytes | nnnG"
63 echo " --qemu-args qemu-arguments"
64 echo " --qemu-cmd qemu-system-..."
65 echo " --results absolute-pathname"
75 checkarg
--bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
80 checkarg
--bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
81 TORTURE_BOOT_IMAGE
="$2"
88 checkarg
--configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
93 checkarg
--cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
95 TORTURE_ALLOTED_CPUS
="$2"
96 max_cpus
="`identify_qemu_vcpus`"
97 if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"
99 TORTURE_ALLOTED_CPUS
=$max_cpus
104 checkarg
--datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
109 checkarg
--defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
114 checkarg
--dryrun "sched|script" $# "$2" 'sched\|script' '^--'
119 checkarg
--duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
124 TORTURE_QEMU_INTERACTIVE
=1; export TORTURE_QEMU_INTERACTIVE
127 checkarg
--jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
132 checkarg
--kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
133 TORTURE_KCONFIG_ARG
="$2"
137 checkarg
--kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
138 TORTURE_KMAKE_ARG
="$2"
142 checkarg
--mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
147 checkarg
--memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error
152 TORTURE_INITRD
=""; export TORTURE_INITRD
154 --qemu-args|
--qemu-arg)
155 checkarg
--qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
156 TORTURE_QEMU_ARG
="$2"
160 checkarg
--qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
161 TORTURE_QEMU_CMD
="$2"
165 checkarg
--results "(absolute pathname)" "$#" "$2" '^/' '^error'
170 checkarg
--shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
171 TORTURE_SHUTDOWN_GRACE
=$2
175 checkarg
--torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
178 if test "$TORTURE_SUITE" = rcuperf
180 # If you really want jitter for rcuperf, specify
181 # it after specifying rcuperf. (But why?)
186 TORTURE_TRUST_MAKE
="y"
189 echo Unknown argument
$1
196 if test -z "$TORTURE_INITRD" || tools
/testing
/selftests
/rcutorture
/bin
/mkinitrd.sh
200 echo No initrd and unable to create one
, aborting
test >&2
204 CONFIGFRAG
=${KVM}/configs
/${TORTURE_SUITE}; export CONFIGFRAG
206 defaultconfigs
="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
207 if test -z "$configs"
209 configs
=$defaultconfigs
217 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
222 [0-9]\
**|
[0-9][0-9]\
**|
[0-9][0-9][0-9]\
**)
223 config_reps
=`echo $CF | sed -e 's/\*.*$//'`
224 CF1
=`echo $CF | sed -e 's/^[^*]*\*//'`
231 for ((cur_rep
=0;cur_rep
<$config_reps;cur_rep
++))
233 configs_derep
="$configs_derep $CF1"
237 configs_derep
="`echo $configs_derep | sed -e "s
/\
<CFLIST\
>/$defaultconfigs/g
"`"
238 for CF1
in $configs_derep
240 if test -f "$CONFIGFRAG/$CF1"
242 cpu_count
=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
243 cpu_count
=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
244 cpu_count
=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
245 echo $CF1 $cpu_count >> $T/cfgcpu
247 echo "The --configs file $CF1 does not exist, terminating."
251 sort -k2nr $T/cfgcpu
-T="$T" > $T/cfgcpu.
sort
253 # Use a greedy bin-packing algorithm, sorting the list accordingly.
254 awk < $T/cfgcpu.
sort > $T/cfgcpu.pack
-v ncpus
=$cpus '
260 # Read file of tests and corresponding required numbers of CPUs.
270 # Each pass through the following loop creates on test batch
271 # that can be executed concurrently given ncpus. Note that a
272 # given test that requires more than the available CPUs will run in
273 # their own batch. Such tests just have to make do with what
275 while (nc != ncpus) {
279 # Each pass through the following loop considers one
280 # test for inclusion in the current batch.
281 for (i = 0; i < njobs; i++) {
283 continue; # Already part of a batch.
284 if (nc >= cpus[i] || nc == ncpus) {
286 # This test fits into the current batch.
290 break; # Too-big test in its own batch.
295 # Dump out the tests in batch order.
296 for (b = 1; b <= batch; b++)
297 for (i = 0; i < njobs; i++)
299 print cf[i], cpus[i];
302 # Generate a script to execute the tests in appropriate batches.
303 cat << ___EOF___ > $T/script
304 CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
305 KVM="$KVM"; export KVM
306 PATH="$PATH"; export PATH
307 TORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS
308 TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
309 TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
310 TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
311 TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
312 TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
313 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
314 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
315 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
316 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
317 TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
318 TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
319 TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
320 TORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE
323 mkdir -p "$resdir" || :
326 echo Results directory: $resdir/$ds
327 echo $scriptname $args
328 touch $resdir/$ds/log
329 echo $scriptname $args >> $resdir/$ds/log
330 echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
331 pwd > $resdir/$ds/testid.txt
334 git status >> $resdir/$ds/testid.txt
335 git rev-parse HEAD >> $resdir/$ds/testid.txt
336 git diff HEAD >> $resdir/$ds/testid.txt
339 awk < $T/cfgcpu.pack \
340 -v TORTURE_BUILDONLY
="$TORTURE_BUILDONLY" \
341 -v CONFIGDIR
="$CONFIGFRAG/" \
344 -v jitter
="$jitter" \
347 -v TORTURE_QEMU_ARG
="$TORTURE_QEMU_ARG" \
348 -v TORTURE_BOOTARGS
="$TORTURE_BOOTARGS" \
359 # Dump out the scripting required to run one test batch.
360 function dump(first, pastlast, batchnum)
362 print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log";
365 for (j = first; j < pastlast; j++) {
366 builddir=KVM "/b" j - first + 1
368 if (cfrep[cf[j]] == "") {
373 cfr[jn] = cf[j] "." cfrep[cf[j]];
375 if (cpusr[jn] > ncpus && ncpus != 0)
379 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
380 print "rm -f " builddir ".*";
381 print "touch " builddir ".wait";
382 print "mkdir " rd cfr[jn] " || :";
383 print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &"
384 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
385 print "while test -f " builddir ".wait"
389 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
392 for (j = 1; j < jn; j++) {
394 print "rm -f " builddir ".ready"
395 print "if test -f \"" rd cfr[j] "/builtkernel\""
397 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
398 print "\tneedqemurun=1"
403 if (ja[1] == -1 && ncpus == 0)
405 else if (ja[1] == -1)
409 if (TORTURE_BUILDONLY && njitter != 0) {
411 print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
413 if (TORTURE_BUILDONLY) {
416 print "if test -n \"$needqemurun\""
418 print "\techo ---- Starting kernels. `date` | tee -a " rd "log";
419 for (j = 0; j < njitter; j++)
420 print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
422 print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
425 print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
427 for (j = 1; j < jn; j++) {
429 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log";
430 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out | tee -a " rd "log";
440 # Each pass through the following loop considers one test.
441 for (i = 0; i < njobs; i++) {
443 # Sequential test specified, each test its own batch.
444 dump(i, i + 1, batchnum);
447 } else if (nc < cpus[i] && i != 0) {
448 # Out of CPUs, dump out a batch.
449 dump(first, i, batchnum);
454 # Account for the CPUs needed by the current test.
457 # Dump the last batch.
459 dump(first, i, batchnum);
462 cat << ___EOF___ >> $T/script
465 echo " --- `date` Test summary:"
466 echo Results directory: $resdir/$ds
467 kvm-recheck.sh $resdir/$ds
470 if test "$dryrun" = script
474 elif test "$dryrun" = sched
476 # Extract the test run schedule from the script.
477 egrep 'Start batch|Starting build\.' $T/script |
479 sed -e 's/:.*$//' -e 's/^echo //'
482 # Not a dryrun, so run the script.
486 # Tracing: trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier
487 # Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop
488 # Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y"