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

Last change on this file since 974 was 974, checked in by cfuguet, 9 years ago

reconf: improve reconf:tsar_generic_iob simulation scripts

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