PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/testing/selftests/rcutorture/bin/kvm.sh

https://gitlab.com/oyvholm/linux
Shell | 469 lines | 420 code | 15 blank | 34 comment | 10 complexity | db275e231fd6f738845cf68cbe9fbcc2 MD5 | raw file
  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=${TMPDIR-/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_KCONFIG_ARG=""
  42. TORTURE_KMAKE_ARG=""
  43. TORTURE_SHUTDOWN_GRACE=180
  44. TORTURE_SUITE=rcu
  45. resdir=""
  46. configs=""
  47. cpus=0
  48. ds=`date +%Y.%m.%d-%H:%M:%S`
  49. jitter="-1"
  50. . functions.sh
  51. usage () {
  52. echo "Usage: $scriptname optional arguments:"
  53. echo " --bootargs kernel-boot-arguments"
  54. echo " --bootimage relative-path-to-kernel-boot-image"
  55. echo " --buildonly"
  56. echo " --configs \"config-file list w/ repeat factor (3*TINY01)\""
  57. echo " --cpus N"
  58. echo " --datestamp string"
  59. echo " --defconfig string"
  60. echo " --dryrun sched|script"
  61. echo " --duration minutes"
  62. echo " --interactive"
  63. echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
  64. echo " --kconfig Kconfig-options"
  65. echo " --kmake-arg kernel-make-arguments"
  66. echo " --mac nn:nn:nn:nn:nn:nn"
  67. echo " --no-initrd"
  68. echo " --qemu-args qemu-system-..."
  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. --no-initrd)
  144. TORTURE_INITRD=""; export TORTURE_INITRD
  145. ;;
  146. --qemu-args|--qemu-arg)
  147. checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
  148. TORTURE_QEMU_ARG="$2"
  149. shift
  150. ;;
  151. --qemu-cmd)
  152. checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
  153. TORTURE_QEMU_CMD="$2"
  154. shift
  155. ;;
  156. --results)
  157. checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
  158. resdir=$2
  159. shift
  160. ;;
  161. --shutdown-grace)
  162. checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error'
  163. TORTURE_SHUTDOWN_GRACE=$2
  164. shift
  165. ;;
  166. --torture)
  167. checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuperf\)$' '^--'
  168. TORTURE_SUITE=$2
  169. shift
  170. ;;
  171. *)
  172. echo Unknown argument $1
  173. usage
  174. ;;
  175. esac
  176. shift
  177. done
  178. CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
  179. if test -z "$configs"
  180. then
  181. configs="`cat $CONFIGFRAG/CFLIST`"
  182. fi
  183. if test -z "$resdir"
  184. then
  185. resdir=$KVM/res
  186. fi
  187. # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
  188. touch $T/cfgcpu
  189. for CF in $configs
  190. do
  191. case $CF in
  192. [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**)
  193. config_reps=`echo $CF | sed -e 's/\*.*$//'`
  194. CF1=`echo $CF | sed -e 's/^[^*]*\*//'`
  195. ;;
  196. *)
  197. config_reps=1
  198. CF1=$CF
  199. ;;
  200. esac
  201. if test -f "$CONFIGFRAG/$CF1"
  202. then
  203. cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
  204. cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
  205. cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
  206. for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
  207. do
  208. echo $CF1 $cpu_count >> $T/cfgcpu
  209. done
  210. else
  211. echo "The --configs file $CF1 does not exist, terminating."
  212. exit 1
  213. fi
  214. done
  215. sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
  216. # Use a greedy bin-packing algorithm, sorting the list accordingly.
  217. awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
  218. BEGIN {
  219. njobs = 0;
  220. }
  221. {
  222. # Read file of tests and corresponding required numbers of CPUs.
  223. cf[njobs] = $1;
  224. cpus[njobs] = $2;
  225. njobs++;
  226. }
  227. END {
  228. alldone = 0;
  229. batch = 0;
  230. nc = -1;
  231. # Each pass through the following loop creates on test batch
  232. # that can be executed concurrently given ncpus. Note that a
  233. # given test that requires more than the available CPUs will run in
  234. # their own batch. Such tests just have to make do with what
  235. # is available.
  236. while (nc != ncpus) {
  237. batch++;
  238. nc = ncpus;
  239. # Each pass through the following loop considers one
  240. # test for inclusion in the current batch.
  241. for (i = 0; i < njobs; i++) {
  242. if (done[i])
  243. continue; # Already part of a batch.
  244. if (nc >= cpus[i] || nc == ncpus) {
  245. # This test fits into the current batch.
  246. done[i] = batch;
  247. nc -= cpus[i];
  248. if (nc <= 0)
  249. break; # Too-big test in its own batch.
  250. }
  251. }
  252. }
  253. # Dump out the tests in batch order.
  254. for (b = 1; b <= batch; b++)
  255. for (i = 0; i < njobs; i++)
  256. if (done[i] == b)
  257. print cf[i], cpus[i];
  258. }'
  259. # Generate a script to execute the tests in appropriate batches.
  260. cat << ___EOF___ > $T/script
  261. CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
  262. KVM="$KVM"; export KVM
  263. PATH="$PATH"; export PATH
  264. TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
  265. TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
  266. TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
  267. TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
  268. TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
  269. TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
  270. TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
  271. TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
  272. TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
  273. TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE
  274. TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
  275. if ! test -e $resdir
  276. then
  277. mkdir -p "$resdir" || :
  278. fi
  279. mkdir $resdir/$ds
  280. echo Results directory: $resdir/$ds
  281. echo $scriptname $args
  282. touch $resdir/$ds/log
  283. echo $scriptname $args >> $resdir/$ds/log
  284. echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
  285. pwd > $resdir/$ds/testid.txt
  286. if test -d .git
  287. then
  288. git status >> $resdir/$ds/testid.txt
  289. git rev-parse HEAD >> $resdir/$ds/testid.txt
  290. git diff HEAD >> $resdir/$ds/testid.txt
  291. fi
  292. ___EOF___
  293. awk < $T/cfgcpu.pack \
  294. -v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \
  295. -v CONFIGDIR="$CONFIGFRAG/" \
  296. -v KVM="$KVM" \
  297. -v ncpus=$cpus \
  298. -v jitter="$jitter" \
  299. -v rd=$resdir/$ds/ \
  300. -v dur=$dur \
  301. -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
  302. -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
  303. 'BEGIN {
  304. i = 0;
  305. }
  306. {
  307. cf[i] = $1;
  308. cpus[i] = $2;
  309. i++;
  310. }
  311. # Dump out the scripting required to run one test batch.
  312. function dump(first, pastlast, batchnum)
  313. {
  314. print "echo ----Start batch " batchnum ": `date`";
  315. print "echo ----Start batch " batchnum ": `date` >> " rd "/log";
  316. print "needqemurun="
  317. jn=1
  318. for (j = first; j < pastlast; j++) {
  319. builddir=KVM "/b" jn
  320. cpusr[jn] = cpus[j];
  321. if (cfrep[cf[j]] == "") {
  322. cfr[jn] = cf[j];
  323. cfrep[cf[j]] = 1;
  324. } else {
  325. cfrep[cf[j]]++;
  326. cfr[jn] = cf[j] "." cfrep[cf[j]];
  327. }
  328. if (cpusr[jn] > ncpus && ncpus != 0)
  329. ovf = "-ovf";
  330. else
  331. ovf = "";
  332. print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
  333. print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
  334. print "rm -f " builddir ".*";
  335. print "touch " builddir ".wait";
  336. print "mkdir " builddir " > /dev/null 2>&1 || :";
  337. print "mkdir " rd cfr[jn] " || :";
  338. 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 &"
  339. print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
  340. print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
  341. print "while test -f " builddir ".wait"
  342. print "do"
  343. print "\tsleep 1"
  344. print "done"
  345. print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
  346. print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
  347. jn++;
  348. }
  349. for (j = 1; j < jn; j++) {
  350. builddir=KVM "/b" j
  351. print "rm -f " builddir ".ready"
  352. print "if test -f \"" rd cfr[j] "/builtkernel\""
  353. print "then"
  354. print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date`";
  355. print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` >> " rd "/log";
  356. print "\tneedqemurun=1"
  357. print "fi"
  358. }
  359. njitter = 0;
  360. split(jitter, ja);
  361. if (ja[1] == -1 && ncpus == 0)
  362. njitter = 1;
  363. else if (ja[1] == -1)
  364. njitter = ncpus;
  365. else
  366. njitter = ja[1];
  367. if (TORTURE_BUILDONLY && njitter != 0) {
  368. njitter = 0;
  369. print "echo Build-only run, so suppressing jitter >> " rd "/log"
  370. }
  371. if (TORTURE_BUILDONLY) {
  372. print "needqemurun="
  373. }
  374. print "if test -n \"$needqemurun\""
  375. print "then"
  376. print "\techo ---- Starting kernels. `date`";
  377. print "\techo ---- Starting kernels. `date` >> " rd "/log";
  378. for (j = 0; j < njitter; j++)
  379. print "\tjitter.sh " j " " dur " " ja[2] " " ja[3] "&"
  380. print "\twait"
  381. print "\techo ---- All kernel runs complete. `date`";
  382. print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
  383. print "else"
  384. print "\twait"
  385. print "\techo ---- No kernel runs. `date`";
  386. print "\techo ---- No kernel runs. `date` >> " rd "/log";
  387. print "fi"
  388. for (j = 1; j < jn; j++) {
  389. builddir=KVM "/b" j
  390. print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
  391. print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
  392. print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
  393. print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
  394. }
  395. }
  396. END {
  397. njobs = i;
  398. nc = ncpus;
  399. first = 0;
  400. batchnum = 1;
  401. # Each pass through the following loop considers one test.
  402. for (i = 0; i < njobs; i++) {
  403. if (ncpus == 0) {
  404. # Sequential test specified, each test its own batch.
  405. dump(i, i + 1, batchnum);
  406. first = i;
  407. batchnum++;
  408. } else if (nc < cpus[i] && i != 0) {
  409. # Out of CPUs, dump out a batch.
  410. dump(first, i, batchnum);
  411. first = i;
  412. nc = ncpus;
  413. batchnum++;
  414. }
  415. # Account for the CPUs needed by the current test.
  416. nc -= cpus[i];
  417. }
  418. # Dump the last batch.
  419. if (ncpus != 0)
  420. dump(first, i, batchnum);
  421. }' >> $T/script
  422. cat << ___EOF___ >> $T/script
  423. echo
  424. echo
  425. echo " --- `date` Test summary:"
  426. echo Results directory: $resdir/$ds
  427. kvm-recheck.sh $resdir/$ds
  428. ___EOF___
  429. if test "$dryrun" = script
  430. then
  431. cat $T/script
  432. exit 0
  433. elif test "$dryrun" = sched
  434. then
  435. # Extract the test run schedule from the script.
  436. egrep 'Start batch|Starting build\.' $T/script |
  437. grep -v ">>" |
  438. sed -e 's/:.*$//' -e 's/^echo //'
  439. exit 0
  440. else
  441. # Not a dryrun, so run the script.
  442. sh $T/script
  443. fi
  444. # 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