-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.bash
executable file
·84 lines (71 loc) · 1.73 KB
/
run.bash
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
#! /usr/bin/bash
set -e
if [[ ! -f pg.txt ]]
then
>&2 echo "File pg.txt is not found in current directory"
exit 2
fi
if [[ ! -x $1 ]]
then
>&2 echo "Usage: bash run.bash ABSOLUTE_PATH_TO_EXECUTABLE [N]"
exit 3
fi
if [[ ! $1 = /* ]]
then
>&2 echo "Value '$1' of the first parameter is not an absolute path"
exit 4
fi
if [[ $2 ]]
then
if [[ ! $2 =~ ^[[:digit:]]+$ ]]
then
>&2 echo "Value '$2' of the second parameter is not a number"
exit 5
fi
N=$2
else
N=1
fi
NPROC="$( nproc )"
if ! WORKSPACE="$( mktemp -d --tmpdir 'freq.XXXXXX' )"
then
>&2 echo "Unable to create temporary directory"
exit 6
fi
function on_exit {
set +e
set -v
popd >/dev/null
if [[ $( cat /sys/devices/system/cpu/smt/control ) == "off" ]]
then
echo on | sudo tee /sys/devices/system/cpu/smt/control >/dev/null
fi
if command -v tuna >/dev/null
then
sudo -A tuna --cpus=0-$NPROC --include
fi
echo powersave | sudo -A tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor >/dev/null
rm -r "$WORKSPACE"
}
trap on_exit EXIT
cp -a pg.txt "$WORKSPACE"
pushd "$WORKSPACE"
echo performance | sudo -A tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor >/dev/null
if [[ NPROC > 1 ]]
then
if [[ $( cat /sys/devices/system/cpu/smt/control ) == "on" ]]
then
echo off | sudo -A tee /sys/devices/system/cpu/smt/control >/dev/null
fi
if command -v tuna >/dev/null
then
sudo -A tuna --cpus=1-$NPROC --isolate
fi
fi
for (( i = 0 ; i < N ; ++i ))
do
time LC_ALL=C taskset --cpu-list 1-$NPROC "$1" pg.txt out.txt
>&2 echo -n
md5sum --check <( echo '850944413ba9fd1dbf2b9694abaa930d -' ) <out.txt
rm out.txt
done