Merge branch 'efi-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / tools / testing / selftests / rcutorture / bin / kvm.sh
CommitLineData
c87b9c60
PM
1#!/bin/bash
2#
3# Run a series of 14 tests under KVM. These are not particularly
4# well-selected or well-tuned, but are the current set. Run from the
5# top level of the source tree.
6#
7# Edit the definitions below to set the locations of the various directories,
8# as well as the test duration.
9#
3327d924 10# Usage: kvm.sh [ options ]
c87b9c60
PM
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
0e342a87
PM
23# along with this program; if not, you can access it online at
24# http://www.gnu.org/licenses/gpl-2.0.html.
c87b9c60
PM
25#
26# Copyright (C) IBM Corporation, 2011
27#
28# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
29
30scriptname=$0
330a76f1 31args="$*"
c87b9c60 32
43e38ab3
PM
33T=/tmp/kvm.sh.$$
34trap 'rm -rf $T' 0
35mkdir $T
36
480b1eb6 37dur=$((30*60))
a7582815 38dryrun=""
73931b5e 39KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
32caccb8 40PATH=${KVM}/bin:$PATH; export PATH
8c55f227 41TORTURE_DEFCONFIG=defconfig
f189cc8c 42TORTURE_BOOT_IMAGE=""
2f66dbc1 43TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
58d280bd 44TORTURE_KMAKE_ARG=""
542e8332 45TORTURE_SHUTDOWN_GRACE=180
61010e74 46TORTURE_SUITE=rcu
c87b9c60 47resdir=""
4275be83 48configs=""
43e38ab3 49cpus=0
847bfd25 50ds=`date +%Y.%m.%d-%H:%M:%S`
6e524a60 51jitter=0
c87b9c60 52
32caccb8
PM
53. functions.sh
54
c87b9c60
PM
55usage () {
56 echo "Usage: $scriptname optional arguments:"
7dca9273 57 echo " --bootargs kernel-boot-arguments"
f189cc8c 58 echo " --bootimage relative-path-to-kernel-boot-image"
11274813 59 echo " --buildonly"
7d3bb54a 60 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
43e38ab3 61 echo " --cpus N"
847bfd25 62 echo " --datestamp string"
8c55f227 63 echo " --defconfig string"
a7582815 64 echo " --dryrun sched|script"
c87b9c60 65 echo " --duration minutes"
315c540d 66 echo " --interactive"
6e524a60 67 echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
74878fb6 68 echo " --kmake-arg kernel-make-arguments"
315c540d 69 echo " --mac nn:nn:nn:nn:nn:nn"
73931b5e 70 echo " --no-initrd"
e9ce6400 71 echo " --qemu-args qemu-system-..."
4f8a0312 72 echo " --qemu-cmd qemu-system-..."
61010e74
PM
73 echo " --results absolute-pathname"
74 echo " --torture rcu"
c87b9c60
PM
75 exit 1
76}
77
c87b9c60
PM
78while test $# -gt 0
79do
c87b9c60 80 case "$1" in
a8c06024 81 --bootargs|--bootarg)
7dca9273 82 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
98bc8cc8 83 TORTURE_BOOTARGS="$2"
7dca9273
PM
84 shift
85 ;;
f189cc8c
PM
86 --bootimage)
87 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
88 TORTURE_BOOT_IMAGE="$2"
89 shift
90 ;;
11274813 91 --buildonly)
805ffee2 92 TORTURE_BUILDONLY=1
11274813 93 ;;
a8c06024 94 --configs|--config)
c87b9c60
PM
95 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
96 configs="$2"
97 shift
98 ;;
43e38ab3
PM
99 --cpus)
100 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
101 cpus=$2
102 shift
103 ;;
847bfd25
PM
104 --datestamp)
105 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
106 ds=$2
107 shift
108 ;;
8c55f227
PM
109 --defconfig)
110 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
111 TORTURE_DEFCONFIG=$2
112 shift
113 ;;
a7582815
PM
114 --dryrun)
115 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
116 dryrun=$2
117 shift
118 ;;
c87b9c60 119 --duration)
e9ce6400 120 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
480b1eb6 121 dur=$(($2*60))
c87b9c60
PM
122 shift
123 ;;
315c540d 124 --interactive)
a0edd47c 125 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
315c540d 126 ;;
6e524a60
PM
127 --jitter)
128 checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$'
129 jitter="$2"
130 shift
131 ;;
74878fb6
PM
132 --kmake-arg)
133 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
58d280bd 134 TORTURE_KMAKE_ARG="$2"
74878fb6
PM
135 shift
136 ;;
315c540d
PM
137 --mac)
138 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
58f724f7 139 TORTURE_QEMU_MAC=$2
315c540d
PM
140 shift
141 ;;
73931b5e 142 --no-initrd)
2f66dbc1 143 TORTURE_INITRD=""; export TORTURE_INITRD
73931b5e 144 ;;
a8c06024 145 --qemu-args|--qemu-arg)
e9ce6400 146 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
d1b1e517 147 TORTURE_QEMU_ARG="$2"
e9ce6400
PM
148 shift
149 ;;
4f8a0312
PM
150 --qemu-cmd)
151 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
250da31e 152 TORTURE_QEMU_CMD="$2"
4f8a0312
PM
153 shift
154 ;;
c87b9c60 155 --results)
e9ce6400 156 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
c87b9c60
PM
157 resdir=$2
158 shift
159 ;;
542e8332
PM
160 --shutdown-grace)
161 checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
162 TORTURE_SHUTDOWN_GRACE=$2
163 shift
164 ;;
61010e74 165 --torture)
fd35be62 166 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
61010e74
PM
167 TORTURE_SUITE=$2
168 shift
169 ;;
c87b9c60 170 *)
2bcdf4e3 171 echo Unknown argument $1
c87b9c60
PM
172 usage
173 ;;
174 esac
175 shift
176done
177
61010e74 178CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
4275be83
PM
179
180if test -z "$configs"
181then
edae018d 182 configs="`cat $CONFIGFRAG/CFLIST`"
4275be83 183fi
c87b9c60
PM
184
185if test -z "$resdir"
186then
187 resdir=$KVM/res
daeda23d
PM
188fi
189
78ad0693 190# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
43e38ab3 191touch $T/cfgcpu
c87b9c60
PM
192for CF in $configs
193do
7d3bb54a
PM
194 case $CF in
195 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
196 config_reps=`echo $CF | sed -e 's/\*.*$//'`
197 CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
198 ;;
199 *)
200 config_reps=1
201 CF1=$CF
202 ;;
203 esac
204 if test -f "$CONFIGFRAG/$CF1"
f43f8f73 205 then
7d3bb54a
PM
206 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
207 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
208 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
209 do
210 echo $CF1 $cpu_count >> $T/cfgcpu
211 done
43e38ab3 212 else
7d3bb54a 213 echo "The --configs file $CF1 does not exist, terminating."
43e38ab3 214 exit 1
f43f8f73 215 fi
c87b9c60 216done
43e38ab3
PM
217sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
218
78ad0693 219# Use a greedy bin-packing algorithm, sorting the list accordingly.
53954671
PM
220awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
221BEGIN {
222 njobs = 0;
223}
224
225{
78ad0693 226 # Read file of tests and corresponding required numbers of CPUs.
53954671
PM
227 cf[njobs] = $1;
228 cpus[njobs] = $2;
229 njobs++;
230}
231
232END {
233 alldone = 0;
234 batch = 0;
235 nc = -1;
78ad0693
PM
236
237 # Each pass through the following loop creates on test batch
238 # that can be executed concurrently given ncpus. Note that a
239 # given test that requires more than the available CPUs will run in
240 # their own batch. Such tests just have to make do with what
241 # is available.
53954671
PM
242 while (nc != ncpus) {
243 batch++;
244 nc = ncpus;
78ad0693
PM
245
246 # Each pass through the following loop considers one
247 # test for inclusion in the current batch.
53954671
PM
248 for (i = 0; i < njobs; i++) {
249 if (done[i])
78ad0693 250 continue; # Already part of a batch.
53954671 251 if (nc >= cpus[i] || nc == ncpus) {
78ad0693
PM
252
253 # This test fits into the current batch.
53954671
PM
254 done[i] = batch;
255 nc -= cpus[i];
256 if (nc <= 0)
78ad0693 257 break; # Too-big test in its own batch.
53954671
PM
258 }
259 }
260 }
78ad0693
PM
261
262 # Dump out the tests in batch order.
53954671
PM
263 for (b = 1; b <= batch; b++)
264 for (i = 0; i < njobs; i++)
265 if (done[i] == b)
266 print cf[i], cpus[i];
267}'
268
78ad0693 269# Generate a script to execute the tests in appropriate batches.
61010e74 270cat << ___EOF___ > $T/script
14d9d84c
PM
271CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
272KVM="$KVM"; export KVM
14d9d84c 273PATH="$PATH"; export PATH
f189cc8c 274TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
14d9d84c 275TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
8c55f227 276TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
14d9d84c
PM
277TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
278TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
279TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
280TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
281TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
542e8332 282TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
14d9d84c 283TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
1f5d0920
PM
284if ! test -e $resdir
285then
286 mkdir -p "$resdir" || :
287fi
288mkdir $resdir/$ds
289echo Results directory: $resdir/$ds
290echo $scriptname $args
291touch $resdir/$ds/log
292echo $scriptname $args >> $resdir/$ds/log
293echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
294pwd > $resdir/$ds/testid.txt
295if test -d .git
296then
297 git status >> $resdir/$ds/testid.txt
298 git rev-parse HEAD >> $resdir/$ds/testid.txt
8be7f505
PM
299 if ! git diff HEAD > $T/git-diff 2>&1
300 then
301 cp $T/git-diff $resdir/$ds
302 fi
1f5d0920 303fi
61010e74 304___EOF___
53954671 305awk < $T/cfgcpu.pack \
edae018d 306 -v CONFIGDIR="$CONFIGFRAG/" \
43e38ab3
PM
307 -v KVM="$KVM" \
308 -v ncpus=$cpus \
6e524a60 309 -v jitter="$jitter" \
43e38ab3
PM
310 -v rd=$resdir/$ds/ \
311 -v dur=$dur \
06188731
PM
312 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
313 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
43e38ab3
PM
314'BEGIN {
315 i = 0;
316}
317
318{
319 cf[i] = $1;
320 cpus[i] = $2;
321 i++;
322}
323
78ad0693 324# Dump out the scripting required to run one test batch.
83977d27 325function dump(first, pastlast, batchnum)
43e38ab3 326{
83977d27
PM
327 print "echo ----Start batch " batchnum ": `date`";
328 print "echo ----Start batch " batchnum ": `date` >> " rd "/log";
43e38ab3
PM
329 jn=1
330 for (j = first; j < pastlast; j++) {
331 builddir=KVM "/b" jn
0ae3f73a 332 cpusr[jn] = cpus[j];
43e38ab3 333 if (cfrep[cf[j]] == "") {
0ae3f73a 334 cfr[jn] = cf[j];
43e38ab3
PM
335 cfrep[cf[j]] = 1;
336 } else {
337 cfrep[cf[j]]++;
0ae3f73a 338 cfr[jn] = cf[j] "." cfrep[cf[j]];
43e38ab3 339 }
df1cc81b 340 if (cpusr[jn] > ncpus && ncpus != 0)
91afa21d 341 ovf = "-ovf";
df1cc81b
PM
342 else
343 ovf = "";
3c626237 344 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
73fa867e 345 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
0ae3f73a
PM
346 print "rm -f " builddir ".*";
347 print "touch " builddir ".wait";
348 print "mkdir " builddir " > /dev/null 2>&1 || :";
349 print "mkdir " rd cfr[jn] " || :";
d1b1e517 350 print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &"
73fa867e
PM
351 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
352 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
43e38ab3
PM
353 print "while test -f " builddir ".wait"
354 print "do"
355 print "\tsleep 1"
356 print "done"
73fa867e
PM
357 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
358 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
43e38ab3
PM
359 jn++;
360 }
43e38ab3
PM
361 for (j = 1; j < jn; j++) {
362 builddir=KVM "/b" j
363 print "rm -f " builddir ".ready"
9bee2c6f
PM
364 print "if test -z \"$TORTURE_BUILDONLY\""
365 print "then"
366 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
367 print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
368 print "fi"
43e38ab3 369 }
6e524a60
PM
370 njitter = 0;
371 split(jitter, ja);
372 if (ja[1] == -1 && ncpus == 0)
373 njitter = 1;
374 else if (ja[1] == -1)
375 njitter = ncpus;
376 else
377 njitter = ja[1];
378 for (j = 0; j < njitter; j++)
379 print "jitter.sh " j " " dur " " ja[2] " " ja[3] "&"
43e38ab3 380 print "wait"
9bee2c6f
PM
381 print "if test -z \"$TORTURE_BUILDONLY\""
382 print "then"
383 print "\techo ---- All kernel runs complete. `date`";
384 print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
385 print "fi"
43e38ab3
PM
386 for (j = 1; j < jn; j++) {
387 builddir=KVM "/b" j
73fa867e
PM
388 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
389 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
390 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
391 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
43e38ab3
PM
392 }
393}
394
395END {
396 njobs = i;
397 nc = ncpus;
398 first = 0;
83977d27 399 batchnum = 1;
78ad0693
PM
400
401 # Each pass through the following loop considers one test.
43e38ab3
PM
402 for (i = 0; i < njobs; i++) {
403 if (ncpus == 0) {
78ad0693 404 # Sequential test specified, each test its own batch.
83977d27 405 dump(i, i + 1, batchnum);
43e38ab3 406 first = i;
83977d27 407 batchnum++;
43e38ab3 408 } else if (nc < cpus[i] && i != 0) {
78ad0693 409 # Out of CPUs, dump out a batch.
83977d27 410 dump(first, i, batchnum);
43e38ab3
PM
411 first = i;
412 nc = ncpus;
83977d27 413 batchnum++;
43e38ab3 414 }
78ad0693 415 # Account for the CPUs needed by the current test.
43e38ab3
PM
416 nc -= cpus[i];
417 }
78ad0693 418 # Dump the last batch.
43e38ab3 419 if (ncpus != 0)
83977d27 420 dump(first, i, batchnum);
61010e74 421}' >> $T/script
43e38ab3 422
1f5d0920
PM
423cat << ___EOF___ >> $T/script
424echo
425echo
426echo " --- `date` Test summary:"
427echo Results directory: $resdir/$ds
9bee2c6f 428kvm-recheck.sh $resdir/$ds
1f5d0920
PM
429___EOF___
430
a7582815
PM
431if test "$dryrun" = script
432then
a7582815
PM
433 cat $T/script
434 exit 0
435elif test "$dryrun" = sched
436then
78ad0693 437 # Extract the test run schedule from the script.
9352ad13
PM
438 egrep 'Start batch|Starting build\.' $T/script |
439 grep -v ">>" |
a7582815
PM
440 sed -e 's/:.*$//' -e 's/^echo //'
441 exit 0
442else
9bee2c6f 443 # Not a dryrun, so run the script.
a7582815
PM
444 sh $T/script
445fi
43e38ab3 446
782ab4cd 447# 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