Subversion Repositories shark

Rev

Rev 1208 | 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 */
1207 giacomo 13
#define CALIBRATION_DELTA 100000
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;
359
  int res = 0;
360
  PI_mutexattr_t a;
361
 
362
  PI_mutexattr_default(a);
363
 
364
  while (current != NULL) {
365
 
366
    if (current->crit_type == PAR_CRIT) {
367
      mutex_init(&mux_table[current->resource],&a);
368
      res++;
369
    }
370
 
371
    current = current->next;
372
 
373
  }
374
 
375
  cprintf("Created %d mutex\n",res);
376
 
377
}
378
 
1203 giacomo 379
/* Task create */
1201 giacomo 380
void loader_task_create(struct loader_task *start_loader_task)
381
{
382
 
383
  struct loader_task *current = start_loader_task;
1203 giacomo 384
  char tmp[30];
1201 giacomo 385
  int i, total_task;
1202 giacomo 386
  int total_group = 0;
1201 giacomo 387
  PID p;
388
 
389
  total_task = 0;
390
 
391
  while (current != NULL) {
392
 
1202 giacomo 393
    total_group++;
394
    current->group = total_group;
1203 giacomo 395
    current->bandwidth = 0;
1202 giacomo 396
 
1201 giacomo 397
    for (i=0; i < current->number; i++) {
398
 
399
      if (current->task_type == PAR_TASK_NRT) {
400
        NRT_TASK_MODEL nrt;
401
 
402
        nrt_task_default_model(nrt);
403
        nrt_task_def_save_arrivals(nrt);
404
        nrt_task_def_arg(nrt,(void *)(current));
405
        nrt_task_def_ctrl_jet(nrt);
406
        nrt_task_def_level(nrt,current->task_level);
1202 giacomo 407
        nrt_task_def_group(nrt,total_group);
1201 giacomo 408
 
1203 giacomo 409
        sprintf(tmp,"NRT %d:%d",current->group,i);
410
        p = task_create(tmp,nrt_test_task,&nrt,NULL);
1201 giacomo 411
        if (p == NIL) {
412
          cprintf("Error nrt task creating\n");
413
          sys_end();
414
        }
415
 
416
        total_task++;
417
 
418
      }
419
 
1208 giacomo 420
      if (current->task_type == PAR_TASK_BACK) {
421
        NRT_TASK_MODEL nrt;
422
 
423
        nrt_task_default_model(nrt);
424
        nrt_task_def_save_arrivals(nrt);
425
        nrt_task_def_arg(nrt,(void *)(current));
426
        nrt_task_def_ctrl_jet(nrt);
427
        nrt_task_def_level(nrt,current->task_level);
428
        nrt_task_def_group(nrt,total_group);
429
 
430
        sprintf(tmp,"BACK %d:%d",current->group,i);
431
        p = task_create(tmp,back_task,&nrt,NULL);
432
        if (p == NIL) {
433
          cprintf("Error back task creating\n");
434
          sys_end();
435
        }
436
 
437
        total_task++;
438
 
439
      }
440
 
1201 giacomo 441
      if (current->task_type == PAR_TASK_HARD) {
442
        HARD_TASK_MODEL ht;
443
 
444
        hard_task_default_model(ht);
445
        hard_task_def_arg(ht,(void *)(current));
446
        hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
447
        hard_task_def_ctrl_jet(ht);
448
        hard_task_def_level(ht,current->task_level);
1202 giacomo 449
        hard_task_def_group(ht,total_group);
1201 giacomo 450
 
1203 giacomo 451
        if (current->act_type != PAR_ACT_PERIODIC) {
452
          hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
453
          current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(&current->deadline)
454
                                 * TIMESPEC2USEC(&current->wcet);
1201 giacomo 455
          hard_task_def_aperiodic(ht);
456
        } else {
1203 giacomo 457
          hard_task_def_mit(ht,TIMESPEC2USEC(&current->act_par_2));
458
          current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(&current->act_par_2)
459
                                 * TIMESPEC2USEC(&current->wcet);
1201 giacomo 460
        }
1203 giacomo 461
 
462
        sprintf(tmp,"HARD %d:%d",current->group,i);
463
        p = task_create(tmp,test_task,&ht,NULL);
1201 giacomo 464
        if (p == NIL) {
465
          cprintf("Error hard task creating\n");
466
          sys_end();
467
        }
468
 
469
        total_task++;
470
 
471
      }
472
 
473
      if (current->task_type == PAR_TASK_SOFT) {
474
        SOFT_TASK_MODEL st;
475
 
476
        soft_task_default_model(st);
477
        soft_task_def_save_arrivals(st);
478
        soft_task_def_arg(st,(void *)(current));
479
        soft_task_def_met(st,TIMESPEC2USEC(&current->wcet));
480
        soft_task_def_ctrl_jet(st);
481
        soft_task_def_level(st,current->task_level);
1202 giacomo 482
        soft_task_def_group(st,total_group);
483
 
1201 giacomo 484
        if (current->act_type == PAR_ACT_PERIODIC) {
485
          soft_task_def_period(st,TIMESPEC2USEC(&current->act_par_2));
1203 giacomo 486
          current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(&current->act_par_2)
487
                                 * TIMESPEC2USEC(&current->wcet);
1201 giacomo 488
        } else if (current->act_type != PAR_ACT_SINGLE) {
489
          soft_task_def_period(st,TIMESPEC2USEC(&current->act_par_2));
1203 giacomo 490
          current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(&current->act_par_2)
491
                                 * TIMESPEC2USEC(&current->wcet);
1201 giacomo 492
          soft_task_def_aperiodic(st);
493
        } else {
1203 giacomo 494
          soft_task_def_period(st,TIMESPEC2USEC(&current->wcet)*1000);
495
          current->bandwidth += MAX_BANDWIDTH / 1000;
1201 giacomo 496
          soft_task_def_aperiodic(st);
497
        }
1203 giacomo 498
 
499
        sprintf(tmp,"SOFT %d:%d",current->group,i);
500
        p = task_create(tmp,test_task,&st,NULL);
1201 giacomo 501
        if (p == NIL) {
502
          cprintf("Error soft task creating\n");
503
          sys_end();
504
        }
505
 
506
        total_task++;
507
 
508
      }
509
 
1209 giacomo 510
      if (current->task_type == PAR_TASK_FSF) {
511
 
512
        if (current->local_scheduler == PAR_POSIX) {
513
          pthread_t j;
514
          int err;
515
          err = fsf_create_thread(current->server,&j,NULL,back_task,(void *)current,NULL);
516
          if (err) {
517
            cprintf("Error fsf task creating\n");
518
            sys_end();
519
          }
520
        }
521
 
522
        if (current->local_scheduler == PAR_EDF) {
523
          HARD_TASK_MODEL ht;
524
          pthread_t j;
525
          int err;
526
 
527
          hard_task_default_model(ht);
528
          hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
529
          hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
530
          err = fsf_create_thread(current->server,&j,NULL,test_task,(void *)current,&ht);
531
          if (err) {
532
            cprintf("Error fsf task creating\n");
533
            sys_end();
534
          }
535
 
536
        }
537
 
538
        if (current->local_scheduler == PAR_RM) {
539
          HARD_TASK_MODEL ht;
540
          pthread_t j;
541
          int err;
542
 
543
          hard_task_default_model(ht);
544
          hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
545
          hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
546
          err = fsf_create_thread(current->server,&j,NULL,test_task,(void *)current,&ht);
547
          if (err) {
548
            cprintf("Error fsf task creating\n");
549
            sys_end();
550
          }
551
 
552
        }
553
 
554
        total_task++;
555
 
556
      }
557
 
1201 giacomo 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
 
1209 giacomo 581
    if (current->task_type != PAR_TASK_FSF) {
582
 
583
      ADDTIMESPEC(&zero_time,&current->act_par_1,&start_time);
1202 giacomo 584
 
1209 giacomo 585
      kern_event_post(&start_time, (void *)((void *)group_activate), (void *)(current->group));
586
 
587
    }
588
 
1202 giacomo 589
    current = current->next;
590
 
591
  }  
592
 
593
}
594
 
1209 giacomo 595
void fsfinit(void);
596
 
1199 giacomo 597
int main()
598
{
599
 
1200 giacomo 600
  struct loader_task *start_loader_task = NULL;
601
  struct timespec total;
1201 giacomo 602
  struct timespec end_time;
1199 giacomo 603
 
1208 giacomo 604
  line_reader(start_file, end_file, &total, &start_loader_task);
1200 giacomo 605
 
1203 giacomo 606
  srand(kern_gettime(NULL));
607
 
608
  calibrate_cycle();
609
 
1209 giacomo 610
  fsfinit();
611
 
1206 giacomo 612
  loader_mutex_create(start_loader_task);
613
 
1201 giacomo 614
  loader_task_create(start_loader_task);
615
 
616
  kern_gettime(&zero_time);
1202 giacomo 617
 
618
  loader_first_execution(start_loader_task);
619
 
1201 giacomo 620
  ADDTIMESPEC(&zero_time,&total,&end_time);
621
  kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL);
622
 
1199 giacomo 623
  return 0;
624
 
625
}