Rev 1207 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1199 | giacomo | 1 | #include <kernel/kern.h> |
2 | #include "parser.h" |
||
1200 | giacomo | 3 | #include "dosread.h" |
1199 | giacomo | 4 | |
1203 | giacomo | 5 | /* Memory pointers on loaded file */ |
1208 | giacomo | 6 | extern void *start_file; |
7 | extern void *end_file; |
||
1200 | giacomo | 8 | |
1203 | giacomo | 9 | /* Calibration Loops */ |
1207 | giacomo | 10 | #define CALIBRATION_DELTA 100000 |
1203 | giacomo | 11 | |
1206 | giacomo | 12 | /* Mutex number */ |
13 | #define MAX_MUTEX 10 |
||
14 | |||
1203 | giacomo | 15 | /* Activate task output */ |
16 | #define TASK_OUTPUT |
||
17 | |||
1202 | giacomo | 18 | struct timespec zero_time; |
1203 | giacomo | 19 | int cal_cycles = 0; |
20 | int cal_rit_start = 0; |
||
21 | int cal_rit_calc_const = 0; |
||
22 | int cal_rit_calc_mean = 0; |
||
23 | int cal_rit_calc_gauss = 0; |
||
1202 | giacomo | 24 | |
1206 | giacomo | 25 | mutex_t mux_table[MAX_MUTEX]; |
26 | |||
1203 | giacomo | 27 | /* Not Real-Time Task */ |
1201 | giacomo | 28 | TASK nrt_test_task(void *arg) |
29 | { |
||
1203 | giacomo | 30 | long long i,exec_cycles = 0; |
31 | int exec_1,exec_2,exec_3; |
||
32 | int act_1,act_2,act_3,next_act; |
||
1206 | giacomo | 33 | int crit_1 = 0,crit_2 = 0,crit_3 = 0,crit_4 = 0; |
34 | int crit_start,crit_len; |
||
35 | long long crit_start_cycles = 0, crit_len_cycles = 0; |
||
1203 | giacomo | 36 | struct timespec next_time; |
37 | static int act= 0; |
||
38 | struct loader_task *l = (struct loader_task *)(arg); |
||
39 | |||
40 | act++; |
||
41 | |||
42 | act_1 = TIMESPEC2USEC(&l->act_par_2); |
||
43 | act_2 = TIMESPEC2USEC(&l->act_par_3); |
||
44 | act_3 = TIMESPEC2USEC(&l->act_par_4); |
||
1202 | giacomo | 45 | |
1203 | giacomo | 46 | if (l->act_type == PAR_ACT_PERIODIC) { |
47 | kern_gettime(&next_time); |
||
48 | ADDUSEC2TIMESPEC(act_1,&next_time); |
||
49 | kern_event_post(&next_time,(void *)((void *)task_activate),(void *)exec_shadow); |
||
50 | } |
||
1201 | giacomo | 51 | |
1203 | giacomo | 52 | if (l->act_type == PAR_ACT_MEAN) { |
53 | next_act = act_1 + rand() % act_2 - act_2/2; |
||
54 | kern_gettime(&next_time); |
||
55 | ADDUSEC2TIMESPEC(next_act,&next_time); |
||
56 | kern_event_post(&next_time,(void *)((void *)task_activate),(void *)exec_shadow); |
||
57 | } |
||
1202 | giacomo | 58 | |
1203 | giacomo | 59 | if (l->act_type == PAR_ACT_GAUSS) { |
1201 | giacomo | 60 | } |
1203 | giacomo | 61 | |
62 | if (l->act_type == PAR_ACT_GAUSS_MAX) { |
||
63 | } |
||
64 | |||
65 | exec_1 = TIMESPEC2USEC(&l->exec_par_1); |
||
66 | exec_2 = TIMESPEC2USEC(&l->exec_par_2); |
||
67 | exec_3 = TIMESPEC2USEC(&l->exec_par_3); |
||
1205 | giacomo | 68 | |
1206 | giacomo | 69 | if (l->crit_type == PAR_CRIT) { |
70 | crit_1 = TIMESPEC2USEC(&l->crit_par_1); |
||
71 | crit_2 = TIMESPEC2USEC(&l->crit_par_2); |
||
72 | crit_3 = TIMESPEC2USEC(&l->crit_par_3); |
||
73 | crit_4 = TIMESPEC2USEC(&l->crit_par_4); |
||
74 | } |
||
75 | |||
1205 | giacomo | 76 | #ifdef TASK_OUTPUT |
1206 | giacomo | 77 | printf_xy(exec_shadow % 20 + 60, exec_shadow / 20, GREEN, "R"); |
1205 | giacomo | 78 | #endif |
79 | |||
1203 | giacomo | 80 | if (l->exec_type == PAR_EXEC_CONST) |
81 | exec_cycles = (long long)(exec_1 - cal_rit_start - cal_rit_calc_const) |
||
82 | * CALIBRATION_DELTA / cal_cycles; |
||
83 | |||
84 | if (l->exec_type == PAR_EXEC_MEAN) |
||
85 | exec_cycles = (long long)(exec_1 - cal_rit_start - cal_rit_calc_mean |
||
86 | + rand() % exec_2 - exec_2/2) * CALIBRATION_DELTA / cal_cycles; |
||
87 | |||
88 | if (l->exec_type == PAR_EXEC_GAUSS) |
||
89 | exec_cycles = 0; |
||
90 | |||
91 | if (l->exec_type == PAR_EXEC_GAUSS_MAX) |
||
92 | exec_cycles = 0; |
||
93 | |||
1206 | giacomo | 94 | if (l->crit_type == PAR_CRIT) { |
95 | crit_start = crit_1 + rand() % crit_2 - crit_2/2; |
||
96 | crit_len = crit_3 + rand() % crit_4 - crit_4/2; |
||
97 | crit_start_cycles = (long long)(crit_start) * CALIBRATION_DELTA / cal_cycles; |
||
98 | crit_len_cycles = (long long)(crit_len) * CALIBRATION_DELTA / cal_cycles; |
||
99 | exec_cycles -= crit_start_cycles + crit_len_cycles; |
||
100 | if (exec_cycles < 0) { |
||
101 | cprintf("Error: exec_cycles < 0\n"); |
||
102 | sys_end(); |
||
103 | } |
||
104 | } |
||
1205 | giacomo | 105 | |
1206 | giacomo | 106 | if (l->crit_type == PAR_NO_CRIT) |
1207 | giacomo | 107 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 108 | else { |
1207 | giacomo | 109 | for (i=0;i<crit_start_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 110 | #ifdef TASK_OUTPUT |
111 | printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, RED,"B"); |
||
112 | #endif |
||
113 | mutex_lock(&mux_table[l->resource]); |
||
1207 | giacomo | 114 | for (i=0;i<crit_len_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 115 | mutex_unlock(&mux_table[l->resource]); |
116 | #ifdef TASK_OUTPUT |
||
117 | printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, GREEN,"R"); |
||
118 | #endif |
||
1207 | giacomo | 119 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 120 | } |
121 | |||
1205 | giacomo | 122 | #ifdef TASK_OUTPUT |
123 | printf_xy(exec_shadow % 20 + 60, exec_shadow / 20, WHITE, "E"); |
||
124 | #endif |
||
1203 | giacomo | 125 | |
1201 | giacomo | 126 | return NULL; |
1203 | giacomo | 127 | |
1201 | giacomo | 128 | } |
129 | |||
1203 | giacomo | 130 | /* Soft and hard Task */ |
1201 | giacomo | 131 | TASK test_task(void *arg) |
132 | { |
||
1203 | giacomo | 133 | long long i,exec_cycles = 0; |
134 | int exec_1,exec_2,exec_3; |
||
135 | int act_1,act_2,act_3,next_act; |
||
1206 | giacomo | 136 | int crit_1 = 0,crit_2 = 0,crit_3 = 0,crit_4 = 0; |
137 | int crit_start,crit_len; |
||
138 | long long crit_start_cycles = 0, crit_len_cycles = 0; |
||
1203 | giacomo | 139 | struct timespec next_time; |
140 | static int act=0; |
||
1205 | giacomo | 141 | int extra_rit, k; |
1203 | giacomo | 142 | struct loader_task *l = (struct loader_task *)(arg); |
143 | |||
144 | act++; |
||
145 | |||
146 | act_1 = TIMESPEC2USEC(&l->act_par_2); |
||
147 | act_2 = TIMESPEC2USEC(&l->act_par_3); |
||
148 | act_3 = TIMESPEC2USEC(&l->act_par_4); |
||
149 | |||
150 | exec_1 = TIMESPEC2USEC(&l->exec_par_1); |
||
151 | exec_2 = TIMESPEC2USEC(&l->exec_par_2); |
||
152 | exec_3 = TIMESPEC2USEC(&l->exec_par_3); |
||
1202 | giacomo | 153 | |
1203 | giacomo | 154 | extra_rit = cal_rit_start; |
1205 | giacomo | 155 | |
1206 | giacomo | 156 | if (l->crit_type == PAR_CRIT) { |
157 | crit_1 = TIMESPEC2USEC(&l->crit_par_1); |
||
158 | crit_2 = TIMESPEC2USEC(&l->crit_par_2); |
||
159 | crit_3 = TIMESPEC2USEC(&l->crit_par_3); |
||
160 | crit_4 = TIMESPEC2USEC(&l->crit_par_4); |
||
161 | } |
||
162 | |||
1205 | giacomo | 163 | k = 0; |
164 | |||
1201 | giacomo | 165 | while(1) { |
166 | |||
1203 | giacomo | 167 | task_testcancel(); |
1202 | giacomo | 168 | |
1205 | giacomo | 169 | #ifdef TASK_OUTPUT |
170 | k++; |
||
171 | if (k > 15) k = 1; |
||
172 | printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X"); |
||
173 | #endif |
||
174 | |||
1203 | giacomo | 175 | if (l->act_type == PAR_ACT_MEAN) { |
176 | next_act = act_1 + rand() % act_2 - act_2/2; |
||
177 | kern_gettime(&next_time); |
||
178 | ADDUSEC2TIMESPEC(next_act,&next_time); |
||
179 | kern_event_post(&next_time,(void *)((void *)task_activate),(void *)exec_shadow); |
||
180 | } |
||
181 | |||
182 | if (l->act_type == PAR_ACT_GAUSS) { |
||
183 | } |
||
184 | |||
185 | if (l->act_type == PAR_ACT_GAUSS_MAX) { |
||
186 | } |
||
187 | |||
188 | if (l->exec_type == PAR_EXEC_CONST) |
||
189 | exec_cycles = (long long)(exec_1 - extra_rit - cal_rit_calc_const) |
||
190 | * CALIBRATION_DELTA / cal_cycles; |
||
191 | |||
192 | if (l->exec_type == PAR_EXEC_MEAN) |
||
193 | exec_cycles = (long long)(exec_1 - extra_rit - cal_rit_calc_mean |
||
194 | + rand() % exec_2 - exec_2/2) * CALIBRATION_DELTA / cal_cycles; |
||
195 | |||
196 | if (l->exec_type == PAR_EXEC_GAUSS) |
||
197 | exec_cycles = 0; |
||
198 | |||
199 | if (l->exec_type == PAR_EXEC_GAUSS_MAX) |
||
200 | exec_cycles = 0; |
||
1206 | giacomo | 201 | |
202 | if (l->crit_type == PAR_CRIT) { |
||
203 | crit_start = crit_1 + rand() % crit_2 - crit_2/2; |
||
204 | crit_len = crit_3 + rand() % crit_4 - crit_4/2; |
||
205 | crit_start_cycles = (long long)(crit_start) * CALIBRATION_DELTA / cal_cycles; |
||
206 | crit_len_cycles = (long long)(crit_len) * CALIBRATION_DELTA / cal_cycles; |
||
207 | exec_cycles -= crit_start_cycles + crit_len_cycles; |
||
208 | if (exec_cycles < 0) { |
||
209 | cprintf("Error: exec_cycles < 0\n"); |
||
210 | sys_end(); |
||
211 | } |
||
212 | } |
||
213 | |||
1203 | giacomo | 214 | extra_rit = 0; |
215 | |||
1206 | giacomo | 216 | if (l->crit_type == PAR_NO_CRIT) |
1207 | giacomo | 217 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 218 | else { |
1207 | giacomo | 219 | for (i=0;i<crit_start_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 220 | #ifdef TASK_OUTPUT |
221 | printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"B"); |
||
222 | #endif |
||
223 | mutex_lock(&mux_table[l->resource]); |
||
1207 | giacomo | 224 | for (i=0;i<crit_len_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 225 | mutex_unlock(&mux_table[l->resource]); |
226 | #ifdef TASK_OUTPUT |
||
227 | printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X"); |
||
228 | #endif |
||
1207 | giacomo | 229 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 230 | } |
1203 | giacomo | 231 | |
1201 | giacomo | 232 | task_endcycle(); |
1203 | giacomo | 233 | |
1201 | giacomo | 234 | } |
1203 | giacomo | 235 | |
1201 | giacomo | 236 | return NULL; |
1203 | giacomo | 237 | |
238 | } |
||
1201 | giacomo | 239 | |
1208 | giacomo | 240 | /* Background Task */ |
241 | TASK back_task(void *arg) |
||
242 | { |
||
243 | long long i,exec_cycles = 0; |
||
244 | int exec_1,exec_2,exec_3; |
||
245 | int act_1,act_2,act_3,next_act; |
||
246 | int crit_1 = 0,crit_2 = 0,crit_3 = 0,crit_4 = 0; |
||
247 | int crit_start,crit_len; |
||
248 | long long crit_start_cycles = 0, crit_len_cycles = 0; |
||
249 | struct timespec next_time; |
||
250 | static int act=0; |
||
251 | int extra_rit, k; |
||
252 | struct loader_task *l = (struct loader_task *)(arg); |
||
253 | |||
254 | act++; |
||
255 | |||
256 | act_1 = TIMESPEC2USEC(&l->act_par_2); |
||
257 | act_2 = TIMESPEC2USEC(&l->act_par_3); |
||
258 | act_3 = TIMESPEC2USEC(&l->act_par_4); |
||
259 | |||
260 | exec_1 = TIMESPEC2USEC(&l->exec_par_1); |
||
261 | exec_2 = TIMESPEC2USEC(&l->exec_par_2); |
||
262 | exec_3 = TIMESPEC2USEC(&l->exec_par_3); |
||
263 | |||
264 | extra_rit = cal_rit_start; |
||
265 | |||
266 | if (l->crit_type == PAR_CRIT) { |
||
267 | crit_1 = TIMESPEC2USEC(&l->crit_par_1); |
||
268 | crit_2 = TIMESPEC2USEC(&l->crit_par_2); |
||
269 | crit_3 = TIMESPEC2USEC(&l->crit_par_3); |
||
270 | crit_4 = TIMESPEC2USEC(&l->crit_par_4); |
||
271 | } |
||
272 | |||
273 | k = 0; |
||
274 | |||
275 | while(1) { |
||
276 | |||
277 | task_testcancel(); |
||
278 | |||
279 | #ifdef TASK_OUTPUT |
||
280 | k++; |
||
281 | if (k > 15) k = 1; |
||
282 | printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X"); |
||
283 | #endif |
||
284 | |||
285 | if (l->act_type == PAR_ACT_MEAN) { |
||
286 | next_act = act_1 + rand() % act_2 - act_2/2; |
||
287 | kern_gettime(&next_time); |
||
288 | ADDUSEC2TIMESPEC(next_act,&next_time); |
||
289 | kern_event_post(&next_time,(void *)((void *)task_activate),(void *)exec_shadow); |
||
290 | } |
||
291 | |||
292 | if (l->act_type == PAR_ACT_GAUSS) { |
||
293 | } |
||
294 | |||
295 | if (l->act_type == PAR_ACT_GAUSS_MAX) { |
||
296 | } |
||
297 | |||
298 | if (l->exec_type == PAR_EXEC_CONST) |
||
299 | exec_cycles = (long long)(exec_1 - extra_rit - cal_rit_calc_const) |
||
300 | * CALIBRATION_DELTA / cal_cycles; |
||
301 | |||
302 | if (l->exec_type == PAR_EXEC_MEAN) |
||
303 | exec_cycles = (long long)(exec_1 - extra_rit - cal_rit_calc_mean |
||
304 | + rand() % exec_2 - exec_2/2) * CALIBRATION_DELTA / cal_cycles; |
||
305 | |||
306 | if (l->exec_type == PAR_EXEC_GAUSS) |
||
307 | exec_cycles = 0; |
||
308 | |||
309 | if (l->exec_type == PAR_EXEC_GAUSS_MAX) |
||
310 | exec_cycles = 0; |
||
311 | |||
312 | if (l->crit_type == PAR_CRIT) { |
||
313 | crit_start = crit_1 + rand() % crit_2 - crit_2/2; |
||
314 | crit_len = crit_3 + rand() % crit_4 - crit_4/2; |
||
315 | crit_start_cycles = (long long)(crit_start) * CALIBRATION_DELTA / cal_cycles; |
||
316 | crit_len_cycles = (long long)(crit_len) * CALIBRATION_DELTA / cal_cycles; |
||
317 | exec_cycles -= crit_start_cycles + crit_len_cycles; |
||
318 | if (exec_cycles < 0) { |
||
319 | cprintf("Error: exec_cycles < 0\n"); |
||
320 | sys_end(); |
||
321 | } |
||
322 | } |
||
323 | |||
324 | extra_rit = 0; |
||
325 | |||
326 | if (l->crit_type == PAR_NO_CRIT) |
||
327 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
||
328 | else { |
||
329 | for (i=0;i<crit_start_cycles;i++) kern_gettime(NULL); |
||
330 | #ifdef TASK_OUTPUT |
||
331 | printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"B"); |
||
332 | #endif |
||
333 | mutex_lock(&mux_table[l->resource]); |
||
334 | for (i=0;i<crit_len_cycles;i++) kern_gettime(NULL); |
||
335 | mutex_unlock(&mux_table[l->resource]); |
||
336 | #ifdef TASK_OUTPUT |
||
337 | printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X"); |
||
338 | #endif |
||
339 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
||
340 | } |
||
341 | |||
342 | } |
||
343 | |||
344 | return NULL; |
||
345 | |||
346 | } |
||
347 | |||
1203 | giacomo | 348 | /* Delay Calibration */ |
349 | int calibrate_cycle() |
||
350 | { |
||
351 | long long i; |
||
352 | struct timespec start,end,diff; |
||
353 | int temp = 1234567; |
||
354 | int temp_1 = 1234567; |
||
355 | int temp_2 = 1234567; |
||
356 | |||
357 | kern_cli(); |
||
358 | kern_gettime(&start); |
||
1207 | giacomo | 359 | for (i=0;i<CALIBRATION_DELTA;i++) kern_gettime(NULL); |
1203 | giacomo | 360 | kern_gettime(&end); |
361 | kern_sti(); |
||
362 | |||
363 | SUBTIMESPEC(&end,&start,&diff); |
||
364 | cal_cycles = TIMESPEC2USEC(&diff); |
||
365 | |||
366 | cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles); |
||
367 | |||
368 | kern_cli(); |
||
369 | kern_gettime(&start); |
||
370 | temp = (long long)(temp_1) * CALIBRATION_DELTA / cal_cycles; |
||
371 | kern_gettime(&end); |
||
372 | kern_sti(); |
||
373 | |||
374 | SUBTIMESPEC(&end,&start,&diff); |
||
375 | cal_rit_calc_const = TIMESPEC2USEC(&diff); |
||
376 | |||
377 | kern_cli(); |
||
378 | kern_gettime(&start); |
||
379 | temp = (long long)(temp_1 + rand() % temp_2 - temp_2/2) * CALIBRATION_DELTA / cal_cycles; |
||
380 | kern_gettime(&end); |
||
381 | kern_sti(); |
||
382 | |||
383 | SUBTIMESPEC(&end,&start,&diff); |
||
384 | cal_rit_calc_mean = TIMESPEC2USEC(&diff); |
||
385 | |||
386 | kern_cli(); |
||
387 | kern_gettime(&start); |
||
388 | temp = TIMESPEC2USEC(&start); |
||
389 | kern_gettime(&end); |
||
390 | kern_sti(); |
||
391 | |||
392 | SUBTIMESPEC(&end,&start,&diff); |
||
393 | cal_rit_start = TIMESPEC2USEC(&diff) * 6 + cal_rit_calc_const; |
||
394 | |||
395 | cprintf("Calibration delay start = %d const = %d mean = %d gauss = %d\n", |
||
396 | cal_rit_start,cal_rit_calc_const,cal_rit_calc_mean,cal_rit_calc_gauss); |
||
397 | |||
398 | return 0; |
||
399 | |||
1201 | giacomo | 400 | } |
401 | |||
1206 | giacomo | 402 | /* Mutex create */ |
403 | void loader_mutex_create(struct loader_task *start_loader_task) |
||
404 | { |
||
405 | |||
406 | struct loader_task *current = start_loader_task; |
||
407 | int res = 0; |
||
408 | PI_mutexattr_t a; |
||
409 | |||
410 | PI_mutexattr_default(a); |
||
411 | |||
412 | while (current != NULL) { |
||
413 | |||
414 | if (current->crit_type == PAR_CRIT) { |
||
415 | mutex_init(&mux_table[current->resource],&a); |
||
416 | res++; |
||
417 | } |
||
418 | |||
419 | current = current->next; |
||
420 | |||
421 | } |
||
422 | |||
423 | cprintf("Created %d mutex\n",res); |
||
424 | |||
425 | } |
||
426 | |||
1203 | giacomo | 427 | /* Task create */ |
1201 | giacomo | 428 | void loader_task_create(struct loader_task *start_loader_task) |
429 | { |
||
430 | |||
431 | struct loader_task *current = start_loader_task; |
||
1203 | giacomo | 432 | char tmp[30]; |
1201 | giacomo | 433 | int i, total_task; |
1202 | giacomo | 434 | int total_group = 0; |
1201 | giacomo | 435 | PID p; |
436 | |||
437 | total_task = 0; |
||
438 | |||
439 | while (current != NULL) { |
||
440 | |||
1202 | giacomo | 441 | total_group++; |
442 | current->group = total_group; |
||
1203 | giacomo | 443 | current->bandwidth = 0; |
1202 | giacomo | 444 | |
1201 | giacomo | 445 | for (i=0; i < current->number; i++) { |
446 | |||
447 | if (current->task_type == PAR_TASK_NRT) { |
||
448 | NRT_TASK_MODEL nrt; |
||
449 | |||
450 | nrt_task_default_model(nrt); |
||
451 | nrt_task_def_save_arrivals(nrt); |
||
452 | nrt_task_def_arg(nrt,(void *)(current)); |
||
453 | nrt_task_def_ctrl_jet(nrt); |
||
454 | nrt_task_def_level(nrt,current->task_level); |
||
1202 | giacomo | 455 | nrt_task_def_group(nrt,total_group); |
1201 | giacomo | 456 | |
1203 | giacomo | 457 | sprintf(tmp,"NRT %d:%d",current->group,i); |
458 | p = task_create(tmp,nrt_test_task,&nrt,NULL); |
||
1201 | giacomo | 459 | if (p == NIL) { |
460 | cprintf("Error nrt task creating\n"); |
||
461 | sys_end(); |
||
462 | } |
||
463 | |||
464 | total_task++; |
||
465 | |||
466 | } |
||
467 | |||
1208 | giacomo | 468 | if (current->task_type == PAR_TASK_BACK) { |
469 | NRT_TASK_MODEL nrt; |
||
470 | |||
471 | nrt_task_default_model(nrt); |
||
472 | nrt_task_def_save_arrivals(nrt); |
||
473 | nrt_task_def_arg(nrt,(void *)(current)); |
||
474 | nrt_task_def_ctrl_jet(nrt); |
||
475 | nrt_task_def_level(nrt,current->task_level); |
||
476 | nrt_task_def_group(nrt,total_group); |
||
477 | |||
478 | sprintf(tmp,"BACK %d:%d",current->group,i); |
||
479 | p = task_create(tmp,back_task,&nrt,NULL); |
||
480 | if (p == NIL) { |
||
481 | cprintf("Error back task creating\n"); |
||
482 | sys_end(); |
||
483 | } |
||
484 | |||
485 | total_task++; |
||
486 | |||
487 | } |
||
488 | |||
1201 | giacomo | 489 | if (current->task_type == PAR_TASK_HARD) { |
490 | HARD_TASK_MODEL ht; |
||
491 | |||
492 | hard_task_default_model(ht); |
||
493 | hard_task_def_arg(ht,(void *)(current)); |
||
494 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
495 | hard_task_def_ctrl_jet(ht); |
||
496 | hard_task_def_level(ht,current->task_level); |
||
1202 | giacomo | 497 | hard_task_def_group(ht,total_group); |
1201 | giacomo | 498 | |
1203 | giacomo | 499 | if (current->act_type != PAR_ACT_PERIODIC) { |
500 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
||
501 | current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(¤t->deadline) |
||
502 | * TIMESPEC2USEC(¤t->wcet); |
||
1201 | giacomo | 503 | hard_task_def_aperiodic(ht); |
504 | } else { |
||
1203 | giacomo | 505 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->act_par_2)); |
506 | current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(¤t->act_par_2) |
||
507 | * TIMESPEC2USEC(¤t->wcet); |
||
1201 | giacomo | 508 | } |
1203 | giacomo | 509 | |
510 | sprintf(tmp,"HARD %d:%d",current->group,i); |
||
511 | p = task_create(tmp,test_task,&ht,NULL); |
||
1201 | giacomo | 512 | if (p == NIL) { |
513 | cprintf("Error hard task creating\n"); |
||
514 | sys_end(); |
||
515 | } |
||
516 | |||
517 | total_task++; |
||
518 | |||
519 | } |
||
520 | |||
521 | if (current->task_type == PAR_TASK_SOFT) { |
||
522 | SOFT_TASK_MODEL st; |
||
523 | |||
524 | soft_task_default_model(st); |
||
525 | soft_task_def_save_arrivals(st); |
||
526 | soft_task_def_arg(st,(void *)(current)); |
||
527 | soft_task_def_met(st,TIMESPEC2USEC(¤t->wcet)); |
||
528 | soft_task_def_ctrl_jet(st); |
||
529 | soft_task_def_level(st,current->task_level); |
||
1202 | giacomo | 530 | soft_task_def_group(st,total_group); |
531 | |||
1201 | giacomo | 532 | if (current->act_type == PAR_ACT_PERIODIC) { |
533 | soft_task_def_period(st,TIMESPEC2USEC(¤t->act_par_2)); |
||
1203 | giacomo | 534 | current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(¤t->act_par_2) |
535 | * TIMESPEC2USEC(¤t->wcet); |
||
1201 | giacomo | 536 | } else if (current->act_type != PAR_ACT_SINGLE) { |
537 | soft_task_def_period(st,TIMESPEC2USEC(¤t->act_par_2)); |
||
1203 | giacomo | 538 | current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(¤t->act_par_2) |
539 | * TIMESPEC2USEC(¤t->wcet); |
||
1201 | giacomo | 540 | soft_task_def_aperiodic(st); |
541 | } else { |
||
1203 | giacomo | 542 | soft_task_def_period(st,TIMESPEC2USEC(¤t->wcet)*1000); |
543 | current->bandwidth += MAX_BANDWIDTH / 1000; |
||
1201 | giacomo | 544 | soft_task_def_aperiodic(st); |
545 | } |
||
1203 | giacomo | 546 | |
547 | sprintf(tmp,"SOFT %d:%d",current->group,i); |
||
548 | p = task_create(tmp,test_task,&st,NULL); |
||
1201 | giacomo | 549 | if (p == NIL) { |
550 | cprintf("Error soft task creating\n"); |
||
551 | sys_end(); |
||
552 | } |
||
553 | |||
554 | total_task++; |
||
555 | |||
556 | } |
||
557 | |||
558 | } |
||
559 | |||
1203 | giacomo | 560 | cprintf("Task group %d created. Worst case BW = %d.%d \n", |
561 | current->group,(int)( (long long)current->bandwidth * 100 / MAX_BANDWIDTH), |
||
562 | (int)( (long long)current->bandwidth* 100000 / MAX_BANDWIDTH % 1000)); |
||
563 | |||
1201 | giacomo | 564 | current = current->next; |
565 | |||
566 | } |
||
567 | |||
568 | cprintf("Created %d tasks\n",total_task); |
||
569 | |||
570 | } |
||
571 | |||
1203 | giacomo | 572 | /* Set the first extivation events */ |
1202 | giacomo | 573 | void loader_first_execution(struct loader_task *start_loader_task) |
574 | { |
||
575 | |||
576 | struct loader_task *current = start_loader_task; |
||
577 | struct timespec start_time; |
||
578 | |||
579 | while (current != NULL) { |
||
580 | |||
581 | ADDTIMESPEC(&zero_time,¤t->act_par_1,&start_time); |
||
582 | |||
583 | kern_event_post(&start_time, (void *)((void *)group_activate), (void *)(current->group)); |
||
584 | |||
585 | current = current->next; |
||
586 | |||
587 | } |
||
588 | |||
589 | } |
||
590 | |||
1199 | giacomo | 591 | int main() |
592 | { |
||
593 | |||
1200 | giacomo | 594 | struct loader_task *start_loader_task = NULL; |
595 | struct timespec total; |
||
1201 | giacomo | 596 | struct timespec end_time; |
1199 | giacomo | 597 | |
1208 | giacomo | 598 | line_reader(start_file, end_file, &total, &start_loader_task); |
1200 | giacomo | 599 | |
1203 | giacomo | 600 | srand(kern_gettime(NULL)); |
601 | |||
602 | calibrate_cycle(); |
||
603 | |||
1206 | giacomo | 604 | loader_mutex_create(start_loader_task); |
605 | |||
1201 | giacomo | 606 | loader_task_create(start_loader_task); |
607 | |||
608 | kern_gettime(&zero_time); |
||
1202 | giacomo | 609 | |
610 | loader_first_execution(start_loader_task); |
||
611 | |||
1201 | giacomo | 612 | ADDTIMESPEC(&zero_time,&total,&end_time); |
613 | kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL); |
||
614 | |||
1199 | giacomo | 615 | return 0; |
616 | |||
617 | } |