kvm.sh 12 KB

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