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_mode_poll.c | |
parent | bfee87a910560e022b04c81a026b1f88522cd62f (diff) |
RTSS17 submitwip-modechange
Diffstat (limited to 'bin/rt_mode_poll.c')
-rw-r--r-- | bin/rt_mode_poll.c | 102 |
1 files changed, 44 insertions, 58 deletions
diff --git a/bin/rt_mode_poll.c b/bin/rt_mode_poll.c index 08e9490..d05521c 100644 --- a/bin/rt_mode_poll.c +++ b/bin/rt_mode_poll.c | |||
@@ -13,15 +13,14 @@ | |||
13 | #include "litmus.h" | 13 | #include "litmus.h" |
14 | #include "common.h" | 14 | #include "common.h" |
15 | 15 | ||
16 | #define __NR_request_mode 408 | ||
16 | #define __NR_enact_mode 409 | 17 | #define __NR_enact_mode 409 |
17 | 18 | ||
18 | int main_job(void){ | 19 | int main_job(void){ |
19 | syscall(__NR_enact_mode); | 20 | return syscall(__NR_enact_mode); |
20 | } | 21 | } |
21 | 22 | ||
22 | static char* progname; | 23 | static char* progname; |
23 | int loops = 1; | ||
24 | //struct timeval t1, t2; | ||
25 | 24 | ||
26 | static void usage(char *error) { | 25 | static void usage(char *error) { |
27 | fprintf(stderr, "Error: %s\n", error); | 26 | fprintf(stderr, "Error: %s\n", error); |
@@ -38,15 +37,7 @@ static void usage(char *error) { | |||
38 | exit(EXIT_FAILURE); | 37 | exit(EXIT_FAILURE); |
39 | } | 38 | } |
40 | 39 | ||
41 | inline unsigned long get_cyclecount (void) | 40 | static int job(double program_end) |
42 | { | ||
43 | unsigned long value; | ||
44 | // Read CCNT Register | ||
45 | asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value)); | ||
46 | return value; | ||
47 | } | ||
48 | |||
49 | static int job(double exec_time, double program_end) | ||
50 | { | 41 | { |
51 | if (wctime() > program_end) | 42 | if (wctime() > program_end) |
52 | return 0; | 43 | return 0; |
@@ -57,41 +48,40 @@ static int job(double exec_time, double program_end) | |||
57 | } | 48 | } |
58 | } | 49 | } |
59 | 50 | ||
60 | #define OPTSTR "p:wves:l:m:i:b:" | 51 | #define OPTSTR "p:wvel:b:k:" |
61 | int main(int argc, char** argv) | 52 | int main(int argc, char** argv) |
62 | { | 53 | { |
63 | int ret; | 54 | int ret; |
64 | lt_t wcet; | 55 | lt_t wcet; |
65 | lt_t period; | 56 | lt_t period; |
66 | lt_t budget; | 57 | lt_t budget; |
67 | double wcet_us, period_us, budget_us; | 58 | double wcet_ms, period_ms, budget_ms; |
68 | unsigned int priority = LITMUS_NO_PRIORITY; | 59 | unsigned int priority = 0; //guarantee highest priority to this task |
69 | int migrate = 0; | 60 | int migrate = 0; |
70 | int cluster = 0; | 61 | int cluster = 0; |
71 | int opt; | 62 | int opt; |
72 | int wait = 0; | 63 | int wait = 0; |
73 | int want_enforcement = 0; | 64 | int want_enforcement = 0; |
74 | double duration = 0, start = 0; | ||
75 | double scale = 1.0; | ||
76 | task_class_t class = RT_CLASS_HARD; | 65 | task_class_t class = RT_CLASS_HARD; |
77 | struct rt_task param; | 66 | struct rt_task param; |
78 | struct mc2_task mc2_param; | 67 | struct mc2_task mc2_param; |
79 | struct reservation_config config; | 68 | struct reservation_config config; |
80 | int res_type = PERIODIC_POLLING; | 69 | int res_type = PERIODIC_POLLING; |
81 | 70 | uint32_t mode_mask = (1 << 0); | |
82 | unsigned int job_no; | 71 | int i; |
83 | 72 | double duration = 0, start = 0; | |
73 | struct control_page* ctl_page = NULL; | ||
84 | 74 | ||
85 | progname = argv[0]; | 75 | progname = argv[0]; |
86 | 76 | ||
87 | /* default for reservation */ | 77 | /* default for reservation */ |
88 | config.id = 0; | 78 | config.id = 0; |
89 | config.priority = LITMUS_NO_PRIORITY; /* use EDF by default */ | 79 | config.priority = 1; |
90 | config.cpu = -1; | 80 | config.cpu = -1; |
91 | 81 | ||
92 | mc2_param.crit = CRIT_LEVEL_C; | 82 | mc2_param.crit = CRIT_LEVEL_A; |
93 | 83 | ||
94 | budget_us = 10000; | 84 | budget_ms = 10; |
95 | 85 | ||
96 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { | 86 | while ((opt = getopt(argc, argv, OPTSTR)) != -1) { |
97 | switch (opt) { | 87 | switch (opt) { |
@@ -106,24 +96,11 @@ int main(int argc, char** argv) | |||
106 | case 'e': | 96 | case 'e': |
107 | want_enforcement = 1; | 97 | want_enforcement = 1; |
108 | break; | 98 | break; |
109 | case 's': | ||
110 | scale = atof(optarg); | ||
111 | break; | ||
112 | case 'l': | ||
113 | loops = atoi(optarg); | ||
114 | break; | ||
115 | case 'm': | ||
116 | mc2_param.crit = atoi(optarg); | ||
117 | if (mc2_param.crit < CRIT_LEVEL_A || mc2_param.crit == NUM_CRIT_LEVELS) { | ||
118 | usage("Invalid criticality level."); | ||
119 | } | ||
120 | res_type = PERIODIC_POLLING; | ||
121 | break; | ||
122 | case 'b': | 99 | case 'b': |
123 | budget_us = atof(optarg); | 100 | budget_ms = atof(optarg); |
124 | break; | 101 | break; |
125 | case 'i': | 102 | case 'k': |
126 | config.priority = atoi(optarg); | 103 | mode_mask = atoi(optarg); |
127 | break; | 104 | break; |
128 | case ':': | 105 | case ':': |
129 | usage("Argument missing."); | 106 | usage("Argument missing."); |
@@ -138,15 +115,15 @@ int main(int argc, char** argv) | |||
138 | if (mc2_param.crit > CRIT_LEVEL_A && config.priority != LITMUS_NO_PRIORITY) | 115 | if (mc2_param.crit > CRIT_LEVEL_A && config.priority != LITMUS_NO_PRIORITY) |
139 | usage("Bad criticailty level or priority"); | 116 | usage("Bad criticailty level or priority"); |
140 | 117 | ||
141 | if (argc - optind < 3) | 118 | if (argc - optind < 2) |
142 | usage("Arguments missing."); | 119 | usage("Arguments missing."); |
143 | 120 | ||
144 | wcet_us = atof(argv[optind + 0]); | 121 | wcet_ms = atof(argv[optind + 0]); |
145 | period_us = atof(argv[optind + 1]); | 122 | period_ms = atof(argv[optind + 1]); |
146 | 123 | ||
147 | wcet = us2ns(wcet_us); | 124 | wcet = ms2ns(wcet_ms); |
148 | period = us2ns(period_us); | 125 | period = ms2ns(period_ms); |
149 | budget = us2ns(budget_us); | 126 | budget = ms2ns(budget_ms); |
150 | 127 | ||
151 | if (wcet <= 0) | 128 | if (wcet <= 0) |
152 | usage("The worst-case execution time must be a " | 129 | usage("The worst-case execution time must be a " |
@@ -159,12 +136,15 @@ int main(int argc, char** argv) | |||
159 | } | 136 | } |
160 | 137 | ||
161 | duration = atof(argv[optind + 2]); | 138 | duration = atof(argv[optind + 2]); |
162 | 139 | ||
163 | if (migrate) { | 140 | if (migrate) { |
164 | ret = be_migrate_to_domain(cluster); | 141 | ret = be_migrate_to_domain(cluster); |
165 | if (ret < 0) | 142 | if (ret < 0) |
166 | bail_out("could not migrate to target partition or cluster."); | 143 | bail_out("could not migrate to target partition or cluster."); |
167 | } | 144 | } |
145 | else{ | ||
146 | bail_out("rt_mode_poll must be migrated."); | ||
147 | } | ||
168 | 148 | ||
169 | /* reservation config */ | 149 | /* reservation config */ |
170 | config.id = gettid(); | 150 | config.id = gettid(); |
@@ -176,11 +156,16 @@ int main(int argc, char** argv) | |||
176 | if (config.polling_params.budget > config.polling_params.period) { | 156 | if (config.polling_params.budget > config.polling_params.period) { |
177 | usage("The budget must not exceed the period."); | 157 | usage("The budget must not exceed the period."); |
178 | } | 158 | } |
179 | 159 | ||
180 | /* create a reservation */ | 160 | /* create reservation's */ |
181 | ret = reservation_create(res_type, &config); | 161 | for( i = 0; i < 32; i++){ |
182 | if (ret < 0) { | 162 | if ( !( (1 << i) & mode_mask ) ) |
183 | bail_out("failed to create reservation."); | 163 | continue; |
164 | config.mode = i; | ||
165 | ret = reservation_create(res_type, &config); | ||
166 | if (ret < 0) { | ||
167 | bail_out("failed to create reservation."); | ||
168 | } | ||
184 | } | 169 | } |
185 | 170 | ||
186 | init_rt_task_param(¶m); | 171 | init_rt_task_param(¶m); |
@@ -200,21 +185,23 @@ int main(int argc, char** argv) | |||
200 | bail_out("could not setup rt task params"); | 185 | bail_out("could not setup rt task params"); |
201 | 186 | ||
202 | mc2_param.res_id = gettid(); | 187 | mc2_param.res_id = gettid(); |
188 | mc2_param.mode_mask = mode_mask; | ||
203 | ret = set_mc2_task_param(gettid(), &mc2_param); | 189 | ret = set_mc2_task_param(gettid(), &mc2_param); |
204 | if (ret < 0) | 190 | if (ret < 0) |
205 | bail_out("could not setup mc2 task params"); | 191 | bail_out("could not setup mc2 task params"); |
206 | 192 | ||
207 | init_litmus(); | 193 | init_litmus(); |
208 | if (mc2_param.crit == CRIT_LEVEL_C) | 194 | ctl_page = get_ctrl_page(); |
209 | set_page_color(8); | 195 | if (!ctl_page) |
210 | else if (mc2_param.crit < CRIT_LEVEL_C) | 196 | bail_out("could not get ctrl_page"); |
211 | set_page_color(config.cpu*2 + mc2_param.crit); | 197 | ctl_page->mode_poll_task = 1; |
212 | 198 | ||
213 | start = wctime(); | 199 | start = wctime(); |
214 | ret = task_mode(LITMUS_RT_TASK); | 200 | ret = task_mode(LITMUS_RT_TASK); |
215 | if (ret != 0) | 201 | if (ret != 0) |
216 | bail_out("could not become RT task"); | 202 | bail_out("could not become RT task"); |
217 | 203 | ||
204 | set_page_color(config.cpu); | ||
218 | 205 | ||
219 | if (wait) { | 206 | if (wait) { |
220 | ret = wait_for_ts_release(); | 207 | ret = wait_for_ts_release(); |
@@ -223,13 +210,12 @@ int main(int argc, char** argv) | |||
223 | start = wctime(); | 210 | start = wctime(); |
224 | } | 211 | } |
225 | 212 | ||
226 | while (job(wcet_us * 0.000001 * scale, start + duration)) {}; | 213 | while (job(start + duration)) {}; |
227 | 214 | ||
228 | ret = task_mode(BACKGROUND_TASK); | 215 | ret = task_mode(BACKGROUND_TASK); |
229 | if (ret != 0) | 216 | if (ret != 0) |
230 | bail_out("could not become regular task (huh?)"); | 217 | bail_out("could not become regular task (huh?)"); |
231 | 218 | ||
232 | reservation_destroy(gettid(), config.cpu); | 219 | reservation_destroy(gettid(), config.cpu); |
233 | printf("%s/%d finished.\n",progname, gettid()); | ||
234 | return 0; | 220 | return 0; |
235 | } | 221 | } |