diff options
Diffstat (limited to 'bin/mc2spin.c')
-rw-r--r-- | bin/mc2spin.c | 83 |
1 files changed, 27 insertions, 56 deletions
diff --git a/bin/mc2spin.c b/bin/mc2spin.c index 25b1c58..dfb5c80 100644 --- a/bin/mc2spin.c +++ b/bin/mc2spin.c | |||
@@ -14,10 +14,6 @@ | |||
14 | #include "common.h" | 14 | #include "common.h" |
15 | 15 | ||
16 | #define PAGE_SIZE 4096 | 16 | #define PAGE_SIZE 4096 |
17 | #define NUM_ITEMS 8192 | ||
18 | |||
19 | int *pages; | ||
20 | unsigned long *access_order; | ||
21 | 17 | ||
22 | static void usage(char *error) { | 18 | static void usage(char *error) { |
23 | fprintf(stderr, "Error: %s\n", error); | 19 | fprintf(stderr, "Error: %s\n", error); |
@@ -105,46 +101,16 @@ static void get_exec_times(const char *file, const int column, | |||
105 | fclose(fstream); | 101 | fclose(fstream); |
106 | } | 102 | } |
107 | 103 | ||
108 | #define NUMS 4096 | 104 | #define NUMS 16 |
109 | static int num[NUMS]; | 105 | static int num[NUMS]; |
110 | static char* progname; | 106 | static char* progname; |
111 | 107 | ||
112 | static int randrange(const int max) | ||
113 | { | ||
114 | return (rand() / (RAND_MAX / max + 1)); | ||
115 | } | ||
116 | |||
117 | static void sattolo(unsigned long *items, const unsigned long len) | ||
118 | { | ||
119 | unsigned long i; | ||
120 | /* first set up 0, 1, ..., n - 1 */ | ||
121 | for (i = 0; i < len; i++) | ||
122 | items[i] = i; | ||
123 | /* note: i is now n */ | ||
124 | while (1 < i--) { | ||
125 | /* 0 <= j < i */ | ||
126 | int t, j = randrange(i); | ||
127 | t = items[i]; | ||
128 | items[i] = items[j]; | ||
129 | items[j] = t; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | static int loop_once(void) | 108 | static int loop_once(void) |
134 | { | 109 | { |
135 | int i, j = 0; | 110 | int i, j = 0; |
136 | for (i = 0; i < NUMS; i++) | 111 | for (i = 0; i < NUMS; i++) |
137 | j += num[i]++; | 112 | j += num[i]; |
138 | return j; | 113 | return j; |
139 | /* | ||
140 | int i, tmp; | ||
141 | for (i = 0; i < NUM_ITEMS; i++) { | ||
142 | tmp = pages[access_order[i]]; | ||
143 | if (access_order[i] % 3 == 0) | ||
144 | pages[access_order[i]] = i+tmp; | ||
145 | } | ||
146 | return 1; | ||
147 | */ | ||
148 | } | 114 | } |
149 | 115 | ||
150 | static int loop_for(double exec_time, double emergency_exit) | 116 | static int loop_for(double exec_time, double emergency_exit) |
@@ -275,7 +241,7 @@ struct lt_interval* parse_td_intervals(int num, char* optarg, unsigned int *num_ | |||
275 | return slots; | 241 | return slots; |
276 | } | 242 | } |
277 | 243 | ||
278 | #define OPTSTR "p:c:wlveo:f:s:q:X:L:Q:vh:m:i:b:" | 244 | #define OPTSTR "p:c:wlveo:f:s:q:X:L:Q:vh:m:i:b:k:" |
279 | int main(int argc, char** argv) | 245 | int main(int argc, char** argv) |
280 | { | 246 | { |
281 | int ret; | 247 | int ret; |
@@ -302,7 +268,8 @@ int main(int argc, char** argv) | |||
302 | struct mc2_task mc2_param; | 268 | struct mc2_task mc2_param; |
303 | struct reservation_config config; | 269 | struct reservation_config config; |
304 | int res_type = PERIODIC_POLLING; | 270 | int res_type = PERIODIC_POLLING; |
305 | int n_str, num_int = 0; | 271 | int i; |
272 | uint32_t mode_mask; | ||
306 | 273 | ||
307 | int verbose = 0; | 274 | int verbose = 0; |
308 | unsigned int job_no; | 275 | unsigned int job_no; |
@@ -395,6 +362,9 @@ int main(int argc, char** argv) | |||
395 | case 'i': | 362 | case 'i': |
396 | config.priority = atoi(optarg); | 363 | config.priority = atoi(optarg); |
397 | break; | 364 | break; |
365 | case 'k': | ||
366 | mode_mask = atoi(optarg); | ||
367 | break; | ||
398 | case ':': | 368 | case ':': |
399 | usage("Argument missing."); | 369 | usage("Argument missing."); |
400 | break; | 370 | break; |
@@ -410,8 +380,16 @@ int main(int argc, char** argv) | |||
410 | return 0; | 380 | return 0; |
411 | } | 381 | } |
412 | 382 | ||
413 | if (mc2_param.crit > CRIT_LEVEL_A && config.priority != LITMUS_NO_PRIORITY) | 383 | if (mc2_param.crit == CRIT_LEVEL_A && config.priority == LITMUS_NO_PRIORITY) |
414 | usage("Bad criticailty level or priority"); | 384 | usage("Bad criticailty level or priority"); |
385 | if (mc2_param.crit == CRIT_LEVEL_B) { | ||
386 | config.priority = LITMUS_NO_PRIORITY; | ||
387 | } | ||
388 | |||
389 | if (mc2_param.crit == CRIT_LEVEL_C) { | ||
390 | config.priority = LITMUS_NO_PRIORITY; | ||
391 | config.cpu = -1; | ||
392 | } | ||
415 | 393 | ||
416 | srand(getpid()); | 394 | srand(getpid()); |
417 | 395 | ||
@@ -477,11 +455,15 @@ int main(int argc, char** argv) | |||
477 | if (config.polling_params.budget > config.polling_params.period) { | 455 | if (config.polling_params.budget > config.polling_params.period) { |
478 | usage("The budget must not exceed the period."); | 456 | usage("The budget must not exceed the period."); |
479 | } | 457 | } |
480 | |||
481 | /* create a reservation */ | 458 | /* create a reservation */ |
482 | ret = reservation_create(res_type, &config); | 459 | for(i = 0; i < 32; i++){ |
483 | if (ret < 0) { | 460 | if ( !( (1 << i) & mode_mask) ) |
484 | bail_out("failed to create reservation."); | 461 | continue; |
462 | config.mode = i; | ||
463 | ret = reservation_create(res_type, &config); | ||
464 | if (ret < 0) { | ||
465 | bail_out("failed to create reservation."); | ||
466 | } | ||
485 | } | 467 | } |
486 | 468 | ||
487 | init_rt_task_param(¶m); | 469 | init_rt_task_param(¶m); |
@@ -501,24 +483,19 @@ int main(int argc, char** argv) | |||
501 | bail_out("could not setup rt task params"); | 483 | bail_out("could not setup rt task params"); |
502 | 484 | ||
503 | mc2_param.res_id = gettid(); | 485 | mc2_param.res_id = gettid(); |
486 | mc2_param.mode_mask = mode_mask; | ||
504 | ret = set_mc2_task_param(gettid(), &mc2_param); | 487 | ret = set_mc2_task_param(gettid(), &mc2_param); |
505 | //printf("SET_MC2_TASK\n"); | 488 | //printf("SET_MC2_TASK\n"); |
506 | if (ret < 0) | 489 | if (ret < 0) |
507 | bail_out("could not setup mc2 task params"); | 490 | bail_out("could not setup mc2 task params"); |
508 | 491 | ||
509 | pages = (int*)malloc(sizeof(int)*NUM_ITEMS); | ||
510 | access_order = (unsigned long*)malloc(sizeof(unsigned long)*NUM_ITEMS); | ||
511 | sattolo(access_order, NUM_ITEMS); | ||
512 | |||
513 | init_litmus(); | 492 | init_litmus(); |
514 | printf("CALL\n"); | ||
515 | set_page_color(config.cpu); | ||
516 | printf("CALL\n"); | ||
517 | 493 | ||
518 | //printf("INIT_LITMUS\n"); | 494 | //printf("INIT_LITMUS\n"); |
519 | start = wctime(); | 495 | start = wctime(); |
520 | ret = task_mode(LITMUS_RT_TASK); | 496 | ret = task_mode(LITMUS_RT_TASK); |
521 | //printf("TASK_MODE\n"); | 497 | //printf("TASK_MODE\n"); |
498 | set_page_color(config.cpu); | ||
522 | if (ret != 0) | 499 | if (ret != 0) |
523 | bail_out("could not become RT task"); | 500 | bail_out("could not become RT task"); |
524 | 501 | ||
@@ -555,7 +532,6 @@ printf("CALL\n"); | |||
555 | } while (job(wcet_ms * 0.001 * scale, start + duration, | 532 | } while (job(wcet_ms * 0.001 * scale, start + duration, |
556 | lock_od, cs_length * 0.001)); | 533 | lock_od, cs_length * 0.001)); |
557 | } | 534 | } |
558 | printf("BEFORE BACK_TASK\n"); | ||
559 | ret = task_mode(BACKGROUND_TASK); | 535 | ret = task_mode(BACKGROUND_TASK); |
560 | if (ret != 0) | 536 | if (ret != 0) |
561 | bail_out("could not become regular task (huh?)"); | 537 | bail_out("could not become regular task (huh?)"); |
@@ -565,10 +541,5 @@ printf("BEFORE BACK_TASK\n"); | |||
565 | 541 | ||
566 | reservation_destroy(gettid(), config.cpu); | 542 | reservation_destroy(gettid(), config.cpu); |
567 | 543 | ||
568 | printf("CALL\n"); | ||
569 | set_page_color(config.cpu); | ||
570 | printf("CALL\n"); | ||
571 | free(pages); | ||
572 | free(access_order); | ||
573 | return 0; | 544 | return 0; |
574 | } | 545 | } |