parameters.sh revision f50cdc36187b137f9420639b21927dfad922e802
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 rm -f cpuctl_task_* 2>/dev/null 81 rmdir /dev/cpuctl/group_* 2> /dev/null 82 umount /dev/cpuctl 2> /dev/null 83 rmdir /dev/cpuctl 2> /dev/null 84 rm -f myfifo 2>/dev/null 85 86} 87 # Create /dev/cpuctl & mount the cgroup file system with cpu controller 88 #clean any group created eralier (if any) 89 90do_setup () 91{ 92 if [ -e /dev/cpuctl ] 93 then 94 echo "WARN:/dev/cpuctl already exist..overwriting"; # or a warning ? 95 cleanup; 96 mkdir /dev/cpuctl; 97 else 98 mkdir /dev/cpuctl 99 fi 100 mount -t cgroup -ocpu cgroup /dev/cpuctl 2> /dev/null 101 if [ $? -ne 0 ] 102 then 103 echo "ERROR: Could not mount cgroup filesystem on /dev/cpuctl..Exiting test"; 104 cleanup; 105 exit -1; 106 fi 107 108 # Group created earlier may again be visible if not cleaned properly...so clean them 109 if [ -e /dev/cpuctl/group_1 ] 110 then 111 rmdir /dev/cpuctl/group* 112 echo "WARN: Earlier groups found and removed..."; 113 fi 114 115 #Create a fifo to make all tasks wait on it 116 mkfifo myfifo 2> /dev/null; 117 if [ $? -ne 0 ] 118 then 119 echo "ERROR: Can't create fifo...Check your permissions..Exiting test"; 120 cleanup; 121 exit -1; 122 fi 123 124 # Create different groups 125 for i in $(seq 1 $NUM_GROUPS) 126 do 127 group=group_$i; 128 mkdir /dev/cpuctl/$group;# 2>/dev/null 129 if [ $? -ne 0 ] 130 then 131 echo "ERROR: Can't create $group...Check your permissions..Exiting test"; 132 cleanup; 133 exit -1; 134 fi 135 done 136} 137 138