diff options
author | Ming Yang <yang@cs.unc.edu> | 2016-02-11 20:31:16 -0500 |
---|---|---|
committer | Ming Yang <yang@cs.unc.edu> | 2016-02-11 20:31:16 -0500 |
commit | 28cef80c0b9da0184ef736ae131b6146c5976422 (patch) | |
tree | ddaa898f1786850dbd3d759a032903f5a7a35ae0 /litmus/mc2_common.c | |
parent | 696546dd52d9baf73920a61e6525a41f3460ba4d (diff) |
Manually patched mc^2 related codewip-mc2-cache-slack
Diffstat (limited to 'litmus/mc2_common.c')
-rw-r--r-- | litmus/mc2_common.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/litmus/mc2_common.c b/litmus/mc2_common.c new file mode 100644 index 000000000000..a8ea5d9889f3 --- /dev/null +++ b/litmus/mc2_common.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | * litmus/mc2_common.c | ||
3 | * | ||
4 | * Common functions for MC2 plugin. | ||
5 | */ | ||
6 | |||
7 | #include <linux/percpu.h> | ||
8 | #include <linux/sched.h> | ||
9 | #include <linux/list.h> | ||
10 | #include <linux/slab.h> | ||
11 | #include <asm/uaccess.h> | ||
12 | |||
13 | #include <litmus/litmus.h> | ||
14 | #include <litmus/sched_plugin.h> | ||
15 | #include <litmus/sched_trace.h> | ||
16 | |||
17 | #include <litmus/mc2_common.h> | ||
18 | |||
19 | long mc2_task_client_init(struct task_client *tc, struct mc2_task *mc2_param, struct task_struct *tsk, struct reservation *res) | ||
20 | { | ||
21 | task_client_init(tc, tsk, res); | ||
22 | if ((mc2_param->crit < CRIT_LEVEL_A) || | ||
23 | (mc2_param->crit > CRIT_LEVEL_C)) | ||
24 | return -EINVAL; | ||
25 | |||
26 | TRACE_TASK(tsk, "mc2_task_client_init: crit_level = %d\n", mc2_param->crit); | ||
27 | |||
28 | return 0; | ||
29 | } | ||
30 | |||
31 | asmlinkage long sys_set_mc2_task_param(pid_t pid, struct mc2_task __user * param) | ||
32 | { | ||
33 | struct task_struct *target; | ||
34 | int retval = -EINVAL; | ||
35 | struct mc2_task *mp = kzalloc(sizeof(*mp), GFP_KERNEL); | ||
36 | |||
37 | if (!mp) | ||
38 | return -ENOMEM; | ||
39 | |||
40 | printk("Setting up mc^2 task parameters for process %d.\n", pid); | ||
41 | |||
42 | if (pid < 0 || param == 0) { | ||
43 | goto out; | ||
44 | } | ||
45 | if (copy_from_user(mp, param, sizeof(*mp))) { | ||
46 | retval = -EFAULT; | ||
47 | goto out; | ||
48 | } | ||
49 | |||
50 | /* Task search and manipulation must be protected */ | ||
51 | read_lock_irq(&tasklist_lock); | ||
52 | if (!(target = find_task_by_vpid(pid))) { | ||
53 | retval = -ESRCH; | ||
54 | goto out_unlock; | ||
55 | } | ||
56 | |||
57 | if (is_realtime(target)) { | ||
58 | /* The task is already a real-time task. | ||
59 | * We cannot not allow parameter changes at this point. | ||
60 | */ | ||
61 | retval = -EBUSY; | ||
62 | goto out_unlock; | ||
63 | } | ||
64 | if (mp->crit < CRIT_LEVEL_A || mp->crit >= NUM_CRIT_LEVELS) { | ||
65 | printk(KERN_INFO "litmus: real-time task %d rejected " | ||
66 | "because of invalid criticality level\n", pid); | ||
67 | goto out_unlock; | ||
68 | } | ||
69 | |||
70 | //target->rt_param.plugin_state = mp; | ||
71 | target->rt_param.mc2_data = mp; | ||
72 | |||
73 | retval = 0; | ||
74 | out_unlock: | ||
75 | read_unlock_irq(&tasklist_lock); | ||
76 | out: | ||
77 | return retval; | ||
78 | } \ No newline at end of file | ||