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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
#!/bin/bash
set -euf -o pipefail
scripts=$(dirname $0)
# shellcheck source=jenkins-helpers.sh
. $scripts/jenkins-helpers.sh
# shellcheck source=round-robin.sh
. $scripts/round-robin.sh
convert_args_to_variables "$@"
obligatory_variables rr[ci_project] rr[ci_config]
declare -A rr
# All bmk config about hw and benchs is implemented in this file
# shellcheck source=tcwg_bmk-config.sh
. $scripts/tcwg_bmk-config.sh
# Execution mode: build or bisect
rr[mode]="${rr[mode]-build}"
# Set custom revision for one of the projects, and use baseline revisions
# for all other projects.
rr[baseline_branch]="${rr[baseline_branch]-linaro-local/ci/${rr[ci_project]}/${rr[ci_config]}}"
rr[update_baseline]="${rr[update_baseline]-ignore}"
rr[top_artifacts]="${rr[top_artifacts]-$(pwd)/artifacts}"
# ${ci_project}--${ci_config} format is :
# 'tcwg_bmk-#{PROFILE_NAME}-#{BMK}--#{TOOLCHAIN}-#{TARGET}-{toolchain_ver}-{cflags}'
IFS=- read -a ci_pjt_cfg <<EOF
${rr[ci_project]}--${rr[ci_config]}
EOF
rr[toolchain]=${rr[toolchain]-${ci_pjt_cfg[4]}}
rr[target]=${rr[target]-${ci_pjt_cfg[5]}}
cflags="${cflags--${ci_pjt_cfg[7]}}"
metric_id="${metric_id-${ci_pjt_cfg[1]}}"
gcc_mode=""
case "${rr[target]}:$cflags" in
"arm:"*"mthumb"*) gcc_mode=thumb ;;
"arm:"*"marm"*) gcc_mode=arm ;;
"arm:-Os"*|"arm:-Oz"*)
gcc_mode=thumb
cflags="${cflags}_mthumb"
;;
"arm:"*)
gcc_mode=arm
cflags="${cflags}_marm"
;;
"arm_eabi:"*)
cflags="${cflags}_mthumb"
;;
esac
case $metric_id in
*_size) metric_id="size";;
*_speed) metric_id="sample";;
*_vect) metric_id="num_vect_loops";;
*_sve) metric_id="num_sve_loops";;
esac
called_from_notify=${called_from_notify-false}
# Temporary code while changing ci_project / ci_config :
#
# Filling RR old_format_* variables to switch smothly between
# - old format :
# ci_project: 'tcwg_bmk_#{TOOLCHAIN}_{hw}'
# ci_config: '#{TOOLCHAIN}-{toolchain_ver}-#{TARGET}-#{BMK}-{cflags}'
# - and new format :
# ci_project: 'tcwg_bmk-#{PROFILE_NAME}-#{BMK}'
# ci_config: '#{TOOLCHAIN}-#{TARGET}-{toolchain_ver}-{cflags}'
hw=$(tcwg_bmk_hw)
hw=${hw%_32} ; hw=${hw%_64}
rr[old_format_ci_project]="tcwg_bmk_${ci_pjt_cfg[4]}_${hw}"
rr[old_format_ci_config]="${ci_pjt_cfg[4]}-${ci_pjt_cfg[6]}-${ci_pjt_cfg[5]}-${ci_pjt_cfg[2]}-${ci_pjt_cfg[7]}"
rr[old_format_baseline_branch]="linaro-local/ci/${rr[old_format_ci_project]}/${rr[old_format_ci_config]}"
# -----------------------------------------------------------------------
gcc_override_configure=()
# Set default ARM/Thumb mode for AArch32 compiler. This ensures that libraries
# (Glibc, libgcc, libstdc++, libgfortran, etc.) are built in the "interesting"
# ISA.
case "$gcc_mode" in
arm|thumb) gcc_override_configure+=("--set" "gcc_override_configure=--with-mode=$gcc_mode") ;;
esac
# Disable libsanitizer because it didn't build in April-June 2018.
# We need to test revisions during that time period for performance regressions.
gcc_override_configure+=("--set" "gcc_override_configure=--disable-libsanitizer")
# Build the right libs depending on the target. Hardcode the
# cpu/float-abit/mode to speed up toolchain builds: the alternative of
# building rmprofile multilibs takes a very long time. Setting the
# values here has the drawback that we have to build one toolchain per
# board type.
case "${rr[target]}" in
"arm_eabi") gcc_override_configure+=("--set" "gcc_override_configure=--disable-multilib"
"--set" "gcc_override_configure=--with-cpu=cortex-m4"
"--set" "gcc_override_configure=--with-mode=thumb"
"--set" "gcc_override_configure=--with-float=hard"
) ;;
esac
case "${rr[toolchain]}" in
llvm)
rr[components]="llvm" ;;
gnu)
rr[components]="binutils gcc linux glibc" ;;
gnu_eabi)
rr[components]="binutils gcc newlib" ;;
*) assert_with_msg "Unknown toolchain \"${rr[toolchain]}\"" false ;;
esac
# Use baseline branches by default.
for c in ${rr[components]}; do
rr[${c}_git]=${rr[${c}_git]-baseline}
done
start_at="${start_at-default}"
finish_at="${finish_at-default}"
verbose="${verbose-true}"
verbose2="${verbose2-false}"
if $verbose2; then set -x; fi
trap print_traceback EXIT
# Set start and finish steps for different modes.
default_start_at=""
default_finish_at=""
case "${rr[mode]}" in
"bisect")
single_updated_component="$(print_single_updated_component)"
case $single_updated_component in
binutils) default_start_at="build_abe-binutils" ;;
gcc) default_start_at="build_abe-stage1" ;;
linux|glibc) default_start_at="clean_sysroot" ;;
llvm) default_start_at="build_bmk_llvm" ;;
newlib) default_start_at="build_abe-newlib" ;;
*) assert_with_msg \
"Invalid single updated component \"$single_updated_component\"" false
;;
esac
;;
esac
if [ x"$start_at" = x"default" ]; then
start_at="$default_start_at"
fi
if [ x"$finish_at" = x"default" ]; then
finish_at="$default_finish_at"
fi
run_step_init "$start_at" "$finish_at" "${rr[top_artifacts]}" "$verbose"
build_bmk_llvm ()
{
(
set -euf -o pipefail
local projects="clang;lld;openmp"
case "${rr[target]}" in
aarch64)
# Flang is not supported for AArch32
projects="$projects;flang"
;;
esac
build_llvm "$projects" "" "$metric_id"
# Copy shared libraries to runtime sysroot dir
mkdir -p llvm-install/libc
rsync -a --del --include "*/" --include "*.so*" --exclude "*" \
--delete-excluded llvm-install/lib/ llvm-install/libc/lib/
)
}
benchmark ()
{
obligatory_variables ssh_host ssh_port
(
set -euf -o pipefail
local bmk_flags="$2"
local results_id_file="$3"
sanity_check_pwd
# shellcheck disable=SC2115
rm -rf "$(pwd)"/bin
mkdir "$(pwd)"/bin
local reboot run_profile
bmk_flags="$(echo $bmk_flags | sed -e "s/_/ -/g" -e "s/LTO/flto/g")"
# Add cflags if necessary for some projects.
# code_sve projects is the only to patch today.
# code_vect projects generates vectorization data by default.
case "${rr[ci_project]}" in
*code_sve*) bmk_flags="$bmk_flags -mcpu=generic+sve" ;;
esac
local hw_tag
hw_tag=$(tcwg_bmk_hw)
case "${rr[ci_project]}" in
*code_size*)
reboot=false
run_profile="parallel"
testmode="verify"
;;
*code_vect*|*code_sve*)
reboot=false
run_profile="parallel"
testmode="verify"
;;
*code_speed*)
reboot=true
run_profile="serial"
testmode="benchmark"
;;
*fujitsu_speed*)
# parallel spec runs. No limit parallel build jobs. Limit run jobs to 4
reboot=false
run_profile="serial"
testmode="benchmark"
;;
*qc_speed*)
# No way to reboot Qualcomm boards for the moment.
reboot=false
run_profile="serial"
testmode="benchmark"
;;
*)
reboot=true
run_profile="serial"
testmode="benchmark"
;;
esac
local bench_list bin cc sysroot toolchain
case "${rr[toolchain]}" in
llvm)
sysroot="$(pwd)/llvm-install/libc"
bin="$(pwd)/llvm-install/bin"
cc="$bin/"
toolchain="llvm"
;;
gnu|gnu_eabi)
local gnu_host gnu_target
gnu_host=$(print_gnu_target native)
gnu_target=$(print_gnu_target ${rr[target]})
sysroot="$(pwd)/abe/builds/destdir/$gnu_host/$gnu_target/libc"
bin="$(pwd)/abe/builds/destdir/$gnu_host/bin"
cc="$bin/$gnu_target-"
toolchain="gnu"
# Append -fdump-statistics-asmname to obtain compile time metrics.
bmk_flags="$bmk_flags -fdump-statistics-asmname -fdump-tree-vect-details"
;;
esac
bench_list="$(tcwg_bmk_benchs)"
# shellcheck disable=SC2154
sysroot="ssh://$ssh_host:$ssh_port:$sysroot"
local hw image_arch toolchain_proto
toolchain_proto=ssh
case "$hw_tag" in
stm32)
hw=stm32; image_arch=amd64
# When running benchmarks on stm32, we prefer to rsync the
# toolchain to the board's host machine -- dev-02.tcwglab.
toolchain_proto=rsync
;;
*_32) hw=${hw_tag/_32}; image_arch=armhf ;;
*_64) hw=${hw_tag/_64}; image_arch=arm64 ;;
*) echo "ERROR: Unknown hw_tag $hw_tag"; exit 1 ;;
esac
# we create a tmpdir in /tmp
local results_dir
results_dir="$(mktemp -d -p /tmp)"
chmod g+wx $results_dir
# Trigger benchmarking job and capture its console output.
# Ignore exit code of the trigger command to detect various failure
# conditions from examining the console log.
# shellcheck disable=SC2154
remote_exec "ci.linaro.org:2222::-l $USER@linaro.org" \
build tcwg-benchmark -f -v \
-p bmk_hw=$hw \
-p bench_list="$bench_list" \
-p cflags="$bmk_flags" \
-p ldflags="$bmk_flags" \
-p testmode="$testmode" \
-p displaytag="${rr[ci_project]}/${rr[ci_config]}-${rr[mode]}" \
-p ignore_errors=true \
-p toolchain_url=$toolchain_proto://$ssh_host:$ssh_port:$cc \
-p toolchain_type=$toolchain \
-p sysroot="$sysroot" \
-p results_dest="$ssh_host:$ssh_port:$results_dir" \
-p reboot="$reboot" \
-p run_profile="$run_profile" \
-p image_arch="$image_arch" \
${scripts_branch+-p scripts_branch="$scripts_branch"} \
${bmk_branch+-p bmk_branch="$bmk_branch"} \
| tee $run_step_artifacts/benchmark-build.log || true
# copy bmk results into artifacts/annex/bmk-data/
rm -rf ${rr[top_artifacts]}/annex/bmk-data/
mkdir -p ${rr[top_artifacts]}/annex/bmk-data/
rsync -rv $results_dir/ ${rr[top_artifacts]}/annex/bmk-data/
# make sure we are deleting a /tmp/xxx directory before forcing with sudo,
# and ignore error if any
if [[ "$results_dir" =~ ^/tmp/ ]]; then
sudo -n rm -rf "$results_dir" || true
fi
local build_num
build_num=$(head -n1 $run_step_artifacts/benchmark-build.log \
| sed -e "s/Started.*#\([0-9]\+\).*/\1/")
assert_with_msg "Benchmark build number should not be 0!" \
[ "$build_num" -gt "0" ]
# The "build" output adds "Completed <build>" to the console output.
# Strip this last line.
head -n -1 $run_step_artifacts/benchmark-build.log \
> $run_step_artifacts/benchmark.log
local build_status
local build_ret
while true; do
# Ssh connection to ci.linaro.org occasionally drops. We need
# to check whether benchmarking has finished, and, if not, continue
# to watch its output. We detect that the job has finished if the last
# line of console output is "Finished: <something>".
build_status=$(tail -n 1 $run_step_artifacts/benchmark.log)
case "$build_status" in
"Finished: SUCCESS")
build_ret=0
break
;;
"Finished: "*)
echo "# Benchmarking infra is offline:" >> ${rr[top_artifacts]}/results
echo "-$EXTERNAL_FAIL" >> ${rr[top_artifacts]}/results
build_ret=1
break
;;
esac
# After ci.linaro.org update on 2021-10-11 behavior of console command
# option has changed: before the update it exited immediately for finished builds,
# and after the update "console" hangs indefinitely for finished builds.
# We workaround this by using "timeout 1m".
sleep 300
(timeout 1m \
ssh -p2222 -l $USER@linaro.org ci.linaro.org \
console tcwg-benchmark $build_num || true) \
| tee $run_step_artifacts/benchmark.log
done
echo "$hw_tag/${rr[ci_project]}/${rr[ci_config]}-${rr[mode]}/$build_num" \
> "$results_id_file"
return $build_ret
)
}
# Compare results obtained from metric data between $1 and $2
# and generate results-vs-prev/compare-results.csv
compare_results ()
{
(
set -euf -o pipefail
local metric_id="$1"
local compare_opts=""
case "${rr[target]}:$cflags" in
"arm_eabi":*"_LTO"*) compare_opts="--num_symbols 0 --entry_threshold 10 --has_perf_logs no" ;;
*:*"_LTO"*) compare_opts="--num_symbols 0 --entry_threshold 10" ;;
"arm_eabi":*) compare_opts="--has_perf_logs no" ;;
*) compare_opts="" ;;
esac
if [ -f /usr/lib/linux-tools/install-armhf-perf-workaround.sh ]; then
# FIXME:
# In some cases perf report crashes when run from armhf container on
# ARMv8 machine.
# Install a workaround while we are investigating the cause.
sudo /usr/lib/linux-tools/install-armhf-perf-workaround.sh
fi
local results_ref results_new
results_new="${rr[top_artifacts]}/annex/bmk-data"
local ref_results_id=base-artifacts/results_id
if ! [ -f $ref_results_id ] && ! [ -d "base-artifacts/annex/bmk-data" ]; then
# base-artifacts has no reference results, neither in results_id nor in annex
# This can happen on initialization of base-artifacts (update_baseline=init)
# or in corner-cases like forced build failing during toolchain build.
# In such cases we compare results to themselves just as an exercise.
results_ref=$results_new
elif [ -d "base-artifacts/annex/bmk-data" ]; then
# Results are part of the annex of the base-artifacts
results_ref="base-artifacts/annex/bmk-data"
# Import this annex locally
git -C base-artifacts annex init bkp-01
git_set_remote base-artifacts "bkp-01" \
"ssh://bkp-01.tcwglab/home/tcwg-buildslave/base-artifacts"
git -C base-artifacts annex copy --from=bkp-01 annex/
else
# FIXME :
# Otherwise, getting it from bkp-01:/home/tcwg-benchmark/results-.
# Probably a builds not using bmk results in annex dir.
# This may be useless at some point, once all results are part of base-artifacts annex.
results_ref="base-artifacts/annex/bmk-data"
mkdir -p $results_ref
rsync -az --delete "bkp-01.tcwglab:/home/tcwg-benchmark/results-$(cat $ref_results_id)/" \
$results_ref/
fi
assert_with_msg "ERROR: No result dir $results_new" [ -d $results_new ]
assert_with_msg "ERROR: No reference dir $results_ref" [ -d $results_ref ]
# Compare vs previous run
mkdir -p ${rr[top_artifacts]}/results-vs-prev
ln -s ../results-vs-prev $run_step_artifacts/results-vs-prev
$scripts/tcwg-benchmark-results.sh \
--results_ref $results_ref ++results $results_new \
--top_artifacts "${rr[top_artifacts]}/results-vs-prev" \
--verbose $verbose --hw_tag "$(tcwg_bmk_hw)" \
$compare_opts \
> ${rr[top_artifacts]}/results-vs-prev/tcwg-benchmark-results.log 2>&1 &
local res
res=0 && wait $! || res=$?
if [ $res != 0 ]; then
return $EXTERNAL_FAIL
fi
# Below call to output-bmk-results.py creates *.regression files.
assert_with_msg "Found stale regression files" \
[ x"$(find $run_step_artifacts/ -name "*.regression" | wc -l)" = x"0" ]
# Extract 5 most recent compare-results-vs-prev-internal.csv files from
# base-artifacts and compute std deviation out of them
local -a history_csvs
history_csvs=("results-vs-prev/compare-results-internal.csv"
"$(basename $run_step_artifacts)/compare-results-vs-prev-internal.csv")
readarray -t history_csvs \
< <(get_git_history 5 base-artifacts "${history_csvs[@]}")
local csv tmpf
local -a compare_results_list=()
tmpf=$(mktemp)
# FIXME:
# To deal with some differences along base-artifacts recent history
# - remove 'Failed for column' message from csv file
# - skip emtpy csv files.
for csv in "${history_csvs[@]:1}"; do
grep -v 'Failed for column' "$csv" > "$tmpf" || true
cp "$tmpf" "$csv"
if [ -s "$csv" ]; then
compare_results_list+=("$csv")
fi
done
if [ ${#compare_results_list[@]} != 0 ]; then
$scripts/../bmk-scripts/samples-variability.py \
--inputs "${compare_results_list[@]}" \
--output $run_step_artifacts/bmk-specific-variability.csv || true
fi
rm -rf "${history_csvs[0]}" "$tmpf"
echo "called_from_notify=$called_from_notify"
local verbose_opt="quiet"
if $called_from_notify; then
verbose_opt="verbose"
fi
$scripts/../bmk-scripts/output-bmk-results.py \
${rr[top_artifacts]}/results-vs-prev/compare-results-internal.csv \
$run_step_artifacts/bmk-specific-variability.csv \
"$run_step_artifacts"/ \
"$metric_id" "${rr[mode]}" $verbose_opt
# copy inputs useful to build the mail / jira / .. to mail dir
for resfile in $run_step_artifacts/{exe,symbol}.{regression,improvement}; do
if [ -f $resfile ]; then
cp $resfile ${rr[top_artifacts]}/notify/
fi
done
assert_with_msg "Found a regression while comparing the build against itself" \
[ "$results_new" != "$results_ref" ]
)
}
# Exit with code 0 if no regression compared to base-artifacts/.
# Inspect build results ./results and performance results in ./results_id.
no_regression_p ()
{
(
set -euf -o pipefail
# check score-based regression
no_build_regression_p "$@"
# At this stage, there's no score-based regression.
# We are now checking metric-based regression.
local score
score=$(grep -v -E "^#|^$" $run_step_top_artifacts/results | tail -n1)
# if score is negative, then benchmarking failed and results aren't valid.
if [ $score -lt 0 ]; then
return 0
fi
assert_with_msg "Benchmarking succeeded, but results_id is missing" \
[ -f $run_step_top_artifacts/results_id ]
# Make sure there is no stray results.regression file, which we use
# as failure marker.
assert ! [ -f $run_step_artifacts/results.regressions ]
# At this stage,
# - new/results_id should exist (score>0)
# - ref/results_id might not exist, (ex: baseline score<0)
# we call compare_results to generate the csv, and check metric regressions.
compare_results "$metric_id"
if [ -f $run_step_artifacts/results.regressions ]; then
return 1
fi
return 0
)
}
# Compiler changes tend to cause the most regressions.
# Breakup updated components into compiler and the rest of components
# to reduce the number of builds.
case "${rr[toolchain]}" in
llvm)
rr[breakup_changed_components]="breakup_changed_components llvm"
;;
gnu|gnu_eabi)
rr[breakup_changed_components]="breakup_changed_components gcc"
;;
*) assert false ;;
esac
run_step stop_on_fail -10 reset_artifacts
case "${rr[toolchain]}" in
gnu*)
run_step stop_on_fail x prepare_abe
run_step skip_on_fail -9 build_abe binutils
run_step skip_on_fail -8 build_abe stage1 -- \
"${gcc_override_configure[@]}"
run_step skip_on_fail x clean_sysroot
case "${rr[components]}" in
*glibc*)
run_step skip_on_fail -7 build_abe linux
run_step skip_on_fail -6 build_abe glibc
;;
*newlib*)
run_step skip_on_fail -6 build_abe newlib
;;
esac
run_step skip_on_fail -5 build_abe stage2 -- \
"${gcc_override_configure[@]}"
;;
llvm)
run_step skip_on_fail -3 build_bmk_llvm
;;
esac
run_step skip_on_fail 1 benchmark -- "$cflags" ${rr[top_artifacts]}/results_id
run_step reset_on_fail x check_regression
trap "" EXIT
|