summaryrefslogtreecommitdiff
blob: ce4f6c67c6ab415830de276326f04bc0780f36e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# vschedcalc - Calculate token buckets
# Copyright (C) 2005 Benedikt Boehm <hollow@gentoo.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

trap "exit 1" INT

echo ">> Welcome to the token bucket calculator"
echo ">> You need to enter some configuration options"
echo "   Default values are shown in brackets"
echo

# get config values
echo -n "Kernel HZ value (1000): "
read hz

[ -z "${hz}" ] && hz=1000

while true; do
	echo -n "Fill rate: "
	read fillrate
	[ -n "${fillrate}" ] && break
	echo "!! Please enter a valid fill rate"
done

while true; do
	echo -n "Avg. CPU usage in %: "
	read avgcpu
	[ -n "${avgcpu}" ] && break
	echo "!! Please enter a valid CPU usage"
done

while true; do
	echo -n "Max. burst time in sec: "
	read maxburst
	[ -n "${maxburst}" ] && break
	echo "!! Please enter a valid burst time"
done

echo -n "Hold processes after burst in sec (0): "
read bursthold

[ -z "${bursthold}" ] && bursthold=0

# calculate token bucket
let interval=100*${fillrate}/${avgcpu}
let tokensmin=${hz}*${bursthold}*${fillrate}/${interval}
let tokensmax=${hz}*${maxburst}-${hz}*${maxburst}*${fillrate}/${interval}

echo
echo ">> Voila. Your token bucket looks like:"
echo "FillRate: ${fillrate}"
echo "Interval: ${interval}"
echo "TokensMin: ${tokensmin}"
echo "TokensMax: ${tokensmax}"