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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
# Copyright (C) 2012, Linaro Limited.
#
# 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.
#
# Author: Amit Pundir <amit.pundir@linaro.org>
# Modified-by: Naresh Kamboju <naresh.kamboju@linaro.org>
#
usage()
{
echo ""
echo "usage: $0 [<option> <argument>] .."
echo ""
echo "Options: -f <operating frequency> [big/little; Default: big]"
echo " -c <operate on this cpu> [this option can be specified multiple times]"
echo " -d <take this cpu offline>"
echo " -e <bring this cpu online>"
echo " -i <number of iterations> [Default: 1]"
echo " -p <input file> [Default: /data/boxes/boxes.ppm]"
echo " -s <periodic switching interval in msec> [Default: 50]"
echo " -r <random switching seed> [Default: 100]"
echo " -l <random switching seed limit> [Default: 1000]"
echo " -n <threads to be executed on specific cpus>"
echo " -S single-sync Sequential half transition (e.g.: big->barrier->little->barrier)"
echo ""
echo "Example of periodic switching: $0 -f big -c 0 -c 1 ... -c $large_cpu_number -s 50"
echo "Example of random switching: $0 -f big -c 0 -c 1 ... -c $large_cpu_number -r 100 -l 1000"
echo "Example of periodic switching while spawning threads on cpu0 and cpu3: $0 -f big -c 0 -c 1 ... -c $large_cpu_number -n 0 ... $large_cpu_number -s 50"
echo "Example of simultaneous thread while spawning threads on all cpus: $0 -f big -c 0 -n 0 ... $large_cpu_number -s 100 -S"
exit 1
}
DC_STATUS=0;
SWITCHER_STATUS=0;
total_no_of_cpu=`ls /sys/devices/system/cpu/cpu*/online | wc -l`
large_cpu_number=$((total_no_of_cpu-1))
TASKSET=affinity_tools
CPU_FAST=
CPU_SLOW=
#ARM
IMPLEMENTER=0x41
#A7
PART_SLOW=0xc07
#A15
PART_FAST=0xc0f
eachslow=
eachfast=
EACH_CPU=
get_no_of_cpus ()
{
cpu=0
while [ $cpu -lt $total_no_of_cpu ];
do
$TASKSET -part $cpu,$IMPLEMENTER,$PART_SLOW >/dev/null
if [ $? == 0 ] ; then
eachslow=" -c "
CPU_SLOW=$CPU_SLOW$eachslow$cpu
fi
$TASKSET -part $cpu,$IMPLEMENTER,$PART_FAST >/dev/null
if [ $? == 0 ] ; then
eachfast=" -c "
CPU_FAST=$CPU_FAST$eachfast$cpu
fi
cpu=$((cpu+1))
done
EACH_CPU="$CPU_SLOW$CPU_FAST"
}
switch()
{
if [ "$FREQ" -eq 0 ]; then
boot_a15
else if [ "$FREQ" -eq 1 ]; then
boot_a7
else
echo "Error: Unknown Operating frequency. Has to be set to either \"big\" or \"little\""
usage
fi
fi
}
boot_a15()
{
echo ""
echo "Switching to big mode if not already in."
boot-a15.sh -c $CPU_NUM
ERR_CODE=$?
if [ $ERR_CODE -ne 0 ]; then
echo "boot-a15 failed. Abort!!"
exit 1
fi
}
boot_a7()
{
echo ""
echo "Switching to little mode if not already in."
boot-a7.sh -c $CPU_NUM
ERR_CODE=$?
if [ $ERR_CODE -ne 0 ]; then
echo "boot-a7 failed. Abort!!"
exit 1
fi
}
disable_cpu()
{
echo ""
echo "Taking CPU$DISABLE_CPU offline .."
STATUS=`cat /sys/devices/system/cpu/cpu$DISABLE_CPU/online`
if [ $STATUS -eq 1 ]; then
echo 0 > /sys/devices/system/cpu/cpu$DISABLE_CPU/online
else
echo "CPU$DISABLE_CPU already in offline mode."
fi
}
enable_cpu()
{
echo ""
echo "Bringing CPU$ENABLE_CPU online .."
STATUS=`cat /sys/devices/system/cpu/cpu$ENABLE_CPU/online`
if [ $STATUS -eq 0 ]; then
echo 1 > /sys/devices/system/cpu/cpu$ENABLE_CPU/online
else
echo "CPU$ENABLE_CPU already in online mode."
fi
}
run_data_corruption()
{
# Set defaults for data-crorruption.sh
if [ -z "$FILE" ]; then
if [ -r /data/boxes/boxes.ppm ]; then
FILE=/data/boxes/boxes.ppm;
elif [ -r /usr/share/testdata/boxes.ppm ]; then
FILE=/usr/share/testdata/boxes.ppm;
fi
fi
if [ -z "$ITR" ]; then
ITR=1;
fi
echo ""
echo "Running data-corruption.sh "$FILE" "$ITR""
data-corruption.sh $FILE $ITR
ERR_CODE=$?
if [ $ERR_CODE -ne 0 ]; then
echo "data-corruption.sh failed. Abort!!"
DC_STATUS=$ERR_CODE;
return 1
else
echo "data-corruption.sh finished successfully"
return 0
fi
}
run_periodic_switcher()
{
echo ""
echo "Starting bigLITTLE periodic switcher in the background"
if [ -z "$THREAD_CPU0" ]; then
bl-agitator -s $INTR &
BL_AGITATOR_PID=$!
else
echo "spawning thread(s) on specified cpu(s)"
echo "bl-agitator -n $EACH_CPU -s $INTR &"
bl-agitator -n $EACH_CPU -s $INTR &
BL_AGITATOR_PID=$!
fi
ERR_CODE=$?
if [ $ERR_CODE -ne 0 ]; then
echo "bigLITTLE periodic switcher failed. Abort!!"
SWITCHER_STATUS=$ERR_CODE;
return 1
else
return 0
fi
}
run_random_switcher()
{
echo ""
echo "Starting bigLITTLE random switcher in the background"
if [ -z "$THREAD_CPU0" ]; then
bl-agitator -r $SEED -l $LIMIT &
BL_AGITATOR_PID=$!
else
echo "spawning thread(s) on specified cpu(s)"
echo "bl-agitator -n $EACH_CPU -r $SEED -l $LIMIT &"
bl-agitator -n $EACH_CPU -r $SEED -l $LIMIT &
BL_AGITATOR_PID=$!
fi
ERR_CODE=$?
if [ $ERR_CODE -ne 0 ]; then
echo "bigLITTLE random switcher failed. Abort!!"
SWITCHER_STATUS=$ERR_CODE;
return 1
else
return 0
fi
}
simultaneous_thread_switcher()
{
echo ""
echo "Starting bigLITTLE simultaneous thread switcher in the background"
if [ -z "$THREAD_CPU0" ]; then
bl-agitator -s $INTR &
BL_AGITATOR_PID=$!
else
echo "spawning thread(s) on specified cpu(s)"
echo "bl-agitator -n $EACH_CPU -s $INTR -S &"
bl-agitator -n $EACH_CPU -s $INTR -S &
BL_AGITATOR_PID=$!
fi
ERR_CODE=$?
if [ $ERR_CODE -ne 0 ]; then
echo "bigLITTLE simultaneous thread switcher failed. Abort!!"
SWITCHER_STATUS=$ERR_CODE;
return 1
else
return 0
fi
}
kill_switcher()
{
echo ""
ANDROID_MOD_PATH=/system/modules
UBUNTU_MOD_PATH=/lib/modules
if [ -d $ANDROID_MOD_PATH ]; then
PID_BL_CHECK=`ps | grep "$BL_AGITATOR_PID" | grep "bl-agitator" | awk '{print $2}'`
else if [ -d $UBUNTU_MOD_PATH ]; then
PID_BL_CHECK=`ps ax | grep "$BL_AGITATOR_PID" | grep "bl-agitator" | awk '{print $1}'`
else
echo "ERROR: Unexpected Environment "
exit 1
fi
fi
echo "Kill bigLITTLE switcher BL_AGITATOR_PID $BL_AGITATOR_PID"
echo "PID_BL_CHECK= $PID_BL_CHECK"
if [ -z "$PID_BL_CHECK" ]; then
echo "bigLITTLE switcher not running. Report Error!!"
exit 1
else
# done with bl-agitator. Kill the process
echo "sending SIGTERM BL_AGITATOR_PID $BL_AGITATOR_PID"
kill $BL_AGITATOR_PID
if [ -d $ANDROID_MOD_PATH ]; then
PID_BL_CHECK_AGAIN=`ps | grep "$BL_AGITATOR_PID" | grep "bl-agitator" | awk '{print $2}'`
else if [ -d $UBUNTU_MOD_PATH ]; then
PID_BL_CHECK_AGAIN=`ps ax | grep "$BL_AGITATOR_PID" | grep "bl-agitator" | awk '{print $1}'`
else
echo "ERROR: Unexpected Environment "
exit 1
fi
fi
if [ -n "$PID_BL_CHECK_AGAIN" ]; then
#if the above kill is not successfull. kill forcefully
echo "sending SIGKILL BL_AGITATOR_PID $BL_AGITATOR_PID"
kill -9 $BL_AGITATOR_PID > /dev/null 2>&1
fi
fi
}
if [ -z "$1" ]; then
usage
fi
get_no_of_cpus
while [ "$1" ]; do
case "$1" in
-f|--frequency)
if [ -z "$2" ]; then
echo "Error: Specify the operating frequency [big/little]"
usage
fi
if [ "$2" = "big" ]; then
FREQ=0;
shift;
else if [ "$2" = "little" ]; then
FREQ=1;
shift;
else
echo "Error: Operating frequency has to be set to either \"big\" or \"little\""
usage
fi
fi
;;
-c|--cpu-num)
if [ -z "$2" ]; then
echo "Error: Specify the CPU core (0-$large_cpu_number) to be switched to the desired frequency"
usage
fi
if [ $(echo "$2" | grep -E "^[0-$large_cpu_number]+$") ]; then
CPU_NUM=$2;
if [ -z "$FREQ" ]; then
echo "Error: Specify the operating frequency [big/little]"
usage
fi
switch
shift;
else
usage
fi
;;
-d|--disable-cpu)
if [ $(echo "$2" | grep -E "^[1-3]+$") ]; then
DISABLE_CPU=$2;
disable_cpu
shift;
fi
;;
-e|--enable-cpu)
if [ $(echo "$2" | grep -E "^[1-3]+$") ]; then
ENABLE_CPU=$2;
enable_cpu
shift;
fi
;;
-i|--iterations)
if [ "$2" -gt 0 ]; then
ITR=$2;
shift;
fi
;;
-p|--input-file)
if [ -e "$2" ]; then
FILE=$2;
shift;
fi
;;
-s|--periodic-switching)
if [ -z "$RANDOM_SWITCH" ]; then
PERIODIC_SWITCH=y;
if [ "$2" -gt 0 ]; then
INTR=$2;
else
INTR=50;
fi
else
echo "Invalid option (-s) !!"
echo "Can't do random and periodic switchings simultaneously"
echo "Set to Random switching mode"
fi
shift;
;;
-r|--random-switching)
if [ -z "$PERIODIC_SWITCH" ]; then
RANDOM_SWITCH=y;
if [ "$2" -gt 0 ]; then
SEED=$2;
else
SEED=100;
fi
else
echo "Invalid option (-r) !!"
echo "Can't do random and periodic switchings simultaneously"
echo "Set to Periodic switching mode"
fi
shift;
;;
-l|--seed-limit)
if [ -z "$PERIODIC_SWITCH" ]; then
if [ -z "$SEED" ]; then
echo "Error: Specify the Seed for the random switcher [-r 100]"
usage
fi
if [ "$2" -gt 0 ]; then
LIMIT=$2;
else
LIMIT=1000;
fi
else
echo "Invalid option (-l) !!"
echo "Can't do random and periodic switchings simultaneously"
echo "Set to Periodic switching mode"
fi
shift;
;;
-n|--thread-switching)
if [ $(echo "$2" | grep -E "^[0-$large_cpu_number]+$") ]; then
THREAD_CPU0="-c $2";
shift;
else
echo "Error: Must specify at least one CPU on which thread has to be spawned"
usage
fi
shift;
;;
-S|--simultaneous_thread_switching)
if [ -z "$RANDOM_SWITCH" ]; then
SIMULTANEOUS_THREAD_SWITCH=y;
else
echo "Invalid option (-S) !!"
echo "Can't do random and simultaneous thread switching at a time"
echo "Set to Random switching mode"
fi
;;
-h | --help | *)
usage
;;
esac
shift;
done
if [ -z "$FREQ" ]; then
echo "Error: Frequency has to be set to either \"big\" or \"little\""
usage
else if [ -z "$CPU_NUM" ]; then
echo "Error: Specify the number of CPU core (0-$large_cpu_number) to be switched to the desired frequency"
usage
fi
fi
if [ "$PERIODIC_SWITCH" = "y" ]; then
if [ "$SIMULTANEOUS_THREAD_SWITCH" = "y" ]; then
echo ""
else
run_periodic_switcher
fi
fi
if [ "$RANDOM_SWITCH" = "y" ]; then
if [ -z "$LIMIT" ]; then
echo "Error: Specify the Seed Limit for the random switcher [-l 1000]"
usage
fi
run_random_switcher
fi
if [ "$SIMULTANEOUS_THREAD_SWITCH" = "y" ]; then
simultaneous_thread_switcher
cluster-status.sh $BL_AGITATOR_PID &
fi
run_data_corruption
if ([ "$PERIODIC_SWITCH" = "y" ] || [ "$RANDOM_SWITCH" = "y" ] || [ "$SIMULTANEOUS_THREAD_SWITCH" = "y" ]); then
kill_switcher
fi
if ([ $DC_STATUS -ne 0 ] || [ $SWITCHER_STATUS -ne 0 ]); then
echo "Test failed. Abort!!"
exit 1
fi
KERNEL_ERR=`dmesg | grep "Unable to handle kernel "`
if [ -n "$KERNEL_ERR" ]; then
echo "Kernel OOPS detected. Abort!!"
exit 1
fi
exit 0
|