summaryrefslogtreecommitdiff
path: root/tcwg_bmk-build.sh
blob: c0b6298414a8e38b729f5631c4e5009b79251b59 (plain)
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
#!/bin/bash

set -euf -o pipefail

scripts=$(dirname $0)
. $scripts/jenkins-helpers.sh
. $scripts/round-robin.sh

convert_args_to_variables "$@"

obligatory_variables rr[ci_config] ssh_host ssh_port

# Execution mode: baseline, bisect, jenkins-full
rr[mode]="${rr[mode]-baseline}"

# Set custom revision for one of the projects, and use baseline revisions
# for all other projects.
rr[ci_project]="${rr[ci_project]-tcwg_bmk}"
rr[baseline_branch]="${rr[baseline_branch]-linaro-local/ci/${rr[ci_project]}/${rr[ci_config]}}"
rr[reset_baseline]="${rr[reset_baseline]-false}"
rr[top_artifacts]="${rr[top_artifacts]-$(pwd)/artifacts}"

# {toolchain_name}-{toolchain_ver}-{target}-{bmk}-{cflags}
IFS=- read -a ci_config <<EOF
${rr[ci_config]}
EOF
rr[toolchain]=${rr[toolchain]-${ci_config[0]}}
rr[target]=${rr[target]-${ci_config[2]}}
cflags=${cflags-${ci_config[4]}}

case "${rr[toolchain]}" in
    llvm) rr[components]="binutils gcc glibc llvm" ;;
    gnu) rr[components]="binutils gcc glibc" ;;
    *) assert false ;;
esac

# Use baseline branches by default.
for c in ${rr[components]}; do
    rr[${c}_branch]=${rr[${c}_branch]-baseline}
    obligatory_variables rr[${c}_url]
done

start_at="${start_at-default}"
finish_at="${finish_at-default}"
verbose="${verbose-true}"
verbose2="${verbose2-false}"

if $verbose2; then set -x; fi

trap "eval \"echo ERROR at \${FUNCNAME[0]}:\${BASH_LINENO[0]}\"" EXIT

# Set start and finish steps for different modes.
default_start_at=""
default_finish_at=""
case "${rr[mode]}" in
    "baseline")
	default_finish_at="update_baseline"
	;;
    "bisect")
	case "$(print_single_updated_component)" in
	    binutils) default_start_at="build_abe-binutils" ;;
	    gcc) default_start_at="build_abe-stage1" ;;
	    glibc) default_start_at="build_abe-glibc" ;;
	    llvm) default_start_at="build_llvm-true" ;;
	    *) assert false ;;
	esac
	default_finish_at="check_regression"
	;;
    "jenkins-full") ;;
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"

benchmark ()
{
    (
    set -euf -o pipefail

    rm -rf $(pwd)/bin
    mkdir $(pwd)/bin

    local bmk_flags
    bmk_flags="$(echo -$cflags | sed -e "s/_/ -/g" -e "s/LTO/flto/g")"
    case "$cflags" in
	"Os*"|"Oz*")
	    # Use static linking for size benchmarking to pickup library
	    # code size increases in the final executable.
	    bmk_flags="$bmk_flags -static"
	    ;;
    esac

    local bench_list bin cc gnu_target sysroot
    gnu_target=$(print_gnu_target ${rr[target]})
    sysroot="$(pwd)/abe/sysroots/$gnu_target"
    case "${rr[toolchain]}" in
	llvm)
	    bench_list="c_and_cxx"
	    bmk_flags="$bmk_flags --target=$gnu_target --sysroot=$sysroot"
	    bin="$(pwd)/llvm-install/bin"
	    cc="$bin/"
	    ;;
	gnu)
	    bench_list="all"
	    bin="$(pwd)/abe/builds/destdir/x86_64-unknown-linux-gnu/bin"
	    cc="$bin/$gnu_target-"
	    ;;
    esac
    sysroot="ssh://$ssh_host:$ssh_port:$sysroot"

    local hw results_id
    case "${rr[target]}" in
	arm*) hw=tk1 ;;
	*) hw=tx1 ;;
    esac
    local results_id="@hw_type@/${rr[ci_project]}/${rr[ci_config]}-@build_num@"

    remote_exec "ci.linaro.org:2222::-l $USER@linaro.org" \
		build tcwg-benchmark -s -v \
		-p bench_list="$bench_list" \
		-p cflags="$bmk_flags" \
		-p testmode=benchmark \
		-p displaytag="${rr[ci_config]}" \
		-p toolchain_url=ssh://$ssh_host:$ssh_port:$cc \
		-p toolchain_type=${rr[toolchain]} \
		-p sysroot="$sysroot" \
		-p results_id="$results_id" \
		-p target_list="$hw" \
		-p scripts_branch="$scripts_branch" \
		-p bmk_branch="$bmk_branch" | tee $run_step_artifacts/benchmark.log
    local build_num
    build_num=$(tail -n1 $run_step_artifacts/benchmark.log \
		    | grep SUCCESS \
		    | sed -e "s/.*#\([0-9]\+\)-.*/\1/")

    echo "$results_id" | sed -e "s/@build_num@/$build_num/g" \
			     > "${rr[top_artifacts]}/results_id"
    )
}

# Exit with code 0 if no regression compared to base-artifacts/results.
no_regression_p ()
{
    (
    set -euf -o pipefail

    if ! [ -f base-artifacts/results ]; then
	return 0
    fi

    local build_result_ref build_result_new
    build_result_ref=$(tail -n1 base-artifacts/results)
    build_result_new=$(tail -n1 ${rr[top_artifacts]}/results)

    if [ $build_result_new -lt $build_result_ref ]; then
	return 1
    fi

    if ! [ -f base-artifacts/results_id ]; then
	return 0
    elif ! [ -f ${rr[top_artifacts]}/results_id ]; then
	return 1
    fi

    local results_ref results_new
    results_ref=$(cat base-artifacts/results_id)
    results_new=$(cat ${rr[top_artifacts]}/results_id)

    $scripts/tcwg-benchmark-results.sh --results_ref $results_ref --results_id $results_new --top_artifacts "${rr[top_artifacts]}" --verbose $verbose

    # Skip header line
    tail -n +2 ${rr[top_artifacts]}/results.csv | \
    while IFS=, read -r bmk symbol speed size; do
	# Skip case where we have no info ("n/a")
	if [ "$size" != "n/a" ]; then
	    if [ "$size" -gt 100 ]; then
		echo "Regression in bench $bmk, symbol $symbol size increased ($size vs 100)"
		return 1
	    fi
	fi
    done
    )
}

run_step stop_on_fail -10 reset_artifacts
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
run_step skip_on_fail -7 build_abe linux
run_step skip_on_fail -6 build_abe glibc
run_step skip_on_fail -5 build_abe stage2
case "${rr[toolchain]}" in
    llvm) run_step skip_on_fail -1 build_llvm true ;;
esac
run_step skip_on_fail 0 benchmark
run_step reset_on_fail x check_regression
run_step stop_on_fail x update_baseline
run_step stop_on_fail x push_baseline

trap "" EXIT