diff options
author | Bryan Ward <bcw@cs.unc.edu> | 2012-08-07 22:29:16 -0400 |
---|---|---|
committer | Bryan Ward <bcw@cs.unc.edu> | 2012-08-07 22:29:16 -0400 |
commit | 29d9fc49d3da6889a4e03f03578398e89f8e2a59 (patch) | |
tree | 3bea744b1ca149650341b4613b190d9c2f1a0583 | |
parent | 3b0411a23c8bb91b5bc201f7df39e6e83e2b38b6 (diff) |
Cleaned up testing script for DGLs.
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | bin/dgl_test.c | 157 | ||||
-rw-r--r-- | include/litmus.h | 10 | ||||
-rw-r--r-- | src/syscalls.c | 2 |
4 files changed, 170 insertions, 3 deletions
@@ -71,7 +71,7 @@ AR := ${CROSS_COMPILE}${AR} | |||
71 | 71 | ||
72 | all = lib ${rt-apps} | 72 | all = lib ${rt-apps} |
73 | rt-apps = cycles base_task rt_launch rtspin release_ts measure_syscall \ | 73 | rt-apps = cycles base_task rt_launch rtspin release_ts measure_syscall \ |
74 | base_mt_task runtests | 74 | base_mt_task runtests dgl_test |
75 | 75 | ||
76 | .PHONY: all lib clean dump-config TAGS tags cscope help | 76 | .PHONY: all lib clean dump-config TAGS tags cscope help |
77 | 77 | ||
@@ -203,6 +203,8 @@ obj-cycles = cycles.o | |||
203 | 203 | ||
204 | obj-base_task = base_task.o | 204 | obj-base_task = base_task.o |
205 | 205 | ||
206 | obj-dgl_test = dgl_test.o | ||
207 | |||
206 | obj-base_mt_task = base_mt_task.o | 208 | obj-base_mt_task = base_mt_task.o |
207 | ldf-base_mt_task = -pthread | 209 | ldf-base_mt_task = -pthread |
208 | 210 | ||
diff --git a/bin/dgl_test.c b/bin/dgl_test.c new file mode 100644 index 0000000..22a13ae --- /dev/null +++ b/bin/dgl_test.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* based_task.c -- A basic real-time task skeleton. | ||
2 | * | ||
3 | * This (by itself useless) task demos how to setup a | ||
4 | * single-threaded LITMUS^RT real-time task. | ||
5 | */ | ||
6 | |||
7 | /* First, we include standard headers. | ||
8 | * Generally speaking, a LITMUS^RT real-time task can perform any | ||
9 | * system call, etc., but no real-time guarantees can be made if a | ||
10 | * system call blocks. To be on the safe side, only use I/O for debugging | ||
11 | * purposes and from non-real-time sections. | ||
12 | */ | ||
13 | #include <stdio.h> | ||
14 | #include <stdlib.h> | ||
15 | #include <fcntl.h> | ||
16 | |||
17 | /* Second, we include the LITMUS^RT user space library header. | ||
18 | * This header, part of liblitmus, provides the user space API of | ||
19 | * LITMUS^RT. | ||
20 | */ | ||
21 | #include "litmus.h" | ||
22 | |||
23 | /* Next, we define period and execution cost to be constant. | ||
24 | * These are only constants for convenience in this example, they can be | ||
25 | * determined at run time, e.g., from command line parameters. | ||
26 | */ | ||
27 | #define PERIOD 100 | ||
28 | #define EXEC_COST 10 | ||
29 | |||
30 | /* Catch errors. | ||
31 | */ | ||
32 | #define CALL( exp ) do { \ | ||
33 | int ret; \ | ||
34 | ret = exp; \ | ||
35 | if (ret != 0) \ | ||
36 | fprintf(stderr, "%s failed: %m\n", #exp);\ | ||
37 | else \ | ||
38 | fprintf(stderr, "%s ok.\n", #exp); \ | ||
39 | } while (0) | ||
40 | |||
41 | |||
42 | /* Declare the periodically invoked job. | ||
43 | * Returns 1 -> task should exit. | ||
44 | * 0 -> task should continue. | ||
45 | */ | ||
46 | int job(void); | ||
47 | |||
48 | /* typically, main() does a couple of things: | ||
49 | * 1) parse command line parameters, etc. | ||
50 | * 2) Setup work environment. | ||
51 | * 3) Setup real-time parameters. | ||
52 | * 4) Transition to real-time mode. | ||
53 | * 5) Invoke periodic or sporadic jobs. | ||
54 | * 6) Transition to background mode. | ||
55 | * 7) Clean up and exit. | ||
56 | * | ||
57 | * The following main() function provides the basic skeleton of a single-threaded | ||
58 | * LITMUS^RT real-time task. In a real program, all the return values should be | ||
59 | * checked for errors. | ||
60 | */ | ||
61 | int main(int argc, char** argv) | ||
62 | { | ||
63 | //int do_exit; | ||
64 | int fd, od_org, od_new; | ||
65 | int* resource; | ||
66 | int mask; | ||
67 | |||
68 | /* The task is in background mode upon startup. */ | ||
69 | |||
70 | |||
71 | /***** | ||
72 | * 1) Command line paramter parsing would be done here. | ||
73 | */ | ||
74 | |||
75 | /***** | ||
76 | * 2) Work environment (e.g., global data structures, file data, etc.) would | ||
77 | * be setup here. | ||
78 | */ | ||
79 | |||
80 | CALL(fd = open(".dgl_locks", O_RDONLY | O_CREAT) ); | ||
81 | resource = (int*)malloc(sizeof(int)); | ||
82 | *resource = -1; | ||
83 | |||
84 | /***** | ||
85 | * 3) Setup real-time parameters. | ||
86 | * In this example, we create a sporadic task that does not specify a | ||
87 | * target partition (and thus is intended to run under global scheduling). | ||
88 | * If this were to execute under a partitioned scheduler, it would be assigned | ||
89 | * to the first partition (since partitioning is performed offline). | ||
90 | */ | ||
91 | |||
92 | CALL( init_litmus() ); | ||
93 | //CALL( sporadic_global(EXEC_COST, PERIOD) ); | ||
94 | CALL( sporadic_partitioned(EXEC_COST, PERIOD, 0) ); | ||
95 | |||
96 | /* To specify a partition, use sporadic_partitioned(). | ||
97 | * Example: | ||
98 | * | ||
99 | * sporadic_partitioned(EXEC_COST, PERIOD, CPU); | ||
100 | * | ||
101 | * where CPU ranges from 0 to "Number of CPUs" - 1. | ||
102 | */ | ||
103 | |||
104 | /***** | ||
105 | * 4) Transition to real-time mode. | ||
106 | */ | ||
107 | CALL( task_mode(LITMUS_RT_TASK) ); | ||
108 | |||
109 | /* The task is now executing as a real-time task if the call didn't fail. | ||
110 | */ | ||
111 | |||
112 | CALL(od_org = open_new_dgl_sem(fd, 0) ); | ||
113 | CALL(od_new = attach_dgl_sem(fd, 1, od_org) ); | ||
114 | |||
115 | mask = (1<<od_org) & (1<<od_new); | ||
116 | |||
117 | |||
118 | //CALL( dynamic_group_lock(0) ); | ||
119 | dynamic_group_lock(mask); | ||
120 | |||
121 | /***** | ||
122 | * 5) Invoke real-time jobs. | ||
123 | */ | ||
124 | //do { | ||
125 | // /* Wait until the next job is released. */ | ||
126 | // sleep_next_period(); | ||
127 | // /* Invoke job. */ | ||
128 | // do_exit = job(); | ||
129 | //} while (!do_exit); | ||
130 | |||
131 | //do_exit=0; | ||
132 | //do_exit++; | ||
133 | //od++; | ||
134 | |||
135 | |||
136 | /***** | ||
137 | * 6) Transition to background mode. | ||
138 | */ | ||
139 | //CALL( task_mode(BACKGROUND_TASK) ); | ||
140 | |||
141 | |||
142 | |||
143 | /***** | ||
144 | * 7) Clean up, maybe print results and stats, and exit. | ||
145 | */ | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | |||
150 | //int job(void) | ||
151 | //{ | ||
152 | // /* Do real-time calculation. */ | ||
153 | // | ||
154 | // | ||
155 | // /* Don't exit. */ | ||
156 | // return 0; | ||
157 | //} | ||
diff --git a/include/litmus.h b/include/litmus.h index fd9c7e3..e8e07dc 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
@@ -145,9 +145,15 @@ static inline int open_fmlp_sem(int fd, int name) | |||
145 | return od_open(fd, FMLP_SEM, name); | 145 | return od_open(fd, FMLP_SEM, name); |
146 | } | 146 | } |
147 | 147 | ||
148 | static inline int open_dgl_sem(int fd, int name) | 148 | static inline int open_new_dgl_sem(int fd, int name) |
149 | { | 149 | { |
150 | return od_open(fd, DGL_SEM, name); | 150 | int tmp = -1; |
151 | return od_openx(fd, DGL_SEM, name, &tmp); | ||
152 | } | ||
153 | |||
154 | static inline int attach_dgl_sem(int fd, int name, int resource) | ||
155 | { | ||
156 | return od_openx(fd, DGL_SEM, name, &resource); | ||
151 | } | 157 | } |
152 | 158 | ||
153 | static inline int open_srp_sem(int fd, int name) | 159 | static inline int open_srp_sem(int fd, int name) |
diff --git a/src/syscalls.c b/src/syscalls.c index e82d987..2c38a04 100644 --- a/src/syscalls.c +++ b/src/syscalls.c | |||
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | /* for syscall() */ | 8 | /* for syscall() */ |
9 | #include <unistd.h> | 9 | #include <unistd.h> |
10 | #include <stdio.h> | ||
10 | 11 | ||
11 | #include "litmus.h" | 12 | #include "litmus.h" |
12 | 13 | ||
@@ -54,6 +55,7 @@ int litmus_unlock(int od) | |||
54 | 55 | ||
55 | int dynamic_group_lock(int mask) | 56 | int dynamic_group_lock(int mask) |
56 | { | 57 | { |
58 | printf("Calling dynamic group lock!!!"); | ||
57 | return syscall(__NR_dynamic_group_lock, mask); | 59 | return syscall(__NR_dynamic_group_lock, mask); |
58 | } | 60 | } |
59 | 61 | ||