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