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