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