kvm.sh 13 KB

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