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