-
Notifications
You must be signed in to change notification settings - Fork 3
/
Hikey-Tester-Util.sh
261 lines (208 loc) · 5.54 KB
/
Hikey-Tester-Util.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
# Copyright (C) 2017 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/>.
# Utility functions for the Hikey-Tester suite
# Change this values only if you now what you are doing
HD=mmcblk0
fiofolder="fiojobs"
# Tracing functions
init_tracing () {
local sched=$1
echo "Initializate tracing..."
if [ "$tracing" == "1" ] ; then
if [ ! -d /sys/kernel/debug/tracing ] ; then
mount -t debugfs none /sys/kernel/debug
fi
echo nop > /sys/kernel/debug/tracing/current_tracer
echo 50000 > /sys/kernel/debug/tracing/buffer_size_kb
echo "Buffer size: $(cat /sys/kernel/debug/tracing/buffer_size_kb) kb"
if [[ "$tracer" == "blk" ]]; then
echo "${sched}*" "__${sched}*" >\
/sys/kernel/debug/tracing/set_ftrace_filter
else
echo "" > /sys/kernel/debug/tracing/set_ftrace_filter
fi
echo $tracer > /sys/kernel/debug/tracing/current_tracer
echo -n "Selected tracer: "
cat /sys/kernel/debug/tracing/current_tracer
fi
}
set_tracing () {
if [ "$1" == "1" ] ; then
echo "Setting tracing..."
fi
# if test -a /sys/kernel/debug/tracing/tracing_enabled; then
#if [[ $tracer == "wakeup_rt" ]]; then
# echo "echo $1 > /sys/kernel/debug/tracing/tracing_on"
# echo $1 > /sys/kernel/debug/tracing/tracing_on
#else
#echo "echo $1 > /sys/kernel/debug/tracing/tracing_enabled"
#echo $1 > /sys/kernel/debug/tracing/tracing_enabled
#fi
#fi
if [ $testing -eq 1 ];then
echo "echo $1 > /sys/kernel/debug/tracing/tracing_on"
echo "echo $1 > /sys/block/$HD/trace/enable"
fi
echo $1 > /sys/kernel/debug/tracing/tracing_on
echo $1 > /sys/block/$HD/trace/enable
}
# Scheduler functions
change_sched () {
echo $1 > /sys/block/$HD/queue/scheduler
# Handle possible error
local error=$?
if [[ "$error" != "0" ]]
then
echo "ERROR: $1 scheduler not found"
exit 1
fi
echo "Current Scheduler:" $(cat /sys/block/$HD/queue/scheduler)
# Temporary disabled slice_idle option
if [[ "$1" == "bfq" ]]
then
echo $low_lat > /sys/block/$HD/queue/iosched/low_latency
echo -n "Low latency:"
cat /sys/block/$HD/queue/iosched/low_latency
# echo $sliceidle > /sys/block/mmcblk0/queue/iosched/slice_idle
# echo -n Slice idle:
# cat /sys/block/mmcblk0/queue/iosched/slice_idle
fi
}
# Change t_slow parameter for BFQ scheduler
# N.B: this function MUST be used only for testing and
# only if the t_slow change is enabled in BFQ.
change_t_slow () {
echo "Changing t_slow time..."
is_a_number $1
echo $1 > /sys/block/$HD/queue/iosched/t_slow
local time=$(cat /sys/block/$HD/queue/iosched/t_slow)
echo "Current t_slow time: $time"
}
# Workload functions
setup_file_to_read () {
for k in $(seq 1 $num_read)
do
if [ ! -f /data/tmp/BIGFILE_read$k ]
then
dd if=/dev/zero of=/data/tmp/BIGFILE_read$k bs=1048576 count=256
fi
done
}
setup_file_to_write () {
for k in $(seq 1 $num_write)
do
if [ -f /data/tmp/BIGFILE_write$k ]
then
rm /data/tmp/BIGFILE_write$k
fi
done
}
setup_test_file () {
# Check if the tmp folder exists
if [ ! -d /data/tmp ]; then
mkdir /data/tmp
fi
setup_file_to_read
if [ $num_write -gt 0 ];then
setup_file_to_write
fi
}
check_fiofolder () {
rm -rf $fiofolder
mkdir $fiofolder 2> /dev/null
}
generate_single_jf () {
local filename="$fiofolder/fiojob${rand}.fio"
local n_write=$num_write
local n_read=$num_read
if [ $n_write -gt 0 ]; then
local size="size=256m"
fi
if [ ! -f $filename ]; then
echo "Creating $filename..."
global="
[global]\n
time_based\n
runtime=$runtime\n
group_reporting\n
$size
"
echo $global > $filename
# Insert write jobs
for n in $(seq 1 $n_write)
do
local job="
[job write-$n]\n
filename=/data/tmp/BIGFILE_write$n\n
rw=${rand}write
"
echo $job >> $filename
done
# Insert read jobs
for n in $(seq 1 $n_read)
do
local job="
[job read-$n]\n
filename=/data/tmp/BIGFILE_read$n\n
rw=${rand}read
"
echo $job >> $filename
done
fi
}
genereate_workload () {
check_fiofolder
generate_single_jf
sync
fio $fiofolder/fiojob${rand}.fio --output=fiout.out &
# File copies test
#cp /data/tmp/BIGFILE_read1 /data/tmp/BIGFILE_read1.1 &
#cp /data/tmp/BIGFILE_read2 /data/tmp/BIGFILE_read2.2 &
}
# Utility functions
contains () {
local e
local ARRAY=$2
for e in ${ARRAY[@]};
do [[ "$e" == "$1" ]] && return 0;
done
return 1
}
is_a_number () {
local number=$1
if [ "$number" -eq "$number" ] 2>/dev/null; then
: # No errors
else
echo "ERROR: $number input not correct..."
exit 1;
fi
}
file_exists () {
if [ ! -f $1 ]; then
echo "ERROR FILE: $1 not found!"
exit 1
fi
}
sleep_for () {
local seconds=$1
while [[ true ]]; do
sleep $seconds &
wait
done
}
display_and_exit () {
local message=$1
echo $message
exit 1
}