From 0c8665f9f796ffa7fc13851316c209d6efc1029f Mon Sep 17 00:00:00 2001 From: Tobias Langer Date: Sun, 9 Oct 2016 10:58:44 +0200 Subject: [PATCH] Adjusted for smaller hyperperiods. --- tasksetgen.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/tasksetgen.py b/tasksetgen.py index 6686ae1..10d928c 100755 --- a/tasksetgen.py +++ b/tasksetgen.py @@ -3,7 +3,7 @@ """ Generates real time tasksets according to the method described in 'A Comparison of Global and Partitioned EDF Schedulability Tests for Multiprocessors'. -Therefore tasks with random periods within the range 1 to 1000 are generated. +Therefore tasks with random periods within the range 1 to 100 are generated. Depending on the mode, the utilization of these tasks is either determined by * uniform distribution between 1/period and 1 * bimodal distribution heavy tasks with uniform distribution between 0.5 / 1 and @@ -14,13 +14,47 @@ is 1/3 """ import datetime +import shutil import sys import os import random import argparse import json +import math from enum import Enum +def query_yes_no(question, default=None): + """ + Queries the user for a decision. + """ + + if default is None: + prompt = ' [y/n]' + elif default.lower() == 'yes': + prompt = ' [Y/n]' + elif default.lower() == 'no': + prompt = ' [y/N]' + else: + raise ValueError('Invalid default answer {}'.format(default)) + + while True: + print(question, prompt, end='') + choice = input().lower() + if 'yes'.find(choice) == 0: + return True + elif 'no'.find(choice) == 0: + return False + +def lcm(a, b): + return (a * b) / math.gcd(a, b) + +def hyperperiod(tasks): + periods = [x.period for task in tasks] + hyperperiod = periods[0] + for period in periods[1:]: + hyperperiod = lcm(hyperperiod, period) + return hyperperiod + class Timebase(Enum): seconds = 1 milliseconds = 2 @@ -59,7 +93,7 @@ def get_timebase_string(base): return 'std::chrono::nanoseconds', 'embb::base::DurationNanoseconds' def create_task(distribution): - period = random.uniform(1, 1000) + period = random.uniform(1, 30) if distribution is Distribution.uniform: util = random.uniform(1.0 / period, 1.0) elif distribution is Distribution.bimodal: @@ -140,7 +174,8 @@ def main(): while len(tasksets) < args.tasksetcount: taskset = [] while len(taskset) < args.cores + 1 or \ - check_taskset(args.cores, taskset) <= 1: + check_taskset(args.cores, taskset) <= 1 and \ + hyperperiod(taskset) < 300000: # Limit hyperperiod to 5 minutes taskset.append(create_task(distribution)) if len(taskset) >= args.cores + 1: tasksets.append(taskset) @@ -149,6 +184,14 @@ def main(): cpp_base, embb_base = get_timebase_string(timebase) + try: + os.makedirs(args.target) + except FileExistsError: + if not query_yes_no('Folder exists, remove?', default='yes'): + sys.exit(1) + shutil.rmtree(args.target) + os.makedirs(args.target) + print('Writing tasks…', file=sys.stderr) for taskset in tasksets: task_out = [] -- libgit2 0.26.0