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/locking.py | |
parent | 972ff75fcdddf59db00b50e8a28414cf0894cc24 (diff) |
Add example code and related end-to-end tests.
Diffstat (limited to 'example/locking.py')
-rw-r--r-- | example/locking.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/example/locking.py b/example/locking.py new file mode 100644 index 0000000..8414dc3 --- /dev/null +++ b/example/locking.py | |||
@@ -0,0 +1,68 @@ | |||
1 | #Necessary includes and stuff | ||
2 | |||
3 | from schedcat.locking.bounds import apply_task_fair_mutex_bounds, \ | ||
4 | assign_prio_pt_locking_prios | ||
5 | |||
6 | from schedcat.overheads.jlfp import charge_scheduling_overheads, \ | ||
7 | quantize_params | ||
8 | |||
9 | from schedcat.sched.edf.gel_pl import \ | ||
10 | bound_gfl_response_times, has_bounded_tardiness | ||
11 | |||
12 | from schedcat.overheads.locking import charge_spinlock_overheads | ||
13 | |||
14 | def copy_ts(ts, clusts): | ||
15 | new_ts = [] | ||
16 | new_clusts = [] | ||
17 | for clust in clusts: | ||
18 | new_clust = clust.copy() | ||
19 | new_clust.cpus = clust.cpus | ||
20 | new_clusts.append(new_clust) | ||
21 | new_ts += new_clust | ||
22 | return (new_ts, new_clusts) | ||
23 | |||
24 | def preprocess_ts(taskset, clusts, oheads): | ||
25 | for clust in clusts: | ||
26 | charge_spinlock_overheads(oheads, clust) | ||
27 | for task in clust: | ||
28 | #Initially assume completion by deadline and use G-FL | ||
29 | task.response_time = task.deadline | ||
30 | task.prio_pt = task.deadline - \ | ||
31 | (clust.cpus - 1) / (clust.cpus) * task.cost | ||
32 | assign_prio_pt_locking_prios(taskset) | ||
33 | |||
34 | def post_blocking_term_oh_inflation(oheads, clusts): | ||
35 | for clust in clusts: | ||
36 | inflation = oheads.syscall_in(len(clust)) | ||
37 | for t in clust: | ||
38 | if t.arrival_blocked: | ||
39 | t.cost += inflation | ||
40 | t.arrival_blocked += inflation | ||
41 | if not charge_scheduling_overheads(oheads, clust.cpus, | ||
42 | True, clust): | ||
43 | return False | ||
44 | quantize_params(clust) | ||
45 | return True | ||
46 | |||
47 | def bound_cfl_with_locks(tasks, clusts, oheads, cluster_size): | ||
48 | preprocess_ts(tasks, clusts, oheads) | ||
49 | completion_ok = False | ||
50 | count = 0 | ||
51 | while not completion_ok: | ||
52 | completion_ok = True | ||
53 | new_ts, new_clusts = copy_ts(tasks, clusts) | ||
54 | count += 1 | ||
55 | if count > 100: | ||
56 | return False | ||
57 | apply_task_fair_mutex_bounds(new_ts, cluster_size, 0) | ||
58 | if not post_blocking_term_oh_inflation(oheads, | ||
59 | new_clusts): | ||
60 | return False | ||
61 | for i, clust in enumerate(new_clusts): | ||
62 | if not has_bounded_tardiness(clust.cpus, clust): | ||
63 | return False | ||
64 | bound_gfl_response_times(clust.cpus, clust, 15) | ||
65 | for j, t in enumerate(clust): | ||
66 | if t.response_time > clusts[i][j].response_time: | ||
67 | completion_ok = False | ||
68 | return new_clusts | ||