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