aboutsummaryrefslogtreecommitdiffstats
path: root/bin/rt_field_spin.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/rt_field_spin.c')
-rw-r--r--bin/rt_field_spin.c385
1 files changed, 0 insertions, 385 deletions
diff --git a/bin/rt_field_spin.c b/bin/rt_field_spin.c
deleted file mode 100644
index 06cabd4..0000000
--- a/bin/rt_field_spin.c
+++ /dev/null
@@ -1,385 +0,0 @@
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
12#include "litmus.h"
13#include "common.h"
14#include "DISstressmarkRNG.h"
15
16#define MIN_FIELD_SIZE 16
17#define MAX_FIELD_SIZE 16777216
18#define MIN_SEED -2147483647
19#define MAX_SEED -1
20#define MIN_MOD_OFFSET 0
21#define MAX_MOD_OFFSET 65535
22#define MIN_TOKENS 1
23#define MAX_TOKENS 256
24#define MIN_TOKEN_LENGTH 1
25#define MAX_TOKEN_LENGTH 8
26#define MIN_TOKEN_VALUE 0
27#define MAX_TOKEN_VALUE 255
28#define MAX_SUBFIELDS 256
29
30static char* progname;
31int loops = 1;
32
33struct timeval t1, t2;
34
35struct tokenS{
36 unsigned char delimiter[MAX_TOKEN_LENGTH];
37 unsigned char length;
38 struct statisticS{
39 unsigned int count;
40 unsigned char min;
41 unsigned char sum;
42 } stat[MAX_SUBFIELDS];
43 unsigned char subfields;
44} token[MAX_TOKENS];
45
46unsigned char *field;
47unsigned int f_max;
48int seed;
49int mod_offset;
50unsigned int n_max;
51
52unsigned char input_token[8] = {0x1, 0x1, 0x22, 0x1, 0xc2, 0x1, 0x2d, 0x0};
53
54int init_job(){
55 //fscanf(stdin, "%d %d %d %d", &f, &seed, &mod_offset, &n);
56 f_max = 262144;
57 seed = -1;
58 n_max = 1;
59
60 assert((seed >= MIN_SEED) && (seed <= MAX_SEED));
61
62 if ((field = (unsigned char*)malloc(f_max*sizeof(unsigned char))) == NULL)
63 return (-1);
64
65 randInit(seed);
66
67 return 0;
68}
69
70int main_job() {
71 unsigned int l, f, n;
72
73 f = randInt(16384, f_max);
74 mod_offset = randInt(128, 8192);
75 n = n_max; //randInt(128,n_max);
76
77 assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE));
78 assert((mod_offset >= MIN_MOD_OFFSET) && (mod_offset <= MAX_MOD_OFFSET));
79 assert((n >= MIN_TOKENS) && (n <= MAX_TOKENS));
80
81 for (l=0; l<n; l++){
82 int index;
83 for (index = 0; index<MAX_TOKEN_LENGTH; index++) {
84 unsigned char x = input_token[index];
85 assert((x >= MIN_TOKEN_VALUE) && (x <= MAX_TOKEN_VALUE));
86 token[l].delimiter[index] = (unsigned char )x;
87 }
88 token[l].length = index;
89 }
90
91 for (l =0; l<f; l++){
92 field[l] = randInt(MIN_TOKEN_VALUE, MAX_TOKEN_VALUE);
93 }
94
95 for (l =0; l<n; l++){
96 unsigned int index;
97
98 token[l].subfields = 0;
99 token[l].stat[0].count = 0;
100 token[l].stat[0].sum = 0;
101 token[l].stat[0].min = MAX_TOKEN_VALUE;
102
103 index = 0;
104 while ((index < f) && (token[l].subfields < MAX_SUBFIELDS)){
105 unsigned char offset;
106 offset = 0;
107 while ((field[index+offset] == token[l].delimiter[offset]) &&
108 (offset < token[l].length)){
109 offset++;
110 }
111
112 if (offset == token[l].length){
113 for (offset=0; offset<token[l].length; offset++){
114 field[index+offset] = (field[index+offset] +
115 field[(index+offset+mod_offset) % f])
116 %(MAX_TOKEN_VALUE+1);
117 }
118 index += token[l].length-1;
119 token[l].subfields++;
120 token[l].stat[token[l].subfields].count = 0;
121 token[l].stat[token[l].subfields].sum = 0;
122 token[l].stat[token[l].subfields].min = MAX_TOKEN_VALUE;
123 }
124 else {
125 token[l].stat[token[l].subfields].count++;
126 token[l].stat[token[l].subfields].sum += field[index];
127 if (token[l].stat[token[l].subfields].min > field[index])
128 token[l].stat[token[l].subfields].min = field[index];
129 }
130 index++;
131 }
132 }
133
134 return 0;
135}
136
137int post_job() {
138 if (field) {
139 free(field);
140 field = NULL;
141 }
142
143 return(0);
144}
145
146static void usage(char *error) {
147 fprintf(stderr, "Error: %s\n", error);
148 fprintf(stderr,
149 "Usage:\n"
150 " rt_spin [COMMON-OPTS] WCET PERIOD DURATION\n"
151 " rt_spin [COMMON-OPTS] -f FILE [-o COLUMN] WCET PERIOD\n"
152 " rt_spin -l\n"
153 "\n"
154 "COMMON-OPTS = [-w] [-s SCALE]\n"
155 " [-p PARTITION/CLUSTER [-z CLUSTER SIZE]] [-c CLASS] [-m CRITICALITY LEVEL]\n"
156 "\n"
157 "WCET and PERIOD are microseconds, DURATION is seconds.\n");
158 exit(EXIT_FAILURE);
159}
160
161inline unsigned long get_cyclecount (void)
162{
163 unsigned long value;
164 // Read CCNT Register
165 asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));
166 return value;
167}
168
169static int loop_main(double exec_time, double emergency_exit)
170{
171 double last_loop = 0, loop_start;
172 int tmp = 0;
173
174 double start = cputime();
175 double now = cputime();
176
177 while (now + last_loop < start + exec_time) {
178 loop_start = now;
179 tmp += main_job();
180 now = cputime();
181 last_loop = now - loop_start;
182 if (emergency_exit && wctime() > emergency_exit) {
183 /* Oops --- this should only be possible if the execution time tracking
184 * is broken in the LITMUS^RT kernel. */
185 fprintf(stderr, "!!! rtspin/%d emergency exit!\n", getpid());
186 fprintf(stderr, "Something is seriously wrong! Do not ignore this.\n");
187 break;
188 }
189 }
190
191 return tmp;
192}
193
194static int job(double exec_time, double program_end)
195{
196 if (wctime() > program_end)
197 return 0;
198 else {
199 loop_main(exec_time, program_end + 1);
200 sleep_next_period();
201 return 1;
202 }
203}
204
205#define OPTSTR "p:wves:l:m:i:b:"
206int main(int argc, char** argv)
207{
208 int ret;
209 lt_t wcet;
210 lt_t period;
211 lt_t budget;
212 double wcet_ms, period_ms, budget_ms;
213 unsigned int priority = LITMUS_NO_PRIORITY;
214 int migrate = 0;
215 int cluster = 0;
216 int opt;
217 int wait = 0;
218 int want_enforcement = 0;
219 double duration = 0, start = 0;
220 double scale = 1.0;
221 task_class_t class = RT_CLASS_HARD;
222 struct rt_task param;
223 struct mc2_task mc2_param;
224 struct reservation_config config;
225 int res_type = PERIODIC_POLLING;
226
227 progname = argv[0];
228
229 /* default for reservation */
230 config.id = 0;
231 config.priority = LITMUS_NO_PRIORITY; /* use EDF by default */
232 config.cpu = -1;
233
234 mc2_param.crit = CRIT_LEVEL_C;
235
236 budget_ms = 10;
237
238 while ((opt = getopt(argc, argv, OPTSTR)) != -1) {
239 switch (opt) {
240 case 'w':
241 wait = 1;
242 break;
243 case 'p':
244 cluster = atoi(optarg);
245 migrate = 1;
246 config.cpu = cluster;
247 break;
248 case 'e':
249 want_enforcement = 1;
250 break;
251 case 's':
252 scale = atof(optarg);
253 break;
254 case 'l':
255 loops = atoi(optarg);
256 break;
257 case 'm':
258 mc2_param.crit = atoi(optarg);
259 if (mc2_param.crit < CRIT_LEVEL_A || mc2_param.crit == NUM_CRIT_LEVELS) {
260 usage("Invalid criticality level.");
261 }
262 res_type = PERIODIC_POLLING;
263 break;
264 case 'b':
265 budget_ms = atof(optarg);
266 break;
267 case 'i':
268 config.priority = atoi(optarg);
269 break;
270 case ':':
271 usage("Argument missing.");
272 break;
273 case '?':
274 default:
275 usage("Bad argument.");
276 break;
277 }
278 }
279
280 if (mc2_param.crit > CRIT_LEVEL_A && config.priority != LITMUS_NO_PRIORITY)
281 usage("Bad criticailty level or priority");
282
283 if (argc - optind < 3)
284 usage("Arguments missing.");
285
286 wcet_ms = atof(argv[optind + 0]);
287 period_ms = atof(argv[optind + 1]);
288
289 wcet = ms2ns(wcet_ms);
290 period = ms2ns(period_ms);
291 budget = ms2ns(budget_ms);
292
293 if (wcet <= 0)
294 usage("The worst-case execution time must be a "
295 "positive number.");
296 if (period <= 0)
297 usage("The period must be a positive number.");
298 if (wcet > period) {
299 usage("The worst-case execution time must not "
300 "exceed the period.");
301 }
302
303 duration = atof(argv[optind + 2]);
304
305 if (migrate) {
306 ret = be_migrate_to_domain(cluster);
307 if (ret < 0)
308 bail_out("could not migrate to target partition or cluster.");
309 }
310
311 /* reservation config */
312 config.id = gettid();
313
314 config.polling_params.budget = budget;
315 config.polling_params.period = period;
316 config.polling_params.offset = 0;
317 config.polling_params.relative_deadline = 0;
318 if (config.polling_params.budget > config.polling_params.period) {
319 usage("The budget must not exceed the period.");
320 }
321
322 /* create a reservation */
323 ret = reservation_create(res_type, &config);
324 if (ret < 0) {
325 bail_out("failed to create reservation.");
326 }
327 init_job();
328
329 init_rt_task_param(&param);
330 param.exec_cost = wcet;
331 param.period = period;
332 param.priority = priority;
333 param.cls = class;
334 param.release_policy = TASK_PERIODIC;
335 param.budget_policy = (want_enforcement) ?
336 PRECISE_ENFORCEMENT : NO_ENFORCEMENT;
337 if (migrate) {
338 param.cpu = gettid();
339 }
340 ret = set_rt_task_param(gettid(), &param);
341
342 if (ret < 0)
343 bail_out("could not setup rt task params");
344
345 mc2_param.res_id = gettid();
346 ret = set_mc2_task_param(gettid(), &mc2_param);
347//printf("SET_MC2_TASK\n");
348 if (ret < 0)
349 bail_out("could not setup mc2 task params");
350
351 init_litmus();
352//printf("CALL\n");
353 if (mc2_param.crit == CRIT_LEVEL_C)
354 set_page_color(-1);
355 else if (mc2_param.crit < CRIT_LEVEL_C)
356 set_page_color(config.cpu);
357//printf("CALL\n");
358
359//printf("INIT_LITMUS\n");
360 start = wctime();
361 ret = task_mode(LITMUS_RT_TASK);
362//printf("TASK_MODE\n");
363 if (ret != 0)
364 bail_out("could not become RT task");
365
366
367 if (wait) {
368//printf("BEFORE WAIT\n");
369 ret = wait_for_ts_release();
370 if (ret != 0)
371 bail_out("wait_for_ts_release()");
372 start = wctime();
373 }
374
375 while (job(wcet_ms * 0.001 * scale, start + duration)) {};
376
377 ret = task_mode(BACKGROUND_TASK);
378 if (ret != 0)
379 bail_out("could not become regular task (huh?)");
380
381 reservation_destroy(gettid(), config.cpu);
382 post_job();
383 //printf("%s/%d finished.\n",progname, gettid());
384 return 0;
385}