aboutsummaryrefslogtreecommitdiffstats
path: root/bin/dgl_test.c
diff options
context:
space:
mode:
authorBryan Ward <bcw@cs.unc.edu>2012-08-07 22:29:16 -0400
committerBryan Ward <bcw@cs.unc.edu>2012-08-07 22:29:16 -0400
commit29d9fc49d3da6889a4e03f03578398e89f8e2a59 (patch)
tree3bea744b1ca149650341b4613b190d9c2f1a0583 /bin/dgl_test.c
parent3b0411a23c8bb91b5bc201f7df39e6e83e2b38b6 (diff)
Cleaned up testing script for DGLs.
Diffstat (limited to 'bin/dgl_test.c')
-rw-r--r--bin/dgl_test.c157
1 files changed, 157 insertions, 0 deletions
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 */
46int 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 */
61int 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//}