diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-03-07 15:06:25 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-03-07 15:07:42 -0500 |
commit | cef97086e881400270141cdf7b22ef68948b3597 (patch) | |
tree | 5ee50dc1a7761b667c54c7a997e49c18b1fe4101 /gen/edf_generators.py | |
parent | e3b7c78aa5b96af6bdbad20a13e0f540d1658b7f (diff) |
Seperated BaseGenerator into EdfGenerator and its superclass Generator.
Diffstat (limited to 'gen/edf_generators.py')
-rw-r--r-- | gen/edf_generators.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/gen/edf_generators.py b/gen/edf_generators.py new file mode 100644 index 0000000..6cca933 --- /dev/null +++ b/gen/edf_generators.py | |||
@@ -0,0 +1,90 @@ | |||
1 | import generator as gen | ||
2 | import random | ||
3 | import run.litmus_util as lu | ||
4 | import schedcat.generator.tasks as tasks | ||
5 | |||
6 | class EdfGenerator(gen.Generator): | ||
7 | '''Creates sporadic task sets with the most common Litmus options.''' | ||
8 | def __init__(self, name, templates, options, params): | ||
9 | super(EdfGenerator, self).__init__(name, templates, | ||
10 | self.__make_options(params) + options, | ||
11 | params) | ||
12 | |||
13 | def __make_options(self, params): | ||
14 | '''Return generic EDF options.''' | ||
15 | if 'cpus' in params: | ||
16 | cpus = min(map(int, params['cpus'])) | ||
17 | else: | ||
18 | cpus = lu.num_cpus() | ||
19 | |||
20 | return [gen.GenOption('num_tasks', int, range(cpus, 5*cpus, cpus), | ||
21 | 'Number of tasks per experiment.'), | ||
22 | gen.Generator._dist_option('utils', ['uni-medium'], | ||
23 | gen.NAMED_UTILIZATIONS, | ||
24 | 'Task utilization distributions.'), | ||
25 | gen.Generator._dist_option('periods', ['harmonic'], | ||
26 | gen.NAMED_PERIODS, | ||
27 | 'Task period distributions.')] | ||
28 | |||
29 | def _create_exp(self, exp_params): | ||
30 | '''Create a single experiment with @exp_params in @out_dir.''' | ||
31 | pdist = self._create_dist('period', | ||
32 | exp_params['periods'], | ||
33 | gen.NAMED_PERIODS) | ||
34 | udist = self._create_dist('utilization', | ||
35 | exp_params['utils'], | ||
36 | gen.NAMED_UTILIZATIONS) | ||
37 | tg = tasks.TaskGenerator(period=pdist, util=udist) | ||
38 | |||
39 | ts = [] | ||
40 | tries = 0 | ||
41 | while len(ts) != exp_params['num_tasks'] and tries < 5: | ||
42 | ts = tg.make_task_set(max_tasks = exp_params['num_tasks']) | ||
43 | tries += 1 | ||
44 | if len(ts) != exp_params['num_tasks']: | ||
45 | print("Failed to create task set with parameters: %s" % exp_params) | ||
46 | |||
47 | self._customize(ts, exp_params) | ||
48 | |||
49 | exp_params['task_set'] = ts | ||
50 | self._write_schedule(exp_params) | ||
51 | |||
52 | del exp_params['task_set'] | ||
53 | del exp_params['num_tasks'] | ||
54 | self._write_params(exp_params) | ||
55 | |||
56 | def _customize(self, taskset, exp_params): | ||
57 | '''Configure a generated taskset with extra parameters.''' | ||
58 | pass | ||
59 | |||
60 | |||
61 | class PartitionedGenerator(EdfGenerator): | ||
62 | def __init__(self, name, templates, options, params): | ||
63 | super(PartitionedGenerator, self).__init__(name, | ||
64 | templates + [gen.TP_PART_TASK], options, params) | ||
65 | |||
66 | def _customize(self, taskset, exp_params): | ||
67 | start = 1 if exp_params['release_master'] else 0 | ||
68 | # Random partition for now: could do a smart partitioning | ||
69 | for t in taskset: | ||
70 | t.cpu = random.randint(start, exp_params['cpus'] - 1) | ||
71 | |||
72 | class PedfGenerator(PartitionedGenerator): | ||
73 | def __init__(self, params={}): | ||
74 | super(PedfGenerator, self).__init__("PSN-EDF", [], [], params) | ||
75 | |||
76 | class CedfGenerator(PartitionedGenerator): | ||
77 | TP_CLUSTER = "plugins/C-EDF/cluster{$level}" | ||
78 | CLUSTER_OPTION = gen.GenOption('level', ['L2', 'L3', 'All'], ['L2'], | ||
79 | 'Cache clustering level.',) | ||
80 | |||
81 | def __init__(self, params={}): | ||
82 | super(CedfGenerator, self).__init__("C-EDF", | ||
83 | [CedfGenerator.TP_CLUSTER], | ||
84 | [CedfGenerator.CLUSTER_OPTION], | ||
85 | params) | ||
86 | |||
87 | class GedfGenerator(EdfGenerator): | ||
88 | def __init__(self, params={}): | ||
89 | super(GedfGenerator, self).__init__("GSN-EDF", [gen.TP_GLOB_TASK], | ||
90 | [], params) | ||