-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecute
321 lines (265 loc) · 9.91 KB
/
execute
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
#!/bin/bash
. lib/settingsreader || exit -1
if [ -z $1 ]
then
echo "$0 XBH-IP [XBH-Port]"
exit -1
fi
# remove invalid characters
xbhIp=`echo $1 | tr -cd '[a-z][A-Z][0-9][\._\-]'`;
if [ -z "$2" ]
then
xbhPort=22595
else
xbhPort=`echo $2 | tr -cd '[0-9]'`;
fi
#debug
xbhCall="$xbhtool -v -i $xbhIp -p $xbhPort"
#silent
#xbhCall="$xbhtool -q -i $xbhIp -p $xbhPort"
xbhRevision=`$xbhCall --xbhRev | head -n 1 | cut -d ":" -f 2`
if [ -z "$xbhRevision" ]
then
echo "XBH at $xbhIp:$xbhPort not ready."
echo "Exiting.";
exit -2
fi
$xbhCall --comm $communicationMode
if [ "$?" != "0" ]
then
echo "Unable to set communication mode on XBH."
echo "Exiting.";
exit -3
fi
status=`$xbhCall -r`
if [ "$status" != "XBD03BLo" ] && [ "$status" != "XBD03AFo" ]
then
echo "Status request failed. XBD communication troubles?."
echo "Exiting.";
exit -4
fi
blRevision=`$xbhCall --blRev | head -n 1 | cut -d ":" -f 2`
if [ -z "$blRevision" ]
then
echo "Boot loader at $xbhIp:$xbhPort not ready."
echo "Exiting.";
exit -5
fi
ORIG_PROMPT_COMMAND="$PROMPT_COMMAND"
unset PROMPT_COMMAND
function title {
echo -ne "\033]0;XBX: $1\007"
#also set as screen window title when running in screen
if [ ! -z ${STY} ]; then
echo -ne "\033kXBX: $1\033\\"
fi
}
title "Starting up"
function doDriftMeasurement
{
doTimeStamp
drift="`$xbhCall --drift --cycles $cyclespersecond`"
nominal=`echo "$drift" | grep "Nominal cycles:" | cut -d ":" -f 2 | cut -b 2-`
measured=`echo "$drift" | grep "Measured cycles:" | cut -d ":" -f 2 | cut -b 2-`
time=`date +"%s"`;
echo "+$version $shorthostname $abi $startdate no op drift $time $nominal $measured" >&5
}
function doManyDriftMeasurements
{
doDriftMeasurement
doDriftMeasurement
doDriftMeasurement
doDriftMeasurement
doDriftMeasurement
}
function doTimeStamp
{
date
}
resultdir="$XBXPATH/bench/${platform}_${xbhIp}_${xbhPort}"
if [ -d "$resultdir" ]
then
rm -rf "$resultdir"
fi
mkdir -p "$resultdir"
exec > >(tee "$resultdir/log")
exec 2>&1
exec 5>"$resultdir/data"
compilerword=`echo "$compilerdesc" | tr ' ' '_'`
startdate=`date +%Y%m%d`
echo "+$version $shorthostname $abi $startdate no op xbhrevision $xbhRevision " >&5
echo "+$version $shorthostname $abi $startdate no op bootloaderrevision $blRevision " >&5
doManyDriftMeasurements
cat $XBXPATH/OPERATIONS \
| while read o macros prototypes
do
opPath="$binaries/$o";
[ -d "$opPath" ] || continue
ls "$opPath" \
| sort \
| while read p
do
[ -n "$onlyhash" ] && [ $p != "$onlyhash" ] && continue
[ -d "$opPath/$p" ] || continue
doDriftMeasurement
expectedchecksum=''
[ -f "$algobase/$o/$p/checksum_128b" ] && expectedchecksum=`cat "$algobase/$o/$p/checksum_128b" | tr A-Z a-z`
op="${o}_${p}"
echo "=== `date` === $abi $o/$p"
outputBytes=""
bestMedian=""
bestBinary=""
lastBinary=""
bestName=""
binaries=`find "$opPath/$p" -follow -name "xbdprog.bin" | sort`
binarySwitch="-f bin"
for binary in $binaries
do
fullimplementationdir=`dirname $binary`
if [ -e "$fullimplementationdir/xbdprog.hex" ]
then
binarySwitch="";
binary="$fullimplementationdir/xbdprog.hex";
fi
shortimplementationdir=`echo $fullimplementationdir | sed -r 's/^.*\/'$o'\/'$p'\///'`
implementationname=`echo $shortimplementationdir | sed -r 's/\/[^\/]+\/?$//' | tr "./ " ___`
compilerword=`echo $shortimplementationdir | sed -r 's/.*\///'| tr "./ " ___`
# fetch info file
compilerversion=""
textSize=""
dataSize=""
bssSize=""
infofile="$fullimplementationdir/xbdprog.txt"
if [ -e "$infofile" ]
then
compilerversion=`cat $infofile | grep "^COMPILERVERSION " | cut -d " " -f 2-`
textSize=`cat $infofile | grep "^TEXT " | cut -d " " -f 2`
dataSize=`cat $infofile | grep "^DATA " | cut -d " " -f 2`
bssSize=`cat $infofile | grep "^BSS " | cut -d " " -f 2`
dirchecksum=`cat $infofile | grep "^DIRCHECKSUM " | cut -d " " -f 2`
fi
echo "+$version $shorthostname $abi $startdate $o $p compilerversion $compilerversion " >&5
echo "+$version $shorthostname $abi $startdate $o $p sizeinfo $textSize $dataSize $bssSize" >&5
echo "+$version $shorthostname $abi $startdate $o $p dirchecksum $dirchecksum" >&5
echo "=== `date` === $abi $o/$p $implementationname $compilerword ($binarySwitch)"
doTimeStamp
title "$o/$p $implementationname $compilerword"
$xbhCall $binarySwitch -u "$binary"
if [ "$?" != "0" ]
then
echo "$version $shorthostname $abi $startdate $o $p tryfails $o/$p/$implementationname $compilerword error upload_failed" >&5
echo "$o $p $implementationname: Upload failed"
lastBinary=""
# try to fetch status twice to cope for a xbh reset
doTimeStamp
status=`$xbhCall --comm $communicationMode -r`
status=`$xbhCall --comm $communicationMode -r`
continue
fi
lastBinary=$binary
# test checksum
outputfile=`tempfile`
doTimeStamp
$xbhCall -c -e > "$outputfile"
returnCode=`head -n 1 "$outputfile"`
checksum=`head -n 2 "$outputfile" | tail -n 1 | tr A-Z a-z`
rm -f "$outputfile"
#echo "Result is $returnCode --- $checksum";
if [ "$returnCode" != "00" ]
then
echo "$version $shorthostname $abi $startdate $o $p tryfails $o/$p/$implementationname $compilerword error $returnCode" >&5
echo "Unable to execute $o $p $implementationname: $returncode";
# try to fetch status twice to cope for a xbh reset
status=`$xbhCall --comm $communicationMode -r`
status=`$xbhCall --comm $communicationMode -r`
continue
fi
checksumok=fails
doTimeStamp
checksumcycles=`$xbhCall --cycles $cyclespersecond -t`
# short benchmark, we only do it 5 times
doTimeStamp
measurementout=`$xbhCall -n 1536 5 --cycles $cyclespersecond`
cycles=`echo "$measurementout" | head -n 1 | cut -d " " -f 1`
stackUsage=`echo "$measurementout" | tail -n 1 | cut -d " " -f 1`
# echo "MO"
# echo $measurementout
# echo "CY"
# echo $cycles
# echo "ST"
# echo $stackUsage
[ -z "$cycles" ] && cycles=0
[ -z "$checksumcycles" ] && cycles=0
if [ "$cycles" == "0" ] || [ "$checksumcycles" == "0" ]
then
echo "$version $shorthostname $abi $startdate $o $p tryfails $o/$p/$implementationname $compilerword error unable to fetch results" >&5
echo "Unable to execute $o $p $implementationname: Duration is 0";
# try to fetch status twice to cope for a xbh reset
doTimeStamp
status=`$xbhCall --comm $communicationMode -r`
status=`$xbhCall --comm $communicationMode -r`
continue
fi
[ "x$expectedchecksum" = "x$checksum" ] && checksumok=ok
[ "x$expectedchecksum" = "x" ] && checksumok=unknown
echo "Benchmark took $cycles cycles, checksum: $checksumok"
echo "+$version $shorthostname $abi $startdate $o $p stackUsage $stackUsage $o/$p/$implementationname $compilerword" >&5
echo "$version $shorthostname $abi $startdate $o $p try $checksum $checksumok $cycles $checksumcycles $cyclespersecond $o/$p/$implementationname $compilerword" >&5
[ "$checksumok" = fails ] && continue
outputBytes=$(( ${#checksum} / 2 ))
if [ -z "$bestBinary" ] || [ $cycles -le $bestCycles ]
then
bestCycles=$cycles
bestBinary="$binary"
bestName=$implementationname
bestCompiler=$compilerword
bestDirchecksum=$dirchecksum
fi
done
if [ -n "$bestBinary" ]
then
echo "=== `date` === $abi $o/$p measuring $bestName, $bestCompiler ($bestCycles)"
if [ "$lastBinary" != "$bestBinary" ]
then
title "Measuring $o/$p $bestName, $bestCompiler"
echo "Uploading $bestName"
doTimeStamp
$xbhCall $binarySwitch -u "$bestBinary"
if [ "$?" != "0" ]
then
echo "$o $p $bestName: Upload for measurement failed"
status=`$xbhCall --comm $communicationMode -r`
status=`$xbhCall --comm $communicationMode -r`
continue
fi
fi
echo "$version $shorthostname $abi $startdate $o $p implementation $o/$p/$bestName $bestDirchecksum" >&5
echo "$version $shorthostname $abi $startdate $o $p outputbytes $outputBytes " >&5
echo "$version $shorthostname $abi $startdate $o $p cpuid $platform" >&5
echo "$version $shorthostname $abi $startdate $o $p cpucycles_persecond $cyclespersecond" >&5
echo "$version $shorthostname $abi $startdate $o $p cpucycles_implementation XBX" >&5
echo "$version $shorthostname $abi $startdate $o $p compiler $bestCompiler" >&5
repeat=8
lengths="0 1 2 4 8 16 32 64 128 256 512 576 1024 1536 2048"
for l in $lengths; do
echo "measuring $l bytes"
doTimeStamp
measurementout=`$xbhCall -n $l $repeat --cycles $cyclespersecond`
cycles=`echo "$measurementout" | head -n 1`
stackUsage=`echo "$measurementout" | tail -n 1`
echo "$version $shorthostname $abi $startdate $o $p cycles $l $cycles" >&5
echo "+$version $shorthostname $abi $startdate $o $p stack $l $stackUsage" >&5
done
fi
done
done
title "Finalising"
doManyDriftMeasurements
sed 's/^/+ /' <"$resultdir/log" >&5
echo "=== `date` === completed"
echo "Results stored in $resultdir/data"
zipfilename="xbxdata-$shorthostname-$xbhIp-`date +"%s"`.gz"
cat "$resultdir/data" | gzip > "$zipfilename"
echo "Compressed result file is $zipfilename"
title ""
PROMPT_COMMAND="$ORIG_PROMPT_COMMAND"