rcutorture: Add missing destroy_timer_on_stack()
[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#
10# Usage: sh kvm.sh [ options ]
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
c87b9c60 37dur=30
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=""
61010e74 45TORTURE_SUITE=rcu
c87b9c60 46resdir=""
4275be83 47configs=""
43e38ab3 48cpus=0
847bfd25 49ds=`date +%Y.%m.%d-%H:%M:%S`
bb918535 50kversion=""
c87b9c60 51
32caccb8
PM
52. functions.sh
53
c87b9c60
PM
54usage () {
55 echo "Usage: $scriptname optional arguments:"
7dca9273 56 echo " --bootargs kernel-boot-arguments"
f189cc8c 57 echo " --bootimage relative-path-to-kernel-boot-image"
11274813 58 echo " --buildonly"
c87b9c60 59 echo " --configs \"config-file list\""
43e38ab3 60 echo " --cpus N"
847bfd25 61 echo " --datestamp string"
8c55f227 62 echo " --defconfig string"
a7582815 63 echo " --dryrun sched|script"
c87b9c60 64 echo " --duration minutes"
315c540d 65 echo " --interactive"
74878fb6 66 echo " --kmake-arg kernel-make-arguments"
bb918535 67 echo " --kversion vN.NN"
315c540d 68 echo " --mac nn:nn:nn:nn:nn:nn"
73931b5e 69 echo " --no-initrd"
e9ce6400 70 echo " --qemu-args qemu-system-..."
4f8a0312 71 echo " --qemu-cmd qemu-system-..."
61010e74
PM
72 echo " --results absolute-pathname"
73 echo " --torture rcu"
c87b9c60
PM
74 exit 1
75}
76
c87b9c60
PM
77while test $# -gt 0
78do
c87b9c60 79 case "$1" in
7dca9273
PM
80 --bootargs)
81 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
98bc8cc8 82 TORTURE_BOOTARGS="$2"
7dca9273
PM
83 shift
84 ;;
f189cc8c
PM
85 --bootimage)
86 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
87 TORTURE_BOOT_IMAGE="$2"
88 shift
89 ;;
11274813 90 --buildonly)
805ffee2 91 TORTURE_BUILDONLY=1
11274813 92 ;;
c87b9c60
PM
93 --configs)
94 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
95 configs="$2"
96 shift
97 ;;
43e38ab3
PM
98 --cpus)
99 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
100 cpus=$2
101 shift
102 ;;
847bfd25
PM
103 --datestamp)
104 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
105 ds=$2
106 shift
107 ;;
8c55f227
PM
108 --defconfig)
109 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
110 TORTURE_DEFCONFIG=$2
111 shift
112 ;;
a7582815
PM
113 --dryrun)
114 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
115 dryrun=$2
116 shift
117 ;;
c87b9c60 118 --duration)
e9ce6400 119 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
c87b9c60
PM
120 dur=$2
121 shift
122 ;;
315c540d 123 --interactive)
a0edd47c 124 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
315c540d 125 ;;
74878fb6
PM
126 --kmake-arg)
127 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
58d280bd 128 TORTURE_KMAKE_ARG="$2"
74878fb6
PM
129 shift
130 ;;
bb918535 131 --kversion)
e9ce6400 132 checkarg --kversion "(kernel version)" $# "$2" '^v[0-9.]*$' '^error'
bb918535
PM
133 kversion=$2
134 shift
135 ;;
315c540d
PM
136 --mac)
137 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
58f724f7 138 TORTURE_QEMU_MAC=$2
315c540d
PM
139 shift
140 ;;
73931b5e 141 --no-initrd)
2f66dbc1 142 TORTURE_INITRD=""; export TORTURE_INITRD
73931b5e 143 ;;
e9ce6400
PM
144 --qemu-args)
145 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
d1b1e517 146 TORTURE_QEMU_ARG="$2"
e9ce6400
PM
147 shift
148 ;;
4f8a0312
PM
149 --qemu-cmd)
150 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
250da31e 151 TORTURE_QEMU_CMD="$2"
4f8a0312
PM
152 shift
153 ;;
c87b9c60 154 --results)
e9ce6400 155 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
c87b9c60
PM
156 resdir=$2
157 shift
158 ;;
61010e74 159 --torture)
9dfa5b35 160 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
61010e74
PM
161 TORTURE_SUITE=$2
162 shift
163 ;;
c87b9c60 164 *)
2bcdf4e3 165 echo Unknown argument $1
c87b9c60
PM
166 usage
167 ;;
168 esac
169 shift
170done
171
61010e74 172CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
4275be83
PM
173KVPATH=${CONFIGFRAG}/$kversion; export KVPATH
174
175if test -z "$configs"
176then
177 configs="`cat $CONFIGFRAG/$kversion/CFLIST`"
178fi
c87b9c60
PM
179
180if test -z "$resdir"
181then
182 resdir=$KVM/res
daeda23d
PM
183fi
184
78ad0693 185# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
43e38ab3 186touch $T/cfgcpu
c87b9c60
PM
187for CF in $configs
188do
43e38ab3 189 if test -f "$CONFIGFRAG/$kversion/$CF"
f43f8f73 190 then
43e38ab3
PM
191 echo $CF `configNR_CPUS.sh $CONFIGFRAG/$kversion/$CF` >> $T/cfgcpu
192 else
193 echo "The --configs file $CF does not exist, terminating."
194 exit 1
f43f8f73 195 fi
c87b9c60 196done
43e38ab3
PM
197sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
198
78ad0693 199# Use a greedy bin-packing algorithm, sorting the list accordingly.
53954671
PM
200awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
201BEGIN {
202 njobs = 0;
203}
204
205{
78ad0693 206 # Read file of tests and corresponding required numbers of CPUs.
53954671
PM
207 cf[njobs] = $1;
208 cpus[njobs] = $2;
209 njobs++;
210}
211
212END {
213 alldone = 0;
214 batch = 0;
215 nc = -1;
78ad0693
PM
216
217 # Each pass through the following loop creates on test batch
218 # that can be executed concurrently given ncpus. Note that a
219 # given test that requires more than the available CPUs will run in
220 # their own batch. Such tests just have to make do with what
221 # is available.
53954671
PM
222 while (nc != ncpus) {
223 batch++;
224 nc = ncpus;
78ad0693
PM
225
226 # Each pass through the following loop considers one
227 # test for inclusion in the current batch.
53954671
PM
228 for (i = 0; i < njobs; i++) {
229 if (done[i])
78ad0693 230 continue; # Already part of a batch.
53954671 231 if (nc >= cpus[i] || nc == ncpus) {
78ad0693
PM
232
233 # This test fits into the current batch.
53954671
PM
234 done[i] = batch;
235 nc -= cpus[i];
236 if (nc <= 0)
78ad0693 237 break; # Too-big test in its own batch.
53954671
PM
238 }
239 }
240 }
78ad0693
PM
241
242 # Dump out the tests in batch order.
53954671
PM
243 for (b = 1; b <= batch; b++)
244 for (i = 0; i < njobs; i++)
245 if (done[i] == b)
246 print cf[i], cpus[i];
247}'
248
78ad0693 249# Generate a script to execute the tests in appropriate batches.
61010e74 250cat << ___EOF___ > $T/script
14d9d84c
PM
251CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
252KVM="$KVM"; export KVM
253KVPATH="$KVPATH"; export KVPATH
254PATH="$PATH"; export PATH
f189cc8c 255TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
14d9d84c 256TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
8c55f227 257TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
14d9d84c
PM
258TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
259TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
260TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
261TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
262TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
263TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
1f5d0920
PM
264if ! test -e $resdir
265then
266 mkdir -p "$resdir" || :
267fi
268mkdir $resdir/$ds
269echo Results directory: $resdir/$ds
270echo $scriptname $args
271touch $resdir/$ds/log
272echo $scriptname $args >> $resdir/$ds/log
273echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
274pwd > $resdir/$ds/testid.txt
275if test -d .git
276then
277 git status >> $resdir/$ds/testid.txt
278 git rev-parse HEAD >> $resdir/$ds/testid.txt
279fi
61010e74 280___EOF___
53954671 281awk < $T/cfgcpu.pack \
43e38ab3
PM
282 -v CONFIGDIR="$CONFIGFRAG/$kversion/" \
283 -v KVM="$KVM" \
284 -v ncpus=$cpus \
285 -v rd=$resdir/$ds/ \
286 -v dur=$dur \
06188731
PM
287 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
288 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
43e38ab3
PM
289'BEGIN {
290 i = 0;
291}
292
293{
294 cf[i] = $1;
295 cpus[i] = $2;
296 i++;
297}
298
78ad0693 299# Dump out the scripting required to run one test batch.
43e38ab3
PM
300function dump(first, pastlast)
301{
73fa867e
PM
302 print "echo ----Start batch: `date`";
303 print "echo ----Start batch: `date` >> " rd "/log";
43e38ab3
PM
304 jn=1
305 for (j = first; j < pastlast; j++) {
306 builddir=KVM "/b" jn
0ae3f73a 307 cpusr[jn] = cpus[j];
43e38ab3 308 if (cfrep[cf[j]] == "") {
0ae3f73a 309 cfr[jn] = cf[j];
43e38ab3
PM
310 cfrep[cf[j]] = 1;
311 } else {
312 cfrep[cf[j]]++;
0ae3f73a 313 cfr[jn] = cf[j] "." cfrep[cf[j]];
43e38ab3 314 }
df1cc81b
PM
315 if (cpusr[jn] > ncpus && ncpus != 0)
316 ovf = "(!)";
317 else
318 ovf = "";
3c626237 319 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
73fa867e 320 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
0ae3f73a
PM
321 print "rm -f " builddir ".*";
322 print "touch " builddir ".wait";
323 print "mkdir " builddir " > /dev/null 2>&1 || :";
324 print "mkdir " rd cfr[jn] " || :";
d1b1e517 325 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
326 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
327 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
43e38ab3
PM
328 print "while test -f " builddir ".wait"
329 print "do"
330 print "\tsleep 1"
331 print "done"
73fa867e
PM
332 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
333 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
43e38ab3
PM
334 jn++;
335 }
43e38ab3
PM
336 for (j = 1; j < jn; j++) {
337 builddir=KVM "/b" j
338 print "rm -f " builddir ".ready"
73fa867e
PM
339 print "echo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
340 print "echo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
43e38ab3
PM
341 }
342 print "wait"
73fa867e
PM
343 print "echo ---- All kernel runs complete. `date`";
344 print "echo ---- All kernel runs complete. `date` >> " rd "/log";
43e38ab3
PM
345 for (j = 1; j < jn; j++) {
346 builddir=KVM "/b" j
73fa867e
PM
347 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
348 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
349 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
350 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
43e38ab3
PM
351 }
352}
353
354END {
355 njobs = i;
356 nc = ncpus;
357 first = 0;
78ad0693
PM
358
359 # Each pass through the following loop considers one test.
43e38ab3
PM
360 for (i = 0; i < njobs; i++) {
361 if (ncpus == 0) {
78ad0693 362 # Sequential test specified, each test its own batch.
43e38ab3
PM
363 dump(i, i + 1);
364 first = i;
365 } else if (nc < cpus[i] && i != 0) {
78ad0693 366 # Out of CPUs, dump out a batch.
43e38ab3
PM
367 dump(first, i);
368 first = i;
369 nc = ncpus;
370 }
78ad0693 371 # Account for the CPUs needed by the current test.
43e38ab3
PM
372 nc -= cpus[i];
373 }
78ad0693 374 # Dump the last batch.
43e38ab3
PM
375 if (ncpus != 0)
376 dump(first, i);
61010e74 377}' >> $T/script
43e38ab3 378
1f5d0920
PM
379cat << ___EOF___ >> $T/script
380echo
381echo
382echo " --- `date` Test summary:"
383echo Results directory: $resdir/$ds
384if test -z "$TORTURE_BUILDONLY"
385then
386 kvm-recheck.sh $resdir/$ds
387fi
388___EOF___
389
a7582815
PM
390if test "$dryrun" = script
391then
a7582815
PM
392 cat $T/script
393 exit 0
394elif test "$dryrun" = sched
395then
78ad0693 396 # Extract the test run schedule from the script.
9352ad13
PM
397 egrep 'Start batch|Starting build\.' $T/script |
398 grep -v ">>" |
a7582815
PM
399 sed -e 's/:.*$//' -e 's/^echo //'
400 exit 0
401else
78ad0693 402 # Not a dryru, so run the script.
a7582815
PM
403 sh $T/script
404fi
43e38ab3 405
782ab4cd 406# 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