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