[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 |
---|
| 28 | """ |
---|
[807] | 29 | |
---|
[890] | 30 | # translate the relative path (if needed) into an absolute path |
---|
| 31 | basedir = os.path.abspath(args.path) |
---|
| 32 | outdir = os.path.abspath(args.outpath) |
---|
| 33 | print "[ run.py ] platform base directory: {0}".format(basedir) |
---|
| 34 | print "[ run.py ] output directory: {0}".format(outdir) |
---|
[807] | 35 | |
---|
[890] | 36 | # 1. generate configuration and ouput directories |
---|
| 37 | try: |
---|
| 38 | os.makedirs(os.path.join(outdir, "config"), 0755) |
---|
| 39 | except OSError: |
---|
| 40 | pass # directory already exists => do nothing |
---|
[807] | 41 | |
---|
[890] | 42 | # 2. generate hard_config.h and fault_config.h files |
---|
| 43 | faultpath = os.path.join(outdir, "config/fault_config.h") |
---|
| 44 | hardpath = os.path.join(outdir, "config/hard_config.h") |
---|
[907] | 45 | xmlpath = os.path.join(outdir, "config/giet.map.xml") |
---|
| 46 | dtspath = os.path.join(outdir, "config/linux.dts") |
---|
| 47 | arch.main(args.x, args.y, args.nprocs, hardpath, xmlpath, dtspath) |
---|
[890] | 48 | faultyprocs.generate(args.faultycore, faultpath) |
---|
[807] | 49 | |
---|
[890] | 50 | # create a log file |
---|
| 51 | logfile = open(os.path.join(outdir, "log"), "w") |
---|
[807] | 52 | |
---|
[890] | 53 | # 3. compile simulator executable |
---|
| 54 | dst = os.path.join(basedir, "hard_config.h") |
---|
| 55 | if os.path.lexists(dst): |
---|
| 56 | os.unlink(dst) |
---|
[807] | 57 | |
---|
[890] | 58 | os.symlink(hardpath, dst) |
---|
[844] | 59 | |
---|
[890] | 60 | print "[ run.py ] compiling simulator" |
---|
| 61 | command = [] |
---|
| 62 | command.extend(['make']) |
---|
| 63 | command.extend(['-C', basedir]) |
---|
| 64 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
[855] | 65 | |
---|
[890] | 66 | # 4. compile distributed boot executable |
---|
| 67 | dst = os.path.join(outdir, "config/boot_config.h") |
---|
| 68 | if os.path.lexists(dst): |
---|
| 69 | os.unlink(dst) |
---|
[859] | 70 | |
---|
[890] | 71 | os.symlink(os.path.join(basedir, "soft/config/boot_config.h"), dst) |
---|
[855] | 72 | |
---|
[890] | 73 | # stop after compiling the platform when the compile-only option is activated |
---|
| 74 | if args.compileonly == True: |
---|
| 75 | exit(0) |
---|
[807] | 76 | |
---|
[890] | 77 | print "[ run.py ] compiling distributed boot procedure" |
---|
| 78 | command = [] |
---|
| 79 | command.extend(['make']) |
---|
| 80 | command.extend(['-C', os.path.join(basedir, "soft")]) |
---|
| 81 | command.extend(["CONFDIR=" + outdir]) |
---|
| 82 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
[807] | 83 | |
---|
[890] | 84 | # 5. execute simulator |
---|
| 85 | os.environ["DISTRIBUTED_BOOT"] = "1" |
---|
| 86 | if args.batchmode: |
---|
| 87 | os.environ["SOCLIB_FB"] = "HEADLESS" |
---|
| 88 | os.environ["SOCLIB_TTY"] = "FILES" |
---|
[807] | 89 | |
---|
[906] | 90 | ompthreads = (args.x * args.y) / 4 |
---|
| 91 | cpucount = multiprocessing.cpu_count() |
---|
| 92 | if ompthreads > cpucount: ompthreads = cpucount |
---|
[807] | 93 | |
---|
[890] | 94 | print "[ run.py ] starting simulation" |
---|
| 95 | command = [] |
---|
| 96 | command.extend([os.path.join(basedir, "simul.x")]) |
---|
| 97 | command.extend(["-SOFT", os.path.join(basedir, "soft/build/soft.elf")]) |
---|
| 98 | command.extend(["-DISK", "/dev/null"]) |
---|
| 99 | command.extend(["-THREADS", str(ompthreads)]) |
---|
[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])]); |
---|
[919] | 111 | elif os.environ.get('SOCLIB_GDB') == None: |
---|
| 112 | # the procedure grows linearly with the diameter of the mesh. |
---|
[904] | 113 | maxcycles = 400000 + (args.x + args.y) * 20000; |
---|
[893] | 114 | command.extend(["-NCYCLES", str(maxcycles)]) |
---|
[844] | 115 | |
---|
[893] | 116 | logfile.write("Execute: {0}\n".format(" ".join(command))) |
---|
| 117 | logfile.flush() |
---|
| 118 | |
---|
[890] | 119 | subprocess.call(command, stdout=logfile, stderr=logfile) |
---|
[807] | 120 | |
---|
[890] | 121 | logfile.close() |
---|
[807] | 122 | |
---|
[890] | 123 | # 6. move simulation terminal output into the target config dir |
---|
| 124 | os.rename("term0", os.path.join(outdir, "term")) |
---|
[844] | 125 | |
---|
[890] | 126 | # get command-line arguments |
---|
| 127 | if __name__ == "__main__": |
---|
| 128 | parser = argparse.ArgumentParser(description='Run simulation') |
---|
[807] | 129 | |
---|
[890] | 130 | parser.add_argument( |
---|
| 131 | '--path', '-p', type=str, dest='path', default=os.getcwd(), |
---|
| 132 | help='relative or absolute path to the platform') |
---|
[844] | 133 | |
---|
[890] | 134 | parser.add_argument( |
---|
| 135 | '--output', '-o', type=str, dest='outpath', default='./output', |
---|
| 136 | help='relative or absolute path to the output directory') |
---|
[807] | 137 | |
---|
[890] | 138 | parser.add_argument( |
---|
| 139 | '--xsize', '-x', type=int, dest='x', default=2, |
---|
| 140 | help='# of clusters in a row') |
---|
[807] | 141 | |
---|
[890] | 142 | parser.add_argument( |
---|
| 143 | '--ysize', '-y', type=int, dest='y', default=2, |
---|
| 144 | help='# of clusters in a column') |
---|
[807] | 145 | |
---|
[890] | 146 | parser.add_argument( |
---|
| 147 | '--nprocs', '-n', type=int, dest='nprocs', default=4, |
---|
| 148 | help='# of processors per cluster') |
---|
[855] | 149 | |
---|
[890] | 150 | parser.add_argument( |
---|
| 151 | '--compile-only', '-c', dest='compileonly', action='store_true', |
---|
| 152 | help='generate config files and compile the platform. Do not simulate') |
---|
[855] | 153 | |
---|
[890] | 154 | parser.add_argument( |
---|
| 155 | '--batch-mode', '-b', dest='batchmode', action='store_true', |
---|
| 156 | help='run simulation in batch mode: no interactive TTY or FrameBuffer') |
---|
[855] | 157 | |
---|
[890] | 158 | parser.add_argument( |
---|
[904] | 159 | '--faulty-router', '-fr', dest='faultyrouter', action='append', nargs=3, |
---|
| 160 | help='ID (T,X,Y) of faulty router. The T is 0:CMD, 1:RSP') |
---|
[807] | 161 | |
---|
[890] | 162 | parser.add_argument( |
---|
| 163 | '--faulty-mask', '-m', dest='faultymask', default=0x1F, |
---|
| 164 | help='Disable mask for faulty router interfaces') |
---|
[807] | 165 | |
---|
[890] | 166 | parser.add_argument( |
---|
| 167 | '--faulty-core', '-fc', dest='faultycore', action='append', nargs=3, |
---|
| 168 | help='ID (X,Y,L) of faulty processor') |
---|
[807] | 169 | |
---|
[890] | 170 | parser.add_argument( |
---|
| 171 | '--debug', '-g', dest='debug', nargs=4, |
---|
| 172 | help='needs four arguments: from, to, procid, memcid') |
---|
| 173 | |
---|
| 174 | run(parser.parse_args()) |
---|
| 175 | |
---|
[807] | 176 | # vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|