diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | bin/mc2mem.c | 304 | ||||
-rw-r--r-- | bin/mc2spin.c | 250 | ||||
-rw-r--r-- | include/cache_common.h | 140 | ||||
-rw-r--r-- | include/litmus.h | 20 | ||||
-rw-r--r-- | src/syscalls.c | 25 |
7 files changed, 753 insertions, 2 deletions
@@ -23,6 +23,10 @@ showst | |||
23 | rtspin | 23 | rtspin |
24 | cycles | 24 | cycles |
25 | measure_syscall | 25 | measure_syscall |
26 | mc2spin | ||
27 | mc2mem_stc | ||
28 | mc2mem_ssh | ||
29 | mc2mem | ||
26 | 30 | ||
27 | # build system files | 31 | # build system files |
28 | .config | 32 | .config |
@@ -19,7 +19,7 @@ LITMUS_KERNEL ?= ../litmus-rt | |||
19 | # Internal configuration. | 19 | # Internal configuration. |
20 | 20 | ||
21 | # compiler flags | 21 | # compiler flags |
22 | flags-debug = -O2 -Wall -Werror -g -Wdeclaration-after-statement | 22 | flags-debug = -O2 -Wall -g -Wdeclaration-after-statement |
23 | flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE | 23 | flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE |
24 | 24 | ||
25 | # architecture-specific flags | 25 | # architecture-specific flags |
@@ -73,7 +73,7 @@ AR := ${CROSS_COMPILE}${AR} | |||
73 | 73 | ||
74 | all = lib ${rt-apps} | 74 | all = lib ${rt-apps} |
75 | rt-apps = cycles base_task rt_launch rtspin release_ts measure_syscall \ | 75 | rt-apps = cycles base_task rt_launch rtspin release_ts measure_syscall \ |
76 | base_mt_task uncache runtests | 76 | base_mt_task uncache runtests mc2mem_stc mc2mem_ssh mc2spin |
77 | 77 | ||
78 | .PHONY: all lib clean dump-config TAGS tags cscope help doc | 78 | .PHONY: all lib clean dump-config TAGS tags cscope help doc |
79 | 79 | ||
@@ -234,6 +234,14 @@ obj-release_ts = release_ts.o | |||
234 | obj-measure_syscall = null_call.o | 234 | obj-measure_syscall = null_call.o |
235 | lib-measure_syscall = -lm | 235 | lib-measure_syscall = -lm |
236 | 236 | ||
237 | obj-mc2mem_stc = mc2mem.o common.o | ||
238 | lib-mc2mem_stc = -lrt -static | ||
239 | |||
240 | obj-mc2mem_ssh = mc2mem.o common.o | ||
241 | lib-mc2mem_ssh = -lrt | ||
242 | |||
243 | obj-mc2spin = mc2spin.o common.o | ||
244 | lib-mc2spin = -lrt | ||
237 | # ############################################################################## | 245 | # ############################################################################## |
238 | # Build everything that depends on liblitmus. | 246 | # Build everything that depends on liblitmus. |
239 | 247 | ||
diff --git a/bin/mc2mem.c b/bin/mc2mem.c new file mode 100644 index 0000000..2fba878 --- /dev/null +++ b/bin/mc2mem.c | |||
@@ -0,0 +1,304 @@ | |||
1 | #include <sys/time.h> | ||
2 | #include <sys/mman.h> | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <unistd.h> | ||
7 | #include <time.h> | ||
8 | #include <string.h> | ||
9 | #include <assert.h> | ||
10 | #include <limits.h> | ||
11 | #include <fcntl.h> | ||
12 | #include <math.h> | ||
13 | |||
14 | #include "litmus.h" | ||
15 | #include "common.h" | ||
16 | #include "cache_common.h" | ||
17 | |||
18 | #define PAGE_SIZE (4096) | ||
19 | #define CACHELINE_SIZE 32 | ||
20 | #define INTS_IN_CACHELINE (CACHELINE_SIZE/sizeof(int)) | ||
21 | #define CACHELINES_IN_1KB (1024 / sizeof(cacheline_t)) | ||
22 | #define INTS_IN_1KB (1024 / sizeof(int)) | ||
23 | #define INTS_IN_CACHELINE (CACHELINE_SIZE/sizeof(int)) | ||
24 | |||
25 | static int loops = 100; | ||
26 | static cacheline_t* arena = NULL; | ||
27 | static int verbose = 0; | ||
28 | |||
29 | #define UNCACHE_DEV "/dev/litmus/uncache" | ||
30 | |||
31 | /* Random walk around the arena in cacheline-sized chunks. | ||
32 | Cacheline-sized chucks ensures the same utilization of each | ||
33 | hit line as sequential read. (Otherwise, our utilization | ||
34 | would only be 1/INTS_IN_CACHELINE.) */ | ||
35 | static int random_walk(cacheline_t *mem, int wss, int write_cycle) | ||
36 | { | ||
37 | /* a random cycle among the cache lines was set up by init_arena(). */ | ||
38 | int sum, i, next; | ||
39 | |||
40 | int numlines = wss * CACHELINES_IN_1KB; | ||
41 | |||
42 | sum = 0; | ||
43 | |||
44 | /* contents of arena is structured s.t. offsets are all | ||
45 | w.r.t. to start of arena, so compute the initial offset */ | ||
46 | next = mem - arena; | ||
47 | |||
48 | if (write_cycle == 0) { | ||
49 | for (i = 0; i < numlines; i++) { | ||
50 | /* every element in the cacheline has the same value */ | ||
51 | next = arena[next].line[0]; | ||
52 | sum += next; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | else { | ||
57 | int w, which_line; | ||
58 | for (i = 0, w = 0; i < numlines; i++) { | ||
59 | which_line = next; | ||
60 | next = arena[next].line[0]; | ||
61 | if((w % write_cycle) != (write_cycle - 1)) { | ||
62 | sum += next; | ||
63 | } | ||
64 | else { | ||
65 | ((volatile cacheline_t*)arena)[which_line].line[0] = next; | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | return sum; | ||
70 | } | ||
71 | |||
72 | static cacheline_t* random_start(int wss) | ||
73 | { | ||
74 | return arena + randrange(0, ((wss * 1024)/sizeof(cacheline_t))); | ||
75 | } | ||
76 | |||
77 | static volatile int dont_optimize_me = 0; | ||
78 | |||
79 | static void usage(char *error) { | ||
80 | fprintf(stderr, "Error: %s\n", error); | ||
81 | fprintf(stderr, | ||
82 | "Usage:\n" | ||
83 | " rt_spin [COMMON-OPTS] WCET PERIOD DURATION\n" | ||
84 | " rt_spin [COMMON-OPTS] -f FILE [-o COLUMN] WCET PERIOD\n" | ||
85 | " rt_spin -l\n" | ||
86 | "\n" | ||
87 | "COMMON-OPTS = [-w] [-s SCALE]\n" | ||
88 | " [-p PARTITION/CLUSTER [-z CLUSTER SIZE]] [-m CRITICALITY LEVEL]\n" | ||
89 | " [-k WSS] [-l LOOPS] [-b BUDGET]\n" | ||
90 | "\n" | ||
91 | "WCET and PERIOD are milliseconds, DURATION is seconds.\n"); | ||
92 | exit(EXIT_FAILURE); | ||
93 | } | ||
94 | |||
95 | static int loop_once(int wss) | ||
96 | { | ||
97 | cacheline_t *mem; | ||
98 | int temp; | ||
99 | |||
100 | mem = random_start(wss); | ||
101 | temp = random_walk(mem, wss, 0); | ||
102 | |||
103 | dont_optimize_me = temp; | ||
104 | |||
105 | return dont_optimize_me; | ||
106 | } | ||
107 | |||
108 | static int job(int wss, double exec_time, double program_end) | ||
109 | { | ||
110 | if (wctime() > program_end) | ||
111 | return 0; | ||
112 | else { | ||
113 | register unsigned int iter = 0; | ||
114 | register cycles_t t; | ||
115 | t = get_cycles(); | ||
116 | while(iter++ < loops) { | ||
117 | loop_once(wss); | ||
118 | } | ||
119 | t = get_cycles() - t; | ||
120 | if (verbose) | ||
121 | printf("%ld cycles\n", t); | ||
122 | sleep_next_period(); | ||
123 | return 1; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | #define OPTSTR "p:wl:m:i:b:k:v" | ||
128 | int main(int argc, char** argv) | ||
129 | { | ||
130 | int ret; | ||
131 | lt_t wcet, period, budget; | ||
132 | double wcet_ms, period_ms, budget_ms; | ||
133 | unsigned int priority = LITMUS_NO_PRIORITY; | ||
134 | int migrate = 0; | ||
135 | int cluster = 0; | ||
136 | int opt; | ||
137 | int wait = 0; | ||
138 | double duration = 0, start = 0; | ||
139 | struct rt_task param; | ||
140 | struct mc2_task mc2_param; | ||
141 | struct reservation_config config; | ||
142 | int res_type = PERIODIC_POLLING; | ||
143 | size_t arena_sz; | ||
144 | int wss = 0; | ||
145 | |||
146 | /* default for reservation */ | ||
147 | config.id = 0; | ||
148 | config.priority = LITMUS_NO_PRIORITY; /* use EDF by default */ | ||
149 | config.cpu = -1; | ||
150 | |||
151 | mc2_param.crit = CRIT_LEVEL_C; | ||
152 | |||
153 | budget_ms = 1000; | ||
154 | |||
155 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { | ||
156 | switch (opt) { | ||
157 | case 'w': | ||
158 | wait = 1; | ||
159 | break; | ||
160 | case 'p': | ||
161 | cluster = atoi(optarg); | ||
162 | migrate = 1; | ||
163 | config.cpu = cluster; | ||
164 | break; | ||
165 | case 'l': | ||
166 | loops = atoi(optarg); | ||
167 | break; | ||
168 | case 'k': | ||
169 | wss = atoi(optarg); | ||
170 | break; | ||
171 | case 'm': | ||
172 | mc2_param.crit = atoi(optarg); | ||
173 | if ((mc2_param.crit >= CRIT_LEVEL_A) && (mc2_param.crit <= CRIT_LEVEL_C)) { | ||
174 | res_type = PERIODIC_POLLING; | ||
175 | } | ||
176 | else | ||
177 | usage("Invalid criticality level."); | ||
178 | break; | ||
179 | case 'b': | ||
180 | budget_ms = atof(optarg); | ||
181 | break; | ||
182 | case 'i': | ||
183 | config.priority = atoi(optarg); | ||
184 | break; | ||
185 | case 'v': | ||
186 | verbose = 1; | ||
187 | break; | ||
188 | case ':': | ||
189 | usage("Argument missing."); | ||
190 | break; | ||
191 | case '?': | ||
192 | default: | ||
193 | usage("Bad argument."); | ||
194 | break; | ||
195 | } | ||
196 | } | ||
197 | srand(getpid()); | ||
198 | |||
199 | /* | ||
200 | * We need three parameters | ||
201 | */ | ||
202 | if (argc - optind < 3) | ||
203 | usage("Arguments missing."); | ||
204 | |||
205 | wcet_ms = atof(argv[optind + 0]); | ||
206 | period_ms = atof(argv[optind + 1]); | ||
207 | |||
208 | wcet = ms2ns(wcet_ms); | ||
209 | period = ms2ns(period_ms); | ||
210 | budget = ms2ns(budget_ms); | ||
211 | if (wcet <= 0) | ||
212 | usage("The worst-case execution time must be a " | ||
213 | "positive number."); | ||
214 | if (period <= 0) | ||
215 | usage("The period must be a positive number."); | ||
216 | if (wcet > period) { | ||
217 | usage("The worst-case execution time must not " | ||
218 | "exceed the period."); | ||
219 | } | ||
220 | if (wss == 0) { | ||
221 | usage("You need to specify a WSS (-k option)."); | ||
222 | } | ||
223 | |||
224 | duration = atof(argv[optind + 2]); | ||
225 | |||
226 | if (migrate) { | ||
227 | ret = be_migrate_to_domain(cluster); | ||
228 | if (ret < 0) | ||
229 | bail_out("could not migrate to target partition or cluster."); | ||
230 | } | ||
231 | |||
232 | /* reservation config */ | ||
233 | config.id = gettid(); | ||
234 | config.polling_params.budget = budget; | ||
235 | config.polling_params.period = period; | ||
236 | config.polling_params.offset = 0; | ||
237 | config.polling_params.relative_deadline = 0; | ||
238 | |||
239 | if (config.polling_params.budget > config.polling_params.period) { | ||
240 | usage("The budget must not exceed the period."); | ||
241 | } | ||
242 | |||
243 | /* create a reservation */ | ||
244 | ret = reservation_create(res_type, &config); | ||
245 | if (ret < 0) { | ||
246 | bail_out("failed to create reservation."); | ||
247 | } | ||
248 | |||
249 | init_rt_task_param(¶m); | ||
250 | param.exec_cost = wcet; | ||
251 | param.period = period; | ||
252 | param.priority = priority; | ||
253 | param.cls = RT_CLASS_HARD; | ||
254 | param.release_policy = TASK_PERIODIC; | ||
255 | param.budget_policy = NO_ENFORCEMENT; | ||
256 | if (migrate) { | ||
257 | param.cpu = gettid(); | ||
258 | } | ||
259 | ret = set_rt_task_param(gettid(), ¶m); | ||
260 | if (ret < 0) | ||
261 | bail_out("could not setup rt task params"); | ||
262 | |||
263 | mc2_param.res_id = gettid(); | ||
264 | ret = set_mc2_task_param(gettid(), &mc2_param); | ||
265 | if (ret < 0) | ||
266 | bail_out("could not setup mc2 task params"); | ||
267 | |||
268 | arena_sz = wss*1024; | ||
269 | arena = alloc_arena(arena_sz, 0, 0); | ||
270 | init_arena(arena, arena_sz); | ||
271 | |||
272 | lock_memory(); | ||
273 | |||
274 | if (mc2_param.crit == CRIT_LEVEL_C) | ||
275 | set_page_color(-1); | ||
276 | else | ||
277 | set_page_color(config.cpu); | ||
278 | |||
279 | ret = init_litmus(); | ||
280 | if (ret != 0) | ||
281 | bail_out("init_litmus() failed\n"); | ||
282 | |||
283 | start = wctime(); | ||
284 | ret = task_mode(LITMUS_RT_TASK); | ||
285 | if (ret != 0) | ||
286 | bail_out("could not become RT task"); | ||
287 | |||
288 | if (wait) { | ||
289 | ret = wait_for_ts_release(); | ||
290 | if (ret != 0) | ||
291 | bail_out("wait_for_ts_release()"); | ||
292 | start = wctime(); | ||
293 | } | ||
294 | |||
295 | while (job(wss, wcet_ms * 0.001, start + duration)) {}; | ||
296 | |||
297 | ret = task_mode(BACKGROUND_TASK); | ||
298 | if (ret != 0) | ||
299 | bail_out("could not become regular task (huh?)"); | ||
300 | |||
301 | reservation_destroy(gettid(), config.cpu); | ||
302 | dealloc_arena(arena, arena_sz); | ||
303 | return 0; | ||
304 | } | ||
diff --git a/bin/mc2spin.c b/bin/mc2spin.c new file mode 100644 index 0000000..e41c62c --- /dev/null +++ b/bin/mc2spin.c | |||
@@ -0,0 +1,250 @@ | |||
1 | #include <sys/time.h> | ||
2 | #include <sys/mman.h> | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <unistd.h> | ||
7 | #include <time.h> | ||
8 | #include <string.h> | ||
9 | #include <assert.h> | ||
10 | #include <limits.h> | ||
11 | #include <fcntl.h> | ||
12 | #include <math.h> | ||
13 | |||
14 | #include "litmus.h" | ||
15 | #include "common.h" | ||
16 | |||
17 | #define PAGE_SIZE (4096) | ||
18 | |||
19 | static int verbose = 0; | ||
20 | |||
21 | #define UNCACHE_DEV "/dev/litmus/uncache" | ||
22 | |||
23 | static void usage(char *error) { | ||
24 | fprintf(stderr, "Error: %s\n", error); | ||
25 | fprintf(stderr, | ||
26 | "Usage:\n" | ||
27 | " rt_spin [COMMON-OPTS] WCET PERIOD DURATION\n" | ||
28 | " rt_spin [COMMON-OPTS] -f FILE [-o COLUMN] WCET PERIOD\n" | ||
29 | " rt_spin -l\n" | ||
30 | "\n" | ||
31 | "COMMON-OPTS = [-w] [-s SCALE]\n" | ||
32 | " [-p PARTITION/CLUSTER [-z CLUSTER SIZE]] [-m CRITICALITY LEVEL]\n" | ||
33 | " [-k WSS] [-l LOOPS] [-b BUDGET]\n" | ||
34 | "\n" | ||
35 | "WCET and PERIOD are milliseconds, DURATION is seconds.\n"); | ||
36 | exit(EXIT_FAILURE); | ||
37 | } | ||
38 | |||
39 | #define NUMS 4096 | ||
40 | static int num[NUMS]; | ||
41 | static char* progname; | ||
42 | |||
43 | static int loop_once(void) | ||
44 | { | ||
45 | int i, j = 0; | ||
46 | for (i = 0; i < NUMS; i++) | ||
47 | j += num[i]++; | ||
48 | return j; | ||
49 | } | ||
50 | |||
51 | static int loop_for(double exec_time, double emergency_exit) | ||
52 | { | ||
53 | double last_loop = 0, loop_start; | ||
54 | int tmp = 0; | ||
55 | |||
56 | double start = cputime(); | ||
57 | double now = cputime(); | ||
58 | |||
59 | while (now + last_loop < start + exec_time) { | ||
60 | loop_start = now; | ||
61 | tmp += loop_once(); | ||
62 | now = cputime(); | ||
63 | last_loop = now - loop_start; | ||
64 | if (emergency_exit && wctime() > emergency_exit) { | ||
65 | /* Oops --- this should only be possible if the execution time tracking | ||
66 | * is broken in the LITMUS^RT kernel. */ | ||
67 | fprintf(stderr, "!!! rtspin/%d emergency exit!\n", getpid()); | ||
68 | fprintf(stderr, "Something is seriously wrong! Do not ignore this.\n"); | ||
69 | break; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | return tmp; | ||
74 | } | ||
75 | |||
76 | static int job(double exec_time, double program_end) | ||
77 | { | ||
78 | if (wctime() > program_end) | ||
79 | return 0; | ||
80 | else { | ||
81 | loop_for(exec_time, program_end + 1); | ||
82 | sleep_next_period(); | ||
83 | return 1; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | #define OPTSTR "p:wm:i:v" | ||
88 | int main(int argc, char** argv) | ||
89 | { | ||
90 | int ret; | ||
91 | lt_t wcet, period, budget; | ||
92 | double wcet_ms, period_ms; | ||
93 | unsigned int priority = LITMUS_NO_PRIORITY; | ||
94 | int migrate = 0; | ||
95 | int cluster = 0; | ||
96 | int opt; | ||
97 | int wait = 0; | ||
98 | double duration = 0, start = 0; | ||
99 | struct rt_task param; | ||
100 | struct mc2_task mc2_param; | ||
101 | struct reservation_config config; | ||
102 | int res_type = PERIODIC_POLLING; | ||
103 | |||
104 | /* default for reservation */ | ||
105 | config.id = 0; | ||
106 | config.priority = LITMUS_NO_PRIORITY; /* use EDF by default */ | ||
107 | config.cpu = -1; | ||
108 | |||
109 | mc2_param.crit = CRIT_LEVEL_C; | ||
110 | |||
111 | progname = argv[0]; | ||
112 | |||
113 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { | ||
114 | switch (opt) { | ||
115 | case 'w': | ||
116 | wait = 1; | ||
117 | break; | ||
118 | case 'p': | ||
119 | cluster = atoi(optarg); | ||
120 | migrate = 1; | ||
121 | config.cpu = cluster; | ||
122 | break; | ||
123 | case 'm': | ||
124 | mc2_param.crit = atoi(optarg); | ||
125 | if ((mc2_param.crit >= CRIT_LEVEL_A) && (mc2_param.crit <= CRIT_LEVEL_C)) { | ||
126 | res_type = PERIODIC_POLLING; | ||
127 | } | ||
128 | else | ||
129 | usage("Invalid criticality level."); | ||
130 | break; | ||
131 | case 'i': | ||
132 | config.priority = atoi(optarg); | ||
133 | break; | ||
134 | case 'v': | ||
135 | verbose = 1; | ||
136 | break; | ||
137 | case ':': | ||
138 | usage("Argument missing."); | ||
139 | break; | ||
140 | case '?': | ||
141 | default: | ||
142 | usage("Bad argument."); | ||
143 | break; | ||
144 | } | ||
145 | } | ||
146 | srand(getpid()); | ||
147 | |||
148 | /* | ||
149 | * We need three parameters | ||
150 | */ | ||
151 | if (argc - optind < 3) | ||
152 | usage("Arguments missing."); | ||
153 | |||
154 | wcet_ms = atof(argv[optind + 0]); | ||
155 | period_ms = atof(argv[optind + 1]); | ||
156 | |||
157 | wcet = ms2ns(wcet_ms); | ||
158 | period = ms2ns(period_ms); | ||
159 | budget = ms2ns(wcet_ms+1); | ||
160 | if (wcet <= 0) | ||
161 | usage("The worst-case execution time must be a " | ||
162 | "positive number."); | ||
163 | if (period <= 0) | ||
164 | usage("The period must be a positive number."); | ||
165 | if (wcet > period) { | ||
166 | usage("The worst-case execution time must not " | ||
167 | "exceed the period."); | ||
168 | } | ||
169 | |||
170 | duration = atof(argv[optind + 2]); | ||
171 | |||
172 | if (mc2_param.crit == CRIT_LEVEL_C) { | ||
173 | migrate = 0; | ||
174 | config.cpu = -1; | ||
175 | } | ||
176 | |||
177 | if (migrate) { | ||
178 | ret = be_migrate_to_domain(cluster); | ||
179 | if (ret < 0) | ||
180 | bail_out("could not migrate to target partition or cluster."); | ||
181 | } | ||
182 | |||
183 | /* reservation config */ | ||
184 | config.id = gettid(); | ||
185 | config.polling_params.budget = budget; | ||
186 | config.polling_params.period = period; | ||
187 | config.polling_params.offset = 0; | ||
188 | config.polling_params.relative_deadline = 0; | ||
189 | |||
190 | if (config.polling_params.budget > config.polling_params.period) { | ||
191 | usage("The budget must not exceed the period."); | ||
192 | } | ||
193 | |||
194 | /* create a reservation */ | ||
195 | ret = reservation_create(res_type, &config); | ||
196 | if (ret < 0) { | ||
197 | bail_out("failed to create reservation."); | ||
198 | } | ||
199 | |||
200 | init_rt_task_param(¶m); | ||
201 | param.exec_cost = wcet; | ||
202 | param.period = period; | ||
203 | param.priority = priority; | ||
204 | param.cls = RT_CLASS_HARD; | ||
205 | param.release_policy = TASK_PERIODIC; | ||
206 | param.budget_policy = NO_ENFORCEMENT; | ||
207 | if (migrate) { | ||
208 | param.cpu = gettid(); | ||
209 | } | ||
210 | ret = set_rt_task_param(gettid(), ¶m); | ||
211 | if (ret < 0) | ||
212 | bail_out("could not setup rt task params"); | ||
213 | |||
214 | mc2_param.res_id = gettid(); | ||
215 | ret = set_mc2_task_param(gettid(), &mc2_param); | ||
216 | if (ret < 0) | ||
217 | bail_out("could not setup mc2 task params"); | ||
218 | |||
219 | ret = init_litmus(); | ||
220 | if (ret != 0) | ||
221 | bail_out("init_litmus() failed\n"); | ||
222 | |||
223 | start = wctime(); | ||
224 | |||
225 | ret = task_mode(LITMUS_RT_TASK); | ||
226 | if (ret != 0) | ||
227 | bail_out("could not become RT task"); | ||
228 | |||
229 | if (wait) { | ||
230 | ret = wait_for_ts_release(); | ||
231 | if (ret != 0) | ||
232 | bail_out("wait_for_ts_release()"); | ||
233 | start = wctime(); | ||
234 | } | ||
235 | |||
236 | do { | ||
237 | if (verbose) { | ||
238 | printf("rtspin:%u @ %.4fms\n", gettid(), | ||
239 | (wctime() - start) * 1000); | ||
240 | } | ||
241 | } while (job(wcet_ms * 0.001, start + duration)); | ||
242 | |||
243 | ret = task_mode(BACKGROUND_TASK); | ||
244 | if (ret != 0) | ||
245 | bail_out("could not become regular task (huh?)"); | ||
246 | |||
247 | reservation_destroy(gettid(), config.cpu); | ||
248 | return 0; | ||
249 | } | ||
250 | |||
diff --git a/include/cache_common.h b/include/cache_common.h new file mode 100644 index 0000000..8239233 --- /dev/null +++ b/include/cache_common.h | |||
@@ -0,0 +1,140 @@ | |||
1 | #ifndef __CACHE_COMMON_H__ | ||
2 | #define __CACHE_COMMON_H__ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <time.h> | ||
7 | #include <string.h> | ||
8 | #include <assert.h> | ||
9 | |||
10 | #include <signal.h> | ||
11 | #include <sys/mman.h> | ||
12 | #include <sys/types.h> | ||
13 | #include <sys/stat.h> | ||
14 | #include <fcntl.h> | ||
15 | #include <unistd.h> | ||
16 | |||
17 | #include <sys/io.h> | ||
18 | #include <sys/utsname.h> | ||
19 | |||
20 | #include <sched.h> | ||
21 | #include <sys/time.h> | ||
22 | #include <sys/resource.h> | ||
23 | |||
24 | #include "litmus.h" | ||
25 | #include "asm/cycles.h" | ||
26 | |||
27 | #if defined(__i386__) || defined(__x86_64__) | ||
28 | #include "asm/irq.h" | ||
29 | #endif | ||
30 | |||
31 | |||
32 | #define UNCACHE_DEV "/dev/litmus/uncache" | ||
33 | |||
34 | static void die(char *error) | ||
35 | { | ||
36 | fprintf(stderr, "Error: %s (errno: %m)\n", | ||
37 | error); | ||
38 | exit(1); | ||
39 | } | ||
40 | |||
41 | static int lock_memory(void) | ||
42 | { | ||
43 | return mlockall(MCL_CURRENT | MCL_FUTURE); | ||
44 | } | ||
45 | |||
46 | /* define CACHELINE_SIZE if not provided by compiler args */ | ||
47 | #ifndef CACHELINE_SIZE | ||
48 | #if defined(__i386__) || defined(__x86_64__) | ||
49 | /* recent intel cpus */ | ||
50 | #define CACHELINE_SIZE 64 | ||
51 | #elif defined(__arm__) | ||
52 | /* at least with Cortex-A9 cpus ("8 words") */ | ||
53 | #define CACHELINE_SIZE 32 | ||
54 | #else | ||
55 | #error "Could not determine cacheline size!" | ||
56 | #endif | ||
57 | #endif | ||
58 | |||
59 | #define INTS_IN_CACHELINE (CACHELINE_SIZE/sizeof(int)) | ||
60 | typedef struct cacheline | ||
61 | { | ||
62 | int line[INTS_IN_CACHELINE]; | ||
63 | } __attribute__((aligned(CACHELINE_SIZE))) cacheline_t; | ||
64 | |||
65 | #define CACHELINES_IN_1KB (1024 / sizeof(cacheline_t)) | ||
66 | |||
67 | |||
68 | static cacheline_t* alloc_arena(size_t size, int use_huge_pages, int use_uncache_pages) | ||
69 | { | ||
70 | int flags = MAP_PRIVATE | MAP_POPULATE; | ||
71 | cacheline_t* arena = NULL; | ||
72 | int fd; | ||
73 | |||
74 | if(use_huge_pages) | ||
75 | flags |= MAP_HUGETLB; | ||
76 | |||
77 | if(use_uncache_pages) { | ||
78 | fd = open(UNCACHE_DEV, O_RDWR); | ||
79 | if (fd == -1) | ||
80 | die("Failed to open uncache device. Are you running the LITMUS^RT kernel?"); | ||
81 | } | ||
82 | else { | ||
83 | fd = -1; | ||
84 | flags |= MAP_ANONYMOUS; | ||
85 | } | ||
86 | |||
87 | arena = mmap(0, size, PROT_READ | PROT_WRITE, flags, fd, 0); | ||
88 | |||
89 | if(use_uncache_pages) | ||
90 | close(fd); | ||
91 | |||
92 | assert(arena); | ||
93 | |||
94 | return arena; | ||
95 | } | ||
96 | |||
97 | static void dealloc_arena(cacheline_t* arena, size_t size) | ||
98 | { | ||
99 | int ret = munmap((void*)arena, size); | ||
100 | if(ret != 0) | ||
101 | die("munmap() error"); | ||
102 | } | ||
103 | |||
104 | static int randrange(int min, int max) | ||
105 | { | ||
106 | /* generate a random number on the range [min, max) w/o skew */ | ||
107 | int limit = max - min; | ||
108 | int devisor = RAND_MAX/limit; | ||
109 | int retval; | ||
110 | |||
111 | do { | ||
112 | retval = rand() / devisor; | ||
113 | } while(retval == limit); | ||
114 | retval += min; | ||
115 | |||
116 | return retval; | ||
117 | } | ||
118 | |||
119 | static void init_arena(cacheline_t* arena, size_t size) | ||
120 | { | ||
121 | int i; | ||
122 | size_t num_arena_elem = size / sizeof(cacheline_t); | ||
123 | |||
124 | /* Generate a cycle among the cache lines using Sattolo's algorithm. | ||
125 | Every int in the cache line points to the same cache line. | ||
126 | Note: Sequential walk doesn't care about these values. */ | ||
127 | for (i = 0; i < num_arena_elem; i++) { | ||
128 | int j; | ||
129 | for(j = 0; j < INTS_IN_CACHELINE; ++j) | ||
130 | arena[i].line[j] = i; | ||
131 | } | ||
132 | while(1 < i--) { | ||
133 | int j = randrange(0, i); | ||
134 | cacheline_t temp = arena[j]; | ||
135 | arena[j] = arena[i]; | ||
136 | arena[i] = temp; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | #endif | ||
diff --git a/include/litmus.h b/include/litmus.h index b9dbdb5..4b97b87 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
@@ -40,6 +40,8 @@ extern "C" { | |||
40 | 40 | ||
41 | #include "migration.h" | 41 | #include "migration.h" |
42 | 42 | ||
43 | #include "litmus/mc2_common.h" | ||
44 | |||
43 | /** | 45 | /** |
44 | * @private | 46 | * @private |
45 | * The numeric ID of the LITMUS^RT scheduling class. | 47 | * The numeric ID of the LITMUS^RT scheduling class. |
@@ -146,6 +148,12 @@ int sporadic_clustered(lt_t e_ns, lt_t p_ns, int cluster); | |||
146 | /** Convert microseconds to nanoseconds | 148 | /** Convert microseconds to nanoseconds |
147 | * @param us Time units in microseconds */ | 149 | * @param us Time units in microseconds */ |
148 | #define us2ns(us) ((us)*1000LL) | 150 | #define us2ns(us) ((us)*1000LL) |
151 | #define ns2s(ns) ((ns)/1000000000LL) | ||
152 | #define ns2ms(ns) ((ns)/1000000LL) | ||
153 | #define ns2us(ns) ((ns)/1000LL) | ||
154 | #define us2ms(us) ((us)/1000LL) | ||
155 | #define us2s(us) ((us)/1000000LL) | ||
156 | #define ms2s(ms) ((ms)/1000LL) | ||
149 | 157 | ||
150 | /** | 158 | /** |
151 | * Locking protocols for allocated shared objects | 159 | * Locking protocols for allocated shared objects |
@@ -416,6 +424,18 @@ int null_call(cycles_t *timestamp); | |||
416 | */ | 424 | */ |
417 | struct control_page* get_ctrl_page(void); | 425 | struct control_page* get_ctrl_page(void); |
418 | 426 | ||
427 | int reservation_create(int rtype, void *config); | ||
428 | |||
429 | int reservation_destroy(unsigned int reservation_id, int cpu); | ||
430 | |||
431 | int set_mc2_task_param(pid_t pid, struct mc2_task* param); | ||
432 | |||
433 | int set_page_color(int cpu); | ||
434 | |||
435 | int test_call(unsigned int param); | ||
436 | |||
437 | typedef struct cacheline cacheline_t; | ||
438 | |||
419 | #ifdef __cplusplus | 439 | #ifdef __cplusplus |
420 | } | 440 | } |
421 | #endif | 441 | #endif |
diff --git a/src/syscalls.c b/src/syscalls.c index c68f15b..ab064ad 100644 --- a/src/syscalls.c +++ b/src/syscalls.c | |||
@@ -86,3 +86,28 @@ int null_call(cycles_t *timestamp) | |||
86 | { | 86 | { |
87 | return syscall(__NR_null_call, timestamp); | 87 | return syscall(__NR_null_call, timestamp); |
88 | } | 88 | } |
89 | |||
90 | int reservation_create(int rtype, void *config) | ||
91 | { | ||
92 | return syscall(__NR_reservation_create, rtype, config); | ||
93 | } | ||
94 | |||
95 | int reservation_destroy(unsigned int reservation_id, int cpu) | ||
96 | { | ||
97 | return syscall(__NR_reservation_destroy, reservation_id, cpu); | ||
98 | } | ||
99 | |||
100 | int set_mc2_task_param(pid_t pid, struct mc2_task *param) | ||
101 | { | ||
102 | return syscall(__NR_set_mc2_task_param, pid, param); | ||
103 | } | ||
104 | |||
105 | int set_page_color(int cpu) | ||
106 | { | ||
107 | return syscall(__NR_set_page_color, cpu); | ||
108 | } | ||
109 | |||
110 | int test_call(unsigned int param) | ||
111 | { | ||
112 | return syscall(__NR_test_call, param); | ||
113 | } | ||