staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / rcutorture / bin / jitter.sh
blobdc49a3ba6111ec8f3323dfa0eebb74a58f47b43f
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
4 # Alternate sleeping and spinning on randomly selected CPUs. The purpose
5 # of this script is to inflict random OS jitter on a concurrently running
6 # test.
8 # Usage: jitter.sh me duration [ sleepmax [ spinmax ] ]
10 # me: Random-number-generator seed salt.
11 # duration: Time to run in seconds.
12 # sleepmax: Maximum microseconds to sleep, defaults to one second.
13 # spinmax: Maximum microseconds to spin, defaults to one millisecond.
15 # Copyright (C) IBM Corporation, 2016
17 # Authors: Paul E. McKenney <paulmck@linux.ibm.com>
19 me=$(($1 * 1000))
20 duration=$2
21 sleepmax=${3-1000000}
22 spinmax=${4-1000}
24 n=1
26 starttime=`awk 'BEGIN { print systime(); }' < /dev/null`
28 while :
30 # Check for done.
31 t=`awk -v s=$starttime 'BEGIN { print systime() - s; }' < /dev/null`
32 if test "$t" -gt "$duration"
33 then
34 exit 0;
37 # Set affinity to randomly selected online CPU
38 cpus=`grep 1 /sys/devices/system/cpu/*/online |
39 sed -e 's,/[^/]*$,,' -e 's/^[^0-9]*//'`
41 # Do not leave out poor old cpu0 which may not be hot-pluggable
42 if [ ! -f "/sys/devices/system/cpu/cpu0/online" ]; then
43 cpus="0 $cpus"
46 cpumask=`awk -v cpus="$cpus" -v me=$me -v n=$n 'BEGIN {
47 srand(n + me + systime());
48 ncpus = split(cpus, ca);
49 curcpu = ca[int(rand() * ncpus + 1)];
50 mask = lshift(1, curcpu);
51 if (mask + 0 <= 0)
52 mask = 1;
53 printf("%#x\n", mask);
54 }' < /dev/null`
55 n=$(($n+1))
56 if ! taskset -p $cpumask $$ > /dev/null 2>&1
57 then
58 echo taskset failure: '"taskset -p ' $cpumask $$ '"'
59 exit 1
62 # Sleep a random duration
63 sleeptime=`awk -v me=$me -v n=$n -v sleepmax=$sleepmax 'BEGIN {
64 srand(n + me + systime());
65 printf("%06d", int(rand() * sleepmax));
66 }' < /dev/null`
67 n=$(($n+1))
68 sleep .$sleeptime
70 # Spin a random duration
71 limit=`awk -v me=$me -v n=$n -v spinmax=$spinmax 'BEGIN {
72 srand(n + me + systime());
73 printf("%06d", int(rand() * spinmax));
74 }' < /dev/null`
75 n=$(($n+1))
76 for i in {1..$limit}
78 echo > /dev/null
79 done
80 done
82 exit 1