• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public
5# License as published by the Free Software Foundation; either
6# version 2 of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11# General Public License for more details.
12#
13# You should have received a copy of the GNU General Public
14# License along with this program; if not, write to the
15# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16# Boston, MA 021110-1307, USA.
17#
18# Copyright (C) 2008 Andrea Righi <righi.andrea@gmail.com>
19#
20# Usage: ./run_io_throttle_test.sh
21# Description: test block device I/O bandwidth controller functionalities
22
23. ./myfunctions-io.sh
24
25trap cleanup SIGINT
26
27BUFSIZE=16m
28DATASIZE=64m
29
30setup
31
32# get the device name of the entire mounted block device
33dev=`df -P . | sed '1d' | cut -d' ' -f1 | sed 's/[p]*[0-9]*$//'`
34
35# evaluate device bandwidth
36export MYGROUP=
37phys_bw=`./iobw -direct 1 $BUFSIZE $DATASIZE | grep TOTAL | awk '{print $7}'`
38if [ $? -ne 0 ]; then
39	echo "ERROR: could not evaluate i/o bandwidth of $dev. Exiting test."
40	cleanup
41	exit 1
42fi
43echo ">> physical i/o bandwidth limit is: $phys_bw KiB/s"
44# show cgroup i/o bandwidth limits
45for i in `seq 1 3`; do
46	MYGROUP=cgroup-$i
47	echo "($MYGROUP) max i/o bw: " \
48		"$(($phys_bw / `echo 2^$i | bc`)) KiB/s + O_DIRECT"
49done
50
51for tasks in 1 2 4; do
52for strategy in 0 1; do
53	# set bw limiting rules
54	if [ -f /dev/blockioctl/blockio.bandwidth ]; then
55		io_throttle_file=blockio.bandwidth
56	elif [ -f /dev/blockioctl/blockio.bandwidth-max ]; then
57		io_throttle_file=blockio.bandwidth-max
58	else
59		echo "ERROR: unknown kernel ABI. Exiting test."
60		cleanup
61		exit 1
62	fi
63	for i in `seq 1 3`; do
64		limit=$(($phys_bw * 1024 / `echo 2^$i | bc`))
65		IOBW[$i]=$(($limit / 1024))
66		/bin/echo $dev:$limit:$strategy:$limit > \
67			/dev/blockioctl/cgroup-$i/${io_throttle_file}
68		if [ $? -ne 0 ]; then
69			echo "ERROR: could not set i/o bandwidth limit for cgroup-$i. Exiting test."
70			cleanup
71			exit 1
72		fi
73	done
74
75	# run benchmark
76	if [ $tasks -eq 1 ]; then
77		stream="stream"
78	else
79		stream="streams"
80	fi
81	echo -n ">> testing $tasks parallel $stream per cgroup "
82	if [ $strategy -eq 0 ]; then
83		echo "(leaky-bucket i/o throttling)"
84	else
85		echo "(token-bucket i/o throttling)"
86	fi
87	for i in `seq 1 3`; do
88		MYGROUP=cgroup-$i
89		/bin/echo $$ > /dev/blockioctl/$MYGROUP/tasks
90		if [ $? -ne 0 ]; then
91			echo "ERROR: could not set i/o bandwidth limit for cgroup-$i. Exiting test."
92			cleanup
93			exit 1
94		fi
95		# exec i/o benchmark
96		./iobw -direct $tasks $BUFSIZE $DATASIZE > /tmp/$MYGROUP.out &
97		PID[$i]=$!
98	done
99	/bin/echo $$ > /dev/blockioctl/tasks
100
101	# wait for children completion
102	for i in `seq 1 3`; do
103		MYGROUP=cgroup-$i
104		wait ${PID[$i]}
105		ret=$?
106		if [ $ret -ne 0 ]; then
107			echo "ERROR: error code $ret during test $tasks.$strategy.$i. Exiting test."
108			cleanup
109			exit 1
110		fi
111		iorate=`grep parent /tmp/${MYGROUP}.out | awk '{print $7}'`
112		diff=$((${IOBW[$i]} - $iorate))
113		echo "($MYGROUP) i/o-bw ${IOBW[$i]} KiB/s, i/o-rate $iorate KiB/s, err $diff KiB/s"
114		if [ ${IOBW[$i]} -ge $iorate ]; then
115			echo "TPASS   Block device I/O bandwidth controller: test $tasks.$strategy.$i PASSED";
116		else
117			echo "TFAIL   Block device I/O bandwidth controller: test $tasks.$strategy.$i FAILED";
118		fi
119	done
120done
121done
122
123cleanup
124