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
|
#!/bin/bash
set -e
bind_cpu="1"
build=""
cc_flags=""
cc_prefix=""
config="default"
helper_cpu="$(($bind_cpu-1))"
mcpu=""
mfpu=""
perf_events=""
profiler="none"
save_temps=false
sysinfo_program="default"
OPTS="`getopt -o ve: -l bind:,build:,ccflags:,ccprefix:,config:,event:,helpercpu:,mcpu:,mfpu:,profiler:,save-temps,sysinfo: -- "$@"`"
while test $# -gt 1; do
case $1 in
--bind) bind_cpu="$2"; shift ;;
--build) build="$2"; shift ;;
--ccflags) cc_flags="$2"; shift ;;
--ccprefix) cc_prefix="$2"; shift ;;
--config) config="$2"; shift ;;
-e|--event) perf_events="$perf_events -e $2"; shift ;;
--helpercpu) helper_cpu="$2"; shift ;;
--mcpu) mcpu="$2"; shift ;;
--mfpu) mfpu="$2"; shift ;;
--profiler) profiler="$2"; shift ;;
--save-temps) save_temps=true ;;
--sysinfo) sysinfo_program="$2"; shift ;;
-v) set -x ;;
esac
shift
done
spec=$(cd $1; pwd)
shift
if ! [ -d "$spec" ]; then
echo "ERROR: SPEC directory does not exist: $spec"
exit 1
fi
if [ $# -gt 0 ]; then
echo "ERROR: Extra arguments: $@"
exit 1
fi
if [ x"$build" != x"" ]; then
# <host>[:<type>][:<parallelize>][:<port>]
build_host="$(echo $build | cut -d: -f 1)"
build_type="$(echo $build | cut -d: -f 2)"
parallelize="$(echo $build | cut -d: -f 3)"
build_port="$(echo $build | cut -d: -f 4)"
if [ x"$build_host" = x"" ]; then
echo "ERROR: wrong --build: $build"
exit 1
fi
if [ x"$build_type" = x"" ]; then build_type="rsync"; fi
if [ x"$parallelize" = x"" ]; then
parallelize="$(ssh $build_port $build_host getconf _NPROCESSORS_ONLN)"
fi
if [ x"$build_port" != x"" ]; then build_port="-p$build_port"; fi
if [ x"$build_type" = x"rsync" ]; then
lock=$spec/bin/ssh-$config.lock
count=$spec/bin/ssh-$config.lockcnt
rm -f $lock $count
for cc in gcc g++ gfortran; do
cat > $spec/bin/ssh-$config-$cc <<EOF
#!/bin/bash
set -e
cmd=\$(echo "\$@" | sed -e 's#"#\\"#g' -e "s#'#\\'#g")
dir=\$(pwd)
if echo \$dir | grep -q $spec/benchspec; then
lock=$lock
count=$count
(
flock -x 123
touch \$count
n=\$(cat \$count)
if [ x"\$n" = x"" ]; then n="0"; fi
if [ x"\$n" = x"0" ]; then
rsync -e "ssh $build_port" --rsync-path "mkdir -p \$dir; rsync" -az --delete \$dir/ $build:\$dir/
fi
n=\$((\$n+1))
echo \$n > \$count
) 123>\$lock
flock -s \$lock ssh $build_port $build_host "cd \$(pwd); exec $cc_prefix$cc \$cmd" | cat
res=\${PIPESTATUS[0]}
(
flock -x 123
n=\$(cat \$count)
if ! [ \$n -gt 0 ]; then exit 1; fi
n=\$((\$n-1))
echo \$n > \$count
if [ x"\$n" = x"0" ]; then
rsync -e "ssh $build_port" -az --delete $build_host:\$dir/ \$dir/
fi
) 123>\$lock
else
ssh $build_port $build_host "cd \$(pwd); exec $cc_prefix$cc \$cmd" | cat
res=\${PIPESTATUS[0]}
fi
exit \$res
EOF
chmod +x $spec/bin/ssh-$config-$cc
done
cat > $spec/bin/ssh-$config-tar <<EOF
#!/bin/sh
set -e
dir=\$(pwd)
rsync -e "ssh $build_port" --rsync-path "mkdir -p \$dir; rsync" -az --delete \$dir/ $build_host:\$dir/
exec ssh $build_port $build_host "cd \$dir; exec tar \$@"
EOF
chmod +x $spec/bin/ssh-$config-tar
elif [ x"$build_type" = x"sshfs" ]; then
for cc in gcc g++ gfortran; do
cat > $spec/bin/ssh-$config-$cc <<EOF
#!/bin/sh
cmd=\$(echo "\$@" | sed -e 's#"#\\"#g' -e "s#'#\\'#g")
exec ssh $build_port $build_host "cd \$(pwd); exec $cc_prefix$cc \$cmd"
EOF
done
cat > $spec/bin/ssh-$config-tar <<EOF
#!/bin/sh
exec ssh $build_port $build_host "cd \$(pwd); exec tar \$@"
EOF
else
echo "ERROR: Wrong --build type: $build_type"
exit 1
fi
for cc in gcc g++ gfortran tar; do
chmod +x $spec/bin/ssh-$config-$cc
done
cc_prefix="$spec/bin/ssh-$config-"
tar_prog=$spec/bin/ssh-$config-tar
ssh -fN -o ControlPersist=yes $build_port $build_host
remotefs_parallelize="$parallelize"
if [ x"$build_type" = x"rsync" ]; then
# Several fortran tests use non-compiler preprocessor, which
# modifies local FS de-synchronizing it with the remote view.
# Therefore we can't use parallel compilation for these tests
# with rsync approach.
remotefs_parallelize="1"
fi
else
tar_prog=tar
parallelize="$(getconf _NPROCESSORS_ONLN)"
remotefs_parallelize="$parallelize"
fi
if $save_temps; then
cc_flags="$cc_flags -save-temps=obj"
save_temps_mark=""
else
save_temps_mark="#"
fi
cpuinfo="/proc/cpuinfo"
hw_model="$(cat $cpuinfo | grep Hardware | head -n 1 | sed -e 's/.*: //')"
hw_cpu="$(cat $cpuinfo | grep "model name\|Processor" | head -n 1 | sed -e 's/.*: //')"
hw_fpu="$(cat $cpuinfo | grep Features | head -n 1 | sed -e 's/.*: //')"
sw_os="$(uname -r | head -n 1)"
sw_compiler="$(${cc_prefix}gcc -v 2>&1 | tail -n 1)"
#sw_compiler="$sw_compiler $(${cc_prefix}gcc -v 2>&1 | grep 'Configured with' | head -n 1)"
case "$mcpu:$hw_cpu" in
"autodetect:"*"v7l"*) mcpu="-mcpu=cortex-a15" ;;
"autodetect:"*"aarch64"*) mcpu="-mcpu=cortex-a57" ;;
"autodetect:"*)
echo "ERROR: Cannot autodetect -mcpu: $hw_cpu"
exit 1
;;
esac
case "$mfpu:$hw_fpu" in
"autodetect:"*"neon"*"vfpv4"*) mfpu="-mfpu=neon-vfpv4" ;;
"autodetect:"*)
echo "ERROR: Cannot autodetect -mfpu: $hw_fpu"
exit 1
;;
esac
arch="$(uname -m)"
case "$arch" in
"aarch64"|"x86_64")
spec_cpu2000_lp64="-DSPEC_CPU2000_LP64"
spec_cpu_lp64="-DSPEC_CPU_LP64"
setarch="linux64"
;;
"armv7l"|"ia32"|*)
spec_cpu2000_lp64=""
spec_cpu_lp64=""
setarch="linux32"
;;
esac
taskset_cpu="$bind_cpu"
rate_copies="1"
if [ "$rate_copies" -gt "1" ]; then
case "$mcpu" in
"-mcpu=cortex-a57.cortex-a53")
bind_cpu="1,2,3,0,4,5,4,5"
taskset_cpu="1"
rate_copies="8"
;;
"-mcpu=cortex-a53")
bind_cpu="1,2,3,0"
taskset_cpu="1"
rate_copies="4"
;;
"-mcpu=cortex-a57")
bind_cpu="4,5"
taskset_cpu="4"
rate_copies="2"
;;
esac
fi
free_ram="$(free | grep "Mem:" | sed -e "s/Mem: *\([0-9]*\).*/\1/")"
max_mcf_rate_copies="$(($free_ram / (2*1024*1024) + 1))"
if [ "$max_mcf_rate_copies" -gt "$rate_copies" ]; then
max_mcf_rate_copies="$rate_copies"
fi
cfg_tmpl="$(dirname $0)/cpu2xxx.cfg"
if grep -q CPU2000 $spec/shrc; then
cfg_tmpl="$cfg_tmpl $(dirname $0)/cpu2000.cfg"
iterations="3"
elif grep -q CPU2006 $spec/shrc; then
cfg_tmpl="$cfg_tmpl $(dirname $0)/cpu2006.cfg"
iterations="1"
fi
if [ x"$sysinfo_program" != x"default" ]; then
sysinfo_program="sysinfo_program = $sysinfo_program"
else
sysinfo_program=""
fi
case "$profiler" in
"none")
profiler_none=""
profiler_perf="#"
;;
"perf"*)
profiler_none="#"
profiler_perf=""
;;
*)
echo "ERROR: Unknown profiler: $profiler"
exit 1
;;
esac
# --profiler perf[-cpu_all][-cg]
# --profiler perf-cpu_all
# --profiler perf-cpu_all
case "$profiler" in
"perf"*"-cpu_all"*)
perf_cpu="-a"
;;
"perf"*"-cpu_bind"*|"perf"*)
perf_cpu="--cpu @BIND@"
;;
esac
case "$profiler" in
"perf"*"-cg"*)
perf_callgraph="-g"
;;
"perf"*"-no_cg"*|"perf"*)
perf_callgraph=""
;;
esac
cpufreq="$(cpufreq-info -c $bind_cpu -f 2>/dev/null | cat)"
while [ x"$cpufreq" != x"" ]; do
if [ x"$perf_events" = x"" ]; then
perf_events="-e cycles/period=10HZ/"
fi
event_freq="$(echo "$perf_events" | sed -e "s#\(.*\)=\([0-9]*\)HZ\(.*\)#\2#")"
if [ x"$event_freq" = x"$perf_events" ]; then
break
fi
event_count=$((1000*$cpufreq/$event_freq))
perf_events="$(echo "$perf_events" | sed -e "s#\(.*\)=\([0-9]*\)HZ\(.*\)#\1=$event_count\3#")"
done
cat $cfg_tmpl | sed \
-e "s#@HW_MODEL@#$hw_model#g" \
-e "s#@HW_CPU@#$hw_cpu#g" \
-e "s#@HW_FPU@#$hw_fpu#g" \
-e "s#@SW_OS@#$sw_os#g" \
-e "s#@SW_COMPILER@#$sw_compiler#g" \
-e "s#@PARALLELIZE@#$parallelize#g" \
-e "s#@HELPER_CPU@#$helper_cpu#g" \
-e "s#@TASKSET_CPU@#$taskset_cpu#g" \
-e "s#@ITERATIONS@#$iterations#g" \
-e "s#@ITERATIONS_2@#$(($iterations+2))#g" \
-e "s#@ITERATIONS_4@#$(($iterations+4))#g" \
-e "s#@CC@#${cc_prefix}gcc#g" \
-e "s#@CXX@#${cc_prefix}g++#g" \
-e "s#@FORTRAN@#${cc_prefix}gfortran#g" \
-e "s#@OPTIMIZE@#$cc_flags#g" \
-e "s#@REMOTEFS_PARALLELIZE@#$remotefs_parallelize#g" \
-e "s#@MCPU@#$mcpu#g" \
-e "s#@MFPU@#$mfpu#g" \
-e "s#@PROFILEDIR@#$spec/profile#g" \
-e "s#@DSPEC_CPU2000_LP64@#$spec_cpu2000_lp64#g" \
-e "s#@DSPEC_CPU_LP64@#$spec_cpu_lp64#g" \
-e "s#@RATE_COPIES@#$rate_copies#g" \
-e "s#@MAX_MCF_RATE_COPIES@#$max_mcf_rate_copies#g" \
-e "s#@PERF_CALLGRAPH@#$perf_callgraph#g" \
-e "s#@PERF_CPU@#$perf_cpu#g" \
-e "s#@BIND@#$bind_cpu#g" \
-e "s#@PERF_EVENTS@#$perf_events#g" \
-e "s/@PROFILER_NONE@/$profiler_none/g" \
-e "s/@PROFILER_PERF@/$profiler_perf/g" \
-e "s/@SAVE_TEMPS@/$save_temps_mark/g" \
-e "s#@SETARCH@#$setarch#g" \
-e "s#@SYSINFO_PROGRAM@#$sysinfo_program#g" \
-e "s#@TAR@#$tar_prog#g" \
> $spec/config/$config.tmp
if ! diff -u $spec/config/$config.tmp $spec/config/$config.cfg 2>&1 | head -n 8 | grep -q __MD5__; then
mv $spec/config/$config.tmp $spec/config/$config.cfg
else
rm $spec/config/$config.tmp
fi
|