• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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_GROUPS=$(( (NUM_CPUS*3 + 1)/2 ))
65}
66
67	# Write the cleanup function
68cleanup ()
69{
70        echo "Cleanup called";
71	killall cpuctl_def_task01 1>/dev/null 2>&1;
72	killall cpuctl_def_task02 1>/dev/null 2>&1;
73	killall cpuctl_task_* 1>/dev/null 2>&1;
74	sleep 1
75        rm -f cpuctl_task_* 2>/dev/null
76	for task in `cat /dev/cpuctl/group_def/tasks`; do
77		echo $task > /dev/cpuctl/tasks 2>/dev/null 1>&2;
78	done
79        rmdir /dev/cpuctl/group* 2> /dev/null
80        umount /dev/cpuctl 2> /dev/null
81        rmdir /dev/cpuctl 2> /dev/null
82        rm -f myfifo 2>/dev/null
83
84}
85        # Create /dev/cpuctl &  mount the cgroup file system with cpu controller
86        #clean any group created eralier (if any)
87
88do_setup ()
89{
90        if [ -e /dev/cpuctl ]
91        then
92                echo "WARN:/dev/cpuctl already exist..overwriting"; # or a warning ?
93                cleanup;
94                mkdir /dev/cpuctl;
95        else
96                mkdir /dev/cpuctl
97        fi
98        mount -t cgroup -ocpu cgroup /dev/cpuctl 2> /dev/null
99        if [ $? -ne 0 ]
100        then
101                echo "ERROR: Could not mount cgroup filesystem on /dev/cpuctl..Exiting test";
102                cleanup;
103                exit -1;
104        fi
105
106        # Group created earlier may again be visible if not cleaned properly...so clean them
107	groups=/dev/cpuctl/group*
108        if [ -z "$groups" ]
109        then
110                rmdir /dev/cpuctl/group*
111                echo "WARN: Earlier groups found and removed...";
112        fi
113
114        #Create a fifo to make all tasks wait on it
115        mkfifo myfifo 2> /dev/null;
116        if [ $? -ne 0 ]
117        then
118                echo "ERROR: Can't create fifo...Check your permissions..Exiting test";
119                cleanup;
120                exit -1;
121        fi
122
123        # Create different groups
124        for i in $(seq 1 $NUM_GROUPS)
125        do
126                group=group_$i;
127                mkdir /dev/cpuctl/$group;# 2>/dev/null
128                if [ $? -ne 0 ]
129                then
130                        echo "ERROR: Can't create $group...Check your permissions..Exiting test";
131                        cleanup;
132                        exit -1;
133                fi
134        done
135}
136
137