def create_system_from_xml(input_file): """ Reads system configuration from param:`xml_system` and returns cls:`System` instances. """ from lxml import objectify root = objectify.fromstring(input_file.read()) for s in root.iterfind('system'): system = System(**dict(s.items())) for c in s.iterfind('component'): component = Component(**dict(c.items())) for t in c.iterfind('task'): task = Task(**dict(t.items())) component.addTask(task) system.addComponent(component) if args.path: system.path = args.path yield system if args.communication_server: yield add_server( system, component_period=args.communication_server_period, component_priority=args.communication_server_priority, component_budget=args.communication_server_budget, tasks=tasks)
def create_system_from_xml(xml_system, output=True): """ Reads system configuration from param:`xml_system` and returns cls:`System` instance. """ system = System(scheduler=xml_system.global_sched, resolution=xml_system.resolution) for c in xml_system.iterfind('component'): component = Component(c.cname, c.cperiod, c.cpriority, float(str(c.budget).replace(',', '.')), c.localsched, cargs.payback) system.addComponent(component) if output: print 'Component:' print 'name', 'period', 'budget', 'priority' print c.cname, c.cperiod, c.budget, c.cpriority print 'Tasks:' print 'name', 'period', 'priority', 'execution time' for t in c.iterfind('task'): if output: print t.tname, t.tperiod, t.tpriority, t.texetime component.addTask(Task(t.tname, float(str(t.tperiod).replace(',', '.')), int(t.tpriority), float(str(t.texetime).\ replace(',', '.')))) if output: print '------------------------------------' system.path = cargs.path if len(cargs.path) > 0 \ else range(len(system.tasks)) return system
def rand_system(minTasks=1, maxTasks=1, minTaskPeriod=0.04, maxTaskPeriod=0.12, resources=0, resolution=1000, minComps=1, maxComps=1, minCompPeriod=0.01, maxCompPeriod=0.02, utilization=0.2, globalsched='FPS', localsched='EDF', payback=False, verbose=False, **kargs): ## FIXME: improve balance of Component and Task utilizations def rand_comp(component, utils): tasks = random.randint(minTasks, maxTasks) xutils = [random.uniform(0.2, 0.8) for i in range(tasks)] sutils = sum(xutils) periods = [random.uniform(minTaskPeriod, maxTaskPeriod) for i in range(tasks)] freq = map(lambda x: 1.0 / x, periods) priorities = list(range(tasks)) random.shuffle(priorities, random.random) rutils = [random.uniform(0.2, 0.8) for i in range(tasks)] srutils = sum(rutils) utilizations = [(rutils[i] / srutils) * utils for i in range(tasks)] sutils = sum(utilizations) utilizations = map(lambda x: utils * x / sutils, utilizations) exectimes = map(lambda (a, b): a / b, zip(utilizations, freq)) if verbose: print 'Component' print '================' print 'periods', periods print 'freq', freq print 'utils', utilizations print 'exec', exectimes print 'utilization', sum(map(lambda c: exectimes[c] * freq[c], range(tasks))) print '----------------' return [Task( 'comp%d:task%d' % (component, t), resolution * periods[t], priorities[t], resolution * exectimes[t]) for t in range(tasks)] components = random.randint(minComps, maxComps) cperiods = [random.uniform(minCompPeriod, maxCompPeriod) for i in range(components)] freq = map(lambda x: 1.0 / x, cperiods) cpriorities = list(range(components)) random.shuffle(cpriorities, random.random) utils = utilization rutils = [random.uniform(0.2, 0.8) for i in range(components)] srutils = sum(rutils) utilizations = [(rutils[i] / srutils) * utils for i in range(components)] sutils = sum(utilizations) # sum(map(freq*budget)) = utilization utilizations = map(lambda x: utils * x / sutils, utilizations) budget = map(lambda (a, b): a / b, zip(utilizations, freq)) if verbose: print 'System' print '================' print 'periods:', cperiods print 'freq:', freq print 'utils:', utilizations print 'budget:', budget print 'utilization:', sum(map(lambda c: budget[c] * freq[c], range(components))) print '----------------' system = System( scheduler=globalsched, resolution=resolution) for c in range(components): component = Component( "comp%d" % (c,), resolution * cperiods[c], cpriorities[c], resolution * budget[c], localsched, payback) for t in rand_comp(c, utils * utilizations[c]): component.addTask(t) system.addComponent(component) return system