162306a36Sopenharmony_ci#!/bin/bash
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# Run a series of tests under KVM.  By default, this series is specified
562306a36Sopenharmony_ci# by the relevant CFLIST file, but can be overridden by the --configs
662306a36Sopenharmony_ci# command-line argument.
762306a36Sopenharmony_ci#
862306a36Sopenharmony_ci# Usage: kvm.sh [ options ]
962306a36Sopenharmony_ci#
1062306a36Sopenharmony_ci# Copyright (C) IBM Corporation, 2011
1162306a36Sopenharmony_ci#
1262306a36Sopenharmony_ci# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciscriptname=$0
1562306a36Sopenharmony_ciargs="$*"
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciT="`mktemp -d ${TMPDIR-/tmp}/kvm.sh.XXXXXX`"
1862306a36Sopenharmony_citrap 'rm -rf $T' 0
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cicd `dirname $scriptname`/../../../../../
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci# This script knows only English.
2362306a36Sopenharmony_ciLANG=en_US.UTF-8; export LANG
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cidur=$((30*60))
2662306a36Sopenharmony_cidryrun=""
2762306a36Sopenharmony_ciRCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
2862306a36Sopenharmony_ciPATH=${RCUTORTURE}/bin:$PATH; export PATH
2962306a36Sopenharmony_ci. functions.sh
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ciTORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"
3262306a36Sopenharmony_ciTORTURE_DEFCONFIG=defconfig
3362306a36Sopenharmony_ciTORTURE_BOOT_IMAGE=""
3462306a36Sopenharmony_ciTORTURE_BUILDONLY=
3562306a36Sopenharmony_ciTORTURE_INITRD="$RCUTORTURE/initrd"; export TORTURE_INITRD
3662306a36Sopenharmony_ciTORTURE_KCONFIG_ARG=""
3762306a36Sopenharmony_ciTORTURE_KCONFIG_GDB_ARG=""
3862306a36Sopenharmony_ciTORTURE_BOOT_GDB_ARG=""
3962306a36Sopenharmony_ciTORTURE_QEMU_GDB_ARG=""
4062306a36Sopenharmony_ciTORTURE_JITTER_START=""
4162306a36Sopenharmony_ciTORTURE_JITTER_STOP=""
4262306a36Sopenharmony_ciTORTURE_KCONFIG_KASAN_ARG=""
4362306a36Sopenharmony_ciTORTURE_KCONFIG_KCSAN_ARG=""
4462306a36Sopenharmony_ciTORTURE_KMAKE_ARG=""
4562306a36Sopenharmony_ciTORTURE_QEMU_MEM=512
4662306a36Sopenharmony_citorture_qemu_mem_default=1
4762306a36Sopenharmony_ciTORTURE_REMOTE=
4862306a36Sopenharmony_ciTORTURE_SHUTDOWN_GRACE=180
4962306a36Sopenharmony_ciTORTURE_SUITE=rcu
5062306a36Sopenharmony_ciTORTURE_MOD=rcutorture
5162306a36Sopenharmony_ciTORTURE_TRUST_MAKE=""
5262306a36Sopenharmony_ciresdir=""
5362306a36Sopenharmony_ciconfigs=""
5462306a36Sopenharmony_cicpus=0
5562306a36Sopenharmony_cids=`date +%Y.%m.%d-%H.%M.%S`
5662306a36Sopenharmony_cijitter="-1"
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cistartdate="`date`"
5962306a36Sopenharmony_cistarttime="`get_starttime`"
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ciusage () {
6262306a36Sopenharmony_ci	echo "Usage: $scriptname optional arguments:"
6362306a36Sopenharmony_ci	echo "       --allcpus"
6462306a36Sopenharmony_ci	echo "       --bootargs kernel-boot-arguments"
6562306a36Sopenharmony_ci	echo "       --bootimage relative-path-to-kernel-boot-image"
6662306a36Sopenharmony_ci	echo "       --buildonly"
6762306a36Sopenharmony_ci	echo "       --configs \"config-file list w/ repeat factor (3*TINY01)\""
6862306a36Sopenharmony_ci	echo "       --cpus N"
6962306a36Sopenharmony_ci	echo "       --datestamp string"
7062306a36Sopenharmony_ci	echo "       --defconfig string"
7162306a36Sopenharmony_ci	echo "       --dryrun batches|scenarios|sched|script"
7262306a36Sopenharmony_ci	echo "       --duration minutes | <seconds>s | <hours>h | <days>d"
7362306a36Sopenharmony_ci	echo "       --gdb"
7462306a36Sopenharmony_ci	echo "       --help"
7562306a36Sopenharmony_ci	echo "       --interactive"
7662306a36Sopenharmony_ci	echo "       --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
7762306a36Sopenharmony_ci	echo "       --kasan"
7862306a36Sopenharmony_ci	echo "       --kconfig Kconfig-options"
7962306a36Sopenharmony_ci	echo "       --kcsan"
8062306a36Sopenharmony_ci	echo "       --kmake-arg kernel-make-arguments"
8162306a36Sopenharmony_ci	echo "       --mac nn:nn:nn:nn:nn:nn"
8262306a36Sopenharmony_ci	echo "       --memory megabytes|nnnG"
8362306a36Sopenharmony_ci	echo "       --no-initrd"
8462306a36Sopenharmony_ci	echo "       --qemu-args qemu-arguments"
8562306a36Sopenharmony_ci	echo "       --qemu-cmd qemu-system-..."
8662306a36Sopenharmony_ci	echo "       --remote"
8762306a36Sopenharmony_ci	echo "       --results absolute-pathname"
8862306a36Sopenharmony_ci	echo "       --shutdown-grace seconds"
8962306a36Sopenharmony_ci	echo "       --torture lock|rcu|rcuscale|refscale|scf|X*"
9062306a36Sopenharmony_ci	echo "       --trust-make"
9162306a36Sopenharmony_ci	exit 1
9262306a36Sopenharmony_ci}
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ciwhile test $# -gt 0
9562306a36Sopenharmony_cido
9662306a36Sopenharmony_ci	case "$1" in
9762306a36Sopenharmony_ci	--allcpus)
9862306a36Sopenharmony_ci		cpus=$TORTURE_ALLOTED_CPUS
9962306a36Sopenharmony_ci		max_cpus=$TORTURE_ALLOTED_CPUS
10062306a36Sopenharmony_ci		;;
10162306a36Sopenharmony_ci	--bootargs|--bootarg)
10262306a36Sopenharmony_ci		checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
10362306a36Sopenharmony_ci		TORTURE_BOOTARGS="$TORTURE_BOOTARGS $2"
10462306a36Sopenharmony_ci		shift
10562306a36Sopenharmony_ci		;;
10662306a36Sopenharmony_ci	--bootimage)
10762306a36Sopenharmony_ci		checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
10862306a36Sopenharmony_ci		TORTURE_BOOT_IMAGE="$2"
10962306a36Sopenharmony_ci		shift
11062306a36Sopenharmony_ci		;;
11162306a36Sopenharmony_ci	--buildonly|--build-only)
11262306a36Sopenharmony_ci		TORTURE_BUILDONLY=1
11362306a36Sopenharmony_ci		;;
11462306a36Sopenharmony_ci	--configs|--config)
11562306a36Sopenharmony_ci		checkarg --configs "(list of config files)" "$#" "$2" '^[^/.a-z]\+$' '^--'
11662306a36Sopenharmony_ci		configs="$configs $2"
11762306a36Sopenharmony_ci		shift
11862306a36Sopenharmony_ci		;;
11962306a36Sopenharmony_ci	--cpus)
12062306a36Sopenharmony_ci		checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
12162306a36Sopenharmony_ci		cpus=$2
12262306a36Sopenharmony_ci		TORTURE_ALLOTED_CPUS="$2"
12362306a36Sopenharmony_ci		if test -z "$TORTURE_REMOTE"
12462306a36Sopenharmony_ci		then
12562306a36Sopenharmony_ci			max_cpus="`identify_qemu_vcpus`"
12662306a36Sopenharmony_ci			if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"
12762306a36Sopenharmony_ci			then
12862306a36Sopenharmony_ci				TORTURE_ALLOTED_CPUS=$max_cpus
12962306a36Sopenharmony_ci			fi
13062306a36Sopenharmony_ci		fi
13162306a36Sopenharmony_ci		shift
13262306a36Sopenharmony_ci		;;
13362306a36Sopenharmony_ci	--datestamp)
13462306a36Sopenharmony_ci		checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--'
13562306a36Sopenharmony_ci		ds=$2
13662306a36Sopenharmony_ci		shift
13762306a36Sopenharmony_ci		;;
13862306a36Sopenharmony_ci	--defconfig)
13962306a36Sopenharmony_ci		checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
14062306a36Sopenharmony_ci		TORTURE_DEFCONFIG=$2
14162306a36Sopenharmony_ci		shift
14262306a36Sopenharmony_ci		;;
14362306a36Sopenharmony_ci	--dryrun)
14462306a36Sopenharmony_ci		checkarg --dryrun "batches|sched|script" $# "$2" 'batches\|scenarios\|sched\|script' '^--'
14562306a36Sopenharmony_ci		dryrun=$2
14662306a36Sopenharmony_ci		shift
14762306a36Sopenharmony_ci		;;
14862306a36Sopenharmony_ci	--duration)
14962306a36Sopenharmony_ci		checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
15062306a36Sopenharmony_ci		mult=60
15162306a36Sopenharmony_ci		if echo "$2" | grep -q 's$'
15262306a36Sopenharmony_ci		then
15362306a36Sopenharmony_ci			mult=1
15462306a36Sopenharmony_ci		elif echo "$2" | grep -q 'h$'
15562306a36Sopenharmony_ci		then
15662306a36Sopenharmony_ci			mult=3600
15762306a36Sopenharmony_ci		elif echo "$2" | grep -q 'd$'
15862306a36Sopenharmony_ci		then
15962306a36Sopenharmony_ci			mult=86400
16062306a36Sopenharmony_ci		fi
16162306a36Sopenharmony_ci		ts=`echo $2 | sed -e 's/[smhd]$//'`
16262306a36Sopenharmony_ci		dur=$(($ts*mult))
16362306a36Sopenharmony_ci		shift
16462306a36Sopenharmony_ci		;;
16562306a36Sopenharmony_ci	--gdb)
16662306a36Sopenharmony_ci		TORTURE_KCONFIG_GDB_ARG="CONFIG_DEBUG_INFO_NONE=n CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y"; export TORTURE_KCONFIG_GDB_ARG
16762306a36Sopenharmony_ci		TORTURE_BOOT_GDB_ARG="nokaslr"; export TORTURE_BOOT_GDB_ARG
16862306a36Sopenharmony_ci		TORTURE_QEMU_GDB_ARG="-s -S"; export TORTURE_QEMU_GDB_ARG
16962306a36Sopenharmony_ci		;;
17062306a36Sopenharmony_ci	--help|-h)
17162306a36Sopenharmony_ci		usage
17262306a36Sopenharmony_ci		;;
17362306a36Sopenharmony_ci	--interactive)
17462306a36Sopenharmony_ci		TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
17562306a36Sopenharmony_ci		;;
17662306a36Sopenharmony_ci	--jitter)
17762306a36Sopenharmony_ci		checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
17862306a36Sopenharmony_ci		jitter="$2"
17962306a36Sopenharmony_ci		shift
18062306a36Sopenharmony_ci		;;
18162306a36Sopenharmony_ci	--kasan)
18262306a36Sopenharmony_ci		TORTURE_KCONFIG_KASAN_ARG="CONFIG_DEBUG_INFO_NONE=n CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y CONFIG_KASAN=y"; export TORTURE_KCONFIG_KASAN_ARG
18362306a36Sopenharmony_ci		if test -n "$torture_qemu_mem_default"
18462306a36Sopenharmony_ci		then
18562306a36Sopenharmony_ci			TORTURE_QEMU_MEM=2G
18662306a36Sopenharmony_ci		fi
18762306a36Sopenharmony_ci		;;
18862306a36Sopenharmony_ci	--kconfig|--kconfigs)
18962306a36Sopenharmony_ci		checkarg --kconfig "(Kconfig options)" $# "$2" '^\(#CHECK#\)\?CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\|"[^"]*"\)\( \(#CHECK#\)\?CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\|"[^"]*"\)\)*$' '^error$'
19062306a36Sopenharmony_ci		TORTURE_KCONFIG_ARG="`echo "$TORTURE_KCONFIG_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
19162306a36Sopenharmony_ci		shift
19262306a36Sopenharmony_ci		;;
19362306a36Sopenharmony_ci	--kcsan)
19462306a36Sopenharmony_ci		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
19562306a36Sopenharmony_ci		;;
19662306a36Sopenharmony_ci	--kmake-arg|--kmake-args)
19762306a36Sopenharmony_ci		checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
19862306a36Sopenharmony_ci		TORTURE_KMAKE_ARG="`echo "$TORTURE_KMAKE_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
19962306a36Sopenharmony_ci		shift
20062306a36Sopenharmony_ci		;;
20162306a36Sopenharmony_ci	--mac)
20262306a36Sopenharmony_ci		checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
20362306a36Sopenharmony_ci		TORTURE_QEMU_MAC=$2
20462306a36Sopenharmony_ci		shift
20562306a36Sopenharmony_ci		;;
20662306a36Sopenharmony_ci	--memory)
20762306a36Sopenharmony_ci		checkarg --memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error
20862306a36Sopenharmony_ci		TORTURE_QEMU_MEM=$2
20962306a36Sopenharmony_ci		torture_qemu_mem_default=
21062306a36Sopenharmony_ci		shift
21162306a36Sopenharmony_ci		;;
21262306a36Sopenharmony_ci	--no-initrd)
21362306a36Sopenharmony_ci		TORTURE_INITRD=""; export TORTURE_INITRD
21462306a36Sopenharmony_ci		;;
21562306a36Sopenharmony_ci	--qemu-args|--qemu-arg)
21662306a36Sopenharmony_ci		checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
21762306a36Sopenharmony_ci		TORTURE_QEMU_ARG="`echo "$TORTURE_QEMU_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
21862306a36Sopenharmony_ci		shift
21962306a36Sopenharmony_ci		;;
22062306a36Sopenharmony_ci	--qemu-cmd)
22162306a36Sopenharmony_ci		checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
22262306a36Sopenharmony_ci		TORTURE_QEMU_CMD="$2"
22362306a36Sopenharmony_ci		shift
22462306a36Sopenharmony_ci		;;
22562306a36Sopenharmony_ci	--remote)
22662306a36Sopenharmony_ci		TORTURE_REMOTE=1
22762306a36Sopenharmony_ci		;;
22862306a36Sopenharmony_ci	--results)
22962306a36Sopenharmony_ci		checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
23062306a36Sopenharmony_ci		resdir=$2
23162306a36Sopenharmony_ci		shift
23262306a36Sopenharmony_ci		;;
23362306a36Sopenharmony_ci	--shutdown-grace)
23462306a36Sopenharmony_ci		checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
23562306a36Sopenharmony_ci		TORTURE_SHUTDOWN_GRACE=$2
23662306a36Sopenharmony_ci		shift
23762306a36Sopenharmony_ci		;;
23862306a36Sopenharmony_ci	--torture)
23962306a36Sopenharmony_ci		checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuscale\|refscale\|scf\|X.*\)$' '^--'
24062306a36Sopenharmony_ci		TORTURE_SUITE=$2
24162306a36Sopenharmony_ci		TORTURE_MOD="`echo $TORTURE_SUITE | sed -e 's/^\(lock\|rcu\|scf\)$/\1torture/'`"
24262306a36Sopenharmony_ci		shift
24362306a36Sopenharmony_ci		if test "$TORTURE_SUITE" = rcuscale || test "$TORTURE_SUITE" = refscale
24462306a36Sopenharmony_ci		then
24562306a36Sopenharmony_ci			# If you really want jitter for refscale or
24662306a36Sopenharmony_ci			# rcuscale, specify it after specifying the rcuscale
24762306a36Sopenharmony_ci			# or the refscale.  (But why jitter in these cases?)
24862306a36Sopenharmony_ci			jitter=0
24962306a36Sopenharmony_ci		fi
25062306a36Sopenharmony_ci		;;
25162306a36Sopenharmony_ci	--trust-make)
25262306a36Sopenharmony_ci		TORTURE_TRUST_MAKE="y"
25362306a36Sopenharmony_ci		;;
25462306a36Sopenharmony_ci	*)
25562306a36Sopenharmony_ci		echo Unknown argument $1
25662306a36Sopenharmony_ci		usage
25762306a36Sopenharmony_ci		;;
25862306a36Sopenharmony_ci	esac
25962306a36Sopenharmony_ci	shift
26062306a36Sopenharmony_cidone
26162306a36Sopenharmony_ci
26262306a36Sopenharmony_ciif test -n "$dryrun" || test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
26362306a36Sopenharmony_cithen
26462306a36Sopenharmony_ci	:
26562306a36Sopenharmony_cielse
26662306a36Sopenharmony_ci	echo No initrd and unable to create one, aborting test >&2
26762306a36Sopenharmony_ci	exit 1
26862306a36Sopenharmony_cifi
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ciCONFIGFRAG=${RCUTORTURE}/configs/${TORTURE_SUITE}; export CONFIGFRAG
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_cidefaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
27362306a36Sopenharmony_ciif test -z "$configs"
27462306a36Sopenharmony_cithen
27562306a36Sopenharmony_ci	configs=$defaultconfigs
27662306a36Sopenharmony_cifi
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ciif test -z "$resdir"
27962306a36Sopenharmony_cithen
28062306a36Sopenharmony_ci	resdir=$RCUTORTURE/res
28162306a36Sopenharmony_cifi
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
28462306a36Sopenharmony_ciconfigs_derep=
28562306a36Sopenharmony_cifor CF in $configs
28662306a36Sopenharmony_cido
28762306a36Sopenharmony_ci	case $CF in
28862306a36Sopenharmony_ci	[0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**|[0-9][0-9][0-9][0-9]\**)
28962306a36Sopenharmony_ci		config_reps=`echo $CF | sed -e 's/\*.*$//'`
29062306a36Sopenharmony_ci		CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
29162306a36Sopenharmony_ci		;;
29262306a36Sopenharmony_ci	*)
29362306a36Sopenharmony_ci		config_reps=1
29462306a36Sopenharmony_ci		CF1=$CF
29562306a36Sopenharmony_ci		;;
29662306a36Sopenharmony_ci	esac
29762306a36Sopenharmony_ci	for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
29862306a36Sopenharmony_ci	do
29962306a36Sopenharmony_ci		configs_derep="$configs_derep $CF1"
30062306a36Sopenharmony_ci	done
30162306a36Sopenharmony_cidone
30262306a36Sopenharmony_citouch $T/cfgcpu
30362306a36Sopenharmony_ciconfigs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
30462306a36Sopenharmony_ciif test -n "$TORTURE_KCONFIG_GDB_ARG"
30562306a36Sopenharmony_cithen
30662306a36Sopenharmony_ci	if test "`echo $configs_derep | wc -w`" -gt 1
30762306a36Sopenharmony_ci	then
30862306a36Sopenharmony_ci		echo "The --config list is: $configs_derep."
30962306a36Sopenharmony_ci		echo "Only one --config permitted with --gdb, terminating."
31062306a36Sopenharmony_ci		exit 1
31162306a36Sopenharmony_ci	fi
31262306a36Sopenharmony_cifi
31362306a36Sopenharmony_ciecho 'BEGIN {' > $T/cfgcpu.awk
31462306a36Sopenharmony_cifor CF1 in `echo $configs_derep | tr -s ' ' '\012' | sort -u`
31562306a36Sopenharmony_cido
31662306a36Sopenharmony_ci	if test -f "$CONFIGFRAG/$CF1"
31762306a36Sopenharmony_ci	then
31862306a36Sopenharmony_ci		if echo "$TORTURE_KCONFIG_ARG" | grep -q '\<CONFIG_NR_CPUS='
31962306a36Sopenharmony_ci		then
32062306a36Sopenharmony_ci			echo "$TORTURE_KCONFIG_ARG" | tr -s ' ' | tr ' ' '\012' > $T/KCONFIG_ARG
32162306a36Sopenharmony_ci			cpu_count=`configNR_CPUS.sh $T/KCONFIG_ARG`
32262306a36Sopenharmony_ci		else
32362306a36Sopenharmony_ci			cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
32462306a36Sopenharmony_ci		fi
32562306a36Sopenharmony_ci		cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
32662306a36Sopenharmony_ci		cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
32762306a36Sopenharmony_ci		echo 'scenariocpu["'"$CF1"'"] = '"$cpu_count"';' >> $T/cfgcpu.awk
32862306a36Sopenharmony_ci	else
32962306a36Sopenharmony_ci		echo "The --configs file $CF1 does not exist, terminating."
33062306a36Sopenharmony_ci		exit 1
33162306a36Sopenharmony_ci	fi
33262306a36Sopenharmony_cidone
33362306a36Sopenharmony_cicat << '___EOF___' >> $T/cfgcpu.awk
33462306a36Sopenharmony_ci}
33562306a36Sopenharmony_ci{
33662306a36Sopenharmony_ci	for (i = 1; i <= NF; i++)
33762306a36Sopenharmony_ci		print $i, scenariocpu[$i];
33862306a36Sopenharmony_ci}
33962306a36Sopenharmony_ci___EOF___
34062306a36Sopenharmony_ciecho $configs_derep | awk -f $T/cfgcpu.awk > $T/cfgcpu
34162306a36Sopenharmony_cisort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci# Use a greedy bin-packing algorithm, sorting the list accordingly.
34462306a36Sopenharmony_ciawk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
34562306a36Sopenharmony_ciBEGIN {
34662306a36Sopenharmony_ci	njobs = 0;
34762306a36Sopenharmony_ci}
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci{
35062306a36Sopenharmony_ci	# Read file of tests and corresponding required numbers of CPUs.
35162306a36Sopenharmony_ci	cf[njobs] = $1;
35262306a36Sopenharmony_ci	cpus[njobs] = $2;
35362306a36Sopenharmony_ci	njobs++;
35462306a36Sopenharmony_ci}
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_ciEND {
35762306a36Sopenharmony_ci	batch = 0;
35862306a36Sopenharmony_ci	nc = -1;
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci	# Each pass through the following loop creates on test batch that
36162306a36Sopenharmony_ci	# can be executed concurrently given ncpus.  Note that a given test
36262306a36Sopenharmony_ci	# that requires more than the available CPUs will run in its own
36362306a36Sopenharmony_ci	# batch.  Such tests just have to make do with what is available.
36462306a36Sopenharmony_ci	while (nc != ncpus) {
36562306a36Sopenharmony_ci		batch++;
36662306a36Sopenharmony_ci		nc = ncpus;
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ci		# Each pass through the following loop considers one
36962306a36Sopenharmony_ci		# test for inclusion in the current batch.
37062306a36Sopenharmony_ci		for (i = 0; i < njobs; i++) {
37162306a36Sopenharmony_ci			if (done[i])
37262306a36Sopenharmony_ci				continue; # Already part of a batch.
37362306a36Sopenharmony_ci			if (nc >= cpus[i] || nc == ncpus) {
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci				# This test fits into the current batch.
37662306a36Sopenharmony_ci				done[i] = batch;
37762306a36Sopenharmony_ci				nc -= cpus[i];
37862306a36Sopenharmony_ci				if (nc <= 0)
37962306a36Sopenharmony_ci					break; # Too-big test in its own batch.
38062306a36Sopenharmony_ci			}
38162306a36Sopenharmony_ci		}
38262306a36Sopenharmony_ci	}
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_ci	# Dump out the tests in batch order.
38562306a36Sopenharmony_ci	for (b = 1; b <= batch; b++)
38662306a36Sopenharmony_ci		for (i = 0; i < njobs; i++)
38762306a36Sopenharmony_ci			if (done[i] == b)
38862306a36Sopenharmony_ci				print cf[i], cpus[i];
38962306a36Sopenharmony_ci}'
39062306a36Sopenharmony_ci
39162306a36Sopenharmony_ci# Generate a script to execute the tests in appropriate batches.
39262306a36Sopenharmony_cicat << ___EOF___ > $T/script
39362306a36Sopenharmony_ciCONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
39462306a36Sopenharmony_ciRCUTORTURE="$RCUTORTURE"; export RCUTORTURE
39562306a36Sopenharmony_ciPATH="$PATH"; export PATH
39662306a36Sopenharmony_ciTORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS
39762306a36Sopenharmony_ciTORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
39862306a36Sopenharmony_ciTORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
39962306a36Sopenharmony_ciTORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
40062306a36Sopenharmony_ciTORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
40162306a36Sopenharmony_ciTORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
40262306a36Sopenharmony_ciTORTURE_KCONFIG_GDB_ARG="$TORTURE_KCONFIG_GDB_ARG"; export TORTURE_KCONFIG_GDB_ARG
40362306a36Sopenharmony_ciTORTURE_BOOT_GDB_ARG="$TORTURE_BOOT_GDB_ARG"; export TORTURE_BOOT_GDB_ARG
40462306a36Sopenharmony_ciTORTURE_QEMU_GDB_ARG="$TORTURE_QEMU_GDB_ARG"; export TORTURE_QEMU_GDB_ARG
40562306a36Sopenharmony_ciTORTURE_KCONFIG_KASAN_ARG="$TORTURE_KCONFIG_KASAN_ARG"; export TORTURE_KCONFIG_KASAN_ARG
40662306a36Sopenharmony_ciTORTURE_KCONFIG_KCSAN_ARG="$TORTURE_KCONFIG_KCSAN_ARG"; export TORTURE_KCONFIG_KCSAN_ARG
40762306a36Sopenharmony_ciTORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
40862306a36Sopenharmony_ciTORTURE_MOD="$TORTURE_MOD"; export TORTURE_MOD
40962306a36Sopenharmony_ciTORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
41062306a36Sopenharmony_ciTORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
41162306a36Sopenharmony_ciTORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
41262306a36Sopenharmony_ciTORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM
41362306a36Sopenharmony_ciTORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
41462306a36Sopenharmony_ciTORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
41562306a36Sopenharmony_ciTORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE
41662306a36Sopenharmony_ciif ! test -e $resdir
41762306a36Sopenharmony_cithen
41862306a36Sopenharmony_ci	mkdir -p "$resdir" || :
41962306a36Sopenharmony_cifi
42062306a36Sopenharmony_cimkdir -p $resdir/$ds
42162306a36Sopenharmony_ciTORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR
42262306a36Sopenharmony_ciTORTURE_STOPFILE="$resdir/$ds/STOP.1"; export TORTURE_STOPFILE
42362306a36Sopenharmony_ciecho Results directory: $resdir/$ds
42462306a36Sopenharmony_ciecho $scriptname $args
42562306a36Sopenharmony_citouch $resdir/$ds/log
42662306a36Sopenharmony_ciecho $scriptname $args >> $resdir/$ds/log
42762306a36Sopenharmony_ciecho ${TORTURE_SUITE} > $resdir/$ds/torture_suite
42862306a36Sopenharmony_ciecho Build directory: `pwd` > $resdir/$ds/testid.txt
42962306a36Sopenharmony_ciif test -d .git
43062306a36Sopenharmony_cithen
43162306a36Sopenharmony_ci	echo Current commit: `git rev-parse HEAD` >> $resdir/$ds/testid.txt
43262306a36Sopenharmony_ci	echo >> $resdir/$ds/testid.txt
43362306a36Sopenharmony_ci	echo ' ---' Output of "'"git status"'": >> $resdir/$ds/testid.txt
43462306a36Sopenharmony_ci	git status >> $resdir/$ds/testid.txt
43562306a36Sopenharmony_ci	echo >> $resdir/$ds/testid.txt
43662306a36Sopenharmony_ci	echo >> $resdir/$ds/testid.txt
43762306a36Sopenharmony_ci	echo ' ---' Output of "'"git diff HEAD"'": >> $resdir/$ds/testid.txt
43862306a36Sopenharmony_ci	git diff HEAD >> $resdir/$ds/testid.txt
43962306a36Sopenharmony_cifi
44062306a36Sopenharmony_ci___EOF___
44162306a36Sopenharmony_cikvm-assign-cpus.sh /sys/devices/system/node > $T/cpuarray.awk
44262306a36Sopenharmony_cikvm-get-cpus-script.sh $T/cpuarray.awk $T/dumpbatches.awk
44362306a36Sopenharmony_cicat << '___EOF___' >> $T/dumpbatches.awk
44462306a36Sopenharmony_ciBEGIN {
44562306a36Sopenharmony_ci	i = 0;
44662306a36Sopenharmony_ci}
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci{
44962306a36Sopenharmony_ci	cf[i] = $1;
45062306a36Sopenharmony_ci	cpus[i] = $2;
45162306a36Sopenharmony_ci	i++;
45262306a36Sopenharmony_ci}
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_ci# Dump out the scripting required to run one test batch.
45562306a36Sopenharmony_cifunction dump(first, pastlast, batchnum,  affinitylist)
45662306a36Sopenharmony_ci{
45762306a36Sopenharmony_ci	print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log";
45862306a36Sopenharmony_ci	print "needqemurun="
45962306a36Sopenharmony_ci	jn=1
46062306a36Sopenharmony_ci	njitter = 0;
46162306a36Sopenharmony_ci	split(jitter, ja);
46262306a36Sopenharmony_ci	if (ja[1] == -1 && ncpus == 0)
46362306a36Sopenharmony_ci		njitter = 1;
46462306a36Sopenharmony_ci	else if (ja[1] == -1)
46562306a36Sopenharmony_ci		njitter = ncpus;
46662306a36Sopenharmony_ci	else
46762306a36Sopenharmony_ci		njitter = ja[1];
46862306a36Sopenharmony_ci	print "TORTURE_JITTER_START=\". jitterstart.sh " njitter " " rd " " dur " " ja[2] " " ja[3] "\"; export TORTURE_JITTER_START";
46962306a36Sopenharmony_ci	print "TORTURE_JITTER_STOP=\". jitterstop.sh " rd " \"; export TORTURE_JITTER_STOP"
47062306a36Sopenharmony_ci	for (j = first; j < pastlast; j++) {
47162306a36Sopenharmony_ci		cpusr[jn] = cpus[j];
47262306a36Sopenharmony_ci		if (cfrep[cf[j]] == "") {
47362306a36Sopenharmony_ci			cfr[jn] = cf[j];
47462306a36Sopenharmony_ci			cfrep[cf[j]] = 1;
47562306a36Sopenharmony_ci		} else {
47662306a36Sopenharmony_ci			cfrep[cf[j]]++;
47762306a36Sopenharmony_ci			cfr[jn] = cf[j] "." cfrep[cf[j]];
47862306a36Sopenharmony_ci		}
47962306a36Sopenharmony_ci		builddir=rd cfr[jn] "/build";
48062306a36Sopenharmony_ci		if (cpusr[jn] > ncpus && ncpus != 0)
48162306a36Sopenharmony_ci			ovf = "-ovf";
48262306a36Sopenharmony_ci		else
48362306a36Sopenharmony_ci			ovf = "";
48462306a36Sopenharmony_ci		print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log";
48562306a36Sopenharmony_ci		print "mkdir " rd cfr[jn] " || :";
48662306a36Sopenharmony_ci		print "touch " builddir ".wait";
48762306a36Sopenharmony_ci		affinitylist = "";
48862306a36Sopenharmony_ci		if (gotcpus()) {
48962306a36Sopenharmony_ci			affinitylist = nextcpus(cpusr[jn]);
49062306a36Sopenharmony_ci		}
49162306a36Sopenharmony_ci		if (affinitylist ~ /^[0-9,-][0-9,-]*$/)
49262306a36Sopenharmony_ci			print "export TORTURE_AFFINITY=" affinitylist;
49362306a36Sopenharmony_ci		else
49462306a36Sopenharmony_ci			print "export TORTURE_AFFINITY=";
49562306a36Sopenharmony_ci		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 &"
49662306a36Sopenharmony_ci		print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log";
49762306a36Sopenharmony_ci		print "while test -f " builddir ".wait"
49862306a36Sopenharmony_ci		print "do"
49962306a36Sopenharmony_ci		print "\tsleep 1"
50062306a36Sopenharmony_ci		print "done"
50162306a36Sopenharmony_ci		print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log";
50262306a36Sopenharmony_ci		jn++;
50362306a36Sopenharmony_ci	}
50462306a36Sopenharmony_ci	print "runfiles="
50562306a36Sopenharmony_ci	for (j = 1; j < jn; j++) {
50662306a36Sopenharmony_ci		builddir=rd cfr[j] "/build";
50762306a36Sopenharmony_ci		if (TORTURE_BUILDONLY)
50862306a36Sopenharmony_ci			print "rm -f " builddir ".ready"
50962306a36Sopenharmony_ci		else
51062306a36Sopenharmony_ci			print "mv " builddir ".ready " builddir ".run"
51162306a36Sopenharmony_ci			print "runfiles=\"$runfiles " builddir ".run\""
51262306a36Sopenharmony_ci		fi
51362306a36Sopenharmony_ci		print "if test -f \"" rd cfr[j] "/builtkernel\""
51462306a36Sopenharmony_ci		print "then"
51562306a36Sopenharmony_ci		print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log";
51662306a36Sopenharmony_ci		print "\tneedqemurun=1"
51762306a36Sopenharmony_ci		print "fi"
51862306a36Sopenharmony_ci	}
51962306a36Sopenharmony_ci	if (TORTURE_BUILDONLY && njitter != 0) {
52062306a36Sopenharmony_ci		njitter = 0;
52162306a36Sopenharmony_ci		print "echo Build-only run, so suppressing jitter | tee -a " rd "log"
52262306a36Sopenharmony_ci	}
52362306a36Sopenharmony_ci	if (TORTURE_BUILDONLY) {
52462306a36Sopenharmony_ci		print "needqemurun="
52562306a36Sopenharmony_ci	}
52662306a36Sopenharmony_ci	print "if test -n \"$needqemurun\""
52762306a36Sopenharmony_ci	print "then"
52862306a36Sopenharmony_ci	print "\techo ---- Starting kernels. `date` | tee -a " rd "log";
52962306a36Sopenharmony_ci	print "\t$TORTURE_JITTER_START";
53062306a36Sopenharmony_ci	print "\twhile ls $runfiles > /dev/null 2>&1"
53162306a36Sopenharmony_ci	print "\tdo"
53262306a36Sopenharmony_ci	print "\t\t:"
53362306a36Sopenharmony_ci	print "\tdone"
53462306a36Sopenharmony_ci	print "\t$TORTURE_JITTER_STOP";
53562306a36Sopenharmony_ci	print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log";
53662306a36Sopenharmony_ci	print "else"
53762306a36Sopenharmony_ci	print "\twait"
53862306a36Sopenharmony_ci	print "\techo ---- No kernel runs. `date` | tee -a " rd "log";
53962306a36Sopenharmony_ci	print "fi"
54062306a36Sopenharmony_ci	for (j = 1; j < jn; j++) {
54162306a36Sopenharmony_ci		print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log";
54262306a36Sopenharmony_ci		print "cat " rd cfr[j]  "/kvm-test-1-run.sh.out | tee -a " rd "log";
54362306a36Sopenharmony_ci	}
54462306a36Sopenharmony_ci}
54562306a36Sopenharmony_ci
54662306a36Sopenharmony_ciEND {
54762306a36Sopenharmony_ci	njobs = i;
54862306a36Sopenharmony_ci	nc = ncpus;
54962306a36Sopenharmony_ci	first = 0;
55062306a36Sopenharmony_ci	batchnum = 1;
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_ci	# Each pass through the following loop considers one test.
55362306a36Sopenharmony_ci	for (i = 0; i < njobs; i++) {
55462306a36Sopenharmony_ci		if (ncpus == 0) {
55562306a36Sopenharmony_ci			# Sequential test specified, each test its own batch.
55662306a36Sopenharmony_ci			dump(i, i + 1, batchnum);
55762306a36Sopenharmony_ci			first = i;
55862306a36Sopenharmony_ci			batchnum++;
55962306a36Sopenharmony_ci		} else if (nc < cpus[i] && i != 0) {
56062306a36Sopenharmony_ci			# Out of CPUs, dump out a batch.
56162306a36Sopenharmony_ci			dump(first, i, batchnum);
56262306a36Sopenharmony_ci			first = i;
56362306a36Sopenharmony_ci			nc = ncpus;
56462306a36Sopenharmony_ci			batchnum++;
56562306a36Sopenharmony_ci		}
56662306a36Sopenharmony_ci		# Account for the CPUs needed by the current test.
56762306a36Sopenharmony_ci		nc -= cpus[i];
56862306a36Sopenharmony_ci	}
56962306a36Sopenharmony_ci	# Dump the last batch.
57062306a36Sopenharmony_ci	if (ncpus != 0)
57162306a36Sopenharmony_ci		dump(first, i, batchnum);
57262306a36Sopenharmony_ci}
57362306a36Sopenharmony_ci___EOF___
57462306a36Sopenharmony_ciawk < $T/cfgcpu.pack \
57562306a36Sopenharmony_ci	-v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \
57662306a36Sopenharmony_ci	-v CONFIGDIR="$CONFIGFRAG/" \
57762306a36Sopenharmony_ci	-v RCUTORTURE="$RCUTORTURE" \
57862306a36Sopenharmony_ci	-v ncpus=$cpus \
57962306a36Sopenharmony_ci	-v jitter="$jitter" \
58062306a36Sopenharmony_ci	-v rd=$resdir/$ds/ \
58162306a36Sopenharmony_ci	-v dur=$dur \
58262306a36Sopenharmony_ci	-v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
58362306a36Sopenharmony_ci	-v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
58462306a36Sopenharmony_ci	-f $T/dumpbatches.awk >> $T/script
58562306a36Sopenharmony_ciecho kvm-end-run-stats.sh "$resdir/$ds" "$starttime" >> $T/script
58662306a36Sopenharmony_ci
58762306a36Sopenharmony_ci# Extract the tests and their batches from the script.
58862306a36Sopenharmony_cigrep -E 'Start batch|Starting build\.' $T/script | grep -v ">>" |
58962306a36Sopenharmony_ci	sed -e 's/:.*$//' -e 's/^echo //' -e 's/-ovf//' |
59062306a36Sopenharmony_ci	awk '
59162306a36Sopenharmony_ci	/^----Start/ {
59262306a36Sopenharmony_ci		batchno = $3;
59362306a36Sopenharmony_ci		next;
59462306a36Sopenharmony_ci	}
59562306a36Sopenharmony_ci	{
59662306a36Sopenharmony_ci		print batchno, $1, $2
59762306a36Sopenharmony_ci	}' > $T/batches
59862306a36Sopenharmony_ci
59962306a36Sopenharmony_ci# As above, but one line per batch.
60062306a36Sopenharmony_cigrep -v '^#' $T/batches | awk '
60162306a36Sopenharmony_ciBEGIN {
60262306a36Sopenharmony_ci	oldbatch = 1;
60362306a36Sopenharmony_ci}
60462306a36Sopenharmony_ci
60562306a36Sopenharmony_ci{
60662306a36Sopenharmony_ci	if (oldbatch != $1) {
60762306a36Sopenharmony_ci		print ++n ". " curbatch;
60862306a36Sopenharmony_ci		curbatch = "";
60962306a36Sopenharmony_ci		oldbatch = $1;
61062306a36Sopenharmony_ci	}
61162306a36Sopenharmony_ci	curbatch = curbatch " " $2;
61262306a36Sopenharmony_ci}
61362306a36Sopenharmony_ci
61462306a36Sopenharmony_ciEND {
61562306a36Sopenharmony_ci	print ++n ". " curbatch;
61662306a36Sopenharmony_ci}' > $T/scenarios
61762306a36Sopenharmony_ci
61862306a36Sopenharmony_ciif test "$dryrun" = script
61962306a36Sopenharmony_cithen
62062306a36Sopenharmony_ci	cat $T/script
62162306a36Sopenharmony_ci	exit 0
62262306a36Sopenharmony_cielif test "$dryrun" = sched
62362306a36Sopenharmony_cithen
62462306a36Sopenharmony_ci	# Extract the test run schedule from the script.
62562306a36Sopenharmony_ci	grep -E 'Start batch|Starting build\.' $T/script | grep -v ">>" |
62662306a36Sopenharmony_ci		sed -e 's/:.*$//' -e 's/^echo //'
62762306a36Sopenharmony_ci	nbuilds="`grep 'Starting build\.' $T/script |
62862306a36Sopenharmony_ci		  grep -v ">>" | sed -e 's/:.*$//' -e 's/^echo //' |
62962306a36Sopenharmony_ci		  awk '{ print $1 }' | grep -v '\.' | wc -l`"
63062306a36Sopenharmony_ci	echo Total number of builds: $nbuilds
63162306a36Sopenharmony_ci	nbatches="`grep 'Start batch' $T/script | grep -v ">>" | wc -l`"
63262306a36Sopenharmony_ci	echo Total number of batches: $nbatches
63362306a36Sopenharmony_ci	exit 0
63462306a36Sopenharmony_cielif test "$dryrun" = batches
63562306a36Sopenharmony_cithen
63662306a36Sopenharmony_ci	cat $T/batches
63762306a36Sopenharmony_ci	exit 0
63862306a36Sopenharmony_cielif test "$dryrun" = scenarios
63962306a36Sopenharmony_cithen
64062306a36Sopenharmony_ci	cat $T/scenarios
64162306a36Sopenharmony_ci	exit 0
64262306a36Sopenharmony_cielse
64362306a36Sopenharmony_ci	# Not a dryrun.  Record the batches and the number of CPUs, then run the script.
64462306a36Sopenharmony_ci	bash $T/script
64562306a36Sopenharmony_ci	ret=$?
64662306a36Sopenharmony_ci	cp $T/batches $resdir/$ds/batches
64762306a36Sopenharmony_ci	cp $T/scenarios $resdir/$ds/scenarios
64862306a36Sopenharmony_ci	echo '#' cpus=$cpus >> $resdir/$ds/batches
64962306a36Sopenharmony_ci	exit $ret
65062306a36Sopenharmony_cifi
65162306a36Sopenharmony_ci
65262306a36Sopenharmony_ci# 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
65362306a36Sopenharmony_ci# Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop
65462306a36Sopenharmony_ci# Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y"
65562306a36Sopenharmony_ci# Control buffer size: --bootargs trace_buf_size=3k
65662306a36Sopenharmony_ci# Get trace-buffer dumps on all oopses: --bootargs ftrace_dump_on_oops
65762306a36Sopenharmony_ci# Ditto, but dump only the oopsing CPU: --bootargs ftrace_dump_on_oops=orig_cpu
65862306a36Sopenharmony_ci# Heavy-handed way to also dump on warnings: --bootargs panic_on_warn=1
659