| 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 | future_time='10'
 | 
|---|
| 97 | future_flags=('-DOR' '-DAND3' '-DANDOR' '-DORAND')
 | 
|---|
| 98 | future_names=('OR' 'AND' 'ANDOR' 'ORAND')
 | 
|---|
| 99 | 
 | 
|---|
| 100 | # toggle benchmarks
 | 
|---|
| 101 | spin=${true}
 | 
|---|
| 102 | contend=${true}
 | 
|---|
| 103 | sidechan=${true}
 | 
|---|
| 104 | future=${true}
 | 
|---|
| 105 | order=${true}
 | 
|---|
| 106 | spin=${false}
 | 
|---|
| 107 | contend=${false}
 | 
|---|
| 108 | sidechan=${false}
 | 
|---|
| 109 | future=${false}
 | 
|---|
| 110 | # order=${false}
 | 
|---|
| 111 | 
 | 
|---|
| 112 | runCFA=${true}
 | 
|---|
| 113 | runGO=${true}
 | 
|---|
| 114 | # runUCPP=${true}
 | 
|---|
| 115 | # runCFA=${false}
 | 
|---|
| 116 | # runGO=${false}
 | 
|---|
| 117 | runUCPP=${false}
 | 
|---|
| 118 | 
 | 
|---|
| 119 | cfa=~/cfa-cc/driver/cfa
 | 
|---|
| 120 | 
 | 
|---|
| 121 | # Helpers to minimize code duplication
 | 
|---|
| 122 | 
 | 
|---|
| 123 | # repeats a command ${numtimes}
 | 
|---|
| 124 | preprint=''
 | 
|---|
| 125 | repeat_command() {
 | 
|---|
| 126 |     t=1
 | 
|---|
| 127 |     while [ ${t} -le ${numtimes} ] ; do
 | 
|---|
| 128 |         echo -n -e ${preprint}
 | 
|---|
| 129 |         "${@}"
 | 
|---|
| 130 |         t=`expr ${t} + 1`
 | 
|---|
| 131 |     done
 | 
|---|
| 132 | }
 | 
|---|
| 133 | 
 | 
|---|
| 134 | # prints the leading info for a given run of a variant
 | 
|---|
| 135 | print_header() {
 | 
|---|
| 136 |     echo ${1}':'
 | 
|---|
| 137 |     echo -e "cores\tthroughput (entries)"
 | 
|---|
| 138 | }
 | 
|---|
| 139 | 
 | 
|---|
| 140 | # runs the current benchmark with provided args
 | 
|---|
| 141 | # only works for standard-run benchmarks (not Akka)
 | 
|---|
| 142 | # must split into pre and post args to be able to supply val of p
 | 
|---|
| 143 | pre_args=''
 | 
|---|
| 144 | post_args=''
 | 
|---|
| 145 | single_run() {
 | 
|---|
| 146 |     affinity ${1}
 | 
|---|
| 147 |     preprint="${1}\t"
 | 
|---|
| 148 |     repeat_command taskset -c ${taskset} ./a.${hostname} ${pre_args} ${1} ${post_args}
 | 
|---|
| 149 | }
 | 
|---|
| 150 | 
 | 
|---|
| 151 | # runs the current bench for all processor vals
 | 
|---|
| 152 | # works for standard benchs that dont need to set a config file (not Akka or CAF)
 | 
|---|
| 153 | run_bench() {
 | 
|---|
| 154 |     for p in ${num_threads} ; do
 | 
|---|
| 155 |         single_run ${p}
 | 
|---|
| 156 |     done
 | 
|---|
| 157 | }
 | 
|---|
| 158 | 
 | 
|---|
| 159 | run_side_chan() {
 | 
|---|
| 160 |     i=1
 | 
|---|
| 161 |     for p in ${side_chan_threads} ; do
 | 
|---|
| 162 |         affinity ${p}
 | 
|---|
| 163 |         preprint="${p}\t"
 | 
|---|
| 164 |         repeat_command taskset -c ${taskset} ./a.${hostname} ${pre_args} ${i} ${post_args}
 | 
|---|
| 165 |         i=`expr ${i} + 1`
 | 
|---|
| 166 |     done
 | 
|---|
| 167 | }
 | 
|---|
| 168 | 
 | 
|---|
| 169 | run_order() {
 | 
|---|
| 170 |     affinity 4
 | 
|---|
| 171 |     preprint="4\t"
 | 
|---|
| 172 |     repeat_command taskset -c ${taskset} ./a.${hostname}
 | 
|---|
| 173 | }
 | 
|---|
| 174 | 
 | 
|---|
| 175 | run_future() {
 | 
|---|
| 176 |     affinity 2
 | 
|---|
| 177 |     preprint="2\t"
 | 
|---|
| 178 |     repeat_command taskset -c ${taskset} ./a.${hostname} ${post_args}
 | 
|---|
| 179 | }
 | 
|---|
| 180 | 
 | 
|---|
| 181 | arch # get hostname
 | 
|---|
| 182 | 
 | 
|---|
| 183 | # set up leading info for python script
 | 
|---|
| 184 | echo $numtimes
 | 
|---|
| 185 | echo $num_threads
 | 
|---|
| 186 | echo $side_chan_threads
 | 
|---|
| 187 | 
 | 
|---|
| 188 | if [ ${runCFA} -eq ${true} ]; then
 | 
|---|
| 189 |     echo -n 'CFA '
 | 
|---|
| 190 | fi
 | 
|---|
| 191 | if [ ${runGO} -eq ${true} ]; then
 | 
|---|
| 192 |     echo -n 'Go '
 | 
|---|
| 193 | fi
 | 
|---|
| 194 | echo ""
 | 
|---|
| 195 | 
 | 
|---|
| 196 | # done printing header info for output
 | 
|---|
| 197 | 
 | 
|---|
| 198 | # cfa flags
 | 
|---|
| 199 | cfa_flags='-quiet -O3 -nodebug -DNDEBUG'
 | 
|---|
| 200 | 
 | 
|---|
| 201 | # UCPP flags
 | 
|---|
| 202 | UCPPflags="-quiet -g -Wall -Wextra -O3 -nodebug -DNDEBUG -multi"
 | 
|---|
| 203 | UCPP=~/ucpp/u++-7.0.0/bin/u++
 | 
|---|
| 204 | 
 | 
|---|
| 205 | # run the benchmarks
 | 
|---|
| 206 | 
 | 
|---|
| 207 | run_contend() {
 | 
|---|
| 208 |     post_args=${1}
 | 
|---|
| 209 | 
 | 
|---|
| 210 |     if [ ${runCFA} -eq ${true} ] ; then
 | 
|---|
| 211 |         cd cfa # CFA RUN
 | 
|---|
| 212 |         print_header 'CFA'
 | 
|---|
| 213 |         ${cfa} ${cfa_flags} '-DNUM_CHANS='${3} ${2}.cfa -o a.${hostname} > /dev/null 2>&1
 | 
|---|
| 214 |         run_bench
 | 
|---|
| 215 |         rm a.${hostname}
 | 
|---|
| 216 |         cd - > /dev/null
 | 
|---|
| 217 |     fi # done CFA
 | 
|---|
| 218 | 
 | 
|---|
| 219 |     if [ ${runGO} -eq ${true} ] ; then
 | 
|---|
| 220 |         cd go/${2}${3} # Go RUN
 | 
|---|
| 221 |         print_header 'Go'
 | 
|---|
| 222 |         go build -o a.${hostname} > /dev/null 2>&1
 | 
|---|
| 223 |         run_bench
 | 
|---|
| 224 |         rm a.${hostname}
 | 
|---|
| 225 |         cd - > /dev/null
 | 
|---|
| 226 |     fi # done Go
 | 
|---|
| 227 | }
 | 
|---|
| 228 | 
 | 
|---|
| 229 | # /usr/bin/time -f "%Uu %Ss %Er %Mkb"
 | 
|---|
| 230 | if [ ${contend} -eq ${true} ] ; then
 | 
|---|
| 231 |     echo "contend2: "
 | 
|---|
| 232 |     run_contend ${chan_size} 'contend' '2'
 | 
|---|
| 233 |     echo "contend4: "
 | 
|---|
| 234 |     run_contend ${chan_size} 'contend' '4'
 | 
|---|
| 235 |     echo "contend8: "
 | 
|---|
| 236 |     run_contend ${chan_size} 'contend' '8'
 | 
|---|
| 237 | fi
 | 
|---|
| 238 | 
 | 
|---|
| 239 | if [ ${spin} -eq ${true} ] ; then
 | 
|---|
| 240 |     echo "spin2: "
 | 
|---|
| 241 |     run_contend ${chan_size} 'spin' '2'
 | 
|---|
| 242 |     echo "spin4: "
 | 
|---|
| 243 |     run_contend ${chan_size} 'spin' '4'
 | 
|---|
| 244 |     echo "spin8: "
 | 
|---|
| 245 |     run_contend ${chan_size} 'spin' '8'
 | 
|---|
| 246 | fi
 | 
|---|
| 247 | 
 | 
|---|
| 248 | if [ ${sidechan} -eq ${true} ] ; then
 | 
|---|
| 249 |     echo "sidechan: "
 | 
|---|
| 250 |     post_args=${chan_size}
 | 
|---|
| 251 |     if [ ${runCFA} -eq ${true} ] ; then
 | 
|---|
| 252 |         cd cfa # CFA RUN
 | 
|---|
| 253 |         print_header 'CFA'
 | 
|---|
| 254 |         ${cfa} ${cfa_flags} sidechan.cfa -o a.${hostname} > /dev/null 2>&1
 | 
|---|
| 255 |         run_side_chan
 | 
|---|
| 256 |         rm a.${hostname}
 | 
|---|
| 257 |         cd - > /dev/null
 | 
|---|
| 258 |     fi # done CFA
 | 
|---|
| 259 | 
 | 
|---|
| 260 |     if [ ${runGO} -eq ${true} ] ; then
 | 
|---|
| 261 |         cd go/sidechan
 | 
|---|
| 262 |         print_header 'Go'
 | 
|---|
| 263 |         go build -o a.${hostname} > /dev/null 2>&1
 | 
|---|
| 264 |         run_side_chan
 | 
|---|
| 265 |         rm a.${hostname}
 | 
|---|
| 266 |         cd - > /dev/null
 | 
|---|
| 267 |     fi # done Go
 | 
|---|
| 268 | fi
 | 
|---|
| 269 | 
 | 
|---|
| 270 | if [ ${future} -eq ${true} ] ; then
 | 
|---|
| 271 |     post_args=${future_time}
 | 
|---|
| 272 |     for i in ${!future_flags[@]}; do
 | 
|---|
| 273 |         echo 'future '${future_names[$i]}':'
 | 
|---|
| 274 |         if [ ${runCFA} -eq ${true} ] ; then
 | 
|---|
| 275 |             cd cfa # CFA RUN
 | 
|---|
| 276 |             print_header 'CFA'
 | 
|---|
| 277 |             ${cfa} ${cfa_flags} ${future_flags[$i]} future.cfa -o a.${hostname} > /dev/null 2>&1
 | 
|---|
| 278 |             run_future
 | 
|---|
| 279 |             rm a.${hostname}
 | 
|---|
| 280 |             cd - > /dev/null
 | 
|---|
| 281 |         fi # done CFA
 | 
|---|
| 282 | 
 | 
|---|
| 283 |         if [ ${runUCPP} -eq ${true} ] ; then
 | 
|---|
| 284 |             cd ucpp
 | 
|---|
| 285 |             print_header 'uC++'
 | 
|---|
| 286 |             ${UCPP} ${UCPPflags} ${future_flags[$i]} future.cc -o a.${hostname} > /dev/null 2>&1
 | 
|---|
| 287 |             run_future
 | 
|---|
| 288 |             rm a.${hostname}
 | 
|---|
| 289 |             cd - > /dev/null
 | 
|---|
| 290 |         fi # done Go
 | 
|---|
| 291 |     done
 | 
|---|
| 292 | fi
 | 
|---|
| 293 | 
 | 
|---|
| 294 | if [ ${order} -eq ${true} ] ; then
 | 
|---|
| 295 |     echo "order: "
 | 
|---|
| 296 |     post_args=${chan_size}
 | 
|---|
| 297 |     if [ ${runCFA} -eq ${true} ] ; then
 | 
|---|
| 298 |         cd cfa # CFA RUN
 | 
|---|
| 299 |         print_header 'CFA'
 | 
|---|
| 300 |         ${cfa} ${cfa_flags} order.cfa -o a.${hostname} > /dev/null 2>&1
 | 
|---|
| 301 |         run_order
 | 
|---|
| 302 |         rm a.${hostname}
 | 
|---|
| 303 |         cd - > /dev/null
 | 
|---|
| 304 |     fi # done CFA
 | 
|---|
| 305 | 
 | 
|---|
| 306 |     if [ ${runGO} -eq ${true} ] ; then
 | 
|---|
| 307 |         cd go/order
 | 
|---|
| 308 |         print_header 'Go'
 | 
|---|
| 309 |         go build -o a.${hostname} > /dev/null 2>&1
 | 
|---|
| 310 |         run_order
 | 
|---|
| 311 |         rm a.${hostname}
 | 
|---|
| 312 |         cd - > /dev/null
 | 
|---|
| 313 |     fi # done Go
 | 
|---|
| 314 | fi
 | 
|---|