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