forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/tools/testing/selftests/rcutorture/bin/jitter.sh
....@@ -1,4 +1,5 @@
11 #!/bin/bash
2
+# SPDX-License-Identifier: GPL-2.0+
23 #
34 # Alternate sleeping and spinning on randomly selected CPUs. The purpose
45 # of this script is to inflict random OS jitter on a concurrently running
....@@ -11,23 +12,9 @@
1112 # sleepmax: Maximum microseconds to sleep, defaults to one second.
1213 # spinmax: Maximum microseconds to spin, defaults to one millisecond.
1314 #
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
-#
2815 # Copyright (C) IBM Corporation, 2016
2916 #
30
-# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
17
+# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
3118
3219 me=$(($1 * 1000))
3320 duration=$2
....@@ -36,21 +23,46 @@
3623
3724 n=1
3825
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
4039
4140 while :
4241 do
4342 # 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`
4544 if test "$t" -gt "$duration"
4645 then
4746 exit 0;
4847 fi
4948
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
+
5466 cpumask=`awk -v cpus="$cpus" -v me=$me -v n=$n 'BEGIN {
5567 srand(n + me + systime());
5668 ncpus = split(cpus, ca);