| 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 | |
|---|
| 11 | def run(args): |
|---|
| 12 | """ Execute the distributed bootloader providing permanent fault-recovery on |
|---|
| 13 | the TSAR platform. |
|---|
| 14 | |
|---|
| 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 | """ |
|---|
| 28 | |
|---|
| 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) |
|---|
| 34 | |
|---|
| 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 |
|---|
| 40 | |
|---|
| 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) |
|---|
| 47 | |
|---|
| 48 | # create a log file |
|---|
| 49 | logfile = open(os.path.join(outdir, "log"), "w") |
|---|
| 50 | |
|---|
| 51 | # 3. compile simulator executable |
|---|
| 52 | dst = os.path.join(basedir, "hard_config.h") |
|---|
| 53 | if os.path.lexists(dst): |
|---|
| 54 | os.unlink(dst) |
|---|
| 55 | |
|---|
| 56 | os.symlink(hardpath, dst) |
|---|
| 57 | |
|---|
| 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) |
|---|
| 63 | |
|---|
| 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) |
|---|
| 68 | |
|---|
| 69 | os.symlink(os.path.join(basedir, "soft/config/boot_config.h"), dst) |
|---|
| 70 | |
|---|
| 71 | # stop after compiling the platform when the compile-only option is activated |
|---|
| 72 | if args.compileonly == True: |
|---|
| 73 | exit(0) |
|---|
| 74 | |
|---|
| 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) |
|---|
| 81 | |
|---|
| 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" |
|---|
| 87 | |
|---|
| 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 |
|---|
| 94 | |
|---|
| 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)]) |
|---|
| 101 | |
|---|
| 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])]) |
|---|
| 106 | |
|---|
| 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: |
|---|
| 113 | command.extend(["-NCYCLES", "1000000"]) |
|---|
| 114 | |
|---|
| 115 | print command |
|---|
| 116 | subprocess.call(command, stdout=logfile, stderr=logfile) |
|---|
| 117 | |
|---|
| 118 | logfile.close() |
|---|
| 119 | |
|---|
| 120 | # 6. move simulation terminal output into the target config dir |
|---|
| 121 | os.rename("term0", os.path.join(outdir, "term")) |
|---|
| 122 | |
|---|
| 123 | # get command-line arguments |
|---|
| 124 | if __name__ == "__main__": |
|---|
| 125 | parser = argparse.ArgumentParser(description='Run simulation') |
|---|
| 126 | |
|---|
| 127 | parser.add_argument( |
|---|
| 128 | '--path', '-p', type=str, dest='path', default=os.getcwd(), |
|---|
| 129 | help='relative or absolute path to the platform') |
|---|
| 130 | |
|---|
| 131 | parser.add_argument( |
|---|
| 132 | '--output', '-o', type=str, dest='outpath', default='./output', |
|---|
| 133 | help='relative or absolute path to the output directory') |
|---|
| 134 | |
|---|
| 135 | parser.add_argument( |
|---|
| 136 | '--xsize', '-x', type=int, dest='x', default=2, |
|---|
| 137 | help='# of clusters in a row') |
|---|
| 138 | |
|---|
| 139 | parser.add_argument( |
|---|
| 140 | '--ysize', '-y', type=int, dest='y', default=2, |
|---|
| 141 | help='# of clusters in a column') |
|---|
| 142 | |
|---|
| 143 | parser.add_argument( |
|---|
| 144 | '--nprocs', '-n', type=int, dest='nprocs', default=4, |
|---|
| 145 | help='# of processors per cluster') |
|---|
| 146 | |
|---|
| 147 | parser.add_argument( |
|---|
| 148 | '--compile-only', '-c', dest='compileonly', action='store_true', |
|---|
| 149 | help='generate config files and compile the platform. Do not simulate') |
|---|
| 150 | |
|---|
| 151 | parser.add_argument( |
|---|
| 152 | '--batch-mode', '-b', dest='batchmode', action='store_true', |
|---|
| 153 | help='run simulation in batch mode: no interactive TTY or FrameBuffer') |
|---|
| 154 | |
|---|
| 155 | parser.add_argument( |
|---|
| 156 | '--faulty-router', '-fr', dest='faultyrouter', action='append', nargs=2, |
|---|
| 157 | help='ID (X,Y) of faulty router') |
|---|
| 158 | |
|---|
| 159 | parser.add_argument( |
|---|
| 160 | '--faulty-mask', '-m', dest='faultymask', default=0x1F, |
|---|
| 161 | help='Disable mask for faulty router interfaces') |
|---|
| 162 | |
|---|
| 163 | parser.add_argument( |
|---|
| 164 | '--faulty-core', '-fc', dest='faultycore', action='append', nargs=3, |
|---|
| 165 | help='ID (X,Y,L) of faulty processor') |
|---|
| 166 | |
|---|
| 167 | parser.add_argument( |
|---|
| 168 | '--debug', '-g', dest='debug', nargs=4, |
|---|
| 169 | help='needs four arguments: from, to, procid, memcid') |
|---|
| 170 | |
|---|
| 171 | run(parser.parse_args()) |
|---|
| 172 | |
|---|
| 173 | # vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
|---|