aboutsummaryrefslogtreecommitdiff
path: root/spec2xxx-prepare
blob: 491422bffa9dfbac195f542c253ffb68c8926e10 (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
#!/bin/bash

set -e
set -x

${0%%-prepare}-check prepare

host=$HOST
target=$TARGET
spec=$SPEC
config=$CONFIG
cc_prefix=$1
optimize="$2"
cpuinfo=$3

if [ "$host" != "$target" ]; then
    local=false
else
    local=true
fi

spec=$(cd $spec; pwd)

$local || sshfs $target:$spec $spec

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")
ssh -S $spec/ssh-%r@%h:%p $host "cd \$(pwd); $cc_prefix$cc \$cmd"
EOF
    chmod +x $spec/bin/ssh-$config-$cc
done

if [ "$cpuinfo" = "" ]; then
    cpuinfo=$spec/cpuinfo
    ssh $target cat /proc/cpuinfo > $cpuinfo
fi

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="$(ssh $target 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 "$hw_cpu" in
    *"v7l"*) mcpu="-mcpu=cortex-a15" ;;
    *"aarch64"*) mcpu="-mcpu=cortex-a57" ;;
    *) mcpu="" ;;
esac

case "$hw_fpu" in
    *"neon"*"vfpv4"*) mfpu="-mfpu=neon-vfpv4" ;;
    *) mfpu="" ;;
esac

arch="$(ssh $target uname -m)"
case "$arch" in
    "aarch64"|"x86_64")
	spec_cpu2000_lp64="-DSPEC_CPU2000_LP64"
	spec_cpu_lp64="-DSPEC_CPU_LP64"
	;;
    "armv7l"|"ia32"|*)
	spec_cpu2000_lp64=""
	spec_cpu_lp64=""
	;;
esac

case "$arch" in
    "aarch64")
	case "$optimize" in
	    *"cortex-a53"*) taskset_cpu="1" ;;
	    *) taskset_cpu="4" ;;
	esac
	;;
    *) taskset_cpu="1" ;;
esac

cfg_tmpl="$(dirname $0)/cpu2xxx.cfg"
if grep CPU2000 $spec/shrc; then
    cfg_tmpl="$cfg_tmpl $(dirname $0)/cpu2000.cfg"
    iterations="3"
elif grep CPU2006 $spec/shrc; then
    cfg_tmpl="$cfg_tmpl $(dirname $0)/cpu2006.cfg"
    iterations="3"
fi

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@#$(getconf _NPROCESSORS_ONLN)#g" \
    -e "s#@SUBMIT@#taskset -c $taskset_cpu \$command#g" \
    -e "s#@ITERATIONS@#$iterations#g" \
    -e "s#@ITERATIONS_2@#$(($iterations+2))#g" \
    -e "s#@ITERATIONS_4@#$(($iterations+4))#g" \
    -e "s#@CC@#ssh-$config-gcc#g" \
    -e "s#@CXX@#ssh-$config-g++#g" \
    -e "s#@FORTRAN@#ssh-$config-gfortran#g" \
    -e "s#@OPTIMIZE@#$optimize#g" \
    -e "s#@MCPU@#$mcpu#g" \
    -e "s#@MFPU@#$mfpu#g" \
    -e "s#@PROFILEDIR@#$spec#g" \
    -e "s#@DSPEC_CPU2000_LP64@#$spec_cpu2000_lp64#g" \
    -e "s#@DSPEC_CPU_LP64@#$spec_cpu_lp64#g" \
    > $spec/config/$config.tmp

if ! diff -u $spec/config/$config.tmp $spec/config/$config.cfg | head -n 8 | grep __MD5__; then
    mv $spec/config/$config.tmp $spec/config/$config.cfg
else
    rm $spec/config/$config.tmp
fi

$local || fusermount -uz $spec