1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0+ 3# 4# Run a series of tests under KVM. By default, this series is specified 5# by the relevant CFLIST file, but can be overridden by the --configs 6# command-line argument. 7# 8# Usage: kvm.sh [ options ] 9# 10# Copyright (C) IBM Corporation, 2011 11# 12# Authors: Paul E. McKenney <paulmck@linux.ibm.com> 13 14scriptname=$0 15args="$*" 16 17T=${TMPDIR-/tmp}/kvm.sh.$$ 18trap 'rm -rf $T' 0 19mkdir $T 20 21cd `dirname $scriptname`/../../../../../ 22 23# This script knows only English. 24LANG=en_US.UTF-8; export LANG 25 26dur=$((30*60)) 27dryrun="" 28KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM 29PATH=${KVM}/bin:$PATH; export PATH 30. functions.sh 31 32TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`" 33TORTURE_DEFCONFIG=defconfig 34TORTURE_BOOT_IMAGE="" 35TORTURE_BUILDONLY= 36TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD 37TORTURE_KCONFIG_ARG="" 38TORTURE_KCONFIG_GDB_ARG="" 39TORTURE_BOOT_GDB_ARG="" 40TORTURE_QEMU_GDB_ARG="" 41TORTURE_JITTER_START="" 42TORTURE_JITTER_STOP="" 43TORTURE_KCONFIG_KASAN_ARG="" 44TORTURE_KCONFIG_KCSAN_ARG="" 45TORTURE_KMAKE_ARG="" 46TORTURE_QEMU_MEM=512 47TORTURE_REMOTE= 48TORTURE_SHUTDOWN_GRACE=180 49TORTURE_SUITE=rcu 50TORTURE_MOD=rcutorture 51TORTURE_TRUST_MAKE="" 52resdir="" 53configs="" 54cpus=0 55ds=`date +%Y.%m.%d-%H.%M.%S` 56jitter="-1" 57 58startdate="`date`" 59starttime="`get_starttime`" 60 61usage () { 62 echo "Usage: $scriptname optional arguments:" 63 echo " --allcpus" 64 echo " --bootargs kernel-boot-arguments" 65 echo " --bootimage relative-path-to-kernel-boot-image" 66 echo " --buildonly" 67 echo " --configs \"config-file list w/ repeat factor (3*TINY01)\"" 68 echo " --cpus N" 69 echo " --datestamp string" 70 echo " --defconfig string" 71 echo " --dryrun batches|scenarios|sched|script" 72 echo " --duration minutes | <seconds>s | <hours>h | <days>d" 73 echo " --gdb" 74 echo " --help" 75 echo " --interactive" 76 echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]" 77 echo " --kasan" 78 echo " --kconfig Kconfig-options" 79 echo " --kcsan" 80 echo " --kmake-arg kernel-make-arguments" 81 echo " --mac nn:nn:nn:nn:nn:nn" 82 echo " --memory megabytes|nnnG" 83 echo " --no-initrd" 84 echo " --qemu-args qemu-arguments" 85 echo " --qemu-cmd qemu-system-..." 86 echo " --remote" 87 echo " --results absolute-pathname" 88 echo " --shutdown-grace seconds" 89 echo " --torture lock|rcu|rcuscale|refscale|scf" 90 echo " --trust-make" 91 exit 1 92} 93 94while test $# -gt 0 95do 96 case "$1" in 97 --allcpus) 98 cpus=$TORTURE_ALLOTED_CPUS 99 max_cpus=$TORTURE_ALLOTED_CPUS 100 ;; 101 --bootargs|--bootarg) 102 checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--' 103 TORTURE_BOOTARGS="$TORTURE_BOOTARGS $2" 104 shift 105 ;; 106 --bootimage) 107 checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--' 108 TORTURE_BOOT_IMAGE="$2" 109 shift 110 ;; 111 --buildonly|--build-only) 112 TORTURE_BUILDONLY=1 113 ;; 114 --configs|--config) 115 checkarg --configs "(list of config files)" "$#" "$2" '^[^/.a-z]\+$' '^--' 116 configs="$configs $2" 117 shift 118 ;; 119 --cpus) 120 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--' 121 cpus=$2 122 TORTURE_ALLOTED_CPUS="$2" 123 if test -z "$TORTURE_REMOTE" 124 then 125 max_cpus="`identify_qemu_vcpus`" 126 if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus" 127 then 128 TORTURE_ALLOTED_CPUS=$max_cpus 129 fi 130 fi 131 shift 132 ;; 133 --datestamp) 134 checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--' 135 ds=$2 136 shift 137 ;; 138 --defconfig) 139 checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--' 140 TORTURE_DEFCONFIG=$2 141 shift 142 ;; 143 --dryrun) 144 checkarg --dryrun "batches|sched|script" $# "$2" 'batches\|scenarios\|sched\|script' '^--' 145 dryrun=$2 146 shift 147 ;; 148 --duration) 149 checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error' 150 mult=60 151 if echo "$2" | grep -q 's$' 152 then 153 mult=1 154 elif echo "$2" | grep -q 'h$' 155 then 156 mult=3600 157 elif echo "$2" | grep -q 'd$' 158 then 159 mult=86400 160 fi 161 ts=`echo $2 | sed -e 's/[smhd]$//'` 162 dur=$(($ts*mult)) 163 shift 164 ;; 165 --gdb) 166 TORTURE_KCONFIG_GDB_ARG="CONFIG_DEBUG_INFO=y"; export TORTURE_KCONFIG_GDB_ARG 167 TORTURE_BOOT_GDB_ARG="nokaslr"; export TORTURE_BOOT_GDB_ARG 168 TORTURE_QEMU_GDB_ARG="-s -S"; export TORTURE_QEMU_GDB_ARG 169 ;; 170 --help|-h) 171 usage 172 ;; 173 --interactive) 174 TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE 175 ;; 176 --jitter) 177 checkarg --jitter "(# threads [ sleep [ spin ] ])" $# "$2" '^-\{,1\}[0-9]\+\( \+[0-9]\+\)\{,2\} *$' '^error$' 178 jitter="$2" 179 shift 180 ;; 181 --kasan) 182 TORTURE_KCONFIG_KASAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KASAN=y"; export TORTURE_KCONFIG_KASAN_ARG 183 ;; 184 --kconfig|--kconfigs) 185 checkarg --kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$' 186 TORTURE_KCONFIG_ARG="`echo "$TORTURE_KCONFIG_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`" 187 shift 188 ;; 189 --kcsan) 190 TORTURE_KCONFIG_KCSAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KCSAN=y CONFIG_KCSAN_STRICT=y CONFIG_KCSAN_REPORT_ONCE_IN_MS=100000 CONFIG_KCSAN_VERBOSE=y CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y"; export TORTURE_KCONFIG_KCSAN_ARG 191 ;; 192 --kmake-arg|--kmake-args) 193 checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$' 194 TORTURE_KMAKE_ARG="`echo "$TORTURE_KMAKE_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`" 195 shift 196 ;; 197 --mac) 198 checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error 199 TORTURE_QEMU_MAC=$2 200 shift 201 ;; 202 --memory) 203 checkarg --memory "(memory size)" $# "$2" '^[0-9]\+[MG]\?$' error 204 TORTURE_QEMU_MEM=$2 205 shift 206 ;; 207 --no-initrd) 208 TORTURE_INITRD=""; export TORTURE_INITRD 209 ;; 210 --qemu-args|--qemu-arg) 211 checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error' 212 TORTURE_QEMU_ARG="`echo "$TORTURE_QEMU_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`" 213 shift 214 ;; 215 --qemu-cmd) 216 checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--' 217 TORTURE_QEMU_CMD="$2" 218 shift 219 ;; 220 --remote) 221 TORTURE_REMOTE=1 222 ;; 223 --results) 224 checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error' 225 resdir=$2 226 shift 227 ;; 228 --shutdown-grace) 229 checkarg --shutdown-grace "(seconds)" "$#" "$2" '^[0-9]*$' '^error' 230 TORTURE_SHUTDOWN_GRACE=$2 231 shift 232 ;; 233 --torture) 234 checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\|rcuscale\|refscale\|scf\)$' '^--' 235 TORTURE_SUITE=$2 236 TORTURE_MOD="`echo $TORTURE_SUITE | sed -e 's/^\(lock\|rcu\|scf\)$/\1torture/'`" 237 shift 238 if test "$TORTURE_SUITE" = rcuscale || test "$TORTURE_SUITE" = refscale 239 then 240 # If you really want jitter for refscale or 241 # rcuscale, specify it after specifying the rcuscale 242 # or the refscale. (But why jitter in these cases?) 243 jitter=0 244 fi 245 ;; 246 --trust-make) 247 TORTURE_TRUST_MAKE="y" 248 ;; 249 *) 250 echo Unknown argument $1 251 usage 252 ;; 253 esac 254 shift 255done 256 257if test -n "$dryrun" || test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh 258then 259 : 260else 261 echo No initrd and unable to create one, aborting test >&2 262 exit 1 263fi 264 265CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG 266 267defaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`" 268if test -z "$configs" 269then 270 configs=$defaultconfigs 271fi 272 273if test -z "$resdir" 274then 275 resdir=$KVM/res 276fi 277 278# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus. 279configs_derep= 280for CF in $configs 281do 282 case $CF in 283 [0-9]\**|[0-9][0-9]\**|[0-9][0-9][0-9]\**) 284 config_reps=`echo $CF | sed -e 's/\*.*$//'` 285 CF1=`echo $CF | sed -e 's/^[^*]*\*//'` 286 ;; 287 *) 288 config_reps=1 289 CF1=$CF 290 ;; 291 esac 292 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++)) 293 do 294 configs_derep="$configs_derep $CF1" 295 done 296done 297touch $T/cfgcpu 298configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`" 299if test -n "$TORTURE_KCONFIG_GDB_ARG" 300then 301 if test "`echo $configs_derep | wc -w`" -gt 1 302 then 303 echo "The --config list is: $configs_derep." 304 echo "Only one --config permitted with --gdb, terminating." 305 exit 1 306 fi 307fi 308echo 'BEGIN {' > $T/cfgcpu.awk 309for CF1 in `echo $configs_derep | tr -s ' ' '\012' | sort -u` 310do 311 if test -f "$CONFIGFRAG/$CF1" 312 then 313 if echo "$TORTURE_KCONFIG_ARG" | grep -q '\<CONFIG_NR_CPUS=' 314 then 315 echo "$TORTURE_KCONFIG_ARG" | tr -s ' ' | tr ' ' '\012' > $T/KCONFIG_ARG 316 cpu_count=`configNR_CPUS.sh $T/KCONFIG_ARG` 317 else 318 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1` 319 fi 320 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"` 321 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"` 322 echo 'scenariocpu["'"$CF1"'"] = '"$cpu_count"';' >> $T/cfgcpu.awk 323 else 324 echo "The --configs file $CF1 does not exist, terminating." 325 exit 1 326 fi 327done 328cat << '___EOF___' >> $T/cfgcpu.awk 329} 330{ 331 for (i = 1; i <= NF; i++) 332 print $i, scenariocpu[$i]; 333} 334___EOF___ 335echo $configs_derep | awk -f $T/cfgcpu.awk > $T/cfgcpu 336sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort 337 338# Use a greedy bin-packing algorithm, sorting the list accordingly. 339awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus ' 340BEGIN { 341 njobs = 0; 342} 343 344{ 345 # Read file of tests and corresponding required numbers of CPUs. 346 cf[njobs] = $1; 347 cpus[njobs] = $2; 348 njobs++; 349} 350 351END { 352 batch = 0; 353 nc = -1; 354 355 # Each pass through the following loop creates on test batch that 356 # can be executed concurrently given ncpus. Note that a given test 357 # that requires more than the available CPUs will run in its own 358 # batch. Such tests just have to make do with what is available. 359 while (nc != ncpus) { 360 batch++; 361 nc = ncpus; 362 363 # Each pass through the following loop considers one 364 # test for inclusion in the current batch. 365 for (i = 0; i < njobs; i++) { 366 if (done[i]) 367 continue; # Already part of a batch. 368 if (nc >= cpus[i] || nc == ncpus) { 369 370 # This test fits into the current batch. 371 done[i] = batch; 372 nc -= cpus[i]; 373 if (nc <= 0) 374 break; # Too-big test in its own batch. 375 } 376 } 377 } 378 379 # Dump out the tests in batch order. 380 for (b = 1; b <= batch; b++) 381 for (i = 0; i < njobs; i++) 382 if (done[i] == b) 383 print cf[i], cpus[i]; 384}' 385 386# Generate a script to execute the tests in appropriate batches. 387cat << ___EOF___ > $T/script 388CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG 389KVM="$KVM"; export KVM 390PATH="$PATH"; export PATH 391TORTURE_ALLOTED_CPUS="$TORTURE_ALLOTED_CPUS"; export TORTURE_ALLOTED_CPUS 392TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE 393TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY 394TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG 395TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD 396TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG 397TORTURE_KCONFIG_GDB_ARG="$TORTURE_KCONFIG_GDB_ARG"; export TORTURE_KCONFIG_GDB_ARG 398TORTURE_BOOT_GDB_ARG="$TORTURE_BOOT_GDB_ARG"; export TORTURE_BOOT_GDB_ARG 399TORTURE_QEMU_GDB_ARG="$TORTURE_QEMU_GDB_ARG"; export TORTURE_QEMU_GDB_ARG 400TORTURE_KCONFIG_KASAN_ARG="$TORTURE_KCONFIG_KASAN_ARG"; export TORTURE_KCONFIG_KASAN_ARG 401TORTURE_KCONFIG_KCSAN_ARG="$TORTURE_KCONFIG_KCSAN_ARG"; export TORTURE_KCONFIG_KCSAN_ARG 402TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG 403TORTURE_MOD="$TORTURE_MOD"; export TORTURE_MOD 404TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD 405TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE 406TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC 407TORTURE_QEMU_MEM="$TORTURE_QEMU_MEM"; export TORTURE_QEMU_MEM 408TORTURE_SHUTDOWN_GRACE="$TORTURE_SHUTDOWN_GRACE"; export TORTURE_SHUTDOWN_GRACE 409TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE 410TORTURE_TRUST_MAKE="$TORTURE_TRUST_MAKE"; export TORTURE_TRUST_MAKE 411if ! test -e $resdir 412then 413 mkdir -p "$resdir" || : 414fi 415mkdir -p $resdir/$ds 416TORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR 417TORTURE_STOPFILE="$resdir/$ds/STOP.1"; export TORTURE_STOPFILE 418echo Results directory: $resdir/$ds 419echo $scriptname $args 420touch $resdir/$ds/log 421echo $scriptname $args >> $resdir/$ds/log 422echo ${TORTURE_SUITE} > $resdir/$ds/torture_suite 423echo Build directory: `pwd` > $resdir/$ds/testid.txt 424if test -d .git 425then 426 echo Current commit: `git rev-parse HEAD` >> $resdir/$ds/testid.txt 427 echo >> $resdir/$ds/testid.txt 428 echo ' ---' Output of "'"git status"'": >> $resdir/$ds/testid.txt 429 git status >> $resdir/$ds/testid.txt 430 echo >> $resdir/$ds/testid.txt 431 echo >> $resdir/$ds/testid.txt 432 echo ' ---' Output of "'"git diff HEAD"'": >> $resdir/$ds/testid.txt 433 git diff HEAD >> $resdir/$ds/testid.txt 434fi 435___EOF___ 436kvm-assign-cpus.sh /sys/devices/system/node > $T/cpuarray.awk 437kvm-get-cpus-script.sh $T/cpuarray.awk $T/dumpbatches.awk 438cat << '___EOF___' >> $T/dumpbatches.awk 439BEGIN { 440 i = 0; 441} 442 443{ 444 cf[i] = $1; 445 cpus[i] = $2; 446 i++; 447} 448 449# Dump out the scripting required to run one test batch. 450function dump(first, pastlast, batchnum, affinitylist) 451{ 452 print "echo ----Start batch " batchnum ": `date` | tee -a " rd "log"; 453 print "needqemurun=" 454 jn=1 455 njitter = 0; 456 split(jitter, ja); 457 if (ja[1] == -1 && ncpus == 0) 458 njitter = 1; 459 else if (ja[1] == -1) 460 njitter = ncpus; 461 else 462 njitter = ja[1]; 463 print "TORTURE_JITTER_START=\". jitterstart.sh " njitter " " rd " " dur " " ja[2] " " ja[3] "\"; export TORTURE_JITTER_START"; 464 print "TORTURE_JITTER_STOP=\". jitterstop.sh " rd " \"; export TORTURE_JITTER_STOP" 465 for (j = first; j < pastlast; j++) { 466 cpusr[jn] = cpus[j]; 467 if (cfrep[cf[j]] == "") { 468 cfr[jn] = cf[j]; 469 cfrep[cf[j]] = 1; 470 } else { 471 cfrep[cf[j]]++; 472 cfr[jn] = cf[j] "." cfrep[cf[j]]; 473 } 474 builddir=rd cfr[jn] "/build"; 475 if (cpusr[jn] > ncpus && ncpus != 0) 476 ovf = "-ovf"; 477 else 478 ovf = ""; 479 print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` | tee -a " rd "log"; 480 print "mkdir " rd cfr[jn] " || :"; 481 print "touch " builddir ".wait"; 482 affinitylist = ""; 483 if (gotcpus()) { 484 affinitylist = nextcpus(cpusr[jn]); 485 } 486 if (affinitylist ~ /^[0-9,-][0-9,-]*$/) 487 print "export TORTURE_AFFINITY=" affinitylist; 488 else 489 print "export TORTURE_AFFINITY="; 490 print "kvm-test-1-run.sh " CONFIGDIR cf[j], rd cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &" 491 print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` | tee -a " rd "log"; 492 print "while test -f " builddir ".wait" 493 print "do" 494 print "\tsleep 1" 495 print "done" 496 print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` | tee -a " rd "log"; 497 jn++; 498 } 499 print "runfiles=" 500 for (j = 1; j < jn; j++) { 501 builddir=rd cfr[j] "/build"; 502 if (TORTURE_BUILDONLY) 503 print "rm -f " builddir ".ready" 504 else 505 print "mv " builddir ".ready " builddir ".run" 506 print "runfiles=\"$runfiles " builddir ".run\"" 507 fi 508 print "if test -f \"" rd cfr[j] "/builtkernel\"" 509 print "then" 510 print "\techo ----", cfr[j], cpusr[j] ovf ": Kernel present. `date` | tee -a " rd "log"; 511 print "\tneedqemurun=1" 512 print "fi" 513 } 514 if (TORTURE_BUILDONLY && njitter != 0) { 515 njitter = 0; 516 print "echo Build-only run, so suppressing jitter | tee -a " rd "log" 517 } 518 if (TORTURE_BUILDONLY) { 519 print "needqemurun=" 520 } 521 print "if test -n \"$needqemurun\"" 522 print "then" 523 print "\techo ---- Starting kernels. `date` | tee -a " rd "log"; 524 print "\t$TORTURE_JITTER_START"; 525 print "\twhile ls $runfiles > /dev/null 2>&1" 526 print "\tdo" 527 print "\t\t:" 528 print "\tdone" 529 print "\t$TORTURE_JITTER_STOP"; 530 print "\techo ---- All kernel runs complete. `date` | tee -a " rd "log"; 531 print "else" 532 print "\twait" 533 print "\techo ---- No kernel runs. `date` | tee -a " rd "log"; 534 print "fi" 535 for (j = 1; j < jn; j++) { 536 print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: | tee -a " rd "log"; 537 print "cat " rd cfr[j] "/kvm-test-1-run.sh.out | tee -a " rd "log"; 538 } 539} 540 541END { 542 njobs = i; 543 nc = ncpus; 544 first = 0; 545 batchnum = 1; 546 547 # Each pass through the following loop considers one test. 548 for (i = 0; i < njobs; i++) { 549 if (ncpus == 0) { 550 # Sequential test specified, each test its own batch. 551 dump(i, i + 1, batchnum); 552 first = i; 553 batchnum++; 554 } else if (nc < cpus[i] && i != 0) { 555 # Out of CPUs, dump out a batch. 556 dump(first, i, batchnum); 557 first = i; 558 nc = ncpus; 559 batchnum++; 560 } 561 # Account for the CPUs needed by the current test. 562 nc -= cpus[i]; 563 } 564 # Dump the last batch. 565 if (ncpus != 0) 566 dump(first, i, batchnum); 567} 568___EOF___ 569awk < $T/cfgcpu.pack \ 570 -v TORTURE_BUILDONLY="$TORTURE_BUILDONLY" \ 571 -v CONFIGDIR="$CONFIGFRAG/" \ 572 -v KVM="$KVM" \ 573 -v ncpus=$cpus \ 574 -v jitter="$jitter" \ 575 -v rd=$resdir/$ds/ \ 576 -v dur=$dur \ 577 -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \ 578 -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \ 579 -f $T/dumpbatches.awk >> $T/script 580echo kvm-end-run-stats.sh "$resdir/$ds" "$starttime" >> $T/script 581 582# Extract the tests and their batches from the script. 583egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" | 584 sed -e 's/:.*$//' -e 's/^echo //' -e 's/-ovf//' | 585 awk ' 586 /^----Start/ { 587 batchno = $3; 588 next; 589 } 590 { 591 print batchno, $1, $2 592 }' > $T/batches 593 594# As above, but one line per batch. 595grep -v '^#' $T/batches | awk ' 596BEGIN { 597 oldbatch = 1; 598} 599 600{ 601 if (oldbatch != $1) { 602 print ++n ". " curbatch; 603 curbatch = ""; 604 oldbatch = $1; 605 } 606 curbatch = curbatch " " $2; 607} 608 609END { 610 print ++n ". " curbatch; 611}' > $T/scenarios 612 613if test "$dryrun" = script 614then 615 cat $T/script 616 exit 0 617elif test "$dryrun" = sched 618then 619 # Extract the test run schedule from the script. 620 egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" | 621 sed -e 's/:.*$//' -e 's/^echo //' 622 nbuilds="`grep 'Starting build\.' $T/script | 623 grep -v ">>" | sed -e 's/:.*$//' -e 's/^echo //' | 624 awk '{ print $1 }' | grep -v '\.' | wc -l`" 625 echo Total number of builds: $nbuilds 626 nbatches="`grep 'Start batch' $T/script | grep -v ">>" | wc -l`" 627 echo Total number of batches: $nbatches 628 exit 0 629elif test "$dryrun" = batches 630then 631 cat $T/batches 632 exit 0 633elif test "$dryrun" = scenarios 634then 635 cat $T/scenarios 636 exit 0 637else 638 # Not a dryrun. Record the batches and the number of CPUs, then run the script. 639 bash $T/script 640 ret=$? 641 cp $T/batches $resdir/$ds/batches 642 cp $T/scenarios $resdir/$ds/scenarios 643 echo '#' cpus=$cpus >> $resdir/$ds/batches 644 exit $ret 645fi 646 647# 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 648# Function-graph tracing: ftrace=function_graph ftrace_graph_filter=sched_setaffinity,migration_cpu_stop 649# Also --kconfig "CONFIG_FUNCTION_TRACER=y CONFIG_FUNCTION_GRAPH_TRACER=y" 650# Control buffer size: --bootargs trace_buf_size=3k 651# Get trace-buffer dumps on all oopses: --bootargs ftrace_dump_on_oops 652# Ditto, but dump only the oopsing CPU: --bootargs ftrace_dump_on_oops=orig_cpu 653# Heavy-handed way to also dump on warnings: --bootargs panic_on_warn 654