4 # Copyright (c) 2015 ARM Limited
7 # The license below extends only to copyright in the software and shall
8 # not be construed as granting a license to any other intellectual
9 # property including but not limited to intellectual property relating
10 # to a hardware implementation of the functionality of the software
11 # licensed hereunder. You may use the software subject to the license
12 # terms below provided that you ensure that this notice is replicated
13 # unmodified and in its entirety in all distributions of the software,
14 # modified or unmodified, in source code or in binary form.
16 # Redistribution and use in source and binary forms, with or without
17 # modification, are permitted provided that the following conditions are
18 # met: redistributions of source code must retain the above copyright
19 # notice, this list of conditions and the following disclaimer;
20 # redistributions in binary form must reproduce the above copyright
21 # notice, this list of conditions and the following disclaimer in the
22 # documentation and/or other materials provided with the distribution;
23 # neither the name of the copyright holders nor the names of its
24 # contributors may be used to endorse or promote products derived from
25 # this software without specific prior written permission.
27 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 # Authors: Gabor Dozsa
42 # This is a wrapper script to run a multi gem5 simulations.
43 # See the usage_func() below for hints on how to use it. Also,
44 # there are some examples in the util/multi directory (e.g.
45 # see util/multi/test-2nodes-AArch64.sh)
48 # Allocated hosts/cores are assumed to be listed in the LSB_MCPU_HOSTS
49 # environment variable (which is what LSF does by default).
50 # E.g. LSB_MCPU_HOSTS=\"hname1 2 hname2 4\" means we have altogether 6 slots
51 # allocated to launch the gem5 processes, 2 of them are on host hname1
52 # and 4 of them are on host hname2.
53 # If LSB_MCPU_HOSTS environment variable is not defined then we launch all
54 # processes on the localhost.
56 # Each gem5 process are passed in a unique rank ID [0..N-1] via the kernel
57 # boot params. The total number of gem5 processes is also passed in.
58 # These values can be used in the boot script to configure the MAC/IP
59 # addresses - among other things (see util/multi/bootscript.rcS).
61 # Each gem5 process will create an m5out.$GEM5_RANK directory for
62 # the usual output files. Furthermore, there will be a separate log file
63 # for each ssh session (we use ssh to start gem5 processes) and one for
64 # the server. These are called log.$GEM5_RANK and log.server.
71 echo "Usage:$0 [-debug] [-n nnodes] [-s server] [-p port] gem5_exe gem5_args"
72 echo " -debug : debug mode (start gem5 in gdb)"
73 echo " nnodes : number of gem5 processes"
74 echo " server : message server executable"
75 echo " port : message server listen port"
76 echo " gem5_exe : gem5 executable (full path required)"
77 echo " gem5_args: usual gem5 arguments ( m5 options, config script options)"
78 echo "Note: if no LSF slots allocation is found all proceses are launched on the localhost."
82 # Process (optional) command line options
109 # The remaining command line args must be the usual gem5 command
110 (($# < 2)) && { usage_func
; exit -1; }
115 # Default values to use (in case they are not defined as command line options)
116 DEFAULT_TCP_SERVER
=$
(dirname $0)/..
/..
/util
/multi
/tcp_server
117 DEFAULT_SERVER_PORT
=2200
119 [ -z "$TCP_SERVER" ] && TCP_SERVER
=$DEFAULT_TCP_SERVER
120 [ -z "$SERVER_PORT" ] && SERVER_PORT
=$DEFAULT_SERVER_PORT
121 [ -z "$NNODES" ] && NNODES
=2
124 # Check if all the executables we need exist
125 [ -x "$TCP_SERVER" ] ||
{ echo "Executable ${TCP_SERVER} not found"; exit 1; }
126 [ -x "$GEM5_EXE" ] ||
{ echo "Executable ${GEM5_EXE} not found"; exit 1; }
133 # Find out which cluster hosts/slots are allocated or
134 # use localhost if there is no LSF allocation.
135 # We assume that allocated slots are listed in the LSB_MCPU_HOSTS
136 # environment variable in the form:
137 # host1 nslots1 host2 nslots2 ...
138 # (This is what LSF does by default.)
140 [ "x$LSB_MCPU_HOSTS" != "x" ] || LSB_MCPU_HOSTS
="localhost $NNODES"
142 for hc
in $LSB_MCPU_HOSTS
144 if [ "x$host" == "x" ]
154 ((NNODES
==NH
)) ||
{ echo "(E) Number of cluster slots ($NH) and gem5 instances ($N) differ"; exit -1; }
155 #echo "hosts: ${HOSTS[@]}"
156 #echo "hosts: ${NCORES[@]}"
160 # function to clean up and abort if something goes wrong
164 echo "KILLED $(date)"
165 # (try to) kill all gem5 processes on all hosts
166 bname
=$
(basename $GEM5_EXE)
170 ssh $h killall
-q $bname
173 # kill the message server and the watchdog
174 [ "x$SERVER_PID" != "x" ] && kill $SERVER_PID 2>/dev
/null
175 [ "x$WATCHDOG_PID" != "x" ] && kill $WATCHDOG_PID 2>/dev
/null
180 # We need a watchdog to trigger full clean up if a gem5 process dies
187 for p
in ${SSH_PIDS[*]}
189 kill -0 $p 2>/dev
/null ||
((NDEAD
+=1))
191 kill -0 $SERVER_PID ||
((NDEAD
+=1))
194 # we may be in the middle of an orderly termination,
195 # give it some time to complete before reporting abort
197 echo -n "(I) (some) gem5 process(es) exited"
203 # This function launches the gem5 processes. We use it only to allow launching
204 # gem5 processes under gdb control (in the foreground) for debugging
211 if [ "x$GEM5_DEBUG" != "x" ]
215 ssh $HOST $ENV_ARGS "$@" &>log.
$N &
220 # Trigger full clean up in case we are being killed by external signal
221 trap 'abort_func' INT TERM
223 # env args to be passed explicitly to gem5 processes started via ssh
224 ENV_ARGS
="LD_LIBRARY_PATH=$LD_LIBRARY_PATH M5_PATH=$M5_PATH"
226 # launch the mesage server and check if it has started okay
227 $TCP_SERVER $GEM5_DEBUG $NNODES $SERVER_PORT &>log.server
&
230 kill -0 $SERVER_PID ||
{ echo "Failed to start message server"; exit -1; }
232 # Now launch all the gem5 processes with ssh.
235 for ((i
=0; i
< ${#HOSTS[@]}; i
++))
238 for ((j
=0; j
< ${NCORES[i]}; j
++))
240 echo "starting gem5 on $h ..."
241 start_func
$n $h "$ENV_ARGS" $GEM5_EXE -d $
(pwd)/m5out.
$n $GEM5_ARGS \
244 --multi-server-name=${HOSTS[0]} \
245 --multi-server-port=$SERVER_PORT \
246 --testsys-toplevel-LinuxArmSystem.boot_osflags
="\"GEM5_RANK=$n GEM5_SIZE=$NNODES\""
252 [ "x$GEM5_DEBUG" == "x" ] ||
{ kill $SERVER_PID; echo "DEBUG exit"; exit -1; }
254 # start watchdog to trigger complete abort (after a grace period) if any
259 # wait for exit statuses
261 for p
in ${SSH_PIDS[*]}
263 wait $p ||
((NFAIL
+=1))
265 wait $SERVER_PID ||
((NFAIL
+=1))
267 # all done, let's terminate the watchdog
268 kill $WATCHDOG_PID 2>/dev
/null