diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-02-12 15:51:00 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-02-12 15:51:00 -0500 |
commit | 2c1f329215e57a6f070cab21236b132b22ef80c2 (patch) | |
tree | c881e0f22793b2ccde306a17a5755f647d42c9ee /src | |
parent | 0530e4fae13d049315f19d6fda4327d6428fd58f (diff) |
first changes to compile with LITMUS 20082008.0
Diffstat (limited to 'src')
-rw-r--r-- | src/syscalls.c | 10 | ||||
-rw-r--r-- | src/task.c | 43 |
2 files changed, 40 insertions, 13 deletions
diff --git a/src/syscalls.c b/src/syscalls.c index 40f5f7f..1ad709b 100644 --- a/src/syscalls.c +++ b/src/syscalls.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* To get syscall() we need to define _GNU_SOURCE | 1 | /* To get syscall() we need to define _GNU_SOURCE |
2 | * in modern glibc versions. | 2 | * in modern glibc versions. |
3 | */ | 3 | */ |
4 | #define _GNU_SOURCE | 4 | #define _GNU_SOURCE |
@@ -87,8 +87,12 @@ int wait_for_job_release(unsigned int job_no) | |||
87 | return syscall(__NR_wait_for_job_release, job_no); | 87 | return syscall(__NR_wait_for_job_release, job_no); |
88 | } | 88 | } |
89 | 89 | ||
90 | int task_mode(int target_mode) | 90 | int sched_setscheduler(pid_t pid, int policy, int* priority) |
91 | { | 91 | { |
92 | return syscall(__NR_task_mode, target_mode); | 92 | return syscall(__NR_sched_setscheduler, pid, policy, priority); |
93 | } | 93 | } |
94 | 94 | ||
95 | int sched_getscheduler(pid_t pid) | ||
96 | { | ||
97 | return syscall(__NR_sched_getscheduler, pid); | ||
98 | } | ||
@@ -1,30 +1,31 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <unistd.h> | 3 | #include <unistd.h> |
4 | #include <errno.h> | ||
4 | 5 | ||
5 | #include "litmus.h" | 6 | #include "litmus.h" |
6 | #include "internal.h" | 7 | #include "internal.h" |
7 | 8 | ||
8 | static void tperrorx(char* msg) | 9 | static void tperrorx(char* msg) |
9 | { | 10 | { |
10 | fprintf(stderr, | 11 | fprintf(stderr, |
11 | "Task %d: %s: %m", | 12 | "Task %d: %s: %m", |
12 | getpid(), msg); | 13 | gettid(), msg); |
13 | exit(-1); | 14 | exit(-1); |
14 | } | 15 | } |
15 | 16 | ||
16 | /* common launch routine */ | 17 | /* common launch routine */ |
17 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, | 18 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, |
18 | void* setup_arg) | 19 | void* setup_arg) |
19 | { | 20 | { |
20 | int ret; | 21 | int ret; |
21 | int rt_task = fork(); | 22 | int rt_task = fork(); |
22 | 23 | ||
23 | if (rt_task == 0) { | 24 | if (rt_task == 0) { |
24 | /* we are the real-time task | 25 | /* we are the real-time task |
25 | * launch task and die when it is done | 26 | * launch task and die when it is done |
26 | */ | 27 | */ |
27 | rt_task = getpid(); | 28 | rt_task = gettid(); |
28 | ret = setup(rt_task, setup_arg); | 29 | ret = setup(rt_task, setup_arg); |
29 | if (ret < 0) | 30 | if (ret < 0) |
30 | tperrorx("could not setup task parameters"); | 31 | tperrorx("could not setup task parameters"); |
@@ -38,14 +39,14 @@ int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, | |||
38 | } | 39 | } |
39 | 40 | ||
40 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period, | 41 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period, |
41 | task_class_t class) | 42 | task_class_t class) |
42 | { | 43 | { |
43 | struct rt_task params; | 44 | struct rt_task params; |
44 | params.cpu = cpu; | 45 | params.cpu = cpu; |
45 | params.period = period; | 46 | params.period = period; |
46 | params.exec_cost = wcet; | 47 | params.exec_cost = wcet; |
47 | params.cls = class; | 48 | params.cls = class; |
48 | return __launch_rt_task(rt_prog, arg, | 49 | return __launch_rt_task(rt_prog, arg, |
49 | (rt_setup_fn_t) set_rt_task_param, ¶ms); | 50 | (rt_setup_fn_t) set_rt_task_param, ¶ms); |
50 | } | 51 | } |
51 | 52 | ||
@@ -53,3 +54,25 @@ int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period) { | |||
53 | return __create_rt_task(rt_prog, arg, cpu, wcet, period, RT_CLASS_HARD); | 54 | return __create_rt_task(rt_prog, arg, cpu, wcet, period, RT_CLASS_HARD); |
54 | } | 55 | } |
55 | 56 | ||
57 | |||
58 | #define SCHED_NORMAL 0 | ||
59 | #define SCHED_LITMUS 6 | ||
60 | |||
61 | int task_mode(int mode) | ||
62 | { | ||
63 | int prio = 0; | ||
64 | int me = gettid(); | ||
65 | int policy = sched_getscheduler(gettid()); | ||
66 | int old_mode = policy == SCHED_LITMUS ? LITMUS_RT_TASK : BACKGROUND_TASK; | ||
67 | |||
68 | if (old_mode == LITMUS_RT_TASK && mode == BACKGROUND_TASK) { | ||
69 | /* transition to normal task */ | ||
70 | return sched_setscheduler(me, SCHED_NORMAL, &prio); | ||
71 | } else if (old_mode == BACKGROUND_TASK && mode == LITMUS_RT_TASK) { | ||
72 | /* transition to RT task */ | ||
73 | return sched_setscheduler(me, SCHED_LITMUS, &prio); | ||
74 | } else { | ||
75 | errno = -EINVAL; | ||
76 | return -1; | ||
77 | } | ||
78 | } | ||