diff options
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | bin/base_mt_task.c | 5 | ||||
-rw-r--r-- | include/litmus.h | 36 | ||||
-rw-r--r-- | include/syscalls.h | 38 | ||||
-rw-r--r-- | src/litmus.c | 8 | ||||
-rw-r--r-- | src/syscalls.c | 126 | ||||
-rw-r--r-- | src/task.c | 25 |
7 files changed, 100 insertions, 145 deletions
@@ -1,4 +1,8 @@ | |||
1 | CFLAGS=-Wall -Wdeclaration-after-statement -g -Iinclude/ -D_XOPEN_SOURCE=600 | 1 | KERNEL_DIR = ../litmus |
2 | |||
3 | INC=-Iinclude/ -I${KERNEL_DIR}/include/ | ||
4 | |||
5 | CFLAGS=-Wall -Wdeclaration-after-statement ${INC} -g -D_XOPEN_SOURCE=600 | ||
2 | CPPFLAGS=-Wall -g | 6 | CPPFLAGS=-Wall -g |
3 | 7 | ||
4 | LIBS= ./liblitmus.a | 8 | LIBS= ./liblitmus.a |
@@ -41,4 +45,3 @@ stdump: liblitmus.a litmus.h sched_trace.h stdump.o | |||
41 | 45 | ||
42 | liblitmus.a: ${LIB_OBJ} litmus.h | 46 | liblitmus.a: ${LIB_OBJ} litmus.h |
43 | ${AR} rcs liblitmus.a ${LIB_OBJ} | 47 | ${AR} rcs liblitmus.a ${LIB_OBJ} |
44 | |||
diff --git a/bin/base_mt_task.c b/bin/base_mt_task.c index 24f2070..a1e3731 100644 --- a/bin/base_mt_task.c +++ b/bin/base_mt_task.c | |||
@@ -121,7 +121,6 @@ int main(int argc, char** argv) | |||
121 | void* rt_thread(struct thread_context* ctx) | 121 | void* rt_thread(struct thread_context* ctx) |
122 | { | 122 | { |
123 | int do_exit; | 123 | int do_exit; |
124 | rt_param_t param; | ||
125 | 124 | ||
126 | /* Make presence visible. */ | 125 | /* Make presence visible. */ |
127 | printf("RT Thread %d active.\n", ctx->id); | 126 | printf("RT Thread %d active.\n", ctx->id); |
@@ -132,10 +131,6 @@ void* rt_thread(struct thread_context* ctx) | |||
132 | CALL( init_rt_thread() ); | 131 | CALL( init_rt_thread() ); |
133 | CALL( sporadic_global(EXEC_COST, PERIOD) ); | 132 | CALL( sporadic_global(EXEC_COST, PERIOD) ); |
134 | 133 | ||
135 | /* Just for fun display the real-time parameters of this thread. */ | ||
136 | CALL( get_rt_task_param(gettid(), ¶m) ); | ||
137 | show_rt_param(¶m); | ||
138 | |||
139 | /***** | 134 | /***** |
140 | * 2) Transition to real-time mode. | 135 | * 2) Transition to real-time mode. |
141 | */ | 136 | */ |
diff --git a/include/litmus.h b/include/litmus.h index 8918ae9..cf39f80 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
@@ -1,41 +1,16 @@ | |||
1 | #ifndef LITMUS_H | 1 | #ifndef LITMUS_H |
2 | #define LITMUS_H | 2 | #define LITMUS_H |
3 | 3 | ||
4 | #include <linux/rt_param.h> | ||
4 | #include <sys/types.h> | 5 | #include <sys/types.h> |
5 | 6 | ||
6 | /* A real-time program. */ | ||
7 | typedef int (*rt_fn_t)(void*); | ||
8 | |||
9 | /* different types of clients */ | ||
10 | typedef enum { | ||
11 | RT_CLASS_HARD, | ||
12 | RT_CLASS_SOFT, | ||
13 | RT_CLASS_BEST_EFFORT | ||
14 | } task_class_t; | ||
15 | |||
16 | /* Task RT params for schedulers */ | ||
17 | /* RT task parameters for scheduling extensions | ||
18 | * These parameters are inherited during clone and therefore must | ||
19 | * be explicitly set up before the task set is launched. | ||
20 | */ | ||
21 | typedef struct rt_param { | ||
22 | /* Execution cost */ | ||
23 | unsigned long exec_cost; | ||
24 | /* Period */ | ||
25 | unsigned long period; | ||
26 | /* Partition */ | ||
27 | unsigned int cpu; | ||
28 | /* type of task */ | ||
29 | task_class_t cls; | ||
30 | } rt_param_t; | ||
31 | |||
32 | typedef int pid_t; /* PID of a task */ | 7 | typedef int pid_t; /* PID of a task */ |
33 | 8 | ||
34 | /* obtain the PID of a thread */ | 9 | /* obtain the PID of a thread */ |
35 | pid_t gettid(void); | 10 | pid_t gettid(void); |
36 | 11 | ||
37 | int set_rt_task_param(pid_t pid, rt_param_t* param); | 12 | int set_rt_task_param(pid_t pid, struct rt_task* param); |
38 | int get_rt_task_param(pid_t pid, rt_param_t* param); | 13 | int get_rt_task_param(pid_t pid, struct rt_task* param); |
39 | 14 | ||
40 | /* setup helper */ | 15 | /* setup helper */ |
41 | int sporadic_task(unsigned long exec_cost, unsigned long period, | 16 | int sporadic_task(unsigned long exec_cost, unsigned long period, |
@@ -77,6 +52,9 @@ int init_litmus(void); | |||
77 | int init_rt_thread(void); | 52 | int init_rt_thread(void); |
78 | void exit_litmus(void); | 53 | void exit_litmus(void); |
79 | 54 | ||
55 | /* A real-time program. */ | ||
56 | typedef int (*rt_fn_t)(void*); | ||
57 | |||
80 | int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period); | 58 | int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period); |
81 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, | 59 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, |
82 | int period, task_class_t cls); | 60 | int period, task_class_t cls); |
@@ -88,7 +66,7 @@ enum rt_task_mode_t { | |||
88 | }; | 66 | }; |
89 | int task_mode(int target_mode); | 67 | int task_mode(int target_mode); |
90 | 68 | ||
91 | void show_rt_param(rt_param_t* tp); | 69 | void show_rt_param(struct rt_task* tp); |
92 | task_class_t str2class(const char* str); | 70 | task_class_t str2class(const char* str); |
93 | 71 | ||
94 | /* non-preemptive section support */ | 72 | /* non-preemptive section support */ |
diff --git a/include/syscalls.h b/include/syscalls.h deleted file mode 100644 index 28f1a39..0000000 --- a/include/syscalls.h +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | #ifndef SYSCALLS_H | ||
2 | #define SYSCALLS_H | ||
3 | |||
4 | /* this is missing in newer linux/unistd.h versions */ | ||
5 | |||
6 | #define _syscall0(type,name) \ | ||
7 | type name(void) \ | ||
8 | {\ | ||
9 | return syscall(__NR_##name);\ | ||
10 | } | ||
11 | |||
12 | #define _syscall1(type,name,type1,arg1) \ | ||
13 | type name(type1 arg1) \ | ||
14 | {\ | ||
15 | return syscall(__NR_##name, arg1);\ | ||
16 | } | ||
17 | |||
18 | |||
19 | #define _syscall2(type,name,type1,arg1,type2,arg2) \ | ||
20 | type name(type1 arg1,type2 arg2) \ | ||
21 | {\ | ||
22 | return syscall(__NR_##name, arg1, arg2);\ | ||
23 | } | ||
24 | |||
25 | #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ | ||
26 | type name(type1 arg1,type2 arg2, type3 arg3) \ | ||
27 | {\ | ||
28 | return syscall(__NR_##name, arg1, arg2, arg3); \ | ||
29 | } | ||
30 | |||
31 | #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ | ||
32 | type name(type1 arg1,type2 arg2, type3 arg3, type4 arg4) \ | ||
33 | {\ | ||
34 | return syscall(__NR_##name, arg1, arg2, arg3, arg4); \ | ||
35 | } | ||
36 | |||
37 | |||
38 | #endif | ||
diff --git a/src/litmus.c b/src/litmus.c index 8f5dfe8..6503088 100644 --- a/src/litmus.c +++ b/src/litmus.c | |||
@@ -8,10 +8,10 @@ | |||
8 | #include "litmus.h" | 8 | #include "litmus.h" |
9 | #include "internal.h" | 9 | #include "internal.h" |
10 | 10 | ||
11 | void show_rt_param(rt_param_t* tp) | 11 | void show_rt_param(struct rt_task* tp) |
12 | { | 12 | { |
13 | printf("rt params:\n\t" | 13 | printf("rt params:\n\t" |
14 | "exec_cost:\t%ld\n\tperiod:\t\t%ld\n\tcpu:\t%d\n", | 14 | "exec_cost:\t%llu\n\tperiod:\t\t%llu\n\tcpu:\t%d\n", |
15 | tp->exec_cost, tp->period, tp->cpu); | 15 | tp->exec_cost, tp->period, tp->cpu); |
16 | } | 16 | } |
17 | 17 | ||
@@ -30,11 +30,11 @@ task_class_t str2class(const char* str) | |||
30 | int sporadic_task(unsigned long e, unsigned long p, | 30 | int sporadic_task(unsigned long e, unsigned long p, |
31 | int cpu, task_class_t cls) | 31 | int cpu, task_class_t cls) |
32 | { | 32 | { |
33 | rt_param_t param; | 33 | struct rt_task param; |
34 | param.exec_cost = e; | 34 | param.exec_cost = e; |
35 | param.period = p; | 35 | param.period = p; |
36 | param.cpu = cpu; | 36 | param.cpu = cpu; |
37 | param.cls = cls; | 37 | param.cls = cls; |
38 | return set_rt_task_param(gettid(), ¶m); | 38 | return set_rt_task_param(gettid(), ¶m); |
39 | } | 39 | } |
40 | 40 | ||
diff --git a/src/syscalls.c b/src/syscalls.c index 0924818..40f5f7f 100644 --- a/src/syscalls.c +++ b/src/syscalls.c | |||
@@ -8,53 +8,87 @@ | |||
8 | 8 | ||
9 | #include "litmus.h" | 9 | #include "litmus.h" |
10 | 10 | ||
11 | #include "syscalls.h" | ||
12 | |||
13 | struct np_flag; | 11 | struct np_flag; |
14 | 12 | ||
15 | /* Litmus syscalls definitions */ | ||
16 | #define __NR_sched_setpolicy 320 | ||
17 | #define __NR_sched_getpolicy 321 | ||
18 | #define __NR_set_rt_mode 322 | ||
19 | #define __NR_set_rt_task_param 323 | ||
20 | #define __NR_get_rt_task_param 324 | ||
21 | #define __NR_sleep_next_period 326 | ||
22 | #define __NR_scheduler_setup 327 | ||
23 | #define __NR_register_np_flag 328 | ||
24 | #define __NR_signal_exit_np 329 | ||
25 | #define __NR_od_openx 330 | ||
26 | #define __NR_od_close 331 | ||
27 | #define __NR_pi_down 332 | ||
28 | #define __NR_pi_up 333 | ||
29 | #define __NR_srp_down 334 | ||
30 | #define __NR_srp_up 335 | ||
31 | #define __NR_reg_task_srp_sem 336 | ||
32 | #define __NR_get_job_no 337 | ||
33 | #define __NR_wait_for_job_release 338 | ||
34 | #define __NR_set_service_levels 339 | ||
35 | #define __NR_get_cur_service_level 340 | ||
36 | #define __NR_reg_ics_cb 341 | ||
37 | #define __NR_start_wcs 342 | ||
38 | #define __NR_task_mode 343 | ||
39 | |||
40 | /* Syscall stub for setting RT mode and scheduling options */ | 13 | /* Syscall stub for setting RT mode and scheduling options */ |
41 | 14 | ||
42 | _syscall0(pid_t, gettid); | 15 | pid_t gettid(void) |
43 | 16 | { | |
44 | _syscall2(int, set_rt_task_param, pid_t, pid, rt_param_t*, arg1); | 17 | return syscall(__NR_gettid); |
45 | _syscall2(int, get_rt_task_param, pid_t, pid, rt_param_t*, arg1); | 18 | } |
46 | _syscall0(int, sleep_next_period); | 19 | |
47 | _syscall1(int, register_np_flag, struct np_flag*, flag); | 20 | int set_rt_task_param(pid_t pid, struct rt_task *param) |
48 | _syscall0(int, signal_exit_np); | 21 | { |
49 | 22 | return syscall(__NR_set_rt_task_param, pid, param); | |
50 | _syscall4(int, od_openx, int, fd, obj_type_t, type, int, obj_id, | 23 | } |
51 | void*, config); | 24 | |
52 | _syscall1(int, od_close, int, od); | 25 | int get_rt_task_param(pid_t pid, struct rt_task *param) |
53 | _syscall1(int, pi_down, int, od); | 26 | { |
54 | _syscall1(int, pi_up, int, od); | 27 | return syscall(__NR_get_rt_task_param, pid, param); |
55 | _syscall1(int, srp_down, int, od); | 28 | } |
56 | _syscall1(int, srp_up, int, od); | 29 | |
57 | _syscall1(int, reg_task_srp_sem, int, od); | 30 | int sleep_next_period(void) |
58 | _syscall1(int, get_job_no, unsigned int*, job_no); | 31 | { |
59 | _syscall1(int, wait_for_job_release, unsigned int, job_no); | 32 | return syscall(__NR_sleep_next_period); |
60 | _syscall1(int, task_mode, int, target_mode); | 33 | } |
34 | |||
35 | int register_np_flag(struct np_flag *flag) | ||
36 | { | ||
37 | return syscall(__NR_register_np_flag, flag); | ||
38 | } | ||
39 | |||
40 | int signal_exit_np(void) | ||
41 | { | ||
42 | return syscall(__NR_exit_np); | ||
43 | } | ||
44 | |||
45 | int od_openx(int fd, obj_type_t type, int obj_id, void *config) | ||
46 | { | ||
47 | return syscall(__NR_od_open, fd, type, obj_id, config); | ||
48 | } | ||
49 | |||
50 | int od_close(int od) | ||
51 | { | ||
52 | return syscall(__NR_od_close, od); | ||
53 | } | ||
54 | |||
55 | int pi_down(int od) | ||
56 | { | ||
57 | return syscall(__NR_pi_down, od); | ||
58 | } | ||
59 | |||
60 | int pi_up(int od) | ||
61 | { | ||
62 | return syscall(__NR_pi_up, od); | ||
63 | } | ||
64 | |||
65 | int srp_down(int od) | ||
66 | { | ||
67 | return syscall(__NR_srp_down, od); | ||
68 | } | ||
69 | |||
70 | int srp_up(int od) | ||
71 | { | ||
72 | return syscall(__NR_srp_up, od); | ||
73 | } | ||
74 | |||
75 | int reg_task_srp_sem(int od) | ||
76 | { | ||
77 | return syscall(__NR_reg_task_srp_sem, od); | ||
78 | } | ||
79 | |||
80 | int get_job_no(unsigned int *job_no) | ||
81 | { | ||
82 | return syscall(__NR_query_job_no, job_no); | ||
83 | } | ||
84 | |||
85 | int wait_for_job_release(unsigned int job_no) | ||
86 | { | ||
87 | return syscall(__NR_wait_for_job_release, job_no); | ||
88 | } | ||
89 | |||
90 | int task_mode(int target_mode) | ||
91 | { | ||
92 | return syscall(__NR_task_mode, target_mode); | ||
93 | } | ||
94 | |||
@@ -37,33 +37,16 @@ int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, | |||
37 | return rt_task; | 37 | return rt_task; |
38 | } | 38 | } |
39 | 39 | ||
40 | struct create_rt_param { | ||
41 | int cpu; | ||
42 | int wcet; | ||
43 | int period; | ||
44 | task_class_t class; | ||
45 | }; | ||
46 | |||
47 | int setup_create_rt(int pid, struct create_rt_param* arg) | ||
48 | { | ||
49 | rt_param_t params; | ||
50 | params.period = arg->period; | ||
51 | params.exec_cost = arg->wcet; | ||
52 | params.cpu = arg->cpu; | ||
53 | params.cls = arg->class; | ||
54 | return set_rt_task_param(pid, ¶ms); | ||
55 | } | ||
56 | |||
57 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period, | 40 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period, |
58 | task_class_t class) | 41 | task_class_t class) |
59 | { | 42 | { |
60 | struct create_rt_param params; | 43 | struct rt_task params; |
61 | params.cpu = cpu; | 44 | params.cpu = cpu; |
62 | params.period = period; | 45 | params.period = period; |
63 | params.wcet = wcet; | 46 | params.exec_cost = wcet; |
64 | params.class = class; | 47 | params.cls = class; |
65 | return __launch_rt_task(rt_prog, arg, | 48 | return __launch_rt_task(rt_prog, arg, |
66 | (rt_setup_fn_t) setup_create_rt, ¶ms); | 49 | (rt_setup_fn_t) set_rt_task_param, ¶ms); |
67 | } | 50 | } |
68 | 51 | ||
69 | int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period) { | 52 | int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period) { |