brintos

brintos / linux-shallow public Read only

0
0
Text · 19.2 KiB · 7af73dd Raw
670 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.0+3#4# Run a series of tests under KVM.  By default, this series is specified5# by the relevant CFLIST file, but can be overridden by the --configs6# command-line argument.7#8# Usage: kvm.sh [ options ]9#10# Copyright (C) IBM Corporation, 201111#12# Authors: Paul E. McKenney <paulmck@linux.ibm.com>13 14scriptname=$015args="$*"16 17T="`mktemp -d ${TMPDIR-/tmp}/kvm.sh.XXXXXX`"18trap 'rm -rf $T' 019 20cd `dirname $scriptname`/../../../../../21 22# This script knows only English.23LANG=en_US.UTF-8; export LANG24 25dur=$((30*60))26dryrun=""27RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE28PATH=${RCUTORTURE}/bin:$PATH; export PATH29. functions.sh30 31TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"32TORTURE_DEFCONFIG=defconfig33TORTURE_BOOT_IMAGE=""34TORTURE_BUILDONLY=35TORTURE_INITRD="$RCUTORTURE/initrd"; export TORTURE_INITRD36TORTURE_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=51246torture_qemu_mem_default=147TORTURE_REMOTE=48TORTURE_SHUTDOWN_GRACE=18049TORTURE_SUITE=rcu50TORTURE_MOD=rcutorture51TORTURE_TRUST_MAKE=""52debuginfo="CONFIG_DEBUG_INFO_NONE=n CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y"53resdir=""54configs=""55cpus=056ds=`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 194}95 96while test $# -gt 097do98	case "$1" in99	--allcpus)100		cpus=$TORTURE_ALLOTED_CPUS101		max_cpus=$TORTURE_ALLOTED_CPUS102		;;103	--bootargs|--bootarg)104		checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'105		TORTURE_BOOTARGS="$TORTURE_BOOTARGS $2"106		shift107		;;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		shift112		;;113	--buildonly|--build-only)114		TORTURE_BUILDONLY=1115		;;116	--configs|--config)117		checkarg --configs "(list of config files)" "$#" "$2" '^[^/.a-z]\+$' '^--'118		configs="$configs $2"119		shift120		;;121	--cpus)122		checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'123		cpus=$2124		TORTURE_ALLOTED_CPUS="$2"125		if test -z "$TORTURE_REMOTE"126		then127			max_cpus="`identify_qemu_vcpus`"128			if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"129			then130				TORTURE_ALLOTED_CPUS=$max_cpus131			fi132		fi133		shift134		;;135	--datestamp)136		checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--'137		ds=$2138		shift139		;;140	--debug-info|--debuginfo)141		if test -z "$TORTURE_KCONFIG_KCSAN_ARG" && test -z "$TORTURE_BOOT_GDB_ARG"142		then143			TORTURE_KCONFIG_KCSAN_ARG="$debuginfo"; export TORTURE_KCONFIG_KCSAN_ARG144			TORTURE_BOOT_GDB_ARG="nokaslr"; export TORTURE_BOOT_GDB_ARG145		else146			echo "Ignored redundant --debug-info (implied by --kcsan &c)"147		fi148		;;149	--defconfig)150		checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'151		TORTURE_DEFCONFIG=$2152		shift153		;;154	--dryrun)155		checkarg --dryrun "batches|sched|script" $# "$2" 'batches\|scenarios\|sched\|script' '^--'156		dryrun=$2157		shift158		;;159	--duration)160		checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'161		mult=60162		if echo "$2" | grep -q 's$'163		then164			mult=1165		elif echo "$2" | grep -q 'h$'166		then167			mult=3600168		elif echo "$2" | grep -q 'd$'169		then170			mult=86400171		fi172		ts=`echo $2 | sed -e 's/[smhd]$//'`173		dur=$(($ts*mult))174		shift175		;;176	--gdb)177		TORTURE_KCONFIG_GDB_ARG="$debuginfo"; export TORTURE_KCONFIG_GDB_ARG178		TORTURE_BOOT_GDB_ARG="nokaslr"; export TORTURE_BOOT_GDB_ARG179		TORTURE_QEMU_GDB_ARG="-s -S"; export TORTURE_QEMU_GDB_ARG180		;;181	--help|-h)182		usage183		;;184	--interactive)185		TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE186		;;187	--jitter)188		checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'189		jitter="$2"190		shift191		;;192	--kasan)193		TORTURE_KCONFIG_KASAN_ARG="$debuginfo CONFIG_KASAN=y"; export TORTURE_KCONFIG_KASAN_ARG194		if test -n "$torture_qemu_mem_default"195		then196			TORTURE_QEMU_MEM=2G197		fi198		;;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		shift203		;;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_ARG206		;;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		shift211		;;212	--mac)213		checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error214		TORTURE_QEMU_MAC=$2215		shift216		;;217	--memory)218		checkarg --memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error219		TORTURE_QEMU_MEM=$2220		torture_qemu_mem_default=221		shift222		;;223	--no-initrd)224		TORTURE_INITRD=""; export TORTURE_INITRD225		;;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		shift230		;;231	--qemu-cmd)232		checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'233		TORTURE_QEMU_CMD="$2"234		shift235		;;236	--remote)237		TORTURE_REMOTE=1238		;;239	--results)240		checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'241		resdir=$2242		shift243		;;244	--shutdown-grace)245		checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'246		TORTURE_SHUTDOWN_GRACE=$2247		shift248		;;249	--torture)250		checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuscale\|refscale\|scf\|X.*\)$' '^--'251		TORTURE_SUITE=$2252		TORTURE_MOD="`echo $TORTURE_SUITE | sed -e 's/^\(lock\|rcu\|scf\)$/\1torture/'`"253		shift254		if test "$TORTURE_SUITE" = rcuscale || test "$TORTURE_SUITE" = refscale255		then256			# If you really want jitter for refscale or257			# rcuscale, specify it after specifying the rcuscale258			# or the refscale.  (But why jitter in these cases?)259			jitter=0260		fi261		;;262	--trust-make)263		TORTURE_TRUST_MAKE="y"264		;;265	*)266		echo Unknown argument $1267		usage268		;;269	esac270	shift271done272 273if test -n "$dryrun" || test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh274then275	:276else277	echo No initrd and unable to create one, aborting test >&2278	exit 1279fi280 281CONFIGFRAG=${RCUTORTURE}/configs/${TORTURE_SUITE}; export CONFIGFRAG282 283defaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"284if test -z "$configs"285then286	configs=$defaultconfigs287fi288 289if test -z "$resdir"290then291	resdir=$RCUTORTURE/res292fi293 294# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.295configs_derep=296for CF in $configs297do298	case $CF in299	[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=1305		CF1=$CF306		;;307	esac308	for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))309	do310		configs_derep="$configs_derep $CF1"311	done312done313touch $T/cfgcpu314configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"315if test -n "$TORTURE_KCONFIG_GDB_ARG"316then317	if test "`echo $configs_derep | wc -w`" -gt 1318	then319		echo "The --config list is: $configs_derep."320		echo "Only one --config permitted with --gdb, terminating."321		exit 1322	fi323fi324echo 'BEGIN {' > $T/cfgcpu.awk325for CF1 in `echo $configs_derep | tr -s ' ' '\012' | sort -u`326do327	if test -f "$CONFIGFRAG/$CF1"328	then329		if echo "$TORTURE_KCONFIG_ARG" | grep -q '\<CONFIG_NR_CPUS='330		then331			echo "$TORTURE_KCONFIG_ARG" | tr -s ' ' | tr ' ' '\012' > $T/KCONFIG_ARG332			cpu_count=`configNR_CPUS.sh $T/KCONFIG_ARG`333		else334			cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`335		fi336		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.awk339	else340		echo "The --configs file $CF1 does not exist, terminating."341		exit 1342	fi343done344cat << '___EOF___' >> $T/cfgcpu.awk345}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/cfgcpu352sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort353 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 that372	# can be executed concurrently given ncpus.  Note that a given test373	# that requires more than the available CPUs will run in its own374	# 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 one380		# 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/script404CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG405RCUTORTURE="$RCUTORTURE"; export RCUTORTURE406PATH="$PATH"; export PATH407TORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS408TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE409TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY410TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG411TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD412TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG413TORTURE_KCONFIG_GDB_ARG="$TORTURE_KCONFIG_GDB_ARG"; export TORTURE_KCONFIG_GDB_ARG414TORTURE_BOOT_GDB_ARG="$TORTURE_BOOT_GDB_ARG"; export TORTURE_BOOT_GDB_ARG415TORTURE_QEMU_GDB_ARG="$TORTURE_QEMU_GDB_ARG"; export TORTURE_QEMU_GDB_ARG416TORTURE_KCONFIG_KASAN_ARG="$TORTURE_KCONFIG_KASAN_ARG"; export TORTURE_KCONFIG_KASAN_ARG417TORTURE_KCONFIG_KCSAN_ARG="$TORTURE_KCONFIG_KCSAN_ARG"; export TORTURE_KCONFIG_KCSAN_ARG418TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG419TORTURE_MOD="$TORTURE_MOD"; export TORTURE_MOD420TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD421TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE422TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC423TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM424TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE425TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE426TORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE427if ! test -e $resdir428then429	mkdir -p "$resdir" || :430fi431mkdir -p $resdir/$ds432TORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR433TORTURE_STOPFILE="$resdir/$ds/STOP.1"; export TORTURE_STOPFILE434echo Results directory: $resdir/$ds435echo $scriptname $args436touch $resdir/$ds/log437echo $scriptname $args >> $resdir/$ds/log438echo ${TORTURE_SUITE} > $resdir/$ds/torture_suite439echo Build directory: `pwd` > $resdir/$ds/testid.txt440if test -d .git441then442	echo Current commit: `git rev-parse HEAD` >> $resdir/$ds/testid.txt443	echo >> $resdir/$ds/testid.txt444	echo ' ---' Output of "'"git status"'": >> $resdir/$ds/testid.txt445	git status >> $resdir/$ds/testid.txt446	echo >> $resdir/$ds/testid.txt447	echo >> $resdir/$ds/testid.txt448	echo ' ---' Output of "'"git diff HEAD"'": >> $resdir/$ds/testid.txt449	git diff HEAD >> $resdir/$ds/testid.txt450fi451___EOF___452kvm-assign-cpus.sh /sys/devices/system/node > $T/cpuarray.awk453kvm-get-cpus-script.sh $T/cpuarray.awk $T/dumpbatches.awk454cat << '___EOF___' >> $T/dumpbatches.awk455BEGIN {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=1471	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	else478		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		else494			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		else505			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		else521			print "mv " builddir ".ready " builddir ".run"522			print "runfiles=\"$runfiles " builddir ".run\""523		fi524		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/script596echo kvm-end-run-stats.sh "$resdir/$ds" "$starttime" >> $T/script597 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, $2608	}' > $T/batches609 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/scenarios628 629if test "$dryrun" = script630then631	cat $T/script632	exit 0633elif test "$dryrun" = sched634then635	# 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: $nbuilds642	nbatches="`grep 'Start batch' $T/script | grep -v ">>" | wc -l`"643	echo Total number of batches: $nbatches644	exit 0645elif test "$dryrun" = batches646then647	cat $T/batches648	exit 0649elif test "$dryrun" = scenarios650then651	cat $T/scenarios652	exit 0653else654	# Not a dryrun.  Record the batches and the number of CPUs, then run the script.655	bash $T/script656	ret=$?657	cp $T/batches $resdir/$ds/batches658	cp $T/scenarios $resdir/$ds/scenarios659	echo '#' cpus=$cpus >> $resdir/$ds/batches660	exit $ret661fi662 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_barrier664# Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop665# Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y"666# Control buffer size: --bootargs trace_buf_size=3k667# Get trace-buffer dumps on all oopses: --bootargs ftrace_dump_on_oops668# Ditto, but dump only the oopsing CPU: --bootargs ftrace_dump_on_oops=orig_cpu669# Heavy-handed way to also dump on warnings: --bootargs panic_on_warn=1670