dev: add support for multi gem5 runs
[gem5.git] / util / multi / bootscript.rcS
1 #!/bin/bash
2
3
4 #
5 # Copyright (c) 2015 ARM Limited
6 # All rights reserved
7 #
8 # The license below extends only to copyright in the software and shall
9 # not be construed as granting a license to any other intellectual
10 # property including but not limited to intellectual property relating
11 # to a hardware implementation of the functionality of the software
12 # licensed hereunder. You may use the software subject to the license
13 # terms below provided that you ensure that this notice is replicated
14 # unmodified and in its entirety in all distributions of the software,
15 # modified or unmodified, in source code or in binary form.
16 #
17 # Redistribution and use in source and binary forms, with or without
18 # modification, are permitted provided that the following conditions are
19 # met: redistributions of source code must retain the above copyright
20 # notice, this list of conditions and the following disclaimer;
21 # redistributions in binary form must reproduce the above copyright
22 # notice, this list of conditions and the following disclaimer in the
23 # documentation and/or other materials provided with the distribution;
24 # neither the name of the copyright holders nor the names of its
25 # contributors may be used to endorse or promote products derived from
26 # this software without specific prior written permission.
27 #
28 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #
40 # Authors: Gabor Dozsa
41 #
42 #
43 # This is an example boot script to use for muti gem5 runs. The important
44 # task here is to extract the rank and size information from the kernel
45 # boot args and use those to configure MAC/IP addresses and hostname.
46 # Then we can kick off our (parallel) workload ...
47 #
48 # You are expected to costumize this scipt for your needs (e.g. change
49 # the command at the end of the scipt to run your tests/workloads.
50
51 source /root/.bashrc
52 echo "bootscript.rcS is running"
53
54 m='GEM5\_RANK=([0-9]+) GEM5\_SIZE=([0-9]+)'
55 if [[ $(cat /proc/cmdline) =~ $m ]]
56 then
57 MY_RANK=${BASH_REMATCH[1]}
58 MY_SIZE=${BASH_REMATCH[2]}
59 else
60 echo "(E) GEM5_RANK/GEM5_SIZE was not defined in bootargs, exiting ..."
61 /sbin/m5 abort
62 fi
63
64 /bin/hostname node${MY_RANK}
65
66 # Keep MAC address assignment simple for now ...
67 (($MY_RANK>97)) && { echo "(E) Rank must be less than 98"; /sbin/m5 abort; }
68 ((MY_ADDR=MY_RANK+2))
69 if (($MY_ADDR<10))
70 then
71 MY_ADDR_PADDED=0${MY_ADDR}
72 else
73 MY_ADDR_PADDED=${MY_ADDR}
74 fi
75
76 /sbin/ifconfig eth0 hw ether 00:90:00:00:00:${MY_ADDR_PADDED}
77 /sbin/ifconfig eth0 192.168.0.${MY_ADDR} netmask 255.255.255.0 up
78
79 /sbin/ifconfig -a
80
81 # Prepare host lists for mpirun
82 MY_MPI_HOSTS="192.168.0.2"
83 for ((i=1; i<MY_SIZE; i++))
84 do
85 MY_MPI_HOSTS+=",192.168.0.$((i+2))"
86 done
87
88 # Check that Ethernet links work, then take a checkpoint
89 if [ "$MY_RANK" == "0" ]
90 then
91 OLDIFS=$IFS
92 IFS=","
93 for i in $MY_MPI_HOSTS
94 do
95 ping -c 1 $i || { echo "ping $i failed, exiting ..."; exit -1; }
96 ssh $i hostname || { echo "ssh $i failed, exiting ..."; exit -1; }
97 done
98 IFS=$OLDIFS
99 /sbin/m5 checkpoint
100 fi
101
102 # --------------------------------------------
103 # ------ Start your tests below ... ---------
104 # --------------------------------------------
105
106 if [ "$MY_RANK" == "0" ]
107 then
108 echo "MPI test"
109 #mpirun -H 192.168.0.3,192.168.0.2 hostname
110 cd /benchmarks
111 mpirun -H $MY_MPI_HOSTS lulesh/lulesh2.0-mpi -s 5
112 else
113 # This is to avoid other (rank!=0) gem5 processes exiting
114 # before the test (started by rank 0) completes. When rank 0 completes the
115 # test it will exit and that will trigger a notification to all the peer
116 # gem5 peocesses to stop the simulation.
117 echo "sleep forever..."
118 while /bin/true
119 do
120 sleep 5
121 done
122 fi