[957] | 1 | #!/usr/bin/env python2 |
---|
[807] | 2 | # @date 22 September, 2014 |
---|
| 3 | # @author cfuguet <cesar.fuguet-tortolero@lip6.fr> |
---|
| 4 | |
---|
| 5 | import os |
---|
| 6 | import subprocess |
---|
| 7 | import arch |
---|
| 8 | import faultyprocs |
---|
| 9 | import argparse |
---|
[906] | 10 | import multiprocessing |
---|
[969] | 11 | import math |
---|
[807] | 12 | |
---|
[890] | 13 | def run(args): |
---|
| 14 | """ Execute the distributed bootloader providing permanent fault-recovery on |
---|
| 15 | the TSAR platform. |
---|
[807] | 16 | |
---|
[890] | 17 | Keyword arguments: |
---|
| 18 | path -- platform's base directory path |
---|
| 19 | outpath -- output's base directory path |
---|
| 20 | x -- number of clusters on the X coordinate |
---|
| 21 | y -- number of clusters on the Y coordinate |
---|
| 22 | nprocs -- number of processors per cluster |
---|
| 23 | compileonly -- stops after platform's compilation |
---|
| 24 | batchmode -- TTY and FB are only redirected to FILES |
---|
[904] | 25 | faultyrouter -- a list containing faulty routers' coordinates (t, x, y) |
---|
[890] | 26 | faultymask -- a mask of disabled routers' interfaces |
---|
| 27 | faultycore -- a list containing faulty cores' coordinates (x, y, l) |
---|
| 28 | debug -- a list with debug's start cycle, stop cycle, PID and MID |
---|
[940] | 29 | threads -- number of OpenMP threads |
---|
| 30 | firmdebug -- activate the DEBUG compilation mode on software |
---|
| 31 | diskimage -- relative or absolute path to the disk image |
---|
[974] | 32 | force -- create configuration files (or overwrite them) |
---|
[890] | 33 | """ |
---|
[807] | 34 | |
---|
[890] | 35 | # translate the relative path (if needed) into an absolute path |
---|
| 36 | basedir = os.path.abspath(args.path) |
---|
| 37 | outdir = os.path.abspath(args.outpath) |
---|
| 38 | print "[ run.py ] platform base directory: {0}".format(basedir) |
---|
| 39 | print "[ run.py ] output directory: {0}".format(outdir) |
---|
[807] | 40 | |
---|
[890] | 41 | # 1. generate configuration and ouput directories |
---|
| 42 | try: |
---|
| 43 | os.makedirs(os.path.join(outdir, "config"), 0755) |
---|
| 44 | except OSError: |
---|
| 45 | pass # directory already exists => do nothing |
---|
[807] | 46 | |
---|
[890] | 47 | # 2. generate hard_config.h and fault_config.h files |
---|
| 48 | faultpath = os.path.join(outdir, "config/fault_config.h") |
---|
| 49 | hardpath = os.path.join(outdir, "config/hard_config.h") |
---|
[907] | 50 | xmlpath = os.path.join(outdir, "config/giet.map.xml") |
---|
[974] | 51 | if args.linux: |
---|
| 52 | dtspath = os.path.join(outdir, "config/platform.dts") |
---|
| 53 | else: |
---|
| 54 | dtspath = None |
---|
[807] | 55 | |
---|
[974] | 56 | exist = True |
---|
| 57 | exist = exist and os.path.exists(faultpath) |
---|
| 58 | exist = exist and os.path.exists(hardpath) |
---|
| 59 | exist = exist and os.path.exists(xmlpath) |
---|
| 60 | if args.linux: exist = exist and os.path.exists(dtspath) |
---|
| 61 | |
---|
| 62 | if not args.force and exist: |
---|
| 63 | print "[ run.py ] Warning: Reusing existing configuration files. " |
---|
| 64 | print "[ run.py ] Script arguments will be ignored (no --force option)" |
---|
| 65 | cmd = raw_input('[ run.py ] Would you like to continue (y/n): ') |
---|
| 66 | if cmd == 'n': exit(0) |
---|
| 67 | if cmd == 'y': pass |
---|
| 68 | else: exit(1) |
---|
| 69 | else: |
---|
| 70 | arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath, dtspath) |
---|
| 71 | faultyprocs.generate(args.faultycore, faultpath) |
---|
| 72 | |
---|
[890] | 73 | # create a log file |
---|
| 74 | logfile = open(os.path.join(outdir, "log"), "w") |
---|
[807] | 75 | |
---|
[890] | 76 | # 3. compile simulator executable |
---|
| 77 | dst = os.path.join(basedir, "hard_config.h") |
---|
| 78 | if os.path.lexists(dst): |
---|
| 79 | os.unlink(dst) |
---|
[807] | 80 | |
---|
[890] | 81 | os.symlink(hardpath, dst) |
---|
[844] | 82 | |
---|
[890] | 83 | print "[ run.py ] compiling simulator" |
---|
| 84 | command = [] |
---|
| 85 | command.extend(['make']) |
---|
| 86 | command.extend(['-C', basedir]) |
---|
[974] | 87 | subprocess.check_call(command, stdout=logfile, stderr=logfile) |
---|
[855] | 88 | |
---|
[890] | 89 | # 4. compile distributed boot executable |
---|
| 90 | dst = os.path.join(outdir, "config/boot_config.h") |
---|
| 91 | if os.path.lexists(dst): |
---|
| 92 | os.unlink(dst) |
---|
[859] | 93 | |
---|
[926] | 94 | os.symlink(os.path.join(basedir, "soft/test/config/boot_config.h"), dst) |
---|
[855] | 95 | |
---|
[890] | 96 | print "[ run.py ] compiling distributed boot procedure" |
---|
| 97 | command = [] |
---|
| 98 | command.extend(['make']) |
---|
| 99 | command.extend(['-C', os.path.join(basedir, "soft")]) |
---|
[929] | 100 | command.extend(["CONFIG=" + outdir]) |
---|
[940] | 101 | command.extend(["DEBUG=" + str(args.firmdebug)]) |
---|
[974] | 102 | if args.linux: |
---|
| 103 | command.extend(["PATCHER_OS=1"]) |
---|
| 104 | else: |
---|
| 105 | command.extend(["PATCHER_OS=0"]) |
---|
[807] | 106 | |
---|
[974] | 107 | subprocess.check_call(command, stdout=logfile, stderr=logfile) |
---|
| 108 | |
---|
[926] | 109 | # stop after compiling when the compile-only option is activated |
---|
[974] | 110 | if args.compileonly == True: exit(0) |
---|
[926] | 111 | |
---|
[890] | 112 | # 5. execute simulator |
---|
| 113 | os.environ["DISTRIBUTED_BOOT"] = "1" |
---|
[927] | 114 | os.environ["SOCLIB_FB"] = "HEADLESS" |
---|
[890] | 115 | if args.batchmode: |
---|
| 116 | os.environ["SOCLIB_TTY"] = "FILES" |
---|
[807] | 117 | |
---|
[890] | 118 | print "[ run.py ] starting simulation" |
---|
| 119 | command = [] |
---|
| 120 | command.extend([os.path.join(basedir, "simul.x")]) |
---|
[940] | 121 | command.extend(["-DSOFT", "soft/build/boot.elf"]) |
---|
| 122 | command.extend(["-SOFT", "soft/build/loader.elf"]) |
---|
| 123 | command.extend(["-DISK", args.diskimage]) |
---|
[807] | 124 | |
---|
[890] | 125 | if args.faultyrouter != None: |
---|
| 126 | command.extend(["-FAULTY_MASK", str(args.faultymask)]) |
---|
| 127 | for f in args.faultyrouter: |
---|
[904] | 128 | command.extend(["-FAULTY_ROUTER", str(f[0]), str(f[1]), str(f[2])]) |
---|
[807] | 129 | |
---|
[890] | 130 | if args.debug != None: |
---|
| 131 | command.extend(["-DEBUG", str(args.debug[0])]); |
---|
[974] | 132 | command.extend(["-PROCID", str(args.debug[1])]); |
---|
| 133 | command.extend(["-MEMCID", str(args.debug[2])]); |
---|
[926] | 134 | |
---|
[974] | 135 | if args.ncycles > 0: |
---|
| 136 | command.extend(["-NCYCLES", str(args.ncycles)]) |
---|
| 137 | |
---|
[919] | 138 | elif os.environ.get('SOCLIB_GDB') == None: |
---|
| 139 | # the procedure grows linearly with the diameter of the mesh. |
---|
[974] | 140 | # maxcycles = 1500000 + (args.x + args.y) * 20000 |
---|
| 141 | # command.extend(["-NCYCLES", str(maxcycles)]) |
---|
| 142 | command.extend(["-NCYCLES", str(200000000)]) |
---|
[844] | 143 | |
---|
[927] | 144 | # OpenMP number of threads definition |
---|
| 145 | ompthreads = args.threads |
---|
[969] | 146 | if ompthreads < 1: |
---|
| 147 | ompthreads = math.ceil(float(args.x * args.y) / 4) |
---|
[927] | 148 | |
---|
[969] | 149 | # be nice and don't use all available processors |
---|
| 150 | maxcpu = math.ceil(float(multiprocessing.cpu_count()) * 2/3) |
---|
| 151 | if ompthreads > maxcpu: ompthreads = maxcpu |
---|
[927] | 152 | |
---|
[926] | 153 | command.extend(["-THREADS", str(ompthreads)]) |
---|
| 154 | |
---|
[927] | 155 | |
---|
[893] | 156 | logfile.write("Execute: {0}\n".format(" ".join(command))) |
---|
| 157 | logfile.flush() |
---|
| 158 | |
---|
[974] | 159 | subprocess.check_call(command, stdout=logfile, stderr=logfile) |
---|
[807] | 160 | |
---|
[890] | 161 | logfile.close() |
---|
[807] | 162 | |
---|
[890] | 163 | # 6. move simulation terminal output into the target config dir |
---|
| 164 | os.rename("term0", os.path.join(outdir, "term")) |
---|
[844] | 165 | |
---|
[890] | 166 | # get command-line arguments |
---|
| 167 | if __name__ == "__main__": |
---|
| 168 | parser = argparse.ArgumentParser(description='Run simulation') |
---|
[807] | 169 | |
---|
[890] | 170 | parser.add_argument( |
---|
| 171 | '--path', '-p', type=str, dest='path', default=os.getcwd(), |
---|
| 172 | help='relative or absolute path to the platform') |
---|
[844] | 173 | |
---|
[890] | 174 | parser.add_argument( |
---|
| 175 | '--output', '-o', type=str, dest='outpath', default='./output', |
---|
| 176 | help='relative or absolute path to the output directory') |
---|
[807] | 177 | |
---|
[890] | 178 | parser.add_argument( |
---|
| 179 | '--xsize', '-x', type=int, dest='x', default=2, |
---|
| 180 | help='# of clusters in a row') |
---|
[807] | 181 | |
---|
[890] | 182 | parser.add_argument( |
---|
| 183 | '--ysize', '-y', type=int, dest='y', default=2, |
---|
| 184 | help='# of clusters in a column') |
---|
[807] | 185 | |
---|
[890] | 186 | parser.add_argument( |
---|
| 187 | '--nprocs', '-n', type=int, dest='nprocs', default=4, |
---|
| 188 | help='# of processors per cluster') |
---|
[855] | 189 | |
---|
[890] | 190 | parser.add_argument( |
---|
| 191 | '--compile-only', '-c', dest='compileonly', action='store_true', |
---|
| 192 | help='generate config files and compile the platform. Do not simulate') |
---|
[855] | 193 | |
---|
[890] | 194 | parser.add_argument( |
---|
| 195 | '--batch-mode', '-b', dest='batchmode', action='store_true', |
---|
| 196 | help='run simulation in batch mode: no interactive TTY or FrameBuffer') |
---|
[855] | 197 | |
---|
[890] | 198 | parser.add_argument( |
---|
[904] | 199 | '--faulty-router', '-fr', dest='faultyrouter', action='append', nargs=3, |
---|
| 200 | help='ID (T,X,Y) of faulty router. The T is 0:CMD, 1:RSP') |
---|
[807] | 201 | |
---|
[890] | 202 | parser.add_argument( |
---|
| 203 | '--faulty-mask', '-m', dest='faultymask', default=0x1F, |
---|
| 204 | help='Disable mask for faulty router interfaces') |
---|
[807] | 205 | |
---|
[890] | 206 | parser.add_argument( |
---|
| 207 | '--faulty-core', '-fc', dest='faultycore', action='append', nargs=3, |
---|
| 208 | help='ID (X,Y,L) of faulty processor') |
---|
[807] | 209 | |
---|
[890] | 210 | parser.add_argument( |
---|
| 211 | '--debug', '-g', dest='debug', nargs=4, |
---|
| 212 | help='needs four arguments: from, to, procid, memcid') |
---|
| 213 | |
---|
[927] | 214 | parser.add_argument( |
---|
[969] | 215 | '--threads', '-t', type=int, dest='threads', default=1, |
---|
[927] | 216 | help='number of OpenMP threads') |
---|
| 217 | |
---|
[940] | 218 | parser.add_argument( |
---|
| 219 | '--firmware-debug', '-fg', dest='firmdebug', default=0, |
---|
| 220 | help='activate the DEBUG compilation mode on software') |
---|
| 221 | |
---|
| 222 | parser.add_argument( |
---|
[957] | 223 | '--disk-image', '-di', dest='diskimage', default="/dev/null", |
---|
[940] | 224 | help='relative or absolute path to the external firmware') |
---|
| 225 | |
---|
[974] | 226 | parser.add_argument( |
---|
| 227 | '--force', '-f', dest='force', action='store_true', |
---|
| 228 | help='create configuration files (or overwrite them)') |
---|
| 229 | |
---|
| 230 | parser.add_argument( |
---|
| 231 | '--linux', dest='linux', action='store_true', |
---|
| 232 | help='generate linux device tree and compile bootloader ' + |
---|
| 233 | 'with linux specifics') |
---|
| 234 | |
---|
| 235 | parser.add_argument( |
---|
| 236 | '--ncycles', type=int, dest='ncycles', default=-1, |
---|
| 237 | help='max simulation cycles') |
---|
| 238 | |
---|
[890] | 239 | run(parser.parse_args()) |
---|
| 240 | |
---|
[807] | 241 | # vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|