~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/rcutorture/bin/jitter.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0+
  3 #
  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.
  7 #
  8 # Usage: jitter.sh me jittering-path duration [ sleepmax [ spinmax ] ]
  9 #
 10 # me: Random-number-generator seed salt.
 11 # duration: Time to run in seconds.
 12 # jittering-path: Path to file whose removal will stop this script.
 13 # sleepmax: Maximum microseconds to sleep, defaults to one second.
 14 # spinmax: Maximum microseconds to spin, defaults to one millisecond.
 15 #
 16 # Copyright (C) IBM Corporation, 2016
 17 #
 18 # Authors: Paul E. McKenney <paulmck@linux.ibm.com>
 19 
 20 me=$(($1 * 1000))
 21 jittering=$2
 22 duration=$3
 23 sleepmax=${4-1000000}
 24 spinmax=${5-1000}
 25 
 26 n=1
 27 
 28 starttime=`gawk 'BEGIN { print systime(); }' < /dev/null`
 29 
 30 nohotplugcpus=
 31 for i in /sys/devices/system/cpu/cpu[0-9]*
 32 do
 33         if test -f $i/online
 34         then
 35                 :
 36         else
 37                 curcpu=`echo $i | sed -e 's/^[^0-9]*//'`
 38                 nohotplugcpus="$nohotplugcpus $curcpu"
 39         fi
 40 done
 41 
 42 while :
 43 do
 44         # Check for done.
 45         t=`gawk -v s=$starttime 'BEGIN { print systime() - s; }' < /dev/null`
 46         if test "$t" -gt "$duration"
 47         then
 48                 exit 0;
 49         fi
 50 
 51         # Check for stop request.
 52         if ! test -f "$jittering"
 53         then
 54                 exit 1;
 55         fi
 56 
 57         # Set affinity to randomly selected online CPU
 58         if cpus=`grep 1 /sys/devices/system/cpu/*/online 2>&1 |
 59                  sed -e 's,/[^/]*$,,' -e 's/^[^0-9]*//'`
 60         then
 61                 :
 62         else
 63                 cpus=
 64         fi
 65         # Do not leave out non-hot-pluggable CPUs
 66         cpus="$cpus $nohotplugcpus"
 67 
 68         cpumask=`awk -v cpus="$cpus" -v me=$me -v n=$n 'BEGIN {
 69                 srand(n + me + systime());
 70                 ncpus = split(cpus, ca);
 71                 print ca[int(rand() * ncpus + 1)];
 72         }' < /dev/null`
 73         n=$(($n+1))
 74         if ! taskset -c -p $cpumask $$ > /dev/null 2>&1
 75         then
 76                 echo taskset failure: '"taskset -c -p ' $cpumask $$ '"'
 77                 exit 1
 78         fi
 79 
 80         # Sleep a random duration
 81         sleeptime=`awk -v me=$me -v n=$n -v sleepmax=$sleepmax 'BEGIN {
 82                 srand(n + me + systime());
 83                 printf("%06d", int(rand() * sleepmax));
 84         }' < /dev/null`
 85         n=$(($n+1))
 86         sleep .$sleeptime
 87 
 88         # Spin a random duration
 89         limit=`awk -v me=$me -v n=$n -v spinmax=$spinmax 'BEGIN {
 90                 srand(n + me + systime());
 91                 printf("%06d", int(rand() * spinmax));
 92         }' < /dev/null`
 93         n=$(($n+1))
 94         for i in {1..$limit}
 95         do
 96                 echo > /dev/null
 97         done
 98 done
 99 
100 exit 1

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php