-
Notifications
You must be signed in to change notification settings - Fork 5
/
IO_sched-utils.sh
216 lines (180 loc) · 5.16 KB
/
IO_sched-utils.sh
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
# Copyright (C) 2016 Luca Miccio <lucmiccio@gmail.com>
# 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 3 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, see <http://www.gnu.org/licenses/>.
# This file contains all the utility functions used by the IO_sched-speedtest.sh
## Input checkers
# Check if the value passed to this function is
# a number.
is_a_number() {
local number=$1
if [[ $number != '' && $number =~ ^-?[0-9]+$ ]];
then
: # No errors
else
echo "$number input not correct..."
exit 1;
fi
}
check_if_value_in () {
local value=$1
shift
local in=1 # default we have no match
for element in "$@"; do
if [ "$element" == "$value" ]; then
in=0
break
fi
done
if [ $in -eq 1 ]; then
echo "ERROR: no value $value found in \""$@"\". Aborting."
exit 1
fi
}
# Check if the test parameters are correct and not empty
check_parameters() {
local AVAILABLE_TYPE=(read write randread randwrite)
if [ ${#SCHEDULERS[@]} -eq 0 ]; then
echo "WARNING: no scheduler found. Aborting test"
echo "For a complete test disable the debug mode in the script file."
exit 1
fi
# Check if the scheduler(s) inserted are available
for sched in "${SCHEDULERS[@]}"; do
check_if_value_in "$sched" "${AVAILABLE_SCHED[@]}"
done
if [ ${#TEST_TYPE[@]} -eq 0 ]; then
echo "WARNING: no type found. Aborting test"
echo "For a complete test disable the debug mode in the script file."
exit 1
fi
# Check if the scheduler(s) inserted are available
for type in "${TEST_TYPE[@]}"; do
check_if_value_in "$type" "${AVAILABLE_TYPE[@]}"
done
}
# Setup cpu governor scaling to $1
# TODO: restore previous value
setup_cpu_governor(){
local SCALING_CPU=$1
echo -n "Setting up cpu governor scaling -> "
for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor;
do [ -f $CPUFREQ ] || continue;
echo -n $SCALING_CPU > $CPUFREQ 2> /dev/null;
done
echo " value set to $SCALING_CPU"
}
### Fiojobs file creator
# Create the fiojob file
create_test_file() {
local RW_TYPE=$1
local TIME=$2
local DEV=$3
local TEST_FILE=$4
TEST_FILE=test_$RW_TYPE.fio
TEST_FILE_CONFIG="
[global]
bs=4k
ioengine=psync
iodepth=4
runtime=$TIME
ramp_time=2
direct=1
filename=/dev/$DEV
rw=$RW_TYPE
group_reporting=1"
echo "$TEST_FILE_CONFIG" > $TEST_FILE
MASK=1
n_proc=$(nproc)
n_proc=$((n_proc - 1 ))
MAX_MASK=$(echo "2^$n_proc" | bc) 2>/dev/null
for i in `seq 1 $N_CPU`;
do
JOB="
[job $i]
cpumask=$MASK
"
if [ $MASK -lt $MAX_MASK ]; then
MASK=$((MASK*2))
fi
echo "$JOB" >> $TEST_FILE
done
}
### Results saving
# Create the correct header for the output
# depending on the type test executed
HEADER=""
create_header() {
HEADER="SCHEDULER\t"
for test_type in ${TEST_TYPE[@]}; do
case "$test_type" in
read)
test_type="SEQREAD\t"
;;
write)
test_type="SEQWRITE\t"
;;
randread)
test_type="RANDREAD\t"
;;
randwrite)
test_type="RANDWRITE\t"
;;
*)
echo "ERROR"
exit 1
esac
HEADER=$HEADER$test_type
done
}
# Save the results
save_results() {
RESULTS=()
file_count=0
while IFS='' read -r line || [[ -n "$line" ]]; do
RESULTS[$file_count]=$line
file_count=$((file_count+1))
done < $FILE_LOG
create_header
# Show data in a table format and save them in a $OUTPUT_FILE
if [ ! -d $RESULTS_FOLDER ];then
echo "Results folder does not exist. Creating it"
mkdir $RESULTS_FOLDER
fi
if [ -f $OUTPUT_FILE ];then
mv $OUTPUT_FILE $OUTPUT_FILE.old
fi
echo
echo Results
echo "Unit of measure: KIOPS Time: ${TIME}s Device: $DEV" | tee $OUTPUT_FILE
echo -n "Number of parallel threads: $N_CPU" | tee -a $OUTPUT_FILE
echo -e "\tNumber of cpu core(s): $(nproc)\n"| tee -a $OUTPUT_FILE
{
printf $HEADER'\n'
k=0
index=0
for (( c=0; c<$N_SCHED; c++ ))
do
local_index=1
for t in ${TEST_TYPE[@]};do
declare "test_${local_index}_value"=${RESULTS[$index]}
index=$((index+1))
local_index=$((local_index+1))
done
printf '%s\t%s\t%s\t%s\t%s\n' "${SCHEDULERS[$c]}" "$test_1_value" "$test_2_value"\
"$test_3_value" "$test_4_value"
k=$((n_k+1))
done
} | column -t -s $'\t'| tee -a $OUTPUT_FILE
echo | tee -a $OUTPUT_FILE
echo "Results written in :" $OUTPUT_FILE
}