Path: blob/master/tools/testing/selftests/cgroup/with_stress.sh
26285 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.023# Kselftest framework requirement - SKIP code is 4.4ksft_skip=456stress_fork()7{8while true ; do9/usr/bin/true10sleep 0.0111done12}1314stress_subsys()15{16local verb=+17while true ; do18echo $verb$subsys_ctrl >$sysfs/cgroup.subtree_control19[ $verb = "+" ] && verb=- || verb=+20# incommensurable period with other stresses21sleep 0.01122done23}2425init_and_check()26{27sysfs=`mount -t cgroup2 | head -1 | awk '{ print $3 }'`28if [ ! -d "$sysfs" ]; then29echo "Skipping: cgroup2 is not mounted" >&230exit $ksft_skip31fi3233if ! echo +$subsys_ctrl >$sysfs/cgroup.subtree_control ; then34echo "Skipping: cannot enable $subsys_ctrl in $sysfs" >&235exit $ksft_skip36fi3738if ! echo -$subsys_ctrl >$sysfs/cgroup.subtree_control ; then39echo "Skipping: cannot disable $subsys_ctrl in $sysfs" >&240exit $ksft_skip41fi42}4344declare -a stresses45declare -a stress_pids46duration=547rc=048subsys_ctrl=cpuset49sysfs=5051while getopts c:d:hs: opt; do52case $opt in53c)54subsys_ctrl=$OPTARG55;;56d)57duration=$OPTARG58;;59h)60echo "Usage $0 [ -s stress ] ... [ -d duration ] [-c controller] cmd args .."61echo -e "\t default duration $duration seconds"62echo -e "\t default controller $subsys_ctrl"63exit64;;65s)66func=stress_$OPTARG67if [ "x$(type -t $func)" != "xfunction" ] ; then68echo "Unknown stress $OPTARG"69exit 170fi71stresses+=($func)72;;73esac74done75shift $((OPTIND - 1))7677init_and_check7879for s in ${stresses[*]} ; do80$s &81stress_pids+=($!)82done838485time=086start=$(date +%s)8788while [ $time -lt $duration ] ; do89$*90rc=$?91[ $rc -eq 0 ] || break92time=$(($(date +%s) - $start))93done9495for pid in ${stress_pids[*]} ; do96kill -SIGTERM $pid97wait $pid98done99100exit $rc101102103