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