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