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