.. | .. |
---|
1 | 1 | #!/bin/bash |
---|
| 2 | +# SPDX-License-Identifier: GPL-2.0+ |
---|
2 | 3 | # |
---|
3 | 4 | # Alternate sleeping and spinning on randomly selected CPUs. The purpose |
---|
4 | 5 | # of this script is to inflict random OS jitter on a concurrently running |
---|
.. | .. |
---|
11 | 12 | # sleepmax: Maximum microseconds to sleep, defaults to one second. |
---|
12 | 13 | # spinmax: Maximum microseconds to spin, defaults to one millisecond. |
---|
13 | 14 | # |
---|
14 | | -# This program is free software; you can redistribute it and/or modify |
---|
15 | | -# it under the terms of the GNU General Public License as published by |
---|
16 | | -# the Free Software Foundation; either version 2 of the License, or |
---|
17 | | -# (at your option) any later version. |
---|
18 | | -# |
---|
19 | | -# This program is distributed in the hope that it will be useful, |
---|
20 | | -# but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
22 | | -# GNU General Public License for more details. |
---|
23 | | -# |
---|
24 | | -# You should have received a copy of the GNU General Public License |
---|
25 | | -# along with this program; if not, you can access it online at |
---|
26 | | -# http://www.gnu.org/licenses/gpl-2.0.html. |
---|
27 | | -# |
---|
28 | 15 | # Copyright (C) IBM Corporation, 2016 |
---|
29 | 16 | # |
---|
30 | | -# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> |
---|
| 17 | +# Authors: Paul E. McKenney <paulmck@linux.ibm.com> |
---|
31 | 18 | |
---|
32 | 19 | me=$(($1 * 1000)) |
---|
33 | 20 | duration=$2 |
---|
.. | .. |
---|
36 | 23 | |
---|
37 | 24 | n=1 |
---|
38 | 25 | |
---|
39 | | -starttime=`awk 'BEGIN { print systime(); }' < /dev/null` |
---|
| 26 | +starttime=`gawk 'BEGIN { print systime(); }' < /dev/null` |
---|
| 27 | + |
---|
| 28 | +nohotplugcpus= |
---|
| 29 | +for i in /sys/devices/system/cpu/cpu[0-9]* |
---|
| 30 | +do |
---|
| 31 | + if test -f $i/online |
---|
| 32 | + then |
---|
| 33 | + : |
---|
| 34 | + else |
---|
| 35 | + curcpu=`echo $i | sed -e 's/^[^0-9]*//'` |
---|
| 36 | + nohotplugcpus="$nohotplugcpus $curcpu" |
---|
| 37 | + fi |
---|
| 38 | +done |
---|
40 | 39 | |
---|
41 | 40 | while : |
---|
42 | 41 | do |
---|
43 | 42 | # Check for done. |
---|
44 | | - t=`awk -v s=$starttime 'BEGIN { print systime() - s; }' < /dev/null` |
---|
| 43 | + t=`gawk -v s=$starttime 'BEGIN { print systime() - s; }' < /dev/null` |
---|
45 | 44 | if test "$t" -gt "$duration" |
---|
46 | 45 | then |
---|
47 | 46 | exit 0; |
---|
48 | 47 | fi |
---|
49 | 48 | |
---|
50 | | - # Set affinity to randomly selected CPU |
---|
51 | | - cpus=`ls /sys/devices/system/cpu/*/online | |
---|
52 | | - sed -e 's,/[^/]*$,,' -e 's/^[^0-9]*//' | |
---|
53 | | - grep -v '^0*$'` |
---|
| 49 | + # Check for stop request. |
---|
| 50 | + if test -f "$TORTURE_STOPFILE" |
---|
| 51 | + then |
---|
| 52 | + exit 1; |
---|
| 53 | + fi |
---|
| 54 | + |
---|
| 55 | + # Set affinity to randomly selected online CPU |
---|
| 56 | + if cpus=`grep 1 /sys/devices/system/cpu/*/online 2>&1 | |
---|
| 57 | + sed -e 's,/[^/]*$,,' -e 's/^[^0-9]*//'` |
---|
| 58 | + then |
---|
| 59 | + : |
---|
| 60 | + else |
---|
| 61 | + cpus= |
---|
| 62 | + fi |
---|
| 63 | + # Do not leave out non-hot-pluggable CPUs |
---|
| 64 | + cpus="$cpus $nohotplugcpus" |
---|
| 65 | + |
---|
54 | 66 | cpumask=`awk -v cpus="$cpus" -v me=$me -v n=$n 'BEGIN { |
---|
55 | 67 | srand(n + me + systime()); |
---|
56 | 68 | ncpus = split(cpus, ca); |
---|