diff options
author | Jeremy Erickson <jerickso@cs.unc.edu> | 2013-11-25 16:00:17 -0500 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2013-11-26 18:14:57 -0500 |
commit | eff718df52ffeb21bff6b59a5584e5b641887832 (patch) | |
tree | 2bcafa03fb5688e112c019095c9d23eca02a7bc5 /example/mapping.py | |
parent | 972ff75fcdddf59db00b50e8a28414cf0894cc24 (diff) |
Add example code and related end-to-end tests.
Diffstat (limited to 'example/mapping.py')
-rw-r--r-- | example/mapping.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/example/mapping.py b/example/mapping.py new file mode 100644 index 0000000..513100b --- /dev/null +++ b/example/mapping.py | |||
@@ -0,0 +1,28 @@ | |||
1 | #Necessary includes and stuff | ||
2 | |||
3 | from schedcat.mapping.rollback import Bin, WorstFit | ||
4 | from schedcat.model.tasks import SporadicTask, TaskSystem | ||
5 | |||
6 | def partition_tasks(cluster_size, clusters, dedicated_irq, | ||
7 | taskset): | ||
8 | first_cap = cluster_size - 1 if dedicated_irq \ | ||
9 | else cluster_size | ||
10 | first_bin = Bin(size=SporadicTask.utilization, | ||
11 | capacity=first_cap) | ||
12 | other_bins = [Bin(size=SporadicTask.utilization, | ||
13 | capacity=cluster_size) | ||
14 | for _ in xrange(1, clusters)] | ||
15 | heuristic = WorstFit(initial_bins=[first_bin] + other_bins) | ||
16 | heuristic.binpack(taskset) | ||
17 | if not (heuristic.misfits): | ||
18 | clusts = [TaskSystem(b.items) for b in heuristic.bins] | ||
19 | for i, c in enumerate(clusts): | ||
20 | if i == 0 and dedicated_irq: | ||
21 | c.cpus = cluster_size - 1 | ||
22 | else: | ||
23 | c.cpus = cluster_size | ||
24 | for task in c: | ||
25 | task.partition = i | ||
26 | return [c for c in clusts if len(c) > 0] | ||
27 | else: | ||
28 | return False | ||