1 | #!/bin/bash -
|
---|
2 |
|
---|
3 | false=0; true=1
|
---|
4 |
|
---|
5 | # Usage: arch [ hostname ] returns hostname, cores, startcore
|
---|
6 | #
|
---|
7 | # Define machine architecture based on starting socket, CPUs (cores) per socket, number of
|
---|
8 | # sockets, has hyperthreading.
|
---|
9 |
|
---|
10 | start=0
|
---|
11 |
|
---|
12 | arch() {
|
---|
13 | hostname=${1:-`hostname`} # return value
|
---|
14 | hashyper=${true} # assume machine has hyperthreads
|
---|
15 | if [ "${hostname}" = "plg2" ] ; then
|
---|
16 | startsocket=${start}
|
---|
17 | cps=16 # coresPerSocket
|
---|
18 | sockets=2
|
---|
19 | hashyper=${false} # has no hyperthreads
|
---|
20 | elif [ "${hostname}" = "nasus" ] ; then
|
---|
21 | startsocket=${start}
|
---|
22 | cps=64 # coresPerSocket
|
---|
23 | sockets=2
|
---|
24 | elif [ "${hostname}" = "pyke" ] ; then
|
---|
25 | startsocket=${start}
|
---|
26 | cps=24 # coresPerSocket
|
---|
27 | sockets=2
|
---|
28 | elif [ "${hostname}" = "jax" ] ; then
|
---|
29 | startsocket=${start}
|
---|
30 | cps=24 # coresPerSocket
|
---|
31 | sockets=4
|
---|
32 | else
|
---|
33 | echo "unsupported host" ${hostname}
|
---|
34 | exit 1
|
---|
35 | fi
|
---|
36 | cores=$(( ${cps} * ${sockets} ))
|
---|
37 | startcore=$(( ${startsocket} * ${cps} ))
|
---|
38 | }
|
---|
39 |
|
---|
40 | # Usage: affinity (global cps, sockets, startsocket, hashyper, cores, startcore, wrap)
|
---|
41 | # returns taskset argument
|
---|
42 | #
|
---|
43 | # This routine assumes hyperthreading has only 2 hyperthreads per core.
|
---|
44 | #
|
---|
45 | # If hyperthread scanning is used: processor units are assigned across the low-number hyperthreads
|
---|
46 | # of the socket's cores. When the low-number hyperthreads are filled, the high-number hyperhtreads
|
---|
47 | # are assigned across the socket's cores. Then the next socket is assigned.
|
---|
48 | #
|
---|
49 | # If hyperthread wrapping is used: processor units are assigned in low/high-number pairs of
|
---|
50 | # hyperthreads across the socket's cores. Then the next socket is assigned.
|
---|
51 |
|
---|
52 | wrap=${false} # set to control hyperthread assignment across socket cores
|
---|
53 |
|
---|
54 | affinity() {
|
---|
55 | if [ ${wrap} -eq ${true} -a ${hashyper} -eq ${false} ] ; then
|
---|
56 | echo "architecture does not support hyperthreading for wrapping"
|
---|
57 | exit 1
|
---|
58 | fi
|
---|
59 | taskset="" # return value
|
---|
60 | set -- $(( ${1} - 1 )) # decrement $1
|
---|
61 | if [ ${1} -eq 0 ] ; then taskset="${startcore}-${startcore}"; return; fi
|
---|
62 | if [ ${1} -ge $(( ${cps} * ( ${sockets} - ${startsocket} ) * ( ${hashyper} + 1 ) )) ] ; then # error
|
---|
63 | echo "not enough cores $(( ${cores} * ${sockets} )) for $(( ${1} + 1 )) starting at ${startcore}"
|
---|
64 | exit 1
|
---|
65 | fi
|
---|
66 | if [ ${hashyper} -eq ${false} ] ; then taskset="${startcore}-$(( ${1} + ${startcore} ))"; return; fi # no hyperthreads
|
---|
67 | start2=$(( ${startcore} + ${cores} ))
|
---|
68 | if [ ${wrap} -eq ${true} ] ; then # hyperthread wrapping
|
---|
69 | end1=$(( ${1} / 2 + ${startcore} ))
|
---|
70 | end2=$(( ${end1} + ${cores} ))
|
---|
71 | if [ $(( ${1} % 2 )) -eq 0 ] ; then
|
---|
72 | end2=$(( ${end2} - 1 ))
|
---|
73 | fi
|
---|
74 | taskset="${startcore}-${end1},${start2}-${end2}"
|
---|
75 | else # hyperthread scanning
|
---|
76 | if [ ${1} -lt ${cps} ] ; then taskset="${startcore}-$(( ${1} + ${startcore} ))"; return; fi
|
---|
77 | filled=$(( ${1} / ( ${cps} * 2 ) * ${cps} ))
|
---|
78 | modulus=$(( ${1} % ( ${cps} * 2 ) )) # leftover cores added to saturated sockets
|
---|
79 | if [ ${modulus} -gt ${cps} ] ; then
|
---|
80 | taskset="${startcore}-$(( ${startcore} + ${filled} + ${cps} - 1 )),${start2}-$(( ${start2} + ${filled} + ${modulus} % ${cps} ))"
|
---|
81 | else
|
---|
82 | taskset="${startcore}-$(( ${startcore} + ${filled} + ${modulus} )),${start2}-$(( ${start2} + ${filled} - 1 ))"
|
---|
83 | fi
|
---|
84 | fi
|
---|
85 | }
|
---|
86 |
|
---|
87 | # numtimes=5
|
---|
88 | numtimes=1
|
---|
89 |
|
---|
90 | # num_threads='2 4 8 16 24 32'
|
---|
91 | # side_chan_threads='6 12 18 24 30' # must be mults of 6
|
---|
92 | num_threads='2'
|
---|
93 | side_chan_threads='6'
|
---|
94 |
|
---|
95 | chan_size='10'
|
---|
96 |
|
---|
97 | # toggle benchmarks
|
---|
98 | spin=${true}
|
---|
99 | contend=${true}
|
---|
100 | sidechan=${true}
|
---|
101 | # spin=${false}
|
---|
102 | # contend=${false}
|
---|
103 | # sidechan=${false}
|
---|
104 |
|
---|
105 | runCFA=${true}
|
---|
106 | runGO=${true}
|
---|
107 | # runCFA=${false}
|
---|
108 | # runGO=${false}
|
---|
109 |
|
---|
110 | cfa=~/cfa-cc/driver/cfa
|
---|
111 |
|
---|
112 | # Helpers to minimize code duplication
|
---|
113 |
|
---|
114 | # repeats a command ${numtimes}
|
---|
115 | preprint=''
|
---|
116 | repeat_command() {
|
---|
117 | t=1
|
---|
118 | while [ ${t} -le ${numtimes} ] ; do
|
---|
119 | echo -n -e ${preprint}
|
---|
120 | "${@}"
|
---|
121 | t=`expr ${t} + 1`
|
---|
122 | done
|
---|
123 | }
|
---|
124 |
|
---|
125 | # prints the leading info for a given run of a variant
|
---|
126 | print_header() {
|
---|
127 | echo ${1}':'
|
---|
128 | echo -e "cores\tthroughput (entries)"
|
---|
129 | }
|
---|
130 |
|
---|
131 | # runs the current benchmark with provided args
|
---|
132 | # only works for standard-run benchmarks (not Akka)
|
---|
133 | # must split into pre and post args to be able to supply val of p
|
---|
134 | pre_args=''
|
---|
135 | post_args=''
|
---|
136 | single_run() {
|
---|
137 | affinity ${1}
|
---|
138 | preprint="${1}\t"
|
---|
139 | repeat_command taskset -c ${taskset} ./a.${hostname} ${pre_args} ${1} ${post_args}
|
---|
140 | }
|
---|
141 |
|
---|
142 | # runs the current bench for all processor vals
|
---|
143 | # works for standard benchs that dont need to set a config file (not Akka or CAF)
|
---|
144 | run_bench() {
|
---|
145 | for p in ${num_threads} ; do
|
---|
146 | single_run ${p}
|
---|
147 | done
|
---|
148 | }
|
---|
149 |
|
---|
150 | run_side_chan() {
|
---|
151 | i=1
|
---|
152 | for p in ${side_chan_threads} ; do
|
---|
153 | affinity ${p}
|
---|
154 | preprint="${p}\t"
|
---|
155 | repeat_command taskset -c ${taskset} ./a.${hostname} ${pre_args} ${i} ${post_args}
|
---|
156 | i=`expr ${i} + 1`
|
---|
157 | done
|
---|
158 | }
|
---|
159 |
|
---|
160 | arch # get hostname
|
---|
161 |
|
---|
162 | # set up leading info for python script
|
---|
163 | echo $numtimes
|
---|
164 | echo $num_threads
|
---|
165 | echo $side_chan_threads
|
---|
166 |
|
---|
167 | if [ ${runCFA} -eq ${true} ]; then
|
---|
168 | echo -n 'CFA '
|
---|
169 | fi
|
---|
170 | if [ ${runGO} -eq ${true} ]; then
|
---|
171 | echo -n 'Go '
|
---|
172 | fi
|
---|
173 | echo ""
|
---|
174 |
|
---|
175 | # done printing header info for output
|
---|
176 |
|
---|
177 | # cfa flags
|
---|
178 | cfa_flags='-quiet -O3 -nodebug -DNDEBUG'
|
---|
179 |
|
---|
180 | # run the benchmarks
|
---|
181 |
|
---|
182 | run_contend() {
|
---|
183 | post_args=${1}
|
---|
184 |
|
---|
185 | if [ ${runCFA} -eq ${true} ] ; then
|
---|
186 | cd cfa # CFA RUN
|
---|
187 | print_header 'CFA'
|
---|
188 | ${cfa} ${cfa_flags} '-DNUM_CHANS='${3} ${2}.cfa -o a.${hostname} > /dev/null 2>&1
|
---|
189 | run_bench
|
---|
190 | rm a.${hostname}
|
---|
191 | cd - > /dev/null
|
---|
192 | fi # done CFA
|
---|
193 |
|
---|
194 | if [ ${runGO} -eq ${true} ] ; then
|
---|
195 | cd go/${2}${3} # Go RUN
|
---|
196 | print_header 'Go'
|
---|
197 | go build -o a.${hostname} > /dev/null 2>&1
|
---|
198 | run_bench
|
---|
199 | rm a.${hostname}
|
---|
200 | cd - > /dev/null
|
---|
201 | fi # done Go
|
---|
202 | }
|
---|
203 |
|
---|
204 | # /usr/bin/time -f "%Uu %Ss %Er %Mkb"
|
---|
205 | if [ ${contend} -eq ${true} ] ; then
|
---|
206 | echo "contend2: "
|
---|
207 | run_contend ${chan_size} 'contend' '2'
|
---|
208 | echo "contend4: "
|
---|
209 | run_contend ${chan_size} 'contend' '4'
|
---|
210 | echo "contend8: "
|
---|
211 | run_contend ${chan_size} 'contend' '8'
|
---|
212 | fi
|
---|
213 |
|
---|
214 | if [ ${spin} -eq ${true} ] ; then
|
---|
215 | echo "spin2: "
|
---|
216 | run_contend ${chan_size} 'spin' '2'
|
---|
217 | echo "spin4: "
|
---|
218 | run_contend ${chan_size} 'spin' '4'
|
---|
219 | echo "spin8: "
|
---|
220 | run_contend ${chan_size} 'spin' '8'
|
---|
221 | fi
|
---|
222 |
|
---|
223 | if [ ${sidechan} -eq ${true} ] ; then
|
---|
224 | echo "sidechan: "
|
---|
225 | post_args=${chan_size}
|
---|
226 | if [ ${runCFA} -eq ${true} ] ; then
|
---|
227 | cd cfa # CFA RUN
|
---|
228 | print_header 'CFA'
|
---|
229 | ${cfa} ${cfa_flags} sidechan.cfa -o a.${hostname} > /dev/null 2>&1
|
---|
230 | run_side_chan
|
---|
231 | rm a.${hostname}
|
---|
232 | cd - > /dev/null
|
---|
233 | fi # done CFA
|
---|
234 |
|
---|
235 | if [ ${runGO} -eq ${true} ] ; then
|
---|
236 | cd go/sidechan
|
---|
237 | print_header 'Go'
|
---|
238 | go build -o a.${hostname} > /dev/null 2>&1
|
---|
239 | run_side_chan
|
---|
240 | rm a.${hostname}
|
---|
241 | cd - > /dev/null
|
---|
242 | fi # done Go
|
---|
243 | fi
|
---|
244 |
|
---|