diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2009-12-17 21:30:11 -0500 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2009-12-17 21:30:11 -0500 |
commit | 337d55668872bbb06622806139ebeb17de54ab39 (patch) | |
tree | c5574f86b5c26f58c228b53079f5766d6edc4a2e /litmus/sync.c | |
parent | 4db5b318390ff38488ef1f066e6cacc8f7479064 (diff) |
Add synchronous task release API
Diffstat (limited to 'litmus/sync.c')
-rw-r--r-- | litmus/sync.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/litmus/sync.c b/litmus/sync.c new file mode 100644 index 000000000000..bf75fde5450b --- /dev/null +++ b/litmus/sync.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* litmus/sync.c - Support for synchronous and asynchronous task system releases. | ||
2 | * | ||
3 | * | ||
4 | */ | ||
5 | |||
6 | #include <asm/atomic.h> | ||
7 | #include <asm/uaccess.h> | ||
8 | #include <linux/spinlock.h> | ||
9 | #include <linux/list.h> | ||
10 | #include <linux/sched.h> | ||
11 | #include <linux/completion.h> | ||
12 | |||
13 | #include <litmus/litmus.h> | ||
14 | #include <litmus/sched_plugin.h> | ||
15 | #include <litmus/jobs.h> | ||
16 | |||
17 | #include <litmus/sched_trace.h> | ||
18 | |||
19 | static DECLARE_COMPLETION(ts_release); | ||
20 | |||
21 | static long do_wait_for_ts_release(void) | ||
22 | { | ||
23 | long ret = 0; | ||
24 | |||
25 | /* If the interruption races with a release, the completion object | ||
26 | * may have a non-zero counter. To avoid this problem, this should | ||
27 | * be replaced by wait_for_completion(). | ||
28 | * | ||
29 | * For debugging purposes, this is interruptible for now. | ||
30 | */ | ||
31 | ret = wait_for_completion_interruptible(&ts_release); | ||
32 | |||
33 | return ret; | ||
34 | } | ||
35 | |||
36 | int count_tasks_waiting_for_release(void) | ||
37 | { | ||
38 | unsigned long flags; | ||
39 | int task_count = 0; | ||
40 | struct list_head *pos; | ||
41 | |||
42 | spin_lock_irqsave(&ts_release.wait.lock, flags); | ||
43 | list_for_each(pos, &ts_release.wait.task_list) { | ||
44 | task_count++; | ||
45 | } | ||
46 | spin_unlock_irqrestore(&ts_release.wait.lock, flags); | ||
47 | |||
48 | return task_count; | ||
49 | } | ||
50 | |||
51 | static long do_release_ts(lt_t start) | ||
52 | { | ||
53 | int task_count = 0; | ||
54 | unsigned long flags; | ||
55 | struct list_head *pos; | ||
56 | struct task_struct *t; | ||
57 | |||
58 | |||
59 | spin_lock_irqsave(&ts_release.wait.lock, flags); | ||
60 | TRACE("<<<<<< synchronous task system release >>>>>>\n"); | ||
61 | |||
62 | sched_trace_sys_release(&start); | ||
63 | list_for_each(pos, &ts_release.wait.task_list) { | ||
64 | t = (struct task_struct*) list_entry(pos, | ||
65 | struct __wait_queue, | ||
66 | task_list)->private; | ||
67 | task_count++; | ||
68 | litmus->release_at(t, start + t->rt_param.task_params.phase); | ||
69 | sched_trace_task_release(t); | ||
70 | } | ||
71 | |||
72 | spin_unlock_irqrestore(&ts_release.wait.lock, flags); | ||
73 | |||
74 | complete_n(&ts_release, task_count); | ||
75 | |||
76 | return task_count; | ||
77 | } | ||
78 | |||
79 | |||
80 | asmlinkage long sys_wait_for_ts_release(void) | ||
81 | { | ||
82 | long ret = -EPERM; | ||
83 | struct task_struct *t = current; | ||
84 | |||
85 | if (is_realtime(t)) | ||
86 | ret = do_wait_for_ts_release(); | ||
87 | |||
88 | return ret; | ||
89 | } | ||
90 | |||
91 | |||
92 | asmlinkage long sys_release_ts(lt_t __user *__delay) | ||
93 | { | ||
94 | long ret; | ||
95 | lt_t delay; | ||
96 | |||
97 | /* FIXME: check capabilities... */ | ||
98 | |||
99 | ret = copy_from_user(&delay, __delay, sizeof(delay)); | ||
100 | if (ret == 0) | ||
101 | ret = do_release_ts(litmus_clock() + delay); | ||
102 | |||
103 | return ret; | ||
104 | } | ||