diff options
| author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-23 11:16:40 -0500 |
|---|---|---|
| committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-01-23 11:16:40 -0500 |
| commit | d56b86e42b72abb68ba74bf540ddc259f6b20f84 (patch) | |
| tree | a9d78e760bcf4254d883c6242d384f9d1261098f /src | |
| parent | 23701920e39a903883f19c2749383bba2a746405 (diff) | |
reorganize liblitmus to be more modular
Diffstat (limited to 'src')
| -rw-r--r-- | src/adaptive.c | 3 | ||||
| -rw-r--r-- | src/kernel_iface.c | 61 | ||||
| -rw-r--r-- | src/litmus.c | 230 | ||||
| -rw-r--r-- | src/syscalls.c | 62 | ||||
| -rw-r--r-- | src/task.c | 72 |
5 files changed, 212 insertions, 216 deletions
diff --git a/src/adaptive.c b/src/adaptive.c index ebf662d..6a7d7a2 100644 --- a/src/adaptive.c +++ b/src/adaptive.c | |||
| @@ -2,6 +2,9 @@ | |||
| 2 | #include <unistd.h> | 2 | #include <unistd.h> |
| 3 | 3 | ||
| 4 | #include "litmus.h" | 4 | #include "litmus.h" |
| 5 | #include "internal.h" | ||
| 6 | #include "syscalls.h" | ||
| 7 | |||
| 5 | #include "adaptive.h" | 8 | #include "adaptive.h" |
| 6 | 9 | ||
| 7 | #define __NR_set_service_levels 346 | 10 | #define __NR_set_service_levels 346 |
diff --git a/src/kernel_iface.c b/src/kernel_iface.c new file mode 100644 index 0000000..5751ca6 --- /dev/null +++ b/src/kernel_iface.c | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | |||
| 3 | #include "litmus.h" | ||
| 4 | #include "internal.h" | ||
| 5 | |||
| 6 | struct np_flag { | ||
| 7 | #define RT_PREEMPTIVE 0x2050 /* = NP */ | ||
| 8 | #define RT_NON_PREEMPTIVE 0x4e50 /* = P */ | ||
| 9 | unsigned short preemptivity; | ||
| 10 | |||
| 11 | #define RT_EXIT_NP_REQUESTED 0x5251 /* = RQ */ | ||
| 12 | unsigned short request; | ||
| 13 | |||
| 14 | unsigned int ctr; | ||
| 15 | }; | ||
| 16 | |||
| 17 | int register_np_flag(struct np_flag* flag); | ||
| 18 | int signal_exit_np(void); | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | static struct np_flag np_flag; | ||
| 23 | |||
| 24 | |||
| 25 | int init_kernel_iface(void) | ||
| 26 | { | ||
| 27 | int ret; | ||
| 28 | np_flag.preemptivity = RT_PREEMPTIVE; | ||
| 29 | np_flag.ctr = 0; | ||
| 30 | ret = register_np_flag(&np_flag); | ||
| 31 | check("register_np_flag()"); | ||
| 32 | return ret; | ||
| 33 | } | ||
| 34 | |||
| 35 | static inline void barrier(void) | ||
| 36 | { | ||
| 37 | __asm__ __volatile__("sfence": : :"memory"); | ||
| 38 | } | ||
| 39 | |||
| 40 | void enter_np(void) | ||
| 41 | { | ||
| 42 | if (++np_flag.ctr == 1) | ||
| 43 | { | ||
| 44 | np_flag.request = 0; | ||
| 45 | barrier(); | ||
| 46 | np_flag.preemptivity = RT_NON_PREEMPTIVE; | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | void exit_np(void) | ||
| 52 | { | ||
| 53 | if (--np_flag.ctr == 0) | ||
| 54 | { | ||
| 55 | np_flag.preemptivity = RT_PREEMPTIVE; | ||
| 56 | barrier(); | ||
| 57 | if (np_flag.request == RT_EXIT_NP_REQUESTED) | ||
| 58 | signal_exit_np(); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
diff --git a/src/litmus.c b/src/litmus.c index 531f501..4005345 100644 --- a/src/litmus.c +++ b/src/litmus.c | |||
| @@ -1,53 +1,12 @@ | |||
| 1 | /* To get syscall() we need to define _GNU_SOURCE | ||
| 2 | * in modern glibc versions. | ||
| 3 | */ | ||
| 4 | #define _GNU_SOURCE | ||
| 5 | #include <unistd.h> | 1 | #include <unistd.h> |
| 6 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 7 | #include <stdio.h> | 3 | #include <stdio.h> |
| 8 | #include <string.h> | 4 | #include <string.h> |
| 9 | #include <sys/types.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <signal.h> | 5 | #include <signal.h> |
| 12 | #include <sys/mman.h> | 6 | #include <sys/mman.h> |
| 13 | 7 | ||
| 14 | |||
| 15 | |||
| 16 | #include "litmus.h" | 8 | #include "litmus.h" |
| 17 | 9 | #include "internal.h" | |
| 18 | |||
| 19 | /* this is missing in newer linux/unistd.h versions */ | ||
| 20 | |||
| 21 | #define _syscall0(type,name) \ | ||
| 22 | type name(void) \ | ||
| 23 | {\ | ||
| 24 | return syscall(__NR_##name);\ | ||
| 25 | } | ||
| 26 | |||
| 27 | #define _syscall1(type,name,type1,arg1) \ | ||
| 28 | type name(type1 arg1) \ | ||
| 29 | {\ | ||
| 30 | return syscall(__NR_##name, arg1);\ | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | #define _syscall2(type,name,type1,arg1,type2,arg2) \ | ||
| 35 | type name(type1 arg1,type2 arg2) \ | ||
| 36 | {\ | ||
| 37 | return syscall(__NR_##name, arg1, arg2);\ | ||
| 38 | } | ||
| 39 | |||
| 40 | #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ | ||
| 41 | type name(type1 arg1,type2 arg2, type3 arg3) \ | ||
| 42 | {\ | ||
| 43 | return syscall(__NR_##name, arg1, arg2, arg3); \ | ||
| 44 | } | ||
| 45 | |||
| 46 | #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\ | ||
| 47 | type name(type1 arg1,type2 arg2, type3 arg3, type4 arg4) \ | ||
| 48 | {\ | ||
| 49 | return syscall(__NR_##name, arg1, arg2, arg3, arg4); \ | ||
| 50 | } | ||
| 51 | 10 | ||
| 52 | const char* get_scheduler_name(spolicy scheduler) | 11 | const char* get_scheduler_name(spolicy scheduler) |
| 53 | { | 12 | { |
| @@ -85,71 +44,6 @@ const char* get_scheduler_name(spolicy scheduler) | |||
| 85 | return name; | 44 | return name; |
| 86 | } | 45 | } |
| 87 | 46 | ||
| 88 | static void tperrorx(char* msg) | ||
| 89 | { | ||
| 90 | fprintf(stderr, | ||
| 91 | "Task %d: %s: %m", | ||
| 92 | getpid(), msg); | ||
| 93 | exit(-1); | ||
| 94 | } | ||
| 95 | |||
| 96 | /* common launch routine */ | ||
| 97 | int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg, rt_setup_fn_t setup, | ||
| 98 | void* setup_arg) | ||
| 99 | { | ||
| 100 | int ret; | ||
| 101 | int rt_task = fork(); | ||
| 102 | |||
| 103 | if (rt_task == 0) { | ||
| 104 | /* we are the real-time task | ||
| 105 | * launch task and die when it is done | ||
| 106 | */ | ||
| 107 | rt_task = getpid(); | ||
| 108 | ret = setup(rt_task, setup_arg); | ||
| 109 | if (ret < 0) | ||
| 110 | tperrorx("could not setup task parameters"); | ||
| 111 | ret = task_mode(LITMUS_RT_TASK); | ||
| 112 | if (ret < 0) | ||
| 113 | tperrorx("could not become real-time task"); | ||
| 114 | exit(rt_prog(rt_arg)); | ||
| 115 | } | ||
| 116 | |||
| 117 | return rt_task; | ||
| 118 | } | ||
| 119 | |||
| 120 | struct create_rt_param { | ||
| 121 | int cpu; | ||
| 122 | int wcet; | ||
| 123 | int period; | ||
| 124 | task_class_t class; | ||
| 125 | }; | ||
| 126 | |||
| 127 | int setup_create_rt(int pid, struct create_rt_param* arg) | ||
| 128 | { | ||
| 129 | rt_param_t params; | ||
| 130 | params.period = arg->period; | ||
| 131 | params.exec_cost = arg->wcet; | ||
| 132 | params.cpu = arg->cpu; | ||
| 133 | params.cls = arg->class; | ||
| 134 | return set_rt_task_param(pid, ¶ms); | ||
| 135 | } | ||
| 136 | |||
| 137 | int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period, | ||
| 138 | task_class_t class) | ||
| 139 | { | ||
| 140 | struct create_rt_param params; | ||
| 141 | params.cpu = cpu; | ||
| 142 | params.period = period; | ||
| 143 | params.wcet = wcet; | ||
| 144 | params.class = class; | ||
| 145 | return __launch_rt_task(rt_prog, arg, | ||
| 146 | (rt_setup_fn_t) setup_create_rt, ¶ms); | ||
| 147 | } | ||
| 148 | |||
| 149 | int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period) { | ||
| 150 | return __create_rt_task(rt_prog, arg, cpu, wcet, period, RT_CLASS_HARD); | ||
| 151 | } | ||
| 152 | |||
| 153 | 47 | ||
| 154 | void show_rt_param(rt_param_t* tp) | 48 | void show_rt_param(rt_param_t* tp) |
| 155 | { | 49 | { |
| @@ -181,49 +75,6 @@ int sporadic_task(unsigned long e, unsigned long p, | |||
| 181 | return set_rt_task_param(getpid(), ¶m); | 75 | return set_rt_task_param(getpid(), ¶m); |
| 182 | } | 76 | } |
| 183 | 77 | ||
| 184 | struct np_flag { | ||
| 185 | #define RT_PREEMPTIVE 0x2050 /* = NP */ | ||
| 186 | #define RT_NON_PREEMPTIVE 0x4e50 /* = P */ | ||
| 187 | unsigned short preemptivity; | ||
| 188 | |||
| 189 | #define RT_EXIT_NP_REQUESTED 0x5251 /* = RQ */ | ||
| 190 | unsigned short request; | ||
| 191 | |||
