0001
0002
0003
0004
0005 ksft_skip=4
0006
0007 stress_fork()
0008 {
0009 while true ; do
0010 /usr/bin/true
0011 sleep 0.01
0012 done
0013 }
0014
0015 stress_subsys()
0016 {
0017 local verb=+
0018 while true ; do
0019 echo $verb$subsys_ctrl >$sysfs/cgroup.subtree_control
0020 [ $verb = "+" ] && verb=- || verb=+
0021
0022 sleep 0.011
0023 done
0024 }
0025
0026 init_and_check()
0027 {
0028 sysfs=`mount -t cgroup2 | head -1 | awk '{ print $3 }'`
0029 if [ ! -d "$sysfs" ]; then
0030 echo "Skipping: cgroup2 is not mounted" >&2
0031 exit $ksft_skip
0032 fi
0033
0034 if ! echo +$subsys_ctrl >$sysfs/cgroup.subtree_control ; then
0035 echo "Skipping: cannot enable $subsys_ctrl in $sysfs" >&2
0036 exit $ksft_skip
0037 fi
0038
0039 if ! echo -$subsys_ctrl >$sysfs/cgroup.subtree_control ; then
0040 echo "Skipping: cannot disable $subsys_ctrl in $sysfs" >&2
0041 exit $ksft_skip
0042 fi
0043 }
0044
0045 declare -a stresses
0046 declare -a stress_pids
0047 duration=5
0048 rc=0
0049 subsys_ctrl=cpuset
0050 sysfs=
0051
0052 while getopts c:d:hs: opt; do
0053 case $opt in
0054 c)
0055 subsys_ctrl=$OPTARG
0056 ;;
0057 d)
0058 duration=$OPTARG
0059 ;;
0060 h)
0061 echo "Usage $0 [ -s stress ] ... [ -d duration ] [-c controller] cmd args .."
0062 echo -e "\t default duration $duration seconds"
0063 echo -e "\t default controller $subsys_ctrl"
0064 exit
0065 ;;
0066 s)
0067 func=stress_$OPTARG
0068 if [ "x$(type -t $func)" != "xfunction" ] ; then
0069 echo "Unknown stress $OPTARG"
0070 exit 1
0071 fi
0072 stresses+=($func)
0073 ;;
0074 esac
0075 done
0076 shift $((OPTIND - 1))
0077
0078 init_and_check
0079
0080 for s in ${stresses[*]} ; do
0081 $s &
0082 stress_pids+=($!)
0083 done
0084
0085
0086 time=0
0087 start=$(date +%s)
0088
0089 while [ $time -lt $duration ] ; do
0090 $*
0091 rc=$?
0092 [ $rc -eq 0 ] || break
0093 time=$(($(date +%s) - $start))
0094 done
0095
0096 for pid in ${stress_pids[*]} ; do
0097 kill -SIGTERM $pid
0098 wait $pid
0099 done
0100
0101 exit $rc