Rev 1215 | Go to most recent revision | 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 | |
1209 | giacomo | 5 | #include "fsf_contract.h" |
6 | #include "fsf_server.h" |
||
7 | |||
1203 | giacomo | 8 | /* Memory pointers on loaded file */ |
1208 | giacomo | 9 | extern void *start_file; |
10 | extern void *end_file; |
||
1200 | giacomo | 11 | |
1203 | giacomo | 12 | /* Calibration Loops */ |
1216 | giacomo | 13 | #define CALIBRATION_DELTA 10000 |
1203 | giacomo | 14 | |
1206 | giacomo | 15 | /* Mutex number */ |
16 | #define MAX_MUTEX 10 |
||
17 | |||
1203 | giacomo | 18 | /* Activate task output */ |
19 | #define TASK_OUTPUT |
||
20 | |||
1202 | giacomo | 21 | struct timespec zero_time; |
1203 | giacomo | 22 | int cal_cycles = 0; |
1202 | giacomo | 23 | |
1206 | giacomo | 24 | mutex_t mux_table[MAX_MUTEX]; |
25 | |||
1203 | giacomo | 26 | /* Not Real-Time Task */ |
1201 | giacomo | 27 | TASK nrt_test_task(void *arg) |
28 | { |
||
1203 | giacomo | 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; |
||
1206 | giacomo | 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; |
||
1203 | giacomo | 35 | struct timespec next_time; |
36 | struct loader_task *l = (struct loader_task *)(arg); |
||
1209 | giacomo | 37 | char tmp[20]; |
38 | |||
1203 | giacomo | 39 | act_1 = TIMESPEC2USEC(&l->act_par_2); |
40 | act_2 = TIMESPEC2USEC(&l->act_par_3); |
||
41 | act_3 = TIMESPEC2USEC(&l->act_par_4); |
||
1202 | giacomo | 42 | |
1203 | giacomo | 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 | } |
||
1201 | giacomo | 48 | |
1203 | giacomo | 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 | } |
||
1202 | giacomo | 55 | |
1203 | giacomo | 56 | if (l->act_type == PAR_ACT_GAUSS) { |
1201 | giacomo | 57 | } |
1203 | giacomo | 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); |
||
1205 | giacomo | 65 | |
1206 | giacomo | 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 | |||
1205 | giacomo | 73 | #ifdef TASK_OUTPUT |
1209 | giacomo | 74 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, "R[000000]"); |
1205 | giacomo | 75 | #endif |
76 | |||
1203 | giacomo | 77 | if (l->exec_type == PAR_EXEC_CONST) |
1209 | giacomo | 78 | exec_cycles = (long long)(exec_1) * CALIBRATION_DELTA / cal_cycles; |
1203 | giacomo | 79 | |
80 | if (l->exec_type == PAR_EXEC_MEAN) |
||
1209 | giacomo | 81 | exec_cycles = (long long)(exec_1 + rand() % exec_2 - exec_2/2) |
82 | * CALIBRATION_DELTA / cal_cycles; |
||
1203 | giacomo | 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 | |||
1206 | giacomo | 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 | } |
||
1205 | giacomo | 101 | |
1206 | giacomo | 102 | if (l->crit_type == PAR_NO_CRIT) |
1207 | giacomo | 103 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 104 | else { |
1207 | giacomo | 105 | for (i=0;i<crit_start_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 106 | #ifdef TASK_OUTPUT |
1209 | giacomo | 107 | sprintf(tmp,"B[%02d][%02d]",exec_shadow,l->resource); |
108 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, RED,tmp); |
||
1206 | giacomo | 109 | #endif |
110 | mutex_lock(&mux_table[l->resource]); |
||
1207 | giacomo | 111 | for (i=0;i<crit_len_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 112 | mutex_unlock(&mux_table[l->resource]); |
113 | #ifdef TASK_OUTPUT |
||
1209 | giacomo | 114 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN,"R[000000]"); |
1206 | giacomo | 115 | #endif |
1207 | giacomo | 116 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 117 | } |
118 | |||
1205 | giacomo | 119 | #ifdef TASK_OUTPUT |
1209 | giacomo | 120 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, BLUE, "E[000000]"); |
1205 | giacomo | 121 | #endif |
1203 | giacomo | 122 | |
1201 | giacomo | 123 | return NULL; |
1203 | giacomo | 124 | |
1201 | giacomo | 125 | } |
126 | |||
1203 | giacomo | 127 | /* Soft and hard Task */ |
1201 | giacomo | 128 | TASK test_task(void *arg) |
129 | { |
||
1203 | giacomo | 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; |
||
1206 | giacomo | 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; |
||
1203 | giacomo | 136 | struct timespec next_time; |
1209 | giacomo | 137 | int act = 0; |
1203 | giacomo | 138 | struct loader_task *l = (struct loader_task *)(arg); |
1209 | giacomo | 139 | char tmp[20]; |
140 | |||
1203 | giacomo | 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); |
||
1202 | giacomo | 148 | |
1206 | giacomo | 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 | |||
1201 | giacomo | 156 | while(1) { |
157 | |||
1203 | giacomo | 158 | task_testcancel(); |
1202 | giacomo | 159 | |
1209 | giacomo | 160 | act++; |
161 | |||
1205 | giacomo | 162 | #ifdef TASK_OUTPUT |
1209 | giacomo | 163 | sprintf(tmp,"X[%06d]",act); |
164 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, tmp); |
||
1205 | giacomo | 165 | #endif |
166 | |||
1203 | giacomo | 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) |
||
1209 | giacomo | 181 | exec_cycles = (long long)(exec_1) * CALIBRATION_DELTA / cal_cycles; |
1203 | giacomo | 182 | |
183 | if (l->exec_type == PAR_EXEC_MEAN) |
||
1209 | giacomo | 184 | exec_cycles = (long long)(exec_1 + rand() % exec_2 - exec_2/2) |
185 | * CALIBRATION_DELTA / cal_cycles; |
||
1203 | giacomo | 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; |
||
1206 | giacomo | 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) |
||
1207 | giacomo | 206 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 207 | else { |
1207 | giacomo | 208 | for (i=0;i<crit_start_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 209 | #ifdef TASK_OUTPUT |
1209 | giacomo | 210 | sprintf(tmp,"B[%02d][%02d]",exec_shadow,l->resource); |
211 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, RED, tmp); |
||
1206 | giacomo | 212 | #endif |
213 | mutex_lock(&mux_table[l->resource]); |
||
1207 | giacomo | 214 | for (i=0;i<crit_len_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 215 | mutex_unlock(&mux_table[l->resource]); |
216 | #ifdef TASK_OUTPUT |
||
1209 | giacomo | 217 | sprintf(tmp,"X[%06d]",act); |
218 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, tmp); |
||
1206 | giacomo | 219 | #endif |
1207 | giacomo | 220 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
1206 | giacomo | 221 | } |
1203 | giacomo | 222 | |
1201 | giacomo | 223 | task_endcycle(); |
1203 | giacomo | 224 | |
1201 | giacomo | 225 | } |
1203 | giacomo | 226 | |
1201 | giacomo | 227 | return NULL; |
1203 | giacomo | 228 | |
229 | } |
||
1201 | giacomo | 230 | |
1208 | giacomo | 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; |
||
1209 | giacomo | 241 | int act = 0; |
1208 | giacomo | 242 | struct loader_task *l = (struct loader_task *)(arg); |
1209 | giacomo | 243 | char tmp[20]; |
1208 | giacomo | 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 | |||
1209 | giacomo | 264 | act++; |
265 | |||
1208 | giacomo | 266 | #ifdef TASK_OUTPUT |
1209 | giacomo | 267 | sprintf(tmp,"X[%06d]",act); |
268 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, tmp); |
||
1208 | giacomo | 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) |
||
1209 | giacomo | 285 | exec_cycles = (long long)(exec_1) * CALIBRATION_DELTA / cal_cycles; |
1208 | giacomo | 286 | |
287 | if (l->exec_type == PAR_EXEC_MEAN) |
||
1209 | giacomo | 288 | exec_cycles = (long long)(exec_1 + rand() % exec_2 - exec_2/2) |
289 | * CALIBRATION_DELTA / cal_cycles; |
||
1208 | giacomo | 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 |
||
1209 | giacomo | 314 | sprintf(tmp,"B[%02d][%02d]",exec_shadow,l->resource); |
315 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, RED, tmp); |
||
1208 | giacomo | 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 |
||
1209 | giacomo | 321 | sprintf(tmp,"X[%06d]",act); |
322 | printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, tmp); |
||
1208 | giacomo | 323 | #endif |
324 | for (i=0;i<exec_cycles;i++) kern_gettime(NULL); |
||
325 | } |
||
326 | |||
327 | } |
||
328 | |||
329 | return NULL; |
||
330 | |||
331 | } |
||
332 | |||
1203 | giacomo | 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); |
||
1207 | giacomo | 341 | for (i=0;i<CALIBRATION_DELTA;i++) kern_gettime(NULL); |
1203 | giacomo | 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 | |||
1201 | giacomo | 352 | } |
353 | |||
1206 | giacomo | 354 | /* Mutex create */ |
355 | void loader_mutex_create(struct loader_task *start_loader_task) |
||
356 | { |
||
357 | |||
358 | struct loader_task *current = start_loader_task; |
||
1214 | giacomo | 359 | int i,res = 0; |
1206 | giacomo | 360 | PI_mutexattr_t a; |
1214 | giacomo | 361 | int init_array[MAX_MUTEX]; |
1206 | giacomo | 362 | |
363 | PI_mutexattr_default(a); |
||
364 | |||
1214 | giacomo | 365 | for (i = 0;i < MAX_MUTEX;i++) init_array[i] = 0; |
366 | |||
1206 | giacomo | 367 | while (current != NULL) { |
368 | |||
369 | if (current->crit_type == PAR_CRIT) { |
||
1214 | giacomo | 370 | if (init_array[current->resource] == 0) { |
371 | mutex_init(&mux_table[current->resource],&a); |
||
372 | init_array[current->resource] = 1; |
||
373 | res++; |
||
374 | } |
||
1206 | giacomo | 375 | } |
376 | |||
377 | current = current->next; |
||
378 | |||
379 | } |
||
380 | |||
381 | cprintf("Created %d mutex\n",res); |
||
382 | |||
383 | } |
||
384 | |||
1203 | giacomo | 385 | /* Task create */ |
1201 | giacomo | 386 | void loader_task_create(struct loader_task *start_loader_task) |
387 | { |
||
388 | |||
389 | struct loader_task *current = start_loader_task; |
||
1203 | giacomo | 390 | char tmp[30]; |
1201 | giacomo | 391 | int i, total_task; |
1202 | giacomo | 392 | int total_group = 0; |
1201 | giacomo | 393 | PID p; |
394 | |||
395 | total_task = 0; |
||
396 | |||
397 | while (current != NULL) { |
||
398 | |||
1202 | giacomo | 399 | total_group++; |
400 | current->group = total_group; |
||
1203 | giacomo | 401 | current->bandwidth = 0; |
1202 | giacomo | 402 | |
1201 | giacomo | 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); |
||
1202 | giacomo | 413 | nrt_task_def_group(nrt,total_group); |
1215 | giacomo | 414 | nrt_task_def_usemath(nrt); |
1201 | giacomo | 415 | |
1203 | giacomo | 416 | sprintf(tmp,"NRT %d:%d",current->group,i); |
417 | p = task_create(tmp,nrt_test_task,&nrt,NULL); |
||
1201 | giacomo | 418 | if (p == NIL) { |
419 | cprintf("Error nrt task creating\n"); |
||
420 | sys_end(); |
||
421 | } |
||
422 | |||
423 | total_task++; |
||
424 | |||
425 | } |
||
426 | |||
1208 | giacomo | 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); |
||
1215 | giacomo | 436 | nrt_task_def_usemath(nrt); |
1208 | giacomo | 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 | |||
1201 | giacomo | 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); |
||
1202 | giacomo | 457 | hard_task_def_group(ht,total_group); |
1215 | giacomo | 458 | hard_task_def_usemath(ht); |
1201 | giacomo | 459 | |
1203 | giacomo | 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); |
||
1201 | giacomo | 464 | hard_task_def_aperiodic(ht); |
465 | } else { |
||
1203 | giacomo | 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); |
||
1201 | giacomo | 469 | } |
1203 | giacomo | 470 | |
471 | sprintf(tmp,"HARD %d:%d",current->group,i); |
||
472 | p = task_create(tmp,test_task,&ht,NULL); |
||
1201 | giacomo | 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); |
||
1202 | giacomo | 491 | soft_task_def_group(st,total_group); |
1215 | giacomo | 492 | soft_task_def_usemath(st); |
1202 | giacomo | 493 | |
1201 | giacomo | 494 | if (current->act_type == PAR_ACT_PERIODIC) { |
495 | soft_task_def_period(st,TIMESPEC2USEC(¤t->act_par_2)); |
||
1203 | giacomo | 496 | current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(¤t->act_par_2) |
497 | * TIMESPEC2USEC(¤t->wcet); |
||
1201 | giacomo | 498 | } else if (current->act_type != PAR_ACT_SINGLE) { |
499 | soft_task_def_period(st,TIMESPEC2USEC(¤t->act_par_2)); |
||
1203 | giacomo | 500 | current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(¤t->act_par_2) |
501 | * TIMESPEC2USEC(¤t->wcet); |
||
1201 | giacomo | 502 | soft_task_def_aperiodic(st); |
503 | } else { |
||
1203 | giacomo | 504 | soft_task_def_period(st,TIMESPEC2USEC(¤t->wcet)*1000); |
505 | current->bandwidth += MAX_BANDWIDTH / 1000; |
||
1201 | giacomo | 506 | soft_task_def_aperiodic(st); |
507 | } |
||
1203 | giacomo | 508 | |
509 | sprintf(tmp,"SOFT %d:%d",current->group,i); |
||
510 | p = task_create(tmp,test_task,&st,NULL); |
||
1201 | giacomo | 511 | if (p == NIL) { |
512 | cprintf("Error soft task creating\n"); |
||
513 | sys_end(); |
||
514 | } |
||
515 | |||
516 | total_task++; |
||
517 | |||
518 | } |
||
519 | |||
1209 | giacomo | 520 | if (current->task_type == PAR_TASK_FSF) { |
521 | |||
522 | if (current->local_scheduler == PAR_POSIX) { |
||
1210 | giacomo | 523 | NRT_TASK_MODEL nrt; |
1209 | giacomo | 524 | pthread_t j; |
525 | int err; |
||
1210 | giacomo | 526 | |
527 | nrt_task_default_model(nrt); |
||
528 | nrt_task_def_save_arrivals(nrt); |
||
529 | nrt_task_def_ctrl_jet(nrt); |
||
1215 | giacomo | 530 | nrt_task_def_usemath(nrt); |
1210 | giacomo | 531 | |
532 | err = fsf_create_thread(current->server,&j,NULL,back_task,(void *)current,&nrt); |
||
1209 | giacomo | 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); |
||
1210 | giacomo | 545 | hard_task_def_ctrl_jet(ht); |
1209 | giacomo | 546 | hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline)); |
547 | hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet)); |
||
1215 | giacomo | 548 | hard_task_def_usemath(ht); |
1210 | giacomo | 549 | |
1209 | giacomo | 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)); |
||
1210 | giacomo | 566 | hard_task_def_ctrl_jet(ht); |
1215 | giacomo | 567 | hard_task_def_usemath(ht); |
1210 | giacomo | 568 | |
1209 | giacomo | 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 | |||
1201 | giacomo | 581 | } |
582 | |||
1203 | giacomo | 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 | |||
1201 | giacomo | 587 | current = current->next; |
588 | |||
589 | } |
||
590 | |||
591 | cprintf("Created %d tasks\n",total_task); |
||
592 | |||
593 | } |
||
594 | |||
1203 | giacomo | 595 | /* Set the first extivation events */ |
1202 | giacomo | 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 | |||
1209 | giacomo | 604 | if (current->task_type != PAR_TASK_FSF) { |
605 | |||
606 | ADDTIMESPEC(&zero_time,¤t->act_par_1,&start_time); |
||
1202 | giacomo | 607 | |
1209 | giacomo | 608 | kern_event_post(&start_time, (void *)((void *)group_activate), (void *)(current->group)); |
609 | |||
610 | } |
||
611 | |||
1202 | giacomo | 612 | current = current->next; |
613 | |||
614 | } |
||
615 | |||
616 | } |
||
617 | |||
1209 | giacomo | 618 | void fsfinit(void); |
619 | |||
1199 | giacomo | 620 | int main() |
621 | { |
||
622 | |||
1200 | giacomo | 623 | struct loader_task *start_loader_task = NULL; |
624 | struct timespec total; |
||
1201 | giacomo | 625 | struct timespec end_time; |
1199 | giacomo | 626 | |
1208 | giacomo | 627 | line_reader(start_file, end_file, &total, &start_loader_task); |
1200 | giacomo | 628 | |
1203 | giacomo | 629 | srand(kern_gettime(NULL)); |
630 | |||
631 | calibrate_cycle(); |
||
632 | |||
1209 | giacomo | 633 | fsfinit(); |
634 | |||
1206 | giacomo | 635 | loader_mutex_create(start_loader_task); |
636 | |||
1201 | giacomo | 637 | loader_task_create(start_loader_task); |
638 | |||
639 | kern_gettime(&zero_time); |
||
1202 | giacomo | 640 | |
641 | loader_first_execution(start_loader_task); |
||
642 | |||
1201 | giacomo | 643 | ADDTIMESPEC(&zero_time,&total,&end_time); |
644 | kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL); |
||
645 | |||
1199 | giacomo | 646 | return 0; |
647 | |||
648 | } |