parameters.sh revision 9073840d951e26db57af6a14a10ff0dc006642c9
1#!/bin/bash 2# usage ./parameters.sh 3 4################################################################################# 5# Copyright (c) International Business Machines Corp., 2007 # 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, # 13# but WITHOUT ANY WARRANTY; without even the implied warranty of # 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # 15# the GNU General Public License 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20# # 21################################################################################# 22# Name Of File: parameters.sh # 23# # 24# Description: This file has functions for the setup for testing cpucontroller # 25# setup includes creating controller device, mounting it with # 26# cgroup filesystem with option cpu and creating groups in it. # 27# # 28# Functions: get_num_groups(): decides number of groups based on num of cpus # 29# setup(): creaes /dev/cpuctl, mounts cgroup fs on it, creates # 30# groups in that, creates fifo to fire tasks at one time. # 31# cleanup(): Does full system cleanup # 32# # 33# Author: Sudhir Kumar <skumar@linux.vnet.ibm.com> # 34# # 35# History: # 36# # 37# DATE NAME EMAIL DESC # 38# # 39# 20/12/07 Sudhir Kumar <skumar@linux.vnet.ibm.com> Created this test # 40# # 41################################################################################# 42 43 44set_def_group() #default group spinning a task to create ideal scenario 45{ 46 [ -d /dev/cpuctl/group_def ] || mkdir /dev/cpuctl/group_def; 47 if [ $? -ne 0 ] 48 then 49 echo "ERROR: Can't create default group... " 50 "Check your permissions..Exiting test"; 51 cleanup; 52 exit -1; 53 fi 54 # Migrate all the running tasks to this group 55 # rt tasks require a finite value to cpu.rt_runtime_us 56 echo 10000 > /dev/cpuctl/group_def/cpu.rt_runtime_us; 57 for task in `cat /dev/cpuctl/tasks`; do 58 echo $task > /dev/cpuctl/group_def/tasks 2>/dev/null 1>&2; 59 done 60} 61 62get_num_groups() # Number of tasks should be >= number of cpu's (to check scheduling fairness) 63{ 64 num_grps=$(echo "$NUM_CPUS * 1.5"|bc) # temp variable num_grps 65 int_part=`echo $num_grps | cut -d"." -f1` 66 dec_part=`echo $num_grps | cut -d"." -f2` 67 68 if [ $dec_part -gt 0 ] 69 then 70 NUM_GROUPS=$(echo "$int_part + 1"|bc) 71 else 72 NUM_GROUPS=$int_part; 73 fi 74} 75 76 # Write the cleanup function 77cleanup () 78{ 79 echo "Cleanup called"; 80 killall cpuctl_def_task01; 81 rm -f cpuctl_task_* 2>/dev/null 82 for task in `cat /dev/cpuctl/group_def/tasks`; do 83 echo $task > /dev/cpuctl/tasks 2>/dev/null 1>&2; 84 done 85 rmdir /dev/cpuctl/group* 2> /dev/null 86 umount /dev/cpuctl 2> /dev/null 87 rmdir /dev/cpuctl 2> /dev/null 88 rm -f myfifo 2>/dev/null 89 90} 91 # Create /dev/cpuctl & mount the cgroup file system with cpu controller 92 #clean any group created eralier (if any) 93 94do_setup () 95{ 96 if [ -e /dev/cpuctl ] 97 then 98 echo "WARN:/dev/cpuctl already exist..overwriting"; # or a warning ? 99 cleanup; 100 mkdir /dev/cpuctl; 101 else 102 mkdir /dev/cpuctl 103 fi 104 mount -t cgroup -ocpu cgroup /dev/cpuctl 2> /dev/null 105 if [ $? -ne 0 ] 106 then 107 echo "ERROR: Could not mount cgroup filesystem on /dev/cpuctl..Exiting test"; 108 cleanup; 109 exit -1; 110 fi 111 112 # Group created earlier may again be visible if not cleaned properly...so clean them 113 groups=/dev/cpuctl/group* 114 if [ -z "$groups" ] 115 then 116 rmdir /dev/cpuctl/group* 117 echo "WARN: Earlier groups found and removed..."; 118 fi 119 120 #Create a fifo to make all tasks wait on it 121 mkfifo myfifo 2> /dev/null; 122 if [ $? -ne 0 ] 123 then 124 echo "ERROR: Can't create fifo...Check your permissions..Exiting test"; 125 cleanup; 126 exit -1; 127 fi 128 129 # Create different groups 130 for i in $(seq 1 $NUM_GROUPS) 131 do 132 group=group_$i; 133 mkdir /dev/cpuctl/$group;# 2>/dev/null 134 if [ $? -ne 0 ] 135 then 136 echo "ERROR: Can't create $group...Check your permissions..Exiting test"; 137 cleanup; 138 exit -1; 139 fi 140 done 141} 142 143