rcutorture: Do better bin packing
[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
73931b5e
PM
41builddir="${KVM}/b1"
42RCU_INITRD="$KVM/initrd"; export RCU_INITRD
74878fb6 43RCU_KMAKE_ARG=""; export RCU_KMAKE_ARG
c87b9c60 44resdir=""
4275be83 45configs=""
43e38ab3 46cpus=0
847bfd25 47ds=`date +%Y.%m.%d-%H:%M:%S`
bb918535 48kversion=""
c87b9c60 49
32caccb8
PM
50. functions.sh
51
c87b9c60
PM
52usage () {
53 echo "Usage: $scriptname optional arguments:"
7dca9273 54 echo " --bootargs kernel-boot-arguments"
c87b9c60 55 echo " --builddir absolute-pathname"
11274813 56 echo " --buildonly"
c87b9c60 57 echo " --configs \"config-file list\""
43e38ab3 58 echo " --cpus N"
847bfd25 59 echo " --datestamp string"
a7582815 60 echo " --dryrun sched|script"
c87b9c60 61 echo " --duration minutes"
315c540d 62 echo " --interactive"
74878fb6 63 echo " --kmake-arg kernel-make-arguments"
bb918535 64 echo " --kversion vN.NN"
315c540d 65 echo " --mac nn:nn:nn:nn:nn:nn"
73931b5e 66 echo " --no-initrd"
e9ce6400 67 echo " --qemu-args qemu-system-..."
4f8a0312 68 echo " --qemu-cmd qemu-system-..."
c87b9c60
PM
69 echo " --results absolute-pathname"
70 echo " --relbuilddir relative-pathname"
71 exit 1
72}
73
c87b9c60
PM
74while test $# -gt 0
75do
c87b9c60 76 case "$1" in
7dca9273
PM
77 --bootargs)
78 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
79 RCU_BOOTARGS="$2"
80 shift
81 ;;
c87b9c60 82 --builddir)
e9ce6400 83 checkarg --builddir "(absolute pathname)" "$#" "$2" '^/' '^error'
c87b9c60
PM
84 builddir=$2
85 gotbuilddir=1
86 shift
87 ;;
11274813
PM
88 --buildonly)
89 RCU_BUILDONLY=1; export RCU_BUILDONLY
90 ;;
c87b9c60
PM
91 --configs)
92 checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
93 configs="$2"
94 shift
95 ;;
43e38ab3
PM
96 --cpus)
97 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
98 cpus=$2
99 shift
100 ;;
847bfd25
PM
101 --datestamp)
102 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
103 ds=$2
104 shift
105 ;;
a7582815
PM
106 --dryrun)
107 checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
108 dryrun=$2
109 shift
110 ;;
c87b9c60 111 --duration)
e9ce6400 112 checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
c87b9c60
PM
113 dur=$2
114 shift
115 ;;
315c540d
PM
116 --interactive)
117 RCU_QEMU_INTERACTIVE=1; export RCU_QEMU_INTERACTIVE
118 ;;
74878fb6
PM
119 --kmake-arg)
120 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
121 RCU_KMAKE_ARG="$2"; export RCU_KMAKE_ARG
122 shift
123 ;;
bb918535 124 --kversion)
e9ce6400 125 checkarg --kversion "(kernel version)" $# "$2" '^v[0-9.]*$' '^error'
bb918535
PM
126 kversion=$2
127 shift
128 ;;
315c540d
PM
129 --mac)
130 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
131 RCU_QEMU_MAC=$2; export RCU_QEMU_MAC
132 shift
133 ;;
73931b5e
PM
134 --no-initrd)
135 RCU_INITRD=""; export RCU_INITRD
136 ;;
e9ce6400
PM
137 --qemu-args)
138 checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
139 RCU_QEMU_ARG="$2"
140 shift
141 ;;
4f8a0312
PM
142 --qemu-cmd)
143 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
144 RCU_QEMU_CMD="$2"; export RCU_QEMU_CMD
145 shift
146 ;;
c87b9c60
PM
147 --relbuilddir)
148 checkarg --relbuilddir "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
149 relbuilddir=$2
150 gotrelbuilddir=1
151 builddir=${KVM}/${relbuilddir}
152 shift
153 ;;
154 --results)
e9ce6400 155 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
c87b9c60
PM
156 resdir=$2
157 shift
158 ;;
159 *)
2bcdf4e3 160 echo Unknown argument $1
c87b9c60
PM
161 usage
162 ;;
163 esac
164 shift
165done
166
c87b9c60 167CONFIGFRAG=${KVM}/configs; export CONFIGFRAG
4275be83
PM
168KVPATH=${CONFIGFRAG}/$kversion; export KVPATH
169
170if test -z "$configs"
171then
172 configs="`cat $CONFIGFRAG/$kversion/CFLIST`"
173fi
c87b9c60
PM
174
175if test -z "$resdir"
176then
177 resdir=$KVM/res
330a76f1
PM
178 if ! test -e $resdir
179 then
180 mkdir $resdir || :
181 fi
c87b9c60 182else
330a76f1
PM
183 if ! test -e $resdir
184 then
185 mkdir -p "$resdir" || :
186 fi
c87b9c60 187fi
847bfd25 188mkdir $resdir/$ds
a7582815
PM
189if test "$dryrun" = ""
190then
191 echo Results directory: $resdir/$ds
192 echo $scriptname $args
193fi
330a76f1
PM
194touch $resdir/$ds/log
195echo $scriptname $args >> $resdir/$ds/log
847bfd25 196
c87b9c60
PM
197pwd > $resdir/$ds/testid.txt
198if test -d .git
199then
200 git status >> $resdir/$ds/testid.txt
201 git rev-parse HEAD >> $resdir/$ds/testid.txt
202fi
c87b9c60 203
43e38ab3 204touch $T/cfgcpu
c87b9c60
PM
205for CF in $configs
206do
43e38ab3 207 if test -f "$CONFIGFRAG/$kversion/$CF"
f43f8f73 208 then
43e38ab3
PM
209 echo $CF `configNR_CPUS.sh $CONFIGFRAG/$kversion/$CF` >> $T/cfgcpu
210 else
211 echo "The --configs file $CF does not exist, terminating."
212 exit 1
f43f8f73 213 fi
c87b9c60 214done
43e38ab3
PM
215sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
216
53954671
PM
217awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
218BEGIN {
219 njobs = 0;
220}
221
222{
223 cf[njobs] = $1;
224 cpus[njobs] = $2;
225 njobs++;
226}
227
228END {
229 alldone = 0;
230 batch = 0;
231 nc = -1;
232 while (nc != ncpus) {
233 batch++;
234 nc = ncpus;
235 for (i = 0; i < njobs; i++) {
236 if (done[i])
237 continue;
238 if (nc >= cpus[i] || nc == ncpus) {
239 done[i] = batch;
240 nc -= cpus[i];
241 if (nc <= 0)
242 break;
243 }
244 }
245 }
246 for (b = 1; b <= batch; b++)
247 for (i = 0; i < njobs; i++)
248 if (done[i] == b)
249 print cf[i], cpus[i];
250}'
251
252awk < $T/cfgcpu.pack \
43e38ab3
PM
253 -v CONFIGDIR="$CONFIGFRAG/$kversion/" \
254 -v KVM="$KVM" \
255 -v ncpus=$cpus \
256 -v rd=$resdir/$ds/ \
257 -v dur=$dur \
258 -v RCU_QEMU_ARG=$RCU_QEMU_ARG \
259 -v RCU_BOOTARGS=$RCU_BOOTARGS \
260'BEGIN {
261 i = 0;
262}
263
264{
265 cf[i] = $1;
266 cpus[i] = $2;
267 i++;
268}
269
270function dump(first, pastlast)
271{
272 print "echo ----start batch----"
273 jn=1
274 for (j = first; j < pastlast; j++) {
275 builddir=KVM "/b" jn
0ae3f73a 276 cpusr[jn] = cpus[j];
43e38ab3 277 if (cfrep[cf[j]] == "") {
0ae3f73a 278 cfr[jn] = cf[j];
43e38ab3
PM
279 cfrep[cf[j]] = 1;
280 } else {
281 cfrep[cf[j]]++;
0ae3f73a 282 cfr[jn] = cf[j] "." cfrep[cf[j]];
43e38ab3 283 }
0ae3f73a
PM
284 print "echo ", cfr[jn], cpusr[jn] ": Starting build.";
285 print "rm -f " builddir ".*";
286 print "touch " builddir ".wait";
287 print "mkdir " builddir " > /dev/null 2>&1 || :";
288 print "mkdir " rd cfr[jn] " || :";
289 print "kvm-test-1-rcu.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" RCU_QEMU_ARG "\" \"" RCU_BOOTARGS "\" > " builddir ".out 2>&1 &"
290 print "echo ", cfr[jn], cpusr[jn] ": Waiting for build to complete."
43e38ab3
PM
291 print "while test -f " builddir ".wait"
292 print "do"
293 print "\tsleep 1"
294 print "done"
0ae3f73a 295 print "echo ", cfr[jn], cpusr[jn] ": Build complete."
43e38ab3
PM
296 jn++;
297 }
43e38ab3
PM
298 for (j = 1; j < jn; j++) {
299 builddir=KVM "/b" j
300 print "rm -f " builddir ".ready"
0ae3f73a 301 print "echo ----", cfr[j], cpusr[j] ": Starting kernel"
43e38ab3
PM
302 }
303 print "wait"
304 print "echo ---- All kernel runs complete"
43e38ab3
PM
305 for (j = 1; j < jn; j++) {
306 builddir=KVM "/b" j
0ae3f73a 307 print "echo ----", cfr[j], cpusr[j] ": Build/run results:"
43e38ab3 308 print "cat " builddir ".out"
43e38ab3
PM
309 }
310}
311
312END {
313 njobs = i;
314 nc = ncpus;
315 first = 0;
316 for (i = 0; i < njobs; i++) {
317 if (ncpus == 0) {
318 dump(i, i + 1);
319 first = i;
320 } else if (nc < cpus[i] && i != 0) {
321 dump(first, i);
322 first = i;
323 nc = ncpus;
324 }
325 nc -= cpus[i];
326 }
327 if (ncpus != 0)
328 dump(first, i);
329}' > $T/script
330
a7582815
PM
331if test "$dryrun" = script
332then
333 echo CONFIGFRAG="$CONFIGFRAG; export CONFIGFRAG"
334 echo KVM="$KVM; export KVM"
335 echo KVPATH="$KVPATH; export KVPATH"
336 echo PATH="$PATH; export PATH"
337 echo RCU_BUILDONLY="$RCU_BUILDONLY; export RCU_BUILDONLY"
338 echo RCU_INITRD="$RCU_INITRD; export RCU_INITRD"
339 echo RCU_KMAKE_ARG="$RCU_KMAKE_ARG; export RCU_KMAKE_ARG"
340 echo RCU_QEMU_CMD="$RCU_QEMU_CMD; export RCU_QEMU_CMD"
341 echo RCU_QEMU_INTERACTIVE="$RCU_QEMU_INTERACTIVE; export RCU_QEMU_INTERACTIVE"
342 echo RCU_QEMU_MAC="$RCU_QEMU_MAC; export RCU_QEMU_MAC"
343 cat $T/script
344 exit 0
345elif test "$dryrun" = sched
346then
347 egrep 'start batch|Starting build\.' $T/script |
348 sed -e 's/:.*$//' -e 's/^echo //'
349 exit 0
350else
351 sh $T/script
352fi
43e38ab3 353
782ab4cd 354# 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
e1362651
PM
355
356echo " --- `date` Test summary:"
357kvm-recheck.sh $resdir/$ds