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