source: branches/reconfiguration/platforms/tsar_generic_iob/scripts/random_faulty_core_router.py @ 991

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

reconf: force the python version 2.7 in simulation scripts.

  • Property svn:executable set to *
File size: 6.0 KB
Line 
1#!/usr/bin/env python2.7
2
3import onerun
4import os
5import random
6from math import ceil
7from sys import exit
8
9class RunArguments:
10    def __init__(self, name, x, y):
11        self.path = os.getcwd()
12        self.outpath = name
13        self.x = x
14        self.y = y
15        self.nprocs = 4
16        self.compileonly = False
17        self.batchmode = True
18        self.faultyrouter = []
19        self.faultymask = 0xF
20        self.faultycore = []
21        self.debug = None
22
23        self.xmax = self.x - 1
24        self.ymax = self.y - 1
25        self.pmax = self.nprocs - 1
26
27        # init random number generator
28        random.seed()
29
30    def add_faultyrouter(self, x):
31        if x in self.faultyrouter:
32            return False
33
34        self.faultyrouter.append(x)
35        return True
36
37    def add_faultycore(self, x):
38        if x in self.faultycore:
39            return False
40
41        self.faultycore.append(x)
42        return True
43
44    def init_faultyrouter(self, x):
45        if x == None: return
46        self.faultyrouter = x
47
48    def init_faultycore(self, x):
49        if x == None: return
50        self.faultycore = x
51
52    def get_faultycount(self, total, pct):
53        """
54            Returns the number of faulty elements in a population
55            Arguments:
56                total -- Total number of elements
57                pct -- Percentage of faulty elements
58        """
59        return int(ceil(total * float(pct)/100))
60
61    def get_faultycorecount(self, pct):
62        """
63            Returns the number of faulty cores in the platform
64            Arguments:
65                pct -- Percentage of faulty cores
66        """
67        return self.get_faultycount(self.get_totalcores(), pct)
68
69    def get_faultyroutercount(self, pct):
70        """
71            Returns the number of faulty routers in the platform
72            Arguments:
73                pct -- Percentage of faulty routers
74        """
75        return self.get_faultycount(self.get_totalclusters(), pct)
76
77    def get_totalclusters(self):
78        return self.x * self.y
79
80    def get_totalcores(self):
81        return self.get_totalclusters() * self.nprocs
82
83# activate the different kinds of simulation
84SIM_FAULTFREE = False
85SIM_FAULTCORES = False
86SIM_FAULTROUTERS = True
87SIM_FAULTMIXED = False
88
89# probability of faulty router (for mixed simul)
90SIM_FAULTMIXED_PROBROUTER = 0.05 # 5%
91
92# NoC index for faulty routers
93CMD = 0
94RSP = 1
95
96for xsize, ysize in [(4, 4), (4, 8), (8, 8), (8, 16), (16, 16)]:
97    if SIM_FAULTFREE:
98        # ---------------------------------------------------------------------
99        # simulation without faults
100        # ---------------------------------------------------------------------
101        cfgname = 'output_{0}_{1}'.format(xsize, ysize)
102        args = RunArguments(cfgname, xsize, ysize)
103        onerun.run(args)
104
105    for pct in xrange(5, 60, 5): # 5, 10, ..., 55
106        if SIM_FAULTCORES:
107            # -----------------------------------------------------------------
108            # simulation with random faulty cores
109            # -----------------------------------------------------------------
110            cfgname = 'output_core_{0}_{1}_{2}'.format(xsize, ysize, pct)
111            args = RunArguments(cfgname, xsize, ysize)
112
113            faultycount = args.get_faultycorecount(pct)
114            print "{0}/{1} faulty cores\n".\
115                  format(faultycount, args.get_totalcores())
116
117            n = 0
118            while n < faultycount:
119                cx = random.randint(0, args.xmax)
120                cy = random.randint(0, args.ymax)
121                cl = random.randint(0, args.pmax)
122                if args.add_faultycore((cx, cy, cl)): n += 1
123
124            onerun.run(args)
125
126        if SIM_FAULTROUTERS:
127            # -----------------------------------------------------------------
128            # simulation with random faulty routers
129            # -----------------------------------------------------------------
130            cfgname = 'output_router_{0}_{1}_{2}'.format(xsize, ysize, pct)
131            args = RunArguments(cfgname, xsize, ysize)
132
133            faultycount = args.get_faultyroutercount(pct)
134            print "{0}/{1} faulty routers\n".\
135                  format(faultycount, args.get_totalclusters())
136
137            n = 0
138            while n < faultycount:
139                cx = random.randint(0, args.xmax)
140                cy = random.randint(0, args.ymax)
141                if args.add_faultyrouter((CMD, cx, cy)): n += 1
142
143            onerun.run(args)
144
145        if SIM_FAULTMIXED:
146            # -----------------------------------------------------------------
147            # simulation with random faulty routers and cores
148            # -----------------------------------------------------------------
149            cfgname = 'output_mixed_{0}_{1}_{2}'.format(xsize, ysize, pct)
150            args = RunArguments(cfgname, xsize, ysize)
151
152            total = args.get_totalclusters() + args.get_totalcores()
153            faultycount = args.get_faultycount(total, pct)
154
155            print "\nprobability of faulty routers: {0}".\
156                  format(SIM_FAULTMIXED_PROBROUTER)
157            fr = 0
158            fc = 0
159            while (fr + fc) < faultycount:
160                cx = random.randint(0, args.xmax)
161                cy = random.randint(0, args.ymax)
162                if (random.random() < SIM_FAULTMIXED_PROBROUTER):
163                    # add faulty router
164                    fr += 1
165                    while not args.add_faultyrouter((CMD, cx, cy)):
166                        cx = random.randint(0, args.xmax)
167                        cy = random.randint(0, args.ymax)
168
169                else:
170                    # add faulty core
171                    fc += 1
172                    cl = random.randint(0, args.pmax)
173                    while not args.add_faultycore((cx, cy, cl)):
174                        cx = random.randint(0, args.xmax)
175                        cy = random.randint(0, args.ymax)
176                        cl = random.randint(0, args.pmax)
177
178            print "faulty routers / faulty cores = {0} / {1}".format(fr, fc)
179            onerun.run(args)
180
181# vim: ts=4 : sts=4 : sw=4 : et
Note: See TracBrowser for help on using the repository browser.