• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# usage ./runcpuctl_latency_test.sh
3
4###############################################################################
5#  Copyright (c) International Business Machines  Corp., 2008                 #
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: run_cpuctl_test.sh                                            #
23#                                                                             #
24# Description: This file runs the setup for testing latency under heavy load  #
25#              when group scheduling is enabled                               #
26#              After setup it runs diff test cases in diff setup.             #
27#                                                                             #
28# Test 01:     Tests latency when no cgroup is mounted                        #
29# Test 02:     Tests latency when cgroup is mounted                           #
30#                                                                             #
31#                                                                             #
32# Author:       Sudhir Kumar   <skumar@linux.vnet.ibm.com>                    #
33#                                                                             #
34# History:                                                                    #
35#                                                                             #
36#  DATE         NAME           EMAIL                         DESC             #
37#                                                                             #
38#  26/11/08  Sudhir Kumar <skumar@linux.vnet.ibm.com>   Created this test     #
39#                                                                             #
40###############################################################################
41
42
43NUM_TASKS=100;
44NUM_GROUPS=2;	#for default
45check_task="";
46declare -a pid;
47allowed_latency=10;
48
49export TCID="cpuctl_latency_test";
50export TST_COUNT=1;
51export TST_TOTAL=2;
52
53. parameters.sh
54
55latency_cleanup()
56{
57	local i;
58
59	if [ -n "${pid[1]}" ]; then
60		for i in $(seq 1 $NUM_TASKS)
61		do
62			kill -s SIGUSR1 ${pid[$i]} 2>/dev/null;
63		done
64	fi
65
66	sleep 2;
67	if [ $TEST_NUM -eq 2 ]; then
68		# move any remaining task
69		sleep 2;
70		for task in `cat /dev/cpuctl/group*/tasks`; do
71	                echo $task > /dev/cpuctl/tasks #2>/dev/null 1>&2;
72	        done
73	        rmdir /dev/cpuctl/group* #2> /dev/null
74        	umount /dev/cpuctl #2> /dev/null
75	        rmdir /dev/cpuctl #2> /dev/null
76		rm -f myfifo;
77	fi;
78	echo "Cleanup done for latency test $TEST_NUM"
79	echo
80}
81
82log2()
83{
84        local x=$1 n=2 l=-1;
85        while((x));do
86                let l+=1
87                let x/=n;
88        done;
89        return $l;
90}
91
92# There is no single criterion for max latency, so pass or fail is only
93# intuitive. Here we use the same logic as by the kernel
94calc_allowed_latency()
95{
96	# default sched granularity=5ms if not exported by kernel
97	def_gran=5000 #in microseconds
98	if [ -f /proc/sys/kernel/sched_wakeup_granularity_ns ]; then
99		sys_latency=`cat /proc/sys/kernel/sched_wakeup_granularity_ns`
100		allowed_latency=`expr $sys_latency / 1000` # in microseconds
101	else
102		num_cpus=`tst_ncpus`
103		log2 $num_cpus;
104		ln_num_cpus=$?
105		ln_num_cpus=`expr $ln_num_cpus + 1`
106		allowed_latency=`expr $ln_num_cpus \* $def_gran`
107	fi
108
109	# To be more practical we will take our criterio as double of this value
110	allowed_latency=`expr $allowed_latency \* 2`
111}
112
113PWD=`pwd`
114
115################################
116# Start
117################################
118
119	TEST_NUM=$1;
120	if [ -z $TEST_NUM  ]; then
121		echo "Invalid test no passed to test script"
122		echo "Exiting the test..."
123		exit 1;
124	fi;
125
126	cd $LTPROOT/testcases/bin/ #Bad idea????????
127
128	# Check if sources are compiled
129	if [ ! -f $cpuctl_latency_test ] || [ ! -f $cpuctl_latency_check_task ]
130	then
131		echo "TBROK The sources are not compiled...."
132		cd $PWD;
133		exit 1;
134	fi
135
136	# Keep the signal handler ready
137	trap 'echo "Doing cleanup"; latency_cleanup;' 0;
138
139	# Calculate the alowed latency value
140	calc_allowed_latency;
141
142	case $TEST_NUM in
143	"1")	#without creating any groups
144		# Run the load creating tasks
145		echo TINFO "Running cpuctl Latency Test 1"
146		for i in $(seq 1 $NUM_TASKS)
147		do
148			# Execute the load tasks
149			./cpuctl_latency_test $TEST_NUM &
150			if [ $? -ne 0 ]
151			then
152				echo "TBROK Failed to execute binary"
153				exit;
154			else
155				pid[$i]=$!;
156			fi
157		done
158
159		# Run the latency checking task
160		./cpuctl_latency_check_task $TEST_NUM $$ $allowed_latency &
161		if [ $? -ne 0 ]
162		then
163			echo "TBROK Failed to execute main binary"
164			exit;
165		else
166			check_task=$!;
167		fi;
168		;;
169
170	"2")	# With group scheduling
171		echo TINFO "Running cpuctl Latency Test 2"
172
173		NUM_CPUS=`tst_ncpus`
174		get_num_groups;	# NUM_GROUPS is set now
175		do_setup;
176
177		for num in $(seq 1 $NUM_TASKS)
178		do
179			group=/dev/cpuctl/group_`expr $num % $NUM_GROUPS + 1`;
180			./cpuctl_latency_test $TEST_NUM $group &
181			if [ $? -ne 0 ]
182			then
183				echo "TBROK Failed to execute binary"
184				exit;
185			else
186				pid[$num]=$!;
187			fi;
188		done;
189
190		# Calculate the alowed latency value
191		./cpuctl_latency_check_task $TEST_NUM $$ $allowed_latency $group &
192		if [ $? -ne 0 ]
193		then
194			echo "TBROK Failed to execute main binary";
195			exit;
196		else
197			check_task=$!;
198		fi;
199		;;
200
201	* )	# wrong test num
202		echo TBROK "Invalid test number passed to the script"
203		exit;
204		;;
205	esac;
206
207	wait $check_task;
208	RC=$?;  # Return status of the task being waited
209	if [ $RC -ne 0 ]
210	then
211		echo "Task $check_task exited abnormaly with return value: $RC";
212		echo TBROK "Test could'nt execute for expected duration";
213	fi
214	cd $PWD;
215