aboutsummaryrefslogtreecommitdiffstats
path: root/gen/mc_generators.py
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-04-23 17:28:12 -0400
committerJonathan Herman <hermanjl@cs.unc.edu>2013-04-23 17:28:12 -0400
commit2ceaa6c607ef85bde4f14017634d9d1621efca29 (patch)
treec85e755e59907a48ff762fd56473449f33c23894 /gen/mc_generators.py
parenta0e4b9fe9d7fab9a50a626cfeda3c614a9a6af5d (diff)
parent7545402506aa76261e18d85af585ff0ac1cf05c1 (diff)
Merge branch 'master' into wip-color-mc
Conflicts: gen/generator.py parse/sched.py parse_exps.py
Diffstat (limited to 'gen/mc_generators.py')
-rw-r--r--gen/mc_generators.py82
1 files changed, 64 insertions, 18 deletions
diff --git a/gen/mc_generators.py b/gen/mc_generators.py
index 704bcc3..8f5bd84 100644
--- a/gen/mc_generators.py
+++ b/gen/mc_generators.py
@@ -1,8 +1,10 @@
1import gen.rv as rv 1import gen.rv as rv
2 2
3from color import get_cache_info,CacheInfo,BlockColorScheme,RandomColorScheme,EvilColorScheme 3from color import get_cache_info,CacheInfo,BlockColorScheme,RandomColorScheme,EvilColorScheme
4from common import try_get_config_option 4from common import try_get_config_option, log_once
5from gen.generator import GenOption,Generator,NAMED_UTILIZATIONS,NAMED_PERIODS 5from gen.generator import GenOption,Generator,NAMED_UTILIZATIONS,NAMED_PERIODS
6from parse.col_map import ColMap
7from parse.tuple_table import TupleTable
6 8
7 9
8NAMED_SHARES = { 10NAMED_SHARES = {
@@ -188,24 +190,24 @@ class McGenerator(Generator):
188 190
189 return self._create_taskset(params, periods, utils, max_util) 191 return self._create_taskset(params, periods, utils, max_util)
190 192
191 def _customize(self, task_system, params): 193 def _get_tasks(self, params):
192 pass 194 return {'lvla': self.__create_lvla_sched(params),
195 'lvlb': self.__create_lvlb_sched(params),
196 'lvlc': self.__create_lvlc_sched(params)}
193 197
194 def _create_exp(self, params): 198 def _create_exp(self, params):
195 # Ugly way of doing it 199 # Ugly way of doing it
196 self.shares = self._create_dist('shares', params['shares'], 200 self.shares = self._create_dist('shares', params['shares'],
197 NAMED_SHARES) 201 NAMED_SHARES)
198 202
199 tasks = {'lvla': self.__create_lvla_sched(params), 203 tasks = self._get_tasks(params)
200 'lvlb': self.__create_lvlb_sched(params),
201 'lvlc': self.__create_lvlc_sched(params)}
202 204
203 conf_options = {MC_OPT : 'y'} 205 conf_options = {MC_OPT : 'y'}
204 if params['timer_merging']: 206 if params['timer_merging']:
205 conf_options[TM_OPT] = 'y' 207 conf_options[TM_OPT] = 'y'
206 if params['redirect']: 208 if params['redirect']:
207 if not params['release_master']: 209 if not params['release_master']:
208 print("Forcing release master option to enable redirection.") 210 log_once("Forcing release master option to enable redirection.")
209 params['release_master'] = 'y' 211 params['release_master'] = 'y'
210 conf_options[RD_OPT] = 'y' 212 conf_options[RD_OPT] = 'y'
211 if params['slack_stealing']: 213 if params['slack_stealing']:
@@ -241,8 +243,11 @@ TP_TYPE = """#if $type != 'unmanaged'
241/proc/sys/litmus/color/preempt_cache{0} 243/proc/sys/litmus/color/preempt_cache{0}
242#end if""" 244#end if"""
243 245
246# Always add some pages
247TP_ADD = """/proc/sys/litmus/color/add_pages{1}"""
248
244# Use special spin for color tasks 249# Use special spin for color tasks
245TP_COLOR_BASE = """colorspin -y $t.id -x $t.colorcsv """ 250TP_COLOR_BASE = """colorspin -y $t.id -x $t.colorcsv -q $t.wss -l $t.loops """
246 251
247TP_COLOR_B = TP_BASE.format("b", TP_COLOR_BASE + "-p $t.cpu ") 252TP_COLOR_B = TP_BASE.format("b", TP_COLOR_BASE + "-p $t.cpu ")
248TP_COLOR_C = TP_BASE.format("c", TP_COLOR_BASE) 253TP_COLOR_C = TP_BASE.format("c", TP_COLOR_BASE)
@@ -255,12 +260,16 @@ TP_CHUNK = """#if $chunk_size > 0
255COLOR_TYPES = ['scheduling', 'locking', 'unmanaged'] 260COLOR_TYPES = ['scheduling', 'locking', 'unmanaged']
256 261
257class ColorMcGenerator(McGenerator): 262class ColorMcGenerator(McGenerator):
263 __SINGLE_PAGE_LOOP_MS = {'ringo': .023}
264
258 def __init__(self, params = {}): 265 def __init__(self, params = {}):
259 super(ColorMcGenerator, self).__init__("MC", 266 super(ColorMcGenerator, self).__init__("MC",
260 templates=[TP_TYPE, TP_CHUNK, TP_COLOR_B, TP_COLOR_C], 267 templates=[TP_ADD, TP_TYPE, TP_CHUNK, TP_COLOR_B, TP_COLOR_C],
261 options=self.__make_options(), 268 options=self.__make_options(),
262 params=self.__extend_params(params)) 269 params=self.__extend_params(params))
263 270
271 self.tasksets = None
272
264 def __extend_params(self, params): 273 def __extend_params(self, params):
265 '''Add in fixed mixed-criticality parameters.''' 274 '''Add in fixed mixed-criticality parameters.'''
266 params['levels'] = 2 275 params['levels'] = 2
@@ -278,6 +287,10 @@ class ColorMcGenerator(McGenerator):
278 287
279 return params 288 return params
280 289
290 def __get_system_name(self):
291 import socket
292 return socket.gethostname().split(".")[0]
293
281 def __make_system_info(self): 294 def __make_system_info(self):
282 info = get_cache_info() 295 info = get_cache_info()
283 296
@@ -298,20 +311,32 @@ class ColorMcGenerator(McGenerator):
298 info = CacheInfo(cache, line=line, page=page, 311 info = CacheInfo(cache, line=line, page=page,
299 ways=ways, sets=sets, colors=colors) 312 ways=ways, sets=sets, colors=colors)
300 313
301 self.system = info 314 self.cache = info
315
316 hostname = self.__get_system_name()
317 if hostname not in self.__SINGLE_PAGE_LOOP_MS:
318 first_host = self.__SINGLE_PAGE_LOOP_MS.keys()[0]
319 log_once("hostname", "No timing info for host %s" % hostname +
320 ", needed to calculate work done per task. Please get the "
321 "timing info and add to __SINGLE_PAGE_LOOP_MS in " +
322 "mc_generators.py. Assuming host %s." % first_host)
323 hostname = first_host
324 self.host = hostname
302 325
303 def __make_options(self): 326 def __make_options(self):
304 self.__make_system_info() 327 self.__make_system_info()
305 328
306 return [GenOption('type', COLOR_TYPES, COLOR_TYPES, 329 return [GenOption('type', COLOR_TYPES, COLOR_TYPES,
307 'Cache management type.'), 330 'Cache management type.'),
308 GenOption('chunk_size', float, [0], 'Chunk size.'), 331 GenOption('host', self.__SINGLE_PAGE_LOOP_MS.keys(), self.host,
309 GenOption('ways', int, [self.system.ways], 'Ways (associativity).'), 332 'System experiment will run on (for calculating work).'),
310 GenOption('colors', int, [self.system.colors], 333 GenOption('chunk_size_ns', float, 0, 'Chunk size. 0 = no chunking.'),
334 GenOption('ways', int, self.cache.ways, 'Ways (associativity).'),
335 GenOption('colors', int, self.cache.colors,
311 'System colors (cache size / ways).'), 336 'System colors (cache size / ways).'),
312 GenOption('page_size', int, [self.system.page], 337 GenOption('page_size', int, self.cache.page,
313 'System page size.'), 338 'System page size.'),
314 GenOption('wss', [float, int], [.5], 339 GenOption('wss', [float, int], .5,
315 'Task working set sizes. Can be expressed as a fraction ' + 340 'Task working set sizes. Can be expressed as a fraction ' +
316 'of the cache.')] 341 'of the cache.')]
317 342
@@ -346,14 +371,37 @@ class ColorMcGenerator(McGenerator):
346 for color, replicas in task.colors.iteritems(): 371 for color, replicas in task.colors.iteritems():
347 f.write("%d, %d\n" % (color, replicas)) 372 f.write("%d, %d\n" % (color, replicas))
348 373
374 def __get_loops(self, task, pages, system):
375 all_pages_loop = self.__SINGLE_PAGE_LOOP_MS[system] * pages
376 return int(task.cost / all_pages_loop) + 1
377
378 def _get_tasks(self, params):
379 # Share tasksets amongst experiments with different types but
380 # identical other parameters for proper comparisons
381 if self.tasksets == None:
382 fields = params.keys()
383 fields.remove("type")
384 self.tasksets = TupleTable( ColMap(fields), lambda:None )
385
386 if params not in self.tasksets:
387 ts = super(ColorMcGenerator, self)._get_tasks(params)
388 self.tasksets[params] = ts
389
390 return self.tasksets[params]
391
349 def _customize(self, task_system, params): 392 def _customize(self, task_system, params):
350 '''Add coloring properties to the mixed-criticality task system.''' 393 '''Add coloring properties to the mixed-criticality task system.'''
394 pages_needed = self.__get_wss_pages(params)
395 real_wss = params['page_size'] * pages_needed
396
351 # Every task needs a unique id for coloring and wss walk order 397 # Every task needs a unique id for coloring and wss walk order
352 all_tasks = [] 398 all_tasks = []
353 for level, tasks in task_system.iteritems(): 399 for level, tasks in task_system.iteritems():
354 all_tasks += tasks 400 all_tasks += tasks
355 for i, task in enumerate(all_tasks): 401 for i, task in enumerate(all_tasks):
356 task.id = i 402 task.id = i
403 task.wss = real_wss
404 task.loops = self.__get_loops(task, pages_needed, params['host'])
357 405
358 c = params['colors'] 406 c = params['colors']
359 w = params['ways'] 407 w = params['ways']
@@ -365,8 +413,6 @@ class ColorMcGenerator(McGenerator):
365 srt_colorer = RandomColorScheme(c, w) 413 srt_colorer = RandomColorScheme(c, w)
366 hrt_colorer = BlockColorScheme(c, w, way_first=True) 414 hrt_colorer = BlockColorScheme(c, w, way_first=True)
367 415
368 pages_needed = self.__get_wss_pages(params)
369
370 hrt_colorer.color(task_system['lvlb'], pages_needed) 416 hrt_colorer.color(task_system['lvlb'], pages_needed)
371 srt_colorer.color(task_system['lvlc'], pages_needed) 417 srt_colorer.color(task_system['lvlc'], pages_needed)
372 418