Subversion Repositories shark

Rev

Rev 1210 | 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;
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);
1201 giacomo 414
 
1203 giacomo 415
        sprintf(tmp,"NRT %d:%d",current->group,i);
416
        p = task_create(tmp,nrt_test_task,&nrt,NULL);
1201 giacomo 417
        if (p == NIL) {
418
          cprintf("Error nrt task creating\n");
419
          sys_end();
420
        }
421
 
422
        total_task++;
423
 
424
      }
425
 
1208 giacomo 426
      if (current->task_type == PAR_TASK_BACK) {
427
        NRT_TASK_MODEL nrt;
428
 
429
        nrt_task_default_model(nrt);
430
        nrt_task_def_save_arrivals(nrt);
431
        nrt_task_def_arg(nrt,(void *)(current));
432
        nrt_task_def_ctrl_jet(nrt);
433
        nrt_task_def_level(nrt,current->task_level);
434
        nrt_task_def_group(nrt,total_group);
435
 
436
        sprintf(tmp,"BACK %d:%d",current->group,i);
437
        p = task_create(tmp,back_task,&nrt,NULL);
438
        if (p == NIL) {
439
          cprintf("Error back task creating\n");
440
          sys_end();
441
        }
442
 
443
        total_task++;
444
 
445
      }
446
 
1201 giacomo 447
      if (current->task_type == PAR_TASK_HARD) {
448
        HARD_TASK_MODEL ht;
449
 
450
        hard_task_default_model(ht);
451
        hard_task_def_arg(ht,(void *)(current));
452
        hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
453
        hard_task_def_ctrl_jet(ht);
454
        hard_task_def_level(ht,current->task_level);
1202 giacomo 455
        hard_task_def_group(ht,total_group);
1201 giacomo 456
 
1203 giacomo 457
        if (current->act_type != PAR_ACT_PERIODIC) {
458
          hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
459
          current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(&current->deadline)
460
                                 * TIMESPEC2USEC(&current->wcet);
1201 giacomo 461
          hard_task_def_aperiodic(ht);
462
        } else {
1203 giacomo 463
          hard_task_def_mit(ht,TIMESPEC2USEC(&current->act_par_2));
464
          current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(&current->act_par_2)
465
                                 * TIMESPEC2USEC(&current->wcet);
1201 giacomo 466
        }
1203 giacomo 467
 
468
        sprintf(tmp,"HARD %d:%d",current->group,i);
469
        p = task_create(tmp,test_task,&ht,NULL);
1201 giacomo 470
        if (p == NIL) {
471
          cprintf("Error hard task creating\n");
472
          sys_end();
473
        }
474
 
475
        total_task++;
476
 
477
      }
478
 
479
      if (current->task_type == PAR_TASK_SOFT) {
480
        SOFT_TASK_MODEL st;
481
 
482
        soft_task_default_model(st);
483
        soft_task_def_save_arrivals(st);
484
        soft_task_def_arg(st,(void *)(current));
485
        soft_task_def_met(st,TIMESPEC2USEC(&current->wcet));
486
        soft_task_def_ctrl_jet(st);
487
        soft_task_def_level(st,current->task_level);
1202 giacomo 488
        soft_task_def_group(st,total_group);
489
 
1201 giacomo 490
        if (current->act_type == PAR_ACT_PERIODIC) {
491
          soft_task_def_period(st,TIMESPEC2USEC(&current->act_par_2));
1203 giacomo 492
          current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(&current->act_par_2)
493
                                 * TIMESPEC2USEC(&current->wcet);
1201 giacomo 494
        } else if (current->act_type != PAR_ACT_SINGLE) {
495
          soft_task_def_period(st,TIMESPEC2USEC(&current->act_par_2));
1203 giacomo 496
          current->bandwidth += MAX_BANDWIDTH / TIMESPEC2USEC(&current->act_par_2)
497
                                 * TIMESPEC2USEC(&current->wcet);
1201 giacomo 498
          soft_task_def_aperiodic(st);
499
        } else {
1203 giacomo 500
          soft_task_def_period(st,TIMESPEC2USEC(&current->wcet)*1000);
501
          current->bandwidth += MAX_BANDWIDTH / 1000;
1201 giacomo 502
          soft_task_def_aperiodic(st);
503
        }
1203 giacomo 504
 
505
        sprintf(tmp,"SOFT %d:%d",current->group,i);
506
        p = task_create(tmp,test_task,&st,NULL);
1201 giacomo 507
        if (p == NIL) {
508
          cprintf("Error soft task creating\n");
509
          sys_end();
510
        }
511
 
512
        total_task++;
513
 
514
      }
515
 
1209 giacomo 516
      if (current->task_type == PAR_TASK_FSF) {
517
 
518
        if (current->local_scheduler == PAR_POSIX) {
1210 giacomo 519
          NRT_TASK_MODEL nrt;
1209 giacomo 520
          pthread_t j;
521
          int err;
1210 giacomo 522
 
523
          nrt_task_default_model(nrt);
524
          nrt_task_def_save_arrivals(nrt);
525
          nrt_task_def_ctrl_jet(nrt);
526
 
527
          err = fsf_create_thread(current->server,&j,NULL,back_task,(void *)current,&nrt);
1209 giacomo 528
          if (err) {
529
            cprintf("Error fsf task creating\n");
530
            sys_end();
531
          }
532
        }
533
 
534
        if (current->local_scheduler == PAR_EDF) {
535
          HARD_TASK_MODEL ht;
536
          pthread_t j;
537
          int err;
538
 
539
          hard_task_default_model(ht);
1210 giacomo 540
          hard_task_def_ctrl_jet(ht);          
1209 giacomo 541
          hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
542
          hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
1210 giacomo 543
 
1209 giacomo 544
          err = fsf_create_thread(current->server,&j,NULL,test_task,(void *)current,&ht);
545
          if (err) {
546
            cprintf("Error fsf task creating\n");
547
            sys_end();
548
          }
549
 
550
        }
551
 
552
        if (current->local_scheduler == PAR_RM) {
553
          HARD_TASK_MODEL ht;
554
          pthread_t j;
555
          int err;
556
 
557
          hard_task_default_model(ht);
558
          hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
559
          hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
1210 giacomo 560
          hard_task_def_ctrl_jet(ht);
561
 
1209 giacomo 562
          err = fsf_create_thread(current->server,&j,NULL,test_task,(void *)current,&ht);
563
          if (err) {
564
            cprintf("Error fsf task creating\n");
565
            sys_end();
566
          }
567
 
568
        }
569
 
570
        total_task++;
571
 
572
      }
573
 
1201 giacomo 574
    }
575
 
1203 giacomo 576
    cprintf("Task group %d created. Worst case BW = %d.%d \n",
577
             current->group,(int)( (long long)current->bandwidth * 100 / MAX_BANDWIDTH),
578
             (int)( (long long)current->bandwidth*  100000 / MAX_BANDWIDTH % 1000));
579
 
1201 giacomo 580
    current = current->next;
581
 
582
  }
583
 
584
  cprintf("Created %d tasks\n",total_task);
585
 
586
}
587
 
1203 giacomo 588
/* Set the first extivation events */
1202 giacomo 589
void loader_first_execution(struct loader_task *start_loader_task)
590
{
591
 
592
  struct loader_task *current = start_loader_task;
593
  struct timespec start_time;  
594
 
595
  while (current != NULL) {
596
 
1209 giacomo 597
    if (current->task_type != PAR_TASK_FSF) {
598
 
599
      ADDTIMESPEC(&zero_time,&current->act_par_1,&start_time);
1202 giacomo 600
 
1209 giacomo 601
      kern_event_post(&start_time, (void *)((void *)group_activate), (void *)(current->group));
602
 
603
    }
604
 
1202 giacomo 605
    current = current->next;
606
 
607
  }  
608
 
609
}
610
 
1209 giacomo 611
void fsfinit(void);
612
 
1199 giacomo 613
int main()
614
{
615
 
1200 giacomo 616
  struct loader_task *start_loader_task = NULL;
617
  struct timespec total;
1201 giacomo 618
  struct timespec end_time;
1199 giacomo 619
 
1208 giacomo 620
  line_reader(start_file, end_file, &total, &start_loader_task);
1200 giacomo 621
 
1203 giacomo 622
  srand(kern_gettime(NULL));
623
 
624
  calibrate_cycle();
625
 
1209 giacomo 626
  fsfinit();
627
 
1206 giacomo 628
  loader_mutex_create(start_loader_task);
629
 
1201 giacomo 630
  loader_task_create(start_loader_task);
631
 
632
  kern_gettime(&zero_time);
1202 giacomo 633
 
634
  loader_first_execution(start_loader_task);
635
 
1201 giacomo 636
  ADDTIMESPEC(&zero_time,&total,&end_time);
637
  kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL);
638
 
1199 giacomo 639
  return 0;
640
 
641
}