1*49cdfc7eSAndroid Build Coastguard Worker#!/bin/bash 2*49cdfc7eSAndroid Build Coastguard Worker# usage ./parameters.sh 3*49cdfc7eSAndroid Build Coastguard Worker 4*49cdfc7eSAndroid Build Coastguard Worker################################################################################# 5*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) International Business Machines Corp., 2007 # 6*49cdfc7eSAndroid Build Coastguard Worker# # 7*49cdfc7eSAndroid Build Coastguard Worker# This program is free software; you can redistribute it and/or modify # 8*49cdfc7eSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by # 9*49cdfc7eSAndroid Build Coastguard Worker# the Free Software Foundation; either version 2 of the License, or # 10*49cdfc7eSAndroid Build Coastguard Worker# (at your option) any later version. # 11*49cdfc7eSAndroid Build Coastguard Worker# # 12*49cdfc7eSAndroid Build Coastguard Worker# This program is distributed in the hope that it will be useful, # 13*49cdfc7eSAndroid Build Coastguard Worker# but WITHOUT ANY WARRANTY; without even the implied warranty of # 14*49cdfc7eSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See # 15*49cdfc7eSAndroid Build Coastguard Worker# the GNU General Public License for more details. # 16*49cdfc7eSAndroid Build Coastguard Worker# # 17*49cdfc7eSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License # 18*49cdfc7eSAndroid Build Coastguard Worker# along with this program; if not, write to the Free Software # 19*49cdfc7eSAndroid Build Coastguard Worker# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # 20*49cdfc7eSAndroid Build Coastguard Worker# # 21*49cdfc7eSAndroid Build Coastguard Worker################################################################################# 22*49cdfc7eSAndroid Build Coastguard Worker# Name Of File: parameters.sh # 23*49cdfc7eSAndroid Build Coastguard Worker# # 24*49cdfc7eSAndroid Build Coastguard Worker# Description: This file has functions for the setup for testing cpucontroller # 25*49cdfc7eSAndroid Build Coastguard Worker# setup includes creating controller device, mounting it with # 26*49cdfc7eSAndroid Build Coastguard Worker# cgroup filesystem with option cpu and creating groups in it. # 27*49cdfc7eSAndroid Build Coastguard Worker# # 28*49cdfc7eSAndroid Build Coastguard Worker# Functions: get_num_groups(): decides number of groups based on num of cpus # 29*49cdfc7eSAndroid Build Coastguard Worker# setup(): creaes /dev/cpuctl, mounts cgroup fs on it, creates # 30*49cdfc7eSAndroid Build Coastguard Worker# groups in that, creates fifo to fire tasks at one time. # 31*49cdfc7eSAndroid Build Coastguard Worker# cleanup(): Does full system cleanup # 32*49cdfc7eSAndroid Build Coastguard Worker# # 33*49cdfc7eSAndroid Build Coastguard Worker# Author: Sudhir Kumar <[email protected]> # 34*49cdfc7eSAndroid Build Coastguard Worker# # 35*49cdfc7eSAndroid Build Coastguard Worker# History: # 36*49cdfc7eSAndroid Build Coastguard Worker# # 37*49cdfc7eSAndroid Build Coastguard Worker# DATE NAME EMAIL DESC # 38*49cdfc7eSAndroid Build Coastguard Worker# # 39*49cdfc7eSAndroid Build Coastguard Worker# 20/12/07 Sudhir Kumar <[email protected]> Created this test # 40*49cdfc7eSAndroid Build Coastguard Worker# # 41*49cdfc7eSAndroid Build Coastguard Worker################################################################################# 42*49cdfc7eSAndroid Build Coastguard Worker 43*49cdfc7eSAndroid Build Coastguard Worker 44*49cdfc7eSAndroid Build Coastguard Workerset_def_group() #default group spinning a task to create ideal scenario 45*49cdfc7eSAndroid Build Coastguard Worker{ 46*49cdfc7eSAndroid Build Coastguard Worker [ -d /dev/cpuctl/group_def ] || mkdir /dev/cpuctl/group_def; 47*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 48*49cdfc7eSAndroid Build Coastguard Worker then 49*49cdfc7eSAndroid Build Coastguard Worker echo "ERROR: Can't create default group... " 50*49cdfc7eSAndroid Build Coastguard Worker "Check your permissions..Exiting test"; 51*49cdfc7eSAndroid Build Coastguard Worker cleanup; 52*49cdfc7eSAndroid Build Coastguard Worker exit -1; 53*49cdfc7eSAndroid Build Coastguard Worker fi 54*49cdfc7eSAndroid Build Coastguard Worker # Migrate all the running tasks to this group 55*49cdfc7eSAndroid Build Coastguard Worker # rt tasks require a finite value to cpu.rt_runtime_us 56*49cdfc7eSAndroid Build Coastguard Worker echo 10000 > /dev/cpuctl/group_def/cpu.rt_runtime_us; 57*49cdfc7eSAndroid Build Coastguard Worker for task in `cat /dev/cpuctl/tasks`; do 58*49cdfc7eSAndroid Build Coastguard Worker echo $task > /dev/cpuctl/group_def/tasks 2>/dev/null 1>&2; 59*49cdfc7eSAndroid Build Coastguard Worker done 60*49cdfc7eSAndroid Build Coastguard Worker} 61*49cdfc7eSAndroid Build Coastguard Worker 62*49cdfc7eSAndroid Build Coastguard Workerget_num_groups() # Number of tasks should be >= number of cpu's (to check scheduling fairness) 63*49cdfc7eSAndroid Build Coastguard Worker{ 64*49cdfc7eSAndroid Build Coastguard Worker NUM_GROUPS=$(( (NUM_CPUS*3 + 1)/2 )) 65*49cdfc7eSAndroid Build Coastguard Worker} 66*49cdfc7eSAndroid Build Coastguard Worker 67*49cdfc7eSAndroid Build Coastguard Worker # Write the cleanup function 68*49cdfc7eSAndroid Build Coastguard Workercleanup () 69*49cdfc7eSAndroid Build Coastguard Worker{ 70*49cdfc7eSAndroid Build Coastguard Worker echo "Cleanup called"; 71*49cdfc7eSAndroid Build Coastguard Worker killall cpuctl_def_task01 1>/dev/null 2>&1; 72*49cdfc7eSAndroid Build Coastguard Worker killall cpuctl_def_task02 1>/dev/null 2>&1; 73*49cdfc7eSAndroid Build Coastguard Worker killall cpuctl_task_* 1>/dev/null 2>&1; 74*49cdfc7eSAndroid Build Coastguard Worker sleep 1 75*49cdfc7eSAndroid Build Coastguard Worker rm -f cpuctl_task_* 2>/dev/null 76*49cdfc7eSAndroid Build Coastguard Worker for task in `cat /dev/cpuctl/group_def/tasks`; do 77*49cdfc7eSAndroid Build Coastguard Worker echo $task > /dev/cpuctl/tasks 2>/dev/null 1>&2; 78*49cdfc7eSAndroid Build Coastguard Worker done 79*49cdfc7eSAndroid Build Coastguard Worker rmdir /dev/cpuctl/group* 2> /dev/null 80*49cdfc7eSAndroid Build Coastguard Worker umount /dev/cpuctl 2> /dev/null 81*49cdfc7eSAndroid Build Coastguard Worker rmdir /dev/cpuctl 2> /dev/null 82*49cdfc7eSAndroid Build Coastguard Worker rm -f myfifo 2>/dev/null 83*49cdfc7eSAndroid Build Coastguard Worker 84*49cdfc7eSAndroid Build Coastguard Worker} 85*49cdfc7eSAndroid Build Coastguard Worker # Create /dev/cpuctl & mount the cgroup file system with cpu controller 86*49cdfc7eSAndroid Build Coastguard Worker #clean any group created eralier (if any) 87*49cdfc7eSAndroid Build Coastguard Worker 88*49cdfc7eSAndroid Build Coastguard Workerdo_setup () 89*49cdfc7eSAndroid Build Coastguard Worker{ 90*49cdfc7eSAndroid Build Coastguard Worker if [ -e /dev/cpuctl ] 91*49cdfc7eSAndroid Build Coastguard Worker then 92*49cdfc7eSAndroid Build Coastguard Worker echo "WARN:/dev/cpuctl already exist..overwriting"; # or a warning ? 93*49cdfc7eSAndroid Build Coastguard Worker cleanup; 94*49cdfc7eSAndroid Build Coastguard Worker mkdir /dev/cpuctl; 95*49cdfc7eSAndroid Build Coastguard Worker else 96*49cdfc7eSAndroid Build Coastguard Worker mkdir /dev/cpuctl 97*49cdfc7eSAndroid Build Coastguard Worker fi 98*49cdfc7eSAndroid Build Coastguard Worker mount -t cgroup -ocpu cgroup /dev/cpuctl 2> /dev/null 99*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 100*49cdfc7eSAndroid Build Coastguard Worker then 101*49cdfc7eSAndroid Build Coastguard Worker echo "ERROR: Could not mount cgroup filesystem on /dev/cpuctl..Exiting test"; 102*49cdfc7eSAndroid Build Coastguard Worker cleanup; 103*49cdfc7eSAndroid Build Coastguard Worker exit -1; 104*49cdfc7eSAndroid Build Coastguard Worker fi 105*49cdfc7eSAndroid Build Coastguard Worker 106*49cdfc7eSAndroid Build Coastguard Worker # Group created earlier may again be visible if not cleaned properly...so clean them 107*49cdfc7eSAndroid Build Coastguard Worker groups=/dev/cpuctl/group* 108*49cdfc7eSAndroid Build Coastguard Worker if [ -z "$groups" ] 109*49cdfc7eSAndroid Build Coastguard Worker then 110*49cdfc7eSAndroid Build Coastguard Worker rmdir /dev/cpuctl/group* 111*49cdfc7eSAndroid Build Coastguard Worker echo "WARN: Earlier groups found and removed..."; 112*49cdfc7eSAndroid Build Coastguard Worker fi 113*49cdfc7eSAndroid Build Coastguard Worker 114*49cdfc7eSAndroid Build Coastguard Worker #Create a fifo to make all tasks wait on it 115*49cdfc7eSAndroid Build Coastguard Worker mkfifo myfifo 2> /dev/null; 116*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 117*49cdfc7eSAndroid Build Coastguard Worker then 118*49cdfc7eSAndroid Build Coastguard Worker echo "ERROR: Can't create fifo...Check your permissions..Exiting test"; 119*49cdfc7eSAndroid Build Coastguard Worker cleanup; 120*49cdfc7eSAndroid Build Coastguard Worker exit -1; 121*49cdfc7eSAndroid Build Coastguard Worker fi 122*49cdfc7eSAndroid Build Coastguard Worker 123*49cdfc7eSAndroid Build Coastguard Worker # Create different groups 124*49cdfc7eSAndroid Build Coastguard Worker for i in $(seq 1 $NUM_GROUPS) 125*49cdfc7eSAndroid Build Coastguard Worker do 126*49cdfc7eSAndroid Build Coastguard Worker group=group_$i; 127*49cdfc7eSAndroid Build Coastguard Worker mkdir /dev/cpuctl/$group;# 2>/dev/null 128*49cdfc7eSAndroid Build Coastguard Worker if [ $? -ne 0 ] 129*49cdfc7eSAndroid Build Coastguard Worker then 130*49cdfc7eSAndroid Build Coastguard Worker echo "ERROR: Can't create $group...Check your permissions..Exiting test"; 131*49cdfc7eSAndroid Build Coastguard Worker cleanup; 132*49cdfc7eSAndroid Build Coastguard Worker exit -1; 133*49cdfc7eSAndroid Build Coastguard Worker fi 134*49cdfc7eSAndroid Build Coastguard Worker done 135*49cdfc7eSAndroid Build Coastguard Worker} 136*49cdfc7eSAndroid Build Coastguard Worker 137