cgroup_fj_stress.sh revision a83bb15f92610c30e458a5edabe6de15a2fc138b
1#!/bin/bash 2 3################################################################################ 4## ## 5## Copyright (c) 2009 FUJITSU LIMITED ## 6## ## 7## This program is free software; you can redistribute it and#or modify ## 8## it under the terms of the GNU General Public License as published by ## 9## the Free Software Foundation; either version 2 of the License, or ## 10## (at your option) any later version. ## 11## ## 12## This program is distributed in the hope that it will be useful, but ## 13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 14## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 15## for more details. ## 16## ## 17## You should have received a copy of the GNU General Public License ## 18## along with this program; if not, write to the Free Software ## 19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 20## ## 21## Author: Shi Weihua <shiwh@cn.fujitsu.com> ## 22## ## 23################################################################################ 24 25subsystem=$1 # 1: debug 26 # 2: cpuset 27 # 3: ns 28 # 4: cpu 29 # 5: cpuacct 30 # 6: memory 31 # 7: all 32mount_times=$2 #1: execute once 33 #2: execute 100 times 34subgroup_num=$3 #subgroup number in the same hierarchy 35 #1: 1 36 #2: 100 37subgroup_hiers=$4 #number of subgroup's hierarchy 38 #1: 1 39 #2: 100 40attach_operation=$5 # 1: attach one process to every subcgroup 41 # 2: attach all processes in root group to one subcgroup 42 # 3: attach all processes in root group to every subcgroup 43mounted=1 44 45usage() 46{ 47 echo "usage of cgroup_fj_stress.sh: " 48 echo " ./cgroup_fj_stress.sh -subsystem -mount_times -subgroup_num -subgroup_hiers -attach_operation" 49 echo " subsystem's usable number" 50 echo " debug" 51 echo " cpuset" 52 echo " ns" 53 echo " cpu" 54 echo " cpuacct" 55 echo " memory" 56 echo " all" 57 echo " mount_times's usable number" 58 echo " 1: execute once" 59 echo " 100: execute 100 times" 60 echo " subgroup_num's usable number" 61 echo " (subgroup number in the same hierarchy)" 62 echo " 1" 63 echo " 100" 64 echo " subgroup_hiers's usable number" 65 echo " (number of subgroup's hierarchy)" 66 echo " 1" 67 echo " 100" 68 echo " attach_operation's usable number" 69 echo " 1: attach one process to every subcgroup" 70 echo " 2: attach all processes in root group to one subcgroup" 71 echo " 3: attach all processes in root group to every subcgroup" 72 echo "example: ./cgroup_fj_stress.sh debug 1 1 1 1" 73 echo " will use "debug" to test, will mount once, will create one subgroup in same hierarchy," 74 echo " will create one hierarchy, will attach one process to every subcgroup" 75} 76 77exit_parameter() 78{ 79 echo "ERROR: Wrong input parameters... Exiting test" 80 exit -1; 81} 82 83export TESTROOT=`pwd` 84export TMPFILE=$TESTROOT/tmp_tasks 85 86. $TESTROOT/cgroup_fj_utility.sh 87 88pid=0; 89release_agent_para=1; 90release_agent_echo=1; 91subsystem_str=$subsystem; 92if [ "$?" -ne "0" ] || [ "$#" -ne "5" ]; then 93 usage; 94 exit_parameter; 95fi 96remount_use_str=""; 97noprefix_use_str=""; 98release_agent_para_str=""; 99ulimit_u=`ulimit -u` 100no_debug=1 101cur_subgroup_path1="" 102cur_subgroup_path2="" 103 104get_subgroup_path1() 105{ 106 cur_subgroup_path1="" 107 if [ "$#" -ne 1 ] || [ "$1" -lt 1 ] || [ "$1" -gt $ulimit_u ]; then 108 return; 109 fi 110 111 cur_subgroup_path1="$mount_point/ltp_subgroup_$1/" 112} 113 114get_subgroup_path2() 115{ 116 cur_subgroup_path2="" 117 if [ "$#" -ne 1 ] || [ "$1" -lt 2 ] || [ "$1" -gt $ulimit_u ]; then 118 return; 119 fi 120 121 for i in `seq 2 $1` 122 do 123 cur_subgroup_path2="$cur_subgroup_path2""s/" 124 done 125} 126 127case $mount_times in 128''|*[!0-9]*) 129 usage 130 exit_parameter;; 131 *) ;; 132esac 133 134case $subgroup_num in 135''|*[!0-9]*) 136 usage 137 exit_parameter;; 138 *) ;; 139esac 140 141case $subgroup_hiers in 142''|*[!0-9]*) 143 usage 144 exit_parameter;; 145 *) ;; 146esac 147 148########################## main ####################### 149 150if ! [ "$subsystem" == "all" ] && ! [ "$subsystem" == "none" ] ; then 151 exist_subsystem; 152fi 153 154setup; 155 156$TESTROOT/cgroup_fj_proc & 157pid=$! 158 159cpus=0 160mems=0 161exist_cpuset=0 162exist_cpuset=`grep -w cpuset /proc/cgroups | cut -f1`; 163if [ "$subsystem" == "cpuset" ] || [ "$subsystem" == "all" ] ; then 164 if [ "$exist_cpuset" != "" ]; then 165 cpus=`cat $mount_point/cpuset.cpus` 166 mems=`cat $mount_point/cpuset.mems` 167 fi 168fi 169 170mkdir_subgroup; 171 172# cpuset.cpus and cpuset.mems should be specified with suitable value 173# before attachint operation if subsystem is cpuset 174if [ "$subsystem" == "cpuset" ] || [ "$subsystem" == "all" ] ; then 175 if [ "$exist_cpuset" != "" ]; then 176 do_echo 1 1 "$cpus" $mount_point/ltp_subgroup_1/cpuset.cpus; 177 do_echo 1 1 "$mems" $mount_point/ltp_subgroup_1/cpuset.mems; 178 fi 179fi 180 181if [ $mount_times -ne 1 ]; then 182 count=0 183 for i in `seq 1 $mount_times` 184 do 185 do_echo 1 1 $pid $mount_point/ltp_subgroup_1/tasks 186 if [ "$subsystem" == "ns" ] || [ "$subsystem" == "all" ] ; then 187 do_kill 1 1 9 $pid 188 $TESTROOT/cgroup_fj_proc & 189 pid=$! 190 else 191 do_echo 1 1 $pid $mount_point/tasks 192 fi 193 setup; 194 $TESTROOT/cgroup_fj_proc & 195 pid=$! 196 if [ $mounted -ne 1 ]; then 197 mount_cgroup; 198 fi 199 mkdir_subgroup; 200 if [ "$subsystem" == "cpuset" ] || [ "$subsystem" == "all" ] ; then 201 if [ "$exist_cpuset" != "" ]; then 202 do_echo 1 1 "$cpus" $mount_point/ltp_subgroup_1/cpuset.cpus; 203 do_echo 1 1 "$mems" $mount_point/ltp_subgroup_1/cpuset.mems; 204 fi 205 fi 206 let "count = $count + 1" 207 echo "$count .. OK" 208 done 209 echo "...executed $count times" 210else 211 get_subgroup_path2 $subgroup_hiers 212 count=0 213 pathes[1]="" 214 for i in `seq 1 $subgroup_num` 215 do 216 get_subgroup_path1 $i 217 do_mkdir 1 1 $cur_subgroup_path1 218 if [ "$subsystem" == "cpuset" ] || [ "$subsystem" == "all" ] ; then 219 if [ "$exist_cpuset" != "" ]; then 220 do_echo 1 1 "$cpus" "$cur_subgroup_path1""cpuset.cpus"; 221 do_echo 1 1 "$mems" "$cur_subgroup_path1""cpuset.mems"; 222 fi 223 fi 224 let "count = $count + 1" 225 pathes[$count]="$cur_subgroup_path1" 226 for j in `seq 2 $subgroup_hiers` 227 do 228 get_subgroup_path2 $j 229 do_mkdir 1 1 "$cur_subgroup_path1""$cur_subgroup_path2" 1 230 if [ "$subsystem" == "cpuset" ] || [ "$subsystem" == "all" ] ; then 231 if [ "$exist_cpuset" != "" ]; then 232 do_echo 1 1 "$cpus" "$cur_subgroup_path1""$cur_subgroup_path2""cpuset.cpus"; 233 do_echo 1 1 "$mems" "$cur_subgroup_path1""$cur_subgroup_path2""cpuset.mems"; 234 fi 235 fi 236 let "count = $count + 1" 237 pathes[$count]="$cur_subgroup_path1""$cur_subgroup_path2" 238 done 239 done 240 echo "...mkdired $count times" 241 242 sleep 1 243 244 case $attach_operation in 245 "1" ) 246 for i in `seq 1 $count` 247 do 248 do_echo 1 1 $pid "${pathes[$i]}""tasks" 249 done 250 do_echo 1 1 $pid $mount_point/tasks 251 ;; 252 "2" ) 253 pathes2[0]="$mount_point" 254 pathes2[1]="${pathes[$count]}" 255 pathes2[3]="$mount_point/" 256 for i in `seq 1 $nlines` 257 do 258 j=$i 259 let "j = $j + 1" 260 cat "${pathes2[$i]}tasks" > $TMPFILE 261 nlines=`cat "$TMPFILE" | wc -l` 262 if [ $no_debug -ne 1 ]; then 263 echo "DEBUG: move $nlines processes from "$i"th path to "$j"th" 264 fi 265 for k in `seq 1 $nlines` 266 do 267 cur_pid=`sed -n "$k""p" $TMPFILE` 268 if [ -e /proc/$cur_pid/ ];then 269 do_echo 0 1 "$cur_pid" "${pathes[$j]}tasks" 270 fi 271 done 272 done 273 ;; 274 "3" ) 275 count2=$count 276 let "count2 = $count2 + 1" 277 pathes[0]="$mount_point/" 278 pathes[$count2]="$mount_point/" 279 for i in `seq 0 $count` 280 do 281 j=$i 282 let "j = $j + 1" 283 cat "${pathes[$i]}tasks" > $TMPFILE 284 nlines=`cat "$TMPFILE" | wc -l` 285 if [ $no_debug -ne 1 ]; then 286 echo "DEBUG: move $nlines processes from "$i"th path to "$j"th" 287 fi 288 for k in `seq 1 $nlines` 289 do 290 cur_pid=`sed -n "$k""p" $TMPFILE` 291 if [ -e /proc/$cur_pid/ ];then 292 do_echo 0 1 "$cur_pid" "${pathes[$j]}tasks" 293 fi 294 done 295 done 296 ;; 297 * ) 298 ;; 299 esac 300 reclaim_foundling; 301 for i in `seq 1 $count` 302 do 303 j=i 304 let "j = $count - $j + 1" 305 do_rmdir 1 1 ${pathes[$j]} 306 done 307fi 308 309do_rmdir 0 1 $mount_point/ltp_subgroup_* 310 311sleep 1 312 313cleanup; 314do_kill 1 1 9 $pid 315sleep 1 316exit 0; 317