source: branches/reconfiguration/platforms/tsar_generic_iob/scripts/onerun.py @ 1027

Last change on this file since 1027 was 1027, checked in by cfuguet, 8 years ago

Improving documentation of the reconfiguration/tsar_generic_iob
platform.

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