-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-pts.bash
executable file
·323 lines (282 loc) · 9.32 KB
/
run-pts.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
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
#!/usr/bin/bash
set -u
declare -r SCRIPT_NAME=${0##*/}
declare -r SCRIPT_PATH=${0%/*}
declare -r OPT_STRING="-h"
declare PTS_PATH="/tmp"
declare -r PTS_HOME="pts-home"
declare -r PTS_INSTALL="pts-install"
declare -r CPU_TURBO_BOOST="/sys/devices/system/cpu/intel_pstate/no_turbo"
declare -r CPU_HYPER_THREAD="/sys/devices/system/cpu/smt/control"
declare -i CPU_CHECK_FAIL=1
declare -i INTERACTIVE=0
declare -r CONTAINER_BASENAME="pts-test"
declare -i CONTAINER_TAG=1
declare -ar CONTAINERS=("docker" "apptainer")
declare CONTAINER_TYPE="docker"
declare LLVM_PATH=""
function setCpuConfiguration() {
echo "1" | sudo tee $CPU_TURBO_BOOST
echo "off" | sudo tee $CPU_HYPER_THREAD
checkCpuPowerCommand && sudo cpupower frequency-set --governor performance
CPU_CHECK_FAIL=1
checkCpuSettings
}
function unsetCpuConfiguration() {
echo "0" | sudo tee $CPU_TURBO_BOOST
echo "on" | sudo tee $CPU_HYPER_THREAD
checkCpuPowerCommand && sudo cpupower frequency-set --governor schedutil
CPU_CHECK_FAIL=0
checkCpuSettings
}
function checkCpuSettings() {
checkCpuTurboBoost
checkCpuHyperThread
checkCpuGovernor
}
function checkCpuPowerCommand() {
command -v cpupower &> /dev/null && true || false
}
function cpuCheckMessage() {
declare header=$([ $1 -eq 0 -a $CPU_CHECK_FAIL -eq 1 ] && echo "ERROR" || echo "INFO")
declare state=$([ $1 -eq 0 ] && echo $3 || echo $4)
printf "%s: %s %s\n" "$header" "$2" "$state"
[ $CPU_CHECK_FAIL -eq 1 -a $1 -eq 0 ] && exit 1
}
function checkCpuTurboBoost() {
grep -q '0' $CPU_TURBO_BOOST
cpuCheckMessage $? "Turbo boost is" "enabled" "disabled"
}
function checkCpuHyperThread() {
grep -q 'on' $CPU_HYPER_THREAD
cpuCheckMessage $? "Hyper-threading is" "enabled" "disabled"
}
function cpuPowerErrorMessage() {
cat <<-EOF
$1: cpupower command was not able to obtain frequency information. This is
most likely caused by a performance related BIOS setting.
"cpupower frequency-info -p" reported the following output:
EOF
cpupower frequency-info -p
}
function checkCpuGovernor() {
if ! checkCpuPowerCommand; then
if [ $CPU_CHECK_FAIL -eq 1 ]; then
printf "ERROR: cpupower command is not available\n" && exit 1
else
printf "WARNING: cpupower command is not available\n"
fi
else
declare -r governor=$(cpupower frequency-info -p | sed -E -e '3!d' -e 's/\s.*+"(.*)".*/\1/')
if [ $? -ne 0 ]; then
if [ $CPU_CHECK_FAIL -eq 1 ]; then
cpuPowerErrorMessage "ERROR"
exit 1
else
cpuPowerErrorMessage "WARNING"
fi
else
printf "INFO: Performance governor is %s\n" "$governor"
[ $CPU_CHECK_FAIL -eq 1 -a ! "$governor" = "performance" ] && exit 1
fi
fi
}
function checkContainerType() {
for ((I=0; I < ${#CONTAINERS[@]}; I++)); do
if [ "$CONTAINER_TYPE" = "${CONTAINERS[$I]}" ]; then
return 0
fi
done
printf 'ERROR: container type "%s" is not defined\n' "$CONTAINER_TYPE"
return 1
}
function createDownloadCacheDirectory() {
declare -r downloadCachePath="${SCRIPT_PATH}/download-cache"
[[ ! -d "$downloadCachePath" ]] && mkdir "$downloadCachePath"
}
function helpMessage () {
cat <<-EOF
Usage: $SCRIPT_NAME [OPTION]... [-- ENTRY_POINT_OPTIONS]
-h, --help Help message
--no-cpu-checks Do not fail, just warn, on CPU governance checks
--cpu-set Set CPU governance to performance, disable turbo
boost and Hyper threading for Phoronix runs
--cpu-unset Undo --cpu-set
--container-type=TYPE The type can be docker or apptainer
--tag Container tag/version
--interactive Start container in interactive mode,
ENTRY_POINT_OPTIONS have not effect
--list-jobs List jobs/tests specified in categorized-profiles.txt
--llvm=PATH Path to llvm-project, also where alive2 is located
--scratch=PATH Path to temporary (fast) storage for building Phoronix tests
ENTRY_POINT_OPTIONS are:
EOF
"${SCRIPT_PATH}/container/build-and-run.bash" --help
echo ""
}
function listJobIds() {
declare -a jobIds=()
for name in $(grep -v -E '^(#|/build-)' "${SCRIPT_PATH}/phoronix-scripts/categorized-profiles.txt"); do
jobIds+=("$name")
done
for index in "${!jobIds[@]}"; do
printf '%2d. %s\n' "$index" "${jobIds[index]}"
done
}
function setupMountPoints() {
[[ -d "$PTS_PATH" ]] || mkdir -p "$PTS_PATH"
declare ptsHome="${PTS_PATH}/${PTS_HOME}"
[[ -d "$ptsHome" ]] || mkdir -p "$ptsHome"
declare ptsInstall="${PTS_PATH}/${PTS_INSTALL}"
[[ -d "$ptsInstall" ]] || mkdir -p "$ptsInstall"
}
function runDocker() {
declare userUID=$(id -u)
declare userGID=$(id -g)
declare -r imageName="${CONTAINER_BASENAME}:${CONTAINER_TAG}"
declare -r ptsInstallPath="${PTS_PATH}/${PTS_INSTALL}"
declare -r ptsHomePath="${PTS_PATH}/${PTS_HOME}"
if [ $INTERACTIVE -eq 1 ]; then
docker \
run \
-it \
--rm \
--cap-add SYS_NICE \
--ulimit core=0 \
--mount type=bind,source="$(pwd)",target="/pts/phoronix" \
--mount type=bind,source="$ptsInstallPath",target="/pts/pts-install" \
--mount type=bind,source="$ptsHomePath",target="/pts/pts-home" \
--mount type=bind,source="$LLVM_PATH",target="/llvm" \
--user "${userUID}:${userGID}" \
--entrypoint=/usr/bin/bash \
"$imageName"
else
docker \
run \
-it \
--rm \
--cap-add SYS_NICE \
--ulimit core=0 \
--mount type=bind,source="$(pwd)",target="/pts/phoronix" \
--mount type=bind,source="$ptsInstallPath",target="/pts/pts-install" \
--mount type=bind,source="$ptsHomePath",target="/pts/pts-home" \
--mount type=bind,source="$LLVM_PATH",target="/llvm" \
--user "${userUID}:${userGID}" \
"$imageName" "$@"
fi
}
function runApptainer() {
declare -r imageName="${SCRIPT_PATH}/container/${CONTAINER_BASENAME}-${CONTAINER_TAG}.sif"
declare -r ptsInstallPath="${PTS_PATH}/${PTS_INSTALL}"
declare -r ptsHomePath="${PTS_PATH}/${PTS_HOME}"
if [ $INTERACTIVE -eq 1 ]; then
apptainer \
shell \
--no-home \
--containall \
--mount type=bind,source="$(pwd)",target="/pts/phoronix" \
--mount type=bind,source="$ptsInstallPath",target="/pts/pts-install" \
--mount type=bind,source="$ptsHomePath",target="/pts/pts-home" \
--mount type=bind,source="$LLVM_PATH",target="/llvm" \
"$imageName"
else
apptainer \
run \
--no-home \
--containall \
--mount type=bind,source="$(pwd)",target="/pts/phoronix" \
--mount type=bind,source="$ptsInstallPath",target="/pts/pts-install" \
--mount type=bind,source="$ptsHomePath",target="/pts/pts-home" \
--mount type=bind,source="$LLVM_PATH",target="/llvm" \
"$imageName" "$@"
fi
}
function createPtsInstallPath() {
if [ ! -d "$PTS_PATH" ]; then
printf "INFO: making pts home and install/build directory in %s\n" "$PTS_PATH"
mkdir -p "$PTS_PATH" && \
mkdir -p "${PTS_PATH}/${PTS_INSTALL}" && \
mkdir -p "${PTS_PATH}/${PTS_HOME}" || \
exit 1
fi
}
RESULT=$(getopt \
--name "$SCRIPT_NAME" \
--options "$OPT_STRING" \
--longoptions "help,container-type:,tag:,interactive,llvm:,scratch:,list-jobs,no-cpu-checks,cpu-set,cpu-unset,cpu-info" \
-- "$@")
[[ $? -eq 0 ]] || exit 1
eval set -- "$RESULT"
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
helpMessage
exit 0
;;
--interactive)
INTERACTIVE=1
;;
--llvm)
shift
LLVM_PATH=$1
;;
--scratch)
shift
PTS_PATH=$1
;;
--no-cpu-checks)
CPU_CHECK_FAIL=0
;;
--cpu-set)
setCpuConfiguration
exit 0
;;
--cpu-unset)
unsetCpuConfiguration
exit 0
;;
--cpu-info)
CPU_CHECK_FAIL=0
checkCpuSettings
exit 0
;;
--container-type)
shift
CONTAINER_TYPE=$1
checkContainerType || exit 1
;;
--tag)
shift
CONTAINER_TAG=$1
;;
--list-jobs)
listJobIds
exit 0
;;
--)
shift
break
;;
esac
shift
done
createPtsInstallPath
checkCpuSettings
if [ -z "$LLVM_PATH" ]; then
printf "ERROR: --llvm=PATH must be specified\n"
exit 1
fi
if [ ! -d "$LLVM_PATH" ]; then
printf "ERROR: --llvm=%s does not specify a real directory\n" "$LLVM_PATH"
exit 1
fi
createDownloadCacheDirectory
setupMountPoints
case "$CONTAINER_TYPE" in
docker)
runDocker "$@"
;;
apptainer)
runApptainer "$@"
;;
esac