cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

kvm.sh (19169B)


      1#!/bin/bash
      2# SPDX-License-Identifier: GPL-2.0+
      3#
      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.
      7#
      8# Usage: kvm.sh [ options ]
      9#
     10# Copyright (C) IBM Corporation, 2011
     11#
     12# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
     13
     14scriptname=$0
     15args="$*"
     16
     17T=${TMPDIR-/tmp}/kvm.sh.$$
     18trap 'rm -rf $T' 0
     19mkdir $T
     20
     21cd `dirname $scriptname`/../../../../../
     22
     23# This script knows only English.
     24LANG=en_US.UTF-8; export LANG
     25
     26dur=$((30*60))
     27dryrun=""
     28RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
     29PATH=${RCUTORTURE}/bin:$PATH; export PATH
     30. functions.sh
     31
     32TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"
     33TORTURE_DEFCONFIG=defconfig
     34TORTURE_BOOT_IMAGE=""
     35TORTURE_BUILDONLY=
     36TORTURE_INITRD="$RCUTORTURE/initrd"; export TORTURE_INITRD
     37TORTURE_KCONFIG_ARG=""
     38TORTURE_KCONFIG_GDB_ARG=""
     39TORTURE_BOOT_GDB_ARG=""
     40TORTURE_QEMU_GDB_ARG=""
     41TORTURE_JITTER_START=""
     42TORTURE_JITTER_STOP=""
     43TORTURE_KCONFIG_KASAN_ARG=""
     44TORTURE_KCONFIG_KCSAN_ARG=""
     45TORTURE_KMAKE_ARG=""
     46TORTURE_QEMU_MEM=512
     47torture_qemu_mem_default=1
     48TORTURE_REMOTE=
     49TORTURE_SHUTDOWN_GRACE=180
     50TORTURE_SUITE=rcu
     51TORTURE_MOD=rcutorture
     52TORTURE_TRUST_MAKE=""
     53resdir=""
     54configs=""
     55cpus=0
     56ds=`date +%Y.%m.%d-%H.%M.%S`
     57jitter="-1"
     58
     59startdate="`date`"
     60starttime="`get_starttime`"
     61
     62usage () {
     63	echo "Usage: $scriptname optional arguments:"
     64	echo "       --allcpus"
     65	echo "       --bootargs kernel-boot-arguments"
     66	echo "       --bootimage relative-path-to-kernel-boot-image"
     67	echo "       --buildonly"
     68	echo "       --configs \"config-file list w/ repeat factor (3*TINY01)\""
     69	echo "       --cpus N"
     70	echo "       --datestamp string"
     71	echo "       --defconfig string"
     72	echo "       --dryrun batches|scenarios|sched|script"
     73	echo "       --duration minutes | <seconds>s | <hours>h | <days>d"
     74	echo "       --gdb"
     75	echo "       --help"
     76	echo "       --interactive"
     77	echo "       --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
     78	echo "       --kasan"
     79	echo "       --kconfig Kconfig-options"
     80	echo "       --kcsan"
     81	echo "       --kmake-arg kernel-make-arguments"
     82	echo "       --mac nn:nn:nn:nn:nn:nn"
     83	echo "       --memory megabytes|nnnG"
     84	echo "       --no-initrd"
     85	echo "       --qemu-args qemu-arguments"
     86	echo "       --qemu-cmd qemu-system-..."
     87	echo "       --remote"
     88	echo "       --results absolute-pathname"
     89	echo "       --shutdown-grace seconds"
     90	echo "       --torture lock|rcu|rcuscale|refscale|scf|X*"
     91	echo "       --trust-make"
     92	exit 1
     93}
     94
     95while test $# -gt 0
     96do
     97	case "$1" in
     98	--allcpus)
     99		cpus=$TORTURE_ALLOTED_CPUS
    100		max_cpus=$TORTURE_ALLOTED_CPUS
    101		;;
    102	--bootargs|--bootarg)
    103		checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
    104		TORTURE_BOOTARGS="$TORTURE_BOOTARGS $2"
    105		shift
    106		;;
    107	--bootimage)
    108		checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
    109		TORTURE_BOOT_IMAGE="$2"
    110		shift
    111		;;
    112	--buildonly|--build-only)
    113		TORTURE_BUILDONLY=1
    114		;;
    115	--configs|--config)
    116		checkarg --configs "(list of config files)" "$#" "$2" '^[^/.a-z]\+$' '^--'
    117		configs="$configs $2"
    118		shift
    119		;;
    120	--cpus)
    121		checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
    122		cpus=$2
    123		TORTURE_ALLOTED_CPUS="$2"
    124		if test -z "$TORTURE_REMOTE"
    125		then
    126			max_cpus="`identify_qemu_vcpus`"
    127			if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"
    128			then
    129				TORTURE_ALLOTED_CPUS=$max_cpus
    130			fi
    131		fi
    132		shift
    133		;;
    134	--datestamp)
    135		checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--'
    136		ds=$2
    137		shift
    138		;;
    139	--defconfig)
    140		checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
    141		TORTURE_DEFCONFIG=$2
    142		shift
    143		;;
    144	--dryrun)
    145		checkarg --dryrun "batches|sched|script" $# "$2" 'batches\|scenarios\|sched\|script' '^--'
    146		dryrun=$2
    147		shift
    148		;;
    149	--duration)
    150		checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
    151		mult=60
    152		if echo "$2" | grep -q 's$'
    153		then
    154			mult=1
    155		elif echo "$2" | grep -q 'h$'
    156		then
    157			mult=3600
    158		elif echo "$2" | grep -q 'd$'
    159		then
    160			mult=86400
    161		fi
    162		ts=`echo $2 | sed -e 's/[smhd]$//'`
    163		dur=$(($ts*mult))
    164		shift
    165		;;
    166	--gdb)
    167		TORTURE_KCONFIG_GDB_ARG="CONFIG_DEBUG_INFO=y"; export TORTURE_KCONFIG_GDB_ARG
    168		TORTURE_BOOT_GDB_ARG="nokaslr"; export TORTURE_BOOT_GDB_ARG
    169		TORTURE_QEMU_GDB_ARG="-s -S"; export TORTURE_QEMU_GDB_ARG
    170		;;
    171	--help|-h)
    172		usage
    173		;;
    174	--interactive)
    175		TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
    176		;;
    177	--jitter)
    178		checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
    179		jitter="$2"
    180		shift
    181		;;
    182	--kasan)
    183		TORTURE_KCONFIG_KASAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KASAN=y"; export TORTURE_KCONFIG_KASAN_ARG
    184		if test -n "$torture_qemu_mem_default"
    185		then
    186			TORTURE_QEMU_MEM=2G
    187		fi
    188		;;
    189	--kconfig|--kconfigs)
    190		checkarg --kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
    191		TORTURE_KCONFIG_ARG="`echo "$TORTURE_KCONFIG_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
    192		shift
    193		;;
    194	--kcsan)
    195		TORTURE_KCONFIG_KCSAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KCSAN=y CONFIG_KCSAN_STRICT=y CONFIG_KCSAN_REPORT_ONCE_IN_MS=100000 CONFIG_KCSAN_VERBOSE=y CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y"; export TORTURE_KCONFIG_KCSAN_ARG
    196		;;
    197	--kmake-arg|--kmake-args)
    198		checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
    199		TORTURE_KMAKE_ARG="`echo "$TORTURE_KMAKE_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
    200		shift
    201		;;
    202	--mac)
    203		checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
    204		TORTURE_QEMU_MAC=$2
    205		shift
    206		;;
    207	--memory)
    208		checkarg --memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error
    209		TORTURE_QEMU_MEM=$2
    210		torture_qemu_mem_default=
    211		shift
    212		;;
    213	--no-initrd)
    214		TORTURE_INITRD=""; export TORTURE_INITRD
    215		;;
    216	--qemu-args|--qemu-arg)
    217		checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
    218		TORTURE_QEMU_ARG="`echo "$TORTURE_QEMU_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
    219		shift
    220		;;
    221	--qemu-cmd)
    222		checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
    223		TORTURE_QEMU_CMD="$2"
    224		shift
    225		;;
    226	--remote)
    227		TORTURE_REMOTE=1
    228		;;
    229	--results)
    230		checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
    231		resdir=$2
    232		shift
    233		;;
    234	--shutdown-grace)
    235		checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
    236		TORTURE_SHUTDOWN_GRACE=$2
    237		shift
    238		;;
    239	--torture)
    240		checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuscale\|refscale\|scf\|X.*\)$' '^--'
    241		TORTURE_SUITE=$2
    242		TORTURE_MOD="`echo $TORTURE_SUITE | sed -e 's/^\(lock\|rcu\|scf\)$/\1torture/'`"
    243		shift
    244		if test "$TORTURE_SUITE" = rcuscale || test "$TORTURE_SUITE" = refscale
    245		then
    246			# If you really want jitter for refscale or
    247			# rcuscale, specify it after specifying the rcuscale
    248			# or the refscale.  (But why jitter in these cases?)
    249			jitter=0
    250		fi
    251		;;
    252	--trust-make)
    253		TORTURE_TRUST_MAKE="y"
    254		;;
    255	*)
    256		echo Unknown argument $1
    257		usage
    258		;;
    259	esac
    260	shift
    261done
    262
    263if test -n "$dryrun" || test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
    264then
    265	:
    266else
    267	echo No initrd and unable to create one, aborting test >&2
    268	exit 1
    269fi
    270
    271CONFIGFRAG=${RCUTORTURE}/configs/${TORTURE_SUITE}; export CONFIGFRAG
    272
    273defaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
    274if test -z "$configs"
    275then
    276	configs=$defaultconfigs
    277fi
    278
    279if test -z "$resdir"
    280then
    281	resdir=$RCUTORTURE/res
    282fi
    283
    284# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
    285configs_derep=
    286for CF in $configs
    287do
    288	case $CF in
    289	[0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**|[0-9][0-9][0-9][0-9]\**)
    290		config_reps=`echo $CF | sed -e 's/\*.*$//'`
    291		CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
    292		;;
    293	*)
    294		config_reps=1
    295		CF1=$CF
    296		;;
    297	esac
    298	for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
    299	do
    300		configs_derep="$configs_derep $CF1"
    301	done
    302done
    303touch $T/cfgcpu
    304configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
    305if test -n "$TORTURE_KCONFIG_GDB_ARG"
    306then
    307	if test "`echo $configs_derep | wc -w`" -gt 1
    308	then
    309		echo "The --config list is: $configs_derep."
    310		echo "Only one --config permitted with --gdb, terminating."
    311		exit 1
    312	fi
    313fi
    314echo 'BEGIN {' > $T/cfgcpu.awk
    315for CF1 in `echo $configs_derep | tr -s ' ' '\012' | sort -u`
    316do
    317	if test -f "$CONFIGFRAG/$CF1"
    318	then
    319		if echo "$TORTURE_KCONFIG_ARG" | grep -q '\<CONFIG_NR_CPUS='
    320		then
    321			echo "$TORTURE_KCONFIG_ARG" | tr -s ' ' | tr ' ' '\012' > $T/KCONFIG_ARG
    322			cpu_count=`configNR_CPUS.sh $T/KCONFIG_ARG`
    323		else
    324			cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
    325		fi
    326		cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
    327		cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
    328		echo 'scenariocpu["'"$CF1"'"] = '"$cpu_count"';' >> $T/cfgcpu.awk
    329	else
    330		echo "The --configs file $CF1 does not exist, terminating."
    331		exit 1
    332	fi
    333done
    334cat << '___EOF___' >> $T/cfgcpu.awk
    335}
    336{
    337	for (i = 1; i <= NF; i++)
    338		print $i, scenariocpu[$i];
    339}
    340___EOF___
    341echo $configs_derep | awk -f $T/cfgcpu.awk > $T/cfgcpu
    342sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
    343
    344# Use a greedy bin-packing algorithm, sorting the list accordingly.
    345awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
    346BEGIN {
    347	njobs = 0;
    348}
    349
    350{
    351	# Read file of tests and corresponding required numbers of CPUs.
    352	cf[njobs] = $1;
    353	cpus[njobs] = $2;
    354	njobs++;
    355}
    356
    357END {
    358	batch = 0;
    359	nc = -1;
    360
    361	# Each pass through the following loop creates on test batch that
    362	# can be executed concurrently given ncpus.  Note that a given test
    363	# that requires more than the available CPUs will run in its own
    364	# batch.  Such tests just have to make do with what is available.
    365	while (nc != ncpus) {
    366		batch++;
    367		nc = ncpus;
    368
    369		# Each pass through the following loop considers one
    370		# test for inclusion in the current batch.
    371		for (i = 0; i < njobs; i++) {
    372			if (done[i])
    373				continue; # Already part of a batch.
    374			if (nc >= cpus[i] || nc == ncpus) {
    375
    376				# This test fits into the current batch.
    377				done[i] = batch;
    378				nc -= cpus[i];
    379				if (nc <= 0)
    380					break; # Too-big test in its own batch.
    381			}
    382		}
    383	}
    384
    385	# Dump out the tests in batch order.
    386	for (b = 1; b <= batch; b++)
    387		for (i = 0; i < njobs; i++)
    388			if (done[i] == b)
    389				print cf[i], cpus[i];
    390}'
    391
    392# Generate a script to execute the tests in appropriate batches.
    393cat << ___EOF___ > $T/script
    394CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
    395RCUTORTURE="$RCUTORTURE"; export RCUTORTURE
    396PATH="$PATH"; export PATH
    397TORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS
    398TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
    399TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
    400TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
    401TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
    402TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
    403TORTURE_KCONFIG_GDB_ARG="$TORTURE_KCONFIG_GDB_ARG"; export TORTURE_KCONFIG_GDB_ARG
    404TORTURE_BOOT_GDB_ARG="$TORTURE_BOOT_GDB_ARG"; export TORTURE_BOOT_GDB_ARG
    405TORTURE_QEMU_GDB_ARG="$TORTURE_QEMU_GDB_ARG"; export TORTURE_QEMU_GDB_ARG
    406TORTURE_KCONFIG_KASAN_ARG="$TORTURE_KCONFIG_KASAN_ARG"; export TORTURE_KCONFIG_KASAN_ARG
    407TORTURE_KCONFIG_KCSAN_ARG="$TORTURE_KCONFIG_KCSAN_ARG"; export TORTURE_KCONFIG_KCSAN_ARG
    408TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
    409TORTURE_MOD="$TORTURE_MOD"; export TORTURE_MOD
    410TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
    411TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
    412TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
    413TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
    414TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
    415TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
    416TORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE
    417if ! test -e $resdir
    418then
    419	mkdir -p "$resdir" || :
    420fi
    421mkdir -p $resdir/$ds
    422TORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR
    423TORTURE_STOPFILE="$resdir/$ds/STOP.1"; export TORTURE_STOPFILE
    424echo Results directory: $resdir/$ds
    425echo $scriptname $args
    426touch $resdir/$ds/log
    427echo $scriptname $args >> $resdir/$ds/log
    428echo ${TORTURE_SUITE} > $resdir/$ds/torture_suite
    429echo Build directory: `pwd` > $resdir/$ds/testid.txt
    430if test -d .git
    431then
    432	echo Current commit: `git rev-parse HEAD` >> $resdir/$ds/testid.txt
    433	echo >> $resdir/$ds/testid.txt
    434	echo ' ---' Output of "'"git status"'": >> $resdir/$ds/testid.txt
    435	git status >> $resdir/$ds/testid.txt
    436	echo >> $resdir/$ds/testid.txt
    437	echo >> $resdir/$ds/testid.txt
    438	echo ' ---' Output of "'"git diff HEAD"'": >> $resdir/$ds/testid.txt
    439	git diff HEAD >> $resdir/$ds/testid.txt
    440fi
    441___EOF___
    442kvm-assign-cpus.sh /sys/devices/system/node > $T/cpuarray.awk
    443kvm-get-cpus-script.sh $T/cpuarray.awk $T/dumpbatches.awk
    444cat << '___EOF___' >> $T/dumpbatches.awk
    445BEGIN {
    446	i = 0;
    447}
    448
    449{
    450	cf[i] = $1;
    451	cpus[i] = $2;
    452	i++;
    453}
    454
    455# Dump out the scripting required to run one test batch.
    456function dump(first, pastlast, batchnum,  affinitylist)
    457{
    458	print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log";
    459	print "needqemurun="
    460	jn=1
    461	njitter = 0;
    462	split(jitter, ja);
    463	if (ja[1] == -1 && ncpus == 0)
    464		njitter = 1;
    465	else if (ja[1] == -1)
    466		njitter = ncpus;
    467	else
    468		njitter = ja[1];
    469	print "TORTURE_JITTER_START=\". jitterstart.sh " njitter " " rd " " dur " " ja[2] " " ja[3] "\"; export TORTURE_JITTER_START";
    470	print "TORTURE_JITTER_STOP=\". jitterstop.sh " rd " \"; export TORTURE_JITTER_STOP"
    471	for (j = first; j < pastlast; j++) {
    472		cpusr[jn] = cpus[j];
    473		if (cfrep[cf[j]] == "") {
    474			cfr[jn] = cf[j];
    475			cfrep[cf[j]] = 1;
    476		} else {
    477			cfrep[cf[j]]++;
    478			cfr[jn] = cf[j] "." cfrep[cf[j]];
    479		}
    480		builddir=rd cfr[jn] "/build";
    481		if (cpusr[jn] > ncpus && ncpus != 0)
    482			ovf = "-ovf";
    483		else
    484			ovf = "";
    485		print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
    486		print "mkdir " rd cfr[jn] " || :";
    487		print "touch " builddir ".wait";
    488		affinitylist = "";
    489		if (gotcpus()) {
    490			affinitylist = nextcpus(cpusr[jn]);
    491		}
    492		if (affinitylist ~ /^[0-9,-][0-9,-]*$/)
    493			print "export TORTURE_AFFINITY=" affinitylist;
    494		else
    495			print "export TORTURE_AFFINITY=";
    496		print "kvm-test-1-run.sh " CONFIGDIR cf[j], rd cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn]  "/kvm-test-1-run.sh.out 2>&1 &"
    497		print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
    498		print "while test -f " builddir ".wait"
    499		print "do"
    500		print "\tsleep 1"
    501		print "done"
    502		print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
    503		jn++;
    504	}
    505	print "runfiles="
    506	for (j = 1; j < jn; j++) {
    507		builddir=rd cfr[j] "/build";
    508		if (TORTURE_BUILDONLY)
    509			print "rm -f " builddir ".ready"
    510		else
    511			print "mv " builddir ".ready " builddir ".run"
    512			print "runfiles=\"$runfiles " builddir ".run\""
    513		fi
    514		print "if test -f \"" rd cfr[j] "/builtkernel\""
    515		print "then"
    516		print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
    517		print "\tneedqemurun=1"
    518		print "fi"
    519	}
    520	if (TORTURE_BUILDONLY && njitter != 0) {
    521		njitter = 0;
    522		print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
    523	}
    524	if (TORTURE_BUILDONLY) {
    525		print "needqemurun="
    526	}
    527	print "if test -n \"$needqemurun\""
    528	print "then"
    529	print "\techo ---- Starting kernels. `date` | tee -a " rd "log";
    530	print "\t$TORTURE_JITTER_START";
    531	print "\twhile ls $runfiles > /dev/null 2>&1"
    532	print "\tdo"
    533	print "\t\t:"
    534	print "\tdone"
    535	print "\t$TORTURE_JITTER_STOP";
    536	print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
    537	print "else"
    538	print "\twait"
    539	print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
    540	print "fi"
    541	for (j = 1; j < jn; j++) {
    542		print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log";
    543		print "cat " rd cfr[j]  "/kvm-test-1-run.sh.out | tee -a " rd "log";
    544	}
    545}
    546
    547END {
    548	njobs = i;
    549	nc = ncpus;
    550	first = 0;
    551	batchnum = 1;
    552
    553	# Each pass through the following loop considers one test.
    554	for (i = 0; i < njobs; i++) {
    555		if (ncpus == 0) {
    556			# Sequential test specified, each test its own batch.
    557			dump(i, i + 1, batchnum);
    558			first = i;
    559			batchnum++;
    560		} else if (nc < cpus[i] && i != 0) {
    561			# Out of CPUs, dump out a batch.
    562			dump(first, i, batchnum);
    563			first = i;
    564			nc = ncpus;
    565			batchnum++;
    566		}
    567		# Account for the CPUs needed by the current test.
    568		nc -= cpus[i];
    569	}
    570	# Dump the last batch.
    571	if (ncpus != 0)
    572		dump(first, i, batchnum);
    573}
    574___EOF___
    575awk < $T/cfgcpu.pack \
    576	-v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \
    577	-v CONFIGDIR="$CONFIGFRAG/" \
    578	-v RCUTORTURE="$RCUTORTURE" \
    579	-v ncpus=$cpus \
    580	-v jitter="$jitter" \
    581	-v rd=$resdir/$ds/ \
    582	-v dur=$dur \
    583	-v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
    584	-v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
    585	-f $T/dumpbatches.awk >> $T/script
    586echo kvm-end-run-stats.sh "$resdir/$ds" "$starttime" >> $T/script
    587
    588# Extract the tests and their batches from the script.
    589egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
    590	sed -e 's/:.*$//' -e 's/^echo //' -e 's/-ovf//' |
    591	awk '
    592	/^----Start/ {
    593		batchno = $3;
    594		next;
    595	}
    596	{
    597		print batchno, $1, $2
    598	}' > $T/batches
    599
    600# As above, but one line per batch.
    601grep -v '^#' $T/batches | awk '
    602BEGIN {
    603	oldbatch = 1;
    604}
    605
    606{
    607	if (oldbatch != $1) {
    608		print ++n ". " curbatch;
    609		curbatch = "";
    610		oldbatch = $1;
    611	}
    612	curbatch = curbatch " " $2;
    613}
    614
    615END {
    616	print ++n ". " curbatch;
    617}' > $T/scenarios
    618
    619if test "$dryrun" = script
    620then
    621	cat $T/script
    622	exit 0
    623elif test "$dryrun" = sched
    624then
    625	# Extract the test run schedule from the script.
    626	egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
    627		sed -e 's/:.*$//' -e 's/^echo //'
    628	nbuilds="`grep 'Starting build\.' $T/script |
    629		  grep -v ">>" | sed -e 's/:.*$//' -e 's/^echo //' |
    630		  awk '{ print $1 }' | grep -v '\.' | wc -l`"
    631	echo Total number of builds: $nbuilds
    632	nbatches="`grep 'Start batch' $T/script | grep -v ">>" | wc -l`"
    633	echo Total number of batches: $nbatches
    634	exit 0
    635elif test "$dryrun" = batches
    636then
    637	cat $T/batches
    638	exit 0
    639elif test "$dryrun" = scenarios
    640then
    641	cat $T/scenarios
    642	exit 0
    643else
    644	# Not a dryrun.  Record the batches and the number of CPUs, then run the script.
    645	bash $T/script
    646	ret=$?
    647	cp $T/batches $resdir/$ds/batches
    648	cp $T/scenarios $resdir/$ds/scenarios
    649	echo '#' cpus=$cpus >> $resdir/$ds/batches
    650	exit $ret
    651fi
    652
    653# 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
    654# Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop
    655# Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y"
    656# Control buffer size: --bootargs trace_buf_size=3k
    657# Get trace-buffer dumps on all oopses: --bootargs ftrace_dump_on_oops
    658# Ditto, but dump only the oopsing CPU: --bootargs ftrace_dump_on_oops=orig_cpu
    659# Heavy-handed way to also dump on warnings: --bootargs panic_on_warn