aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-01-23 11:16:40 -0500
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-01-23 11:16:40 -0500
commitd56b86e42b72abb68ba74bf540ddc259f6b20f84 (patch)
treea9d78e760bcf4254d883c6242d384f9d1261098f
parent23701920e39a903883f19c2749383bba2a746405 (diff)
reorganize liblitmus to be more modular
-rw-r--r--Makefile10
-rw-r--r--include/internal.h21
-rw-r--r--include/litmus.h16
-rw-r--r--include/syscalls.h38
-rw-r--r--src/adaptive.c3
-rw-r--r--src/kernel_iface.c61
-rw-r--r--src/litmus.c230
-rw-r--r--src/syscalls.c62
-rw-r--r--src/task.c72
9 files changed, 280 insertions, 233 deletions
diff --git a/Makefile b/Makefile
index ac463f3..5144f52 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,10 @@ CPPFLAGS=-Wall -g
3 3
4LIBS= ./liblitmus.a 4LIBS= ./liblitmus.a
5 5
6TARGETS = showsched iotest set_rt_mode run timeout rt_launch edfhsb liblitmus.a wait_test np_test stdump mode_test 6LIB_OBJ= litmus.o syscalls.o sched_trace.o adaptive.o edf-hsb.o task.o kernel_iface.o
7
8TARGETS = showsched iotest set_rt_mode run timeout rt_launch edfhsb liblitmus.a \
9 wait_test np_test stdump mode_test
7 10
8vpath %.h include/ 11vpath %.h include/
9vpath %.c src/ 12vpath %.c src/
@@ -45,5 +48,6 @@ edfhsb: liblitmus.a edf-hsb.o litmus.h edf-hsb.h hrt.o
45stdump: liblitmus.a litmus.h sched_trace.h stdump.o 48stdump: liblitmus.a litmus.h sched_trace.h stdump.o
46 cc -o stdump stdump.o ${LIBS} 49 cc -o stdump stdump.o ${LIBS}
47 50
48liblitmus.a: litmus.o sched_trace.o adaptive.o adaptive.h litmus.h edf-hsb.o edf-hsb.h 51liblitmus.a: ${LIB_OBJ} adaptive.h litmus.h edf-hsb.h
49 ${AR} rcs liblitmus.a litmus.o adaptive.o edf-hsb.o sched_trace.o 52 ${AR} rcs liblitmus.a ${LIB_OBJ}
53
diff --git a/include/internal.h b/include/internal.h
new file mode 100644
index 0000000..25e1573
--- /dev/null
+++ b/include/internal.h
@@ -0,0 +1,21 @@
1#ifndef INTERNAL_H
2#define INTERNAL_H
3
4/* low level operations, not intended for API use */
5
6/* prepare a real-time task */
7typedef int (*rt_setup_fn_t)(int pid, void* arg);
8int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg,
9 rt_setup_fn_t setup, void* setup_arg);
10
11#define check(str) \
12 if (ret == -1) { \
13 perror(str); \
14 fprintf(stderr, \
15 "Warning: Could not initialize LITMUS^RT, " \
16 "%s failed.\n", str \
17 ); \
18 }
19
20
21#endif
diff --git a/include/litmus.h b/include/litmus.h
index 925cb44..ff21963 100644
--- a/include/litmus.h
+++ b/include/litmus.h
@@ -126,12 +126,8 @@ int reg_ics_cb(struct ics_cb* ics_cb);
126int start_wcs(int od); 126int start_wcs(int od);
127 127
128/* library functions */ 128/* library functions */
129void init_litmus(void); 129int init_litmus(void);
130/* exit is currently unused, but was needed for syscall 130void exit_litmus(void);
131 * tracing and may be needed in the future. Leave it in
132 * for the purpose of source code compatability.
133 */
134#define exit_litmus() {}
135 131
136int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period); 132int create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, int period);
137int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet, 133int __create_rt_task(rt_fn_t rt_prog, void *arg, int cpu, int wcet,
@@ -157,12 +153,4 @@ void exit_np(void);
157 */ 153 */
158int litmus_task_active(); 154int litmus_task_active();
159 155
160
161/* low level operations, not intended for API use */
162
163/* prepare a real-time task */
164typedef int (*rt_setup_fn_t)(int pid, void* arg);
165int __launch_rt_task(rt_fn_t rt_prog, void *rt_arg,
166 rt_setup_fn_t setup, void* setup_arg);
167
168#endif 156#endif
diff --git a/include/syscalls.h b/include/syscalls.h
new file mode 100644
index 0000000..28f1a39
--- /dev/null
+++ b/include/syscalls.h
@@ -0,0 +1,38 @@
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) \
7type name(void) \
8{\
9 return syscall(__NR_##name);\
10}
11
12#define _syscall1(type,name,type1,arg1) \
13type name(type1 arg1) \
14{\
15 return syscall(__NR_##name, arg1);\
16}
17
18
19#define _syscall2(type,name,type1,arg1,type2,arg2) \
20type 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) \
26type 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)\
32type 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/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
6struct 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
17int register_np_flag(struct np_flag* flag);
18int signal_exit_np(void);
19
20
21
22static struct np_flag np_flag;
23
24
25int 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
35static inline void barrier(void)
36{
37 __asm__ __volatile__("sfence": : :"memory");
38}
39
40void 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
51void 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"