[991] | 1 | #!/usr/bin/env python2.7 |
---|
[894] | 2 | |
---|
| 3 | import onerun |
---|
| 4 | import os |
---|
| 5 | import random |
---|
| 6 | from math import ceil |
---|
| 7 | from sys import exit |
---|
| 8 | |
---|
| 9 | class 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 |
---|
[1000] | 22 | self.linux = False |
---|
| 23 | self.force = True |
---|
| 24 | self.firmdebug = False |
---|
| 25 | self.diskimage = "/dev/null" |
---|
| 26 | self.ncycles = -1 |
---|
| 27 | self.threads = -1 |
---|
[894] | 28 | |
---|
| 29 | self.xmax = self.x - 1 |
---|
| 30 | self.ymax = self.y - 1 |
---|
| 31 | self.pmax = self.nprocs - 1 |
---|
| 32 | |
---|
| 33 | # init random number generator |
---|
| 34 | random.seed() |
---|
| 35 | |
---|
| 36 | def add_faultyrouter(self, x): |
---|
| 37 | if x in self.faultyrouter: |
---|
| 38 | return False |
---|
| 39 | |
---|
| 40 | self.faultyrouter.append(x) |
---|
| 41 | return True |
---|
| 42 | |
---|
| 43 | def add_faultycore(self, x): |
---|
| 44 | if x in self.faultycore: |
---|
| 45 | return False |
---|
| 46 | |
---|
| 47 | self.faultycore.append(x) |
---|
| 48 | return True |
---|
| 49 | |
---|
| 50 | def init_faultyrouter(self, x): |
---|
| 51 | if x == None: return |
---|
| 52 | self.faultyrouter = x |
---|
| 53 | |
---|
| 54 | def init_faultycore(self, x): |
---|
| 55 | if x == None: return |
---|
| 56 | self.faultycore = x |
---|
| 57 | |
---|
| 58 | def get_faultycount(self, total, pct): |
---|
| 59 | """ |
---|
| 60 | Returns the number of faulty elements in a population |
---|
| 61 | Arguments: |
---|
| 62 | total -- Total number of elements |
---|
| 63 | pct -- Percentage of faulty elements |
---|
| 64 | """ |
---|
| 65 | return int(ceil(total * float(pct)/100)) |
---|
| 66 | |
---|
| 67 | def get_faultycorecount(self, pct): |
---|
| 68 | """ |
---|
| 69 | Returns the number of faulty cores in the platform |
---|
| 70 | Arguments: |
---|
| 71 | pct -- Percentage of faulty cores |
---|
| 72 | """ |
---|
| 73 | return self.get_faultycount(self.get_totalcores(), pct) |
---|
| 74 | |
---|
| 75 | def get_faultyroutercount(self, pct): |
---|
| 76 | """ |
---|
| 77 | Returns the number of faulty routers in the platform |
---|
| 78 | Arguments: |
---|
| 79 | pct -- Percentage of faulty routers |
---|
| 80 | """ |
---|
| 81 | return self.get_faultycount(self.get_totalclusters(), pct) |
---|
| 82 | |
---|
| 83 | def get_totalclusters(self): |
---|
| 84 | return self.x * self.y |
---|
| 85 | |
---|
| 86 | def get_totalcores(self): |
---|
| 87 | return self.get_totalclusters() * self.nprocs |
---|
| 88 | |
---|
[902] | 89 | # activate the different kinds of simulation |
---|
| 90 | SIM_FAULTFREE = False |
---|
| 91 | SIM_FAULTCORES = False |
---|
[1000] | 92 | SIM_FAULTROUTERS = False |
---|
[904] | 93 | SIM_FAULTMIXED = False |
---|
[1000] | 94 | SIM_CUSTOM = True |
---|
[894] | 95 | |
---|
[902] | 96 | # probability of faulty router (for mixed simul) |
---|
| 97 | SIM_FAULTMIXED_PROBROUTER = 0.05 # 5% |
---|
| 98 | |
---|
[904] | 99 | # NoC index for faulty routers |
---|
| 100 | CMD = 0 |
---|
| 101 | RSP = 1 |
---|
| 102 | |
---|
[1000] | 103 | # Mesh parameters list |
---|
| 104 | MESH = [] |
---|
| 105 | MESH.append((2, 2)) |
---|
| 106 | MESH.append((2, 4)) |
---|
| 107 | MESH.append((4, 4)) |
---|
| 108 | MESH.append((4, 8)) |
---|
| 109 | #MESH.append((8, 8)) |
---|
| 110 | |
---|
| 111 | for xsize, ysize in MESH: |
---|
[902] | 112 | if SIM_FAULTFREE: |
---|
| 113 | # --------------------------------------------------------------------- |
---|
| 114 | # simulation without faults |
---|
| 115 | # --------------------------------------------------------------------- |
---|
| 116 | cfgname = 'output_{0}_{1}'.format(xsize, ysize) |
---|
[894] | 117 | args = RunArguments(cfgname, xsize, ysize) |
---|
[902] | 118 | onerun.run(args) |
---|
[894] | 119 | |
---|
[1000] | 120 | if SIM_CUSTOM: |
---|
| 121 | # ----------------------------------------------------------------- |
---|
| 122 | # simulation with list of faulty routers and cores |
---|
| 123 | # ----------------------------------------------------------------- |
---|
| 124 | cfgname = 'output_custom_{0}_{1}_fc'.format(xsize, ysize) |
---|
| 125 | args = RunArguments(cfgname, xsize, ysize) |
---|
| 126 | # args.add_faultyrouter((RSP, args.xmax - 1, args.ymax - 1)) |
---|
| 127 | args.add_faultycore((0, 0, 0)) |
---|
| 128 | onerun.run(args) |
---|
| 129 | |
---|
[902] | 130 | for pct in xrange(5, 60, 5): # 5, 10, ..., 55 |
---|
| 131 | if SIM_FAULTCORES: |
---|
| 132 | # ----------------------------------------------------------------- |
---|
| 133 | # simulation with random faulty cores |
---|
| 134 | # ----------------------------------------------------------------- |
---|
| 135 | cfgname = 'output_core_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 136 | args = RunArguments(cfgname, xsize, ysize) |
---|
[894] | 137 | |
---|
[902] | 138 | faultycount = args.get_faultycorecount(pct) |
---|
| 139 | print "{0}/{1} faulty cores\n".\ |
---|
| 140 | format(faultycount, args.get_totalcores()) |
---|
[894] | 141 | |
---|
[902] | 142 | n = 0 |
---|
| 143 | while n < faultycount: |
---|
| 144 | cx = random.randint(0, args.xmax) |
---|
| 145 | cy = random.randint(0, args.ymax) |
---|
| 146 | cl = random.randint(0, args.pmax) |
---|
| 147 | if args.add_faultycore((cx, cy, cl)): n += 1 |
---|
[894] | 148 | |
---|
[902] | 149 | onerun.run(args) |
---|
[894] | 150 | |
---|
[902] | 151 | if SIM_FAULTROUTERS: |
---|
| 152 | # ----------------------------------------------------------------- |
---|
| 153 | # simulation with random faulty routers |
---|
| 154 | # ----------------------------------------------------------------- |
---|
| 155 | cfgname = 'output_router_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 156 | args = RunArguments(cfgname, xsize, ysize) |
---|
[894] | 157 | |
---|
[902] | 158 | faultycount = args.get_faultyroutercount(pct) |
---|
| 159 | print "{0}/{1} faulty routers\n".\ |
---|
| 160 | format(faultycount, args.get_totalclusters()) |
---|
[894] | 161 | |
---|
[902] | 162 | n = 0 |
---|
| 163 | while n < faultycount: |
---|
| 164 | cx = random.randint(0, args.xmax) |
---|
| 165 | cy = random.randint(0, args.ymax) |
---|
[904] | 166 | if args.add_faultyrouter((CMD, cx, cy)): n += 1 |
---|
[894] | 167 | |
---|
[902] | 168 | onerun.run(args) |
---|
[894] | 169 | |
---|
[902] | 170 | if SIM_FAULTMIXED: |
---|
| 171 | # ----------------------------------------------------------------- |
---|
| 172 | # simulation with random faulty routers and cores |
---|
| 173 | # ----------------------------------------------------------------- |
---|
| 174 | cfgname = 'output_mixed_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 175 | args = RunArguments(cfgname, xsize, ysize) |
---|
[894] | 176 | |
---|
[902] | 177 | total = args.get_totalclusters() + args.get_totalcores() |
---|
| 178 | faultycount = args.get_faultycount(total, pct) |
---|
[894] | 179 | |
---|
[902] | 180 | print "\nprobability of faulty routers: {0}".\ |
---|
| 181 | format(SIM_FAULTMIXED_PROBROUTER) |
---|
| 182 | fr = 0 |
---|
| 183 | fc = 0 |
---|
| 184 | while (fr + fc) < faultycount: |
---|
| 185 | cx = random.randint(0, args.xmax) |
---|
| 186 | cy = random.randint(0, args.ymax) |
---|
| 187 | if (random.random() < SIM_FAULTMIXED_PROBROUTER): |
---|
| 188 | # add faulty router |
---|
| 189 | fr += 1 |
---|
[904] | 190 | while not args.add_faultyrouter((CMD, cx, cy)): |
---|
[902] | 191 | cx = random.randint(0, args.xmax) |
---|
| 192 | cy = random.randint(0, args.ymax) |
---|
[894] | 193 | |
---|
[902] | 194 | else: |
---|
| 195 | # add faulty core |
---|
| 196 | fc += 1 |
---|
| 197 | cl = random.randint(0, args.pmax) |
---|
| 198 | while not args.add_faultycore((cx, cy, cl)): |
---|
| 199 | cx = random.randint(0, args.xmax) |
---|
| 200 | cy = random.randint(0, args.ymax) |
---|
| 201 | cl = random.randint(0, args.pmax) |
---|
[894] | 202 | |
---|
[902] | 203 | print "faulty routers / faulty cores = {0} / {1}".format(fr, fc) |
---|
| 204 | onerun.run(args) |
---|
[894] | 205 | |
---|
[902] | 206 | # vim: ts=4 : sts=4 : sw=4 : et |
---|