Subversion Repositories shark

Rev

Rev 293 | Rev 298 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
221 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * Copyright (C) 2001 Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 */
37
 
38
#include "edfstar.h"
39
#include <ll/stdio.h>
40
#include <ll/string.h>
41
#include <kernel/model.h>
42
#include <kernel/descr.h>
43
#include <kernel/var.h>
44
#include <kernel/func.h>
45
#include <kernel/trace.h>
46
 
47
 
48
#define EDFSTAR_CHANGE_LEVEL 1
49
 
50
/* for iqueues */
51
/* #include "iqueue.h" Now iqueues are the only queue type available
52
   into the kernel */
53
#include <kernel/iqueue.h>
54
 
55
/* for BUDGET_TASK_MODEL */
241 giacomo 56
#include "fsf_server.h"
221 giacomo 57
 
58
/*
59
 * DEBUG stuffs begin
60
 */
61
 
224 giacomo 62
//#define EDFSTAR_DEBUG
221 giacomo 63
 
64
#ifdef EDFSTAR_DEBUG
65
 
66
static __inline__ fake_printf(char *fmt, ...) {}
67
 
68
//#define edfstar_printf fake_printf
69
//#define edfstar_printf2 fake_printf
70
//#define edfstar_printf3 fake_printf
71
 
72
#define edfstar_printf kern_printf
73
#define edfstar_printf2 kern_printf
74
#define edfstar_printf3 kern_printf
75
#endif
76
 
77
/*
78
 * DEBUG stuffs end
79
 */
80
 
81
/* Status used in the level */
82
#define EDFSTAR_READY         MODULE_STATUS_BASE    /* - Ready status        */
83
#define EDFSTAR_IDLE          MODULE_STATUS_BASE+4  /* to wait the deadline  */
84
 
85
/* flags */
86
#define EDFSTAR_FLAG_NORAISEEXC  2
87
 
88
/* the level redefinition for the Earliest Deadline First level */
89
typedef struct {
90
  level_des l;     /* the standard level descriptor          */
91
 
92
  TIME period[MAX_PROC]; /* The task periods; the deadlines are
93
                       stored in the priority field           */
94
  int deadline_timer[MAX_PROC];
95
                   /* The task deadline timers               */
96
 
97
  struct timespec deadline_timespec[MAX_PROC];
98
 
99
  int dline_miss[MAX_PROC]; /* Deadline miss counter */
100
  int wcet_miss[MAX_PROC];  /* Wcet miss counter */
101
 
102
  int nact[MAX_PROC];       /* Wcet miss counter */
103
 
104
  int flag[MAX_PROC];
105
                   /* used to manage the JOB_TASK_MODEL and the
106
                       periodicity                            */
107
 
108
  IQUEUE ready;     /* the ready queue                        */
109
 
110
  PID activated;   /* the task that has been inserted into the
111
                       master module */
112
 
113
  int budget[MAX_PROC];
114
 
115
  int scheduling_level;
116
 
296 trimarchi 117
  int cap_lev;
118
  struct timespec cap_lasttime;
119
 
120
 
221 giacomo 121
} EDFSTAR_level_des;
122
 
296 trimarchi 123
 
124
 
125
static void capacity_handler(void *l)
126
{
127
  EDFSTAR_level_des *lev = l;
128
  lev->cap_lev = NIL;
129
  //kern_printf("(/)");
130
  event_need_reschedule();
131
}
132
 
221 giacomo 133
static void EDFSTAR_check_preemption(EDFSTAR_level_des *lev)
134
{
135
  PID first;
136
 
137
#ifdef EDFSTAR_DEBUG
138
  edfstar_printf("(E:chk)");
139
#endif
140
 
141
  if ((first = iq_query_first(&lev->ready)) != lev->activated) {
142
    if (lev->activated != NIL)
143
      level_table[ lev->scheduling_level ]->
144
        private_extract(lev->scheduling_level, lev->activated);
145
 
146
    lev->activated = first;
147
 
148
    if (first != NIL) {
149
      BUDGET_TASK_MODEL b;
150
      budget_task_default_model(b, lev->budget[first]);
151
 
152
      level_table[ lev->scheduling_level ]->
153
        private_insert(lev->scheduling_level, first, (TASK_MODEL *)&b);
154
    }
155
  }
156
}
157
 
158
static void EDFSTAR_timer_deadline(void *par);
159
 
160
static void EDFSTAR_internal_activate(EDFSTAR_level_des *lev, PID p,
161
                                      struct timespec *t)
162
{
163
#ifdef EDFSTAR_DEBUG
164
  edfstar_printf("(E:iact)");
165
#endif
166
 
167
  ADDUSEC2TIMESPEC(lev->period[p], t);
168
 
169
  *iq_query_timespec(p, &lev->ready) = *t;
170
  lev->deadline_timespec[p] = *t;
171
 
172
  /* Insert task in the correct position */
173
  proc_table[p].status = EDFSTAR_READY;
174
  iq_timespec_insert(p,&lev->ready);
296 trimarchi 175
  proc_table[p].control &= ~CONTROL_CAP;
221 giacomo 176
 
177
  /* needed because when there is a wcet miss I disable CONTROL_CAP */
296 trimarchi 178
  //proc_table[p].control |= CONTROL_CAP;
221 giacomo 179
 
180
  /* check for preemption */
181
  EDFSTAR_check_preemption(lev);
182
}
183
 
184
static void EDFSTAR_timer_deadline(void *par)
185
{
186
  PID p = (PID) par;
187
  EDFSTAR_level_des *lev;
188
 
189
#ifdef EDFSTAR_DEBUG
190
//  edfstar_printf("(E:tdl ");
191
#endif
192
 
193
  lev = (EDFSTAR_level_des *)level_table[proc_table[p].task_level];
194
 
195
  switch (proc_table[p].status) {
196
    case EDFSTAR_IDLE:
197
#ifdef EDFSTAR_DEBUG
198
//      edfstar_printf2("I%d",p);
199
#endif
200
      /* set the request time */
201
      EDFSTAR_internal_activate(lev,p,iq_query_timespec(p, &lev->ready));
202
 
203
      event_need_reschedule();
204
      break;
205
 
206
    default:
224 giacomo 207
  #ifdef EDFSTAR_DEBUG
221 giacomo 208
      kern_printf("(E:Dl:%d)",p);
224 giacomo 209
  #endif
221 giacomo 210
      /* else, a deadline miss occurred!!! */
211
      lev->dline_miss[p]++;
212
 
213
      /* the task is into another state */
214
      lev->nact[p]++;
215
 
216
      /* Set the deadline timer */
217
      ADDUSEC2TIMESPEC(lev->period[p], &lev->deadline_timespec[p]);
218
  }
219
 
220
  /* Set the deadline timer */
221
  lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
222
                                           EDFSTAR_timer_deadline,
223
                                           (void *)p);
224
 
225
#ifdef EDFSTAR_DEBUG
226
//  edfstar_printf(")");
227
#endif
228
}
229
 
230
static void EDFSTAR_timer_guest_deadline(void *par)
231
{
232
  PID p = (PID) par;
233
 
234
#ifdef EDFSTAR_DEBUG
235
  edfstar_printf("(E:gdl)");
236
#endif
237
 
238
  kern_raise(XDEADLINE_MISS,p);
239
}
240
 
241
static int EDFSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m)
242
{
243
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
244
 
245
  /* if the EDFSTAR_task_create is called, then the pclass must be a
246
     valid pclass. */
247
  HARD_TASK_MODEL *h;
248
 
249
  if (m->pclass != HARD_PCLASS) return -1;
250
  if (m->level != 0 && m->level != l) return -1;
251
  h = (HARD_TASK_MODEL *)m;
252
  if (!h->wcet || !h->mit || h->periodicity != PERIODIC) return -1;
253
  /* now we know that m is a valid model */
254
 
255
 
256
#ifdef EDFSTAR_DEBUG
257
  edfstar_printf("(E:tcr)");
258
#endif
259
 
260
  lev->period[p] = h->mit;
261
 
262
  lev->flag[p] = 0;
263
  lev->deadline_timer[p] = -1;
264
  lev->dline_miss[p]     = 0;
265
  lev->wcet_miss[p]      = 0;
266
  lev->nact[p]           = 0;
267
 
268
  /* Enable wcet check */
269
  proc_table[p].avail_time = h->wcet;
270
  proc_table[p].wcet       = h->wcet;
296 trimarchi 271
  //proc_table[p].control |= CONTROL_CAP;
221 giacomo 272
 
273
  return 0; /* OK, also if the task cannot be guaranteed... */
274
}
275
 
296 trimarchi 276
 
277
static void EDFSTAR_account_capacity(EDFSTAR_level_des *lev, PID p)
278
{
279
  struct timespec ty;
280
  TIME tx;
281
 
282
  SUBTIMESPEC(&schedule_time, &lev->cap_lasttime, &ty);
283
  tx = TIMESPEC2USEC(&ty);
284
 
285
  proc_table[p].avail_time -= tx;
286
  //kern_printf("avail time pid %d , %d", p, proc_table[p].avail_time);
287
 
288
}
221 giacomo 289
static int EDFSTAR_public_eligible(LEVEL l, PID p)
290
{
291
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
292
 
293
#ifdef EDFSTAR_DEBUG
294
  edfstar_printf2("(E:eli)");
295
#endif
296
 
297
  return level_table[ lev->scheduling_level ]->
298
    private_eligible(lev->scheduling_level,p);
299
}
300
 
301
static void EDFSTAR_public_dispatch(LEVEL l, PID p, int nostop)
302
{
303
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
296 trimarchi 304
  struct timespec ty;
221 giacomo 305
 
306
#ifdef EDFSTAR_DEBUG
307
  edfstar_printf("(E:dis)");
308
 
309
  edfstar_printf3("(%d %d)",
310
                  iq_query_timespec(p, &lev->ready)->tv_nsec/1000000,
311
                  schedule_time.tv_nsec/1000000);
312
#endif
296 trimarchi 313
  if (!nostop || proc_table[exec].task_level==l) {
314
      TIMESPEC_ASSIGN(&ty, &schedule_time);
315
      TIMESPEC_ASSIGN(&lev->cap_lasttime, &schedule_time);
221 giacomo 316
 
296 trimarchi 317
      /* ...and finally, we have to post a capacity event on exec task because the shadow_task consume
318
       *      *        capacity on exe task always */
319
      ADDUSEC2TIMESPEC(proc_table[exec].avail_time ,&ty);
320
      lev->cap_lev = kern_event_post(&ty,capacity_handler, lev);
321
      level_table[lev->scheduling_level]->private_dispatch(lev->scheduling_level, p, nostop);
322
  }
323
  else
324
      level_table[proc_table[exec].task_level]->public_dispatch(proc_table[exec].task_level, p, nostop);
325
 
221 giacomo 326
}
327
 
328
static void EDFSTAR_public_epilogue(LEVEL l, PID p)
329
{
330
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
331
 
332
#ifdef EDFSTAR_DEBUG
333
  edfstar_printf("(E:epi ");
334
#endif
335
 
296 trimarchi 336
  if (lev->cap_lev!=NIL) {
337
       kern_event_delete(lev->cap_lev);
338
       lev->cap_lev=NIL;
339
  }
340
 
341
 
342
  if ( proc_table[exec].task_level==l ) {
343
 
344
     EDFSTAR_account_capacity(lev,exec);
345
 
346
     /* check if the wcet is finished... */
347
     if (proc_table[exec].avail_time <= 0) {
348
        /* wcet finished: disable wcet event and count wcet miss */
221 giacomo 349
#ifdef EDFSTAR_DEBUG
350
    edfstar_printf2("W%d",p);
351
#endif
296 trimarchi 352
        //proc_table[p].control &= ~CONTROL_CAP;
353
        lev->wcet_miss[exec]++;
354
     }
221 giacomo 355
#ifdef EDFSTAR_DEBUG
356
  edfstar_printf(")");
357
#endif
358
 
359
  level_table[ lev->scheduling_level ]->
360
    private_epilogue(lev->scheduling_level,p);
361
 
296 trimarchi 362
  proc_table[exec].status = EDFSTAR_READY;
363
    } else
364
        level_table[proc_table[exec].task_level]->public_epilogue(proc_table[exec].task_level,p);
365
 
221 giacomo 366
}
367
 
368
static void EDFSTAR_public_activate(LEVEL l, PID p)
369
{
370
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
371
  struct timespec t;
372
 
373
  #ifdef EDFSTAR_DEBUG
374
    edfstar_printf("(E:act:%d)",p);
375
  #endif
376
 
377
  /* Test if we are trying to activate a non sleeping task    */
378
  /* save activation (only if needed... */
379
  if (proc_table[p].status != SLEEP) {
380
    /* a periodic task cannot be activated when it is already active */
381
    kern_raise(XACTIVATION,p);
382
    return;
383
  }
384
 
385
  kern_gettime(&t);
386
 
387
  EDFSTAR_internal_activate(lev,p, &t);
388
 
389
  /* Set the deadline timer */
390
  lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
391
                                           EDFSTAR_timer_deadline,
392
                                           (void *)p);
393
 
394
}
395
 
396
static void EDFSTAR_public_unblock(LEVEL l, PID p)
397
{
398
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
399
 
400
#ifdef EDFSTAR_DEBUG
401
  edfstar_printf("(E:ins)");
402
#endif
403
 
404
  /* Insert task in the correct position */
405
  proc_table[p].status = EDFSTAR_READY;
406
  iq_timespec_insert(p,&lev->ready);
407
 
408
  /* and check for preemption! */
409
  EDFSTAR_check_preemption(lev);
410
}
411
 
412
static void EDFSTAR_public_block(LEVEL l, PID p)
413
{
414
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
415
 
416
#ifdef EDFSTAR_DEBUG
417
  edfstar_printf("(E:ext)");
418
#endif
419
 
420
  /* the task is blocked on a synchronization primitive. we have to
421
     remove it from the master module -and- from the local queue! */
422
  iq_extract(p,&lev->ready);
423
 
424
  /* and finally, a preemption check! (it will also call guest_end) */
425
  EDFSTAR_check_preemption(lev);
426
}
427
 
428
static int EDFSTAR_public_message(LEVEL l, PID p, void *m)
429
{
430
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
431
  struct timespec temp;
432
 
433
#ifdef EDFSTAR_DEBUG
434
  edfstar_printf("(E:ecy ");
435
#endif
436
 
437
  switch ((long)(m)) {
438
 
439
    /* Task EndCycle */
440
  case (long)(NULL):
441
 
442
    /* we call guest_end directly here because the same task may
443
       be reinserted in the queue before calling the preemption check! */
444
    level_table[ lev->scheduling_level ]->
445
      private_extract(lev->scheduling_level,p);
446
    lev->activated = NIL;
447
 
448
    iq_extract(p,&lev->ready);
449
 
450
    /* we reset the capacity counters... */
451
    proc_table[p].avail_time = proc_table[p].wcet;
452
 
453
    if (lev->nact[p] > 0) {
454
 
455
      #ifdef EDFSTAR_DEBUG
456
        edfstar_printf2("E%d",p);
457
      #endif
458
 
459
      /* Pending activation: reactivate the thread!!! */
460
      lev->nact[p]--;
461
 
462
      /* see also EDFSTAR_timer_deadline */
463
      kern_gettime(&temp);
464
 
465
      EDFSTAR_internal_activate(lev,p, &temp);
466
 
467
      /* check if the deadline has already expired */
468
      temp = *iq_query_timespec(p, &lev->ready);
469
      if (TIMESPEC_A_LT_B(&temp, &schedule_time)) {
470
          /* count the deadline miss */
471
          lev->dline_miss[p]++;
472
          kern_event_delete(lev->deadline_timer[p]);
473
      }
474
 
475
    } else {
476
 
477
      #ifdef EDFSTAR_DEBUG
478
        edfstar_printf("e%d",p);
479
      #endif
480
 
481
      /* the task has terminated his job before it consume the wcet. All OK! */
482
      proc_table[p].status = EDFSTAR_IDLE;
483
 
484
      /* and finally, a preemption check! */
485
      EDFSTAR_check_preemption(lev);
486
 
487
      /* when the deadline timer fire, it recognize the situation and set
488
         correctly all the stuffs (like reactivation, etc... ) */
489
    }
490
#ifdef EDFSTAR_DEBUG
491
    edfstar_printf(")");
492
#endif
493
 
494
    jet_update_endcycle(); /* Update the Jet data... */
495
    trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */
496
    break;
497
 
498
  default:
499
 
241 giacomo 500
    break;
221 giacomo 501
 
502
  }
503
  return 0;
504
}
505
 
506
static void EDFSTAR_public_end(LEVEL l, PID p)
507
{
508
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
509
 
510
#ifdef EDFSTAR_DEBUG
511
  edfstar_printf("(E:end)");
512
#endif
513
 
514
  iq_extract(p,&lev->ready);
515
 
516
  /* we finally put the task in the ready queue */
517
  proc_table[p].status = FREE;
518
 
519
  iq_insertfirst(p,&freedesc);
520
 
521
  if (lev->deadline_timer[p] != -1) {
522
    kern_event_delete(lev->deadline_timer[p]);
523
  }
524
 
525
  /* and finally, a preemption check! (it will also call guest_end) */
526
  EDFSTAR_check_preemption(lev);
527
}
528
 
529
/* Guest Functions
530
   These functions manages a JOB_TASK_MODEL, that is used to put
531
   a guest task in the EDFSTAR ready queue. */
532
 
533
static void EDFSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m)
534
{
535
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
536
  JOB_TASK_MODEL *job;
537
 
538
  if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) {
539
    kern_raise(XINVALID_TASK, p);
540
    return;
541
  }
542
 
543
  job = (JOB_TASK_MODEL *)m;
544
 
545
  /* if the EDFSTAR_guest_create is called, then the pclass must be a
546
     valid pclass. */
547
 
548
  *iq_query_timespec(p, &lev->ready) = job->deadline;
549
 
550
  lev->deadline_timer[p] = -1;
551
  lev->dline_miss[p]     = 0;
552
  lev->wcet_miss[p]      = 0;
553
  lev->nact[p]           = 0;
554
 
555
  if (job->noraiseexc)
556
    lev->flag[p] |= EDFSTAR_FLAG_NORAISEEXC;
557
  else {
558
    lev->flag[p] &= ~EDFSTAR_FLAG_NORAISEEXC;
559
    lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
560
                                             EDFSTAR_timer_guest_deadline,
561
                                             (void *)p);
562
  }
563
 
564
  lev->period[p] = job->period;
565
 
566
  /* Insert task in the correct position */
567
  iq_timespec_insert(p,&lev->ready);
568
  proc_table[p].status = EDFSTAR_READY;
569
 
570
  /* check for preemption */
571
  EDFSTAR_check_preemption(lev);
572
 
573
  /* there is no bandwidth guarantee at this level, it is performed
574
     by the level that inserts guest tasks... */
575
}
576
 
577
static void EDFSTAR_private_dispatch(LEVEL l, PID p, int nostop)
578
{
579
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
580
 
581
  level_table[ lev->scheduling_level ]->
582
    private_dispatch(lev->scheduling_level,p,nostop);
583
}
584
 
585
static void EDFSTAR_private_epilogue(LEVEL l, PID p)
586
{
587
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
588
 
589
  /* the task has been preempted. it returns into the ready queue... */
590
  level_table[ lev->scheduling_level ]->
591
    private_epilogue(lev->scheduling_level,p);
592
 
593
  proc_table[p].status = EDFSTAR_READY;
594
}
595
 
596
static void EDFSTAR_private_extract(LEVEL l, PID p)
597
{
598
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
599
 
600
#ifdef EDFSTAR_DEBUG
601
  //kern_printf("EDFSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
602
#endif
603
 
604
  iq_extract(p, &lev->ready);
605
 
606
  /* we remove the deadline timer, because the slice is finished */
607
  if (lev->deadline_timer[p] != NIL) {
608
#ifdef EDFSTAR_DEBUG
609
//    kern_printf("EDFSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
610
#endif
611
    kern_event_delete(lev->deadline_timer[p]);
612
    lev->deadline_timer[p] = NIL;
613
  }
614
 
615
  /* and finally, a preemption check! (it will also call guest_end() */
616
  EDFSTAR_check_preemption(lev);
617
}
618
 
619
/* Registration functions */
620
 
621
/* Registration function:
622
    int flags                 the init flags ... see EDFSTAR.h */
623
 
624
LEVEL EDFSTAR_register_level(int master)
625
{
626
  LEVEL l;            /* the level that we register */
627
  EDFSTAR_level_des *lev;  /* for readableness only */
628
  PID i;              /* a counter */
629
 
630
#ifdef EDFSTAR_DEBUG
631
  printk("EDFSTAR_register_level\n");
632
#endif
633
 
634
  /* request an entry in the level_table */
635
  l = level_alloc_descriptor(sizeof(EDFSTAR_level_des));
636
 
637
  lev = (EDFSTAR_level_des *)level_table[l];
638
 
639
  printk("    lev=%d\n",(int)lev);
640
 
641
  /* fill the standard descriptor */
642
  lev->l.private_insert   = EDFSTAR_private_insert;
643
  lev->l.private_extract  = EDFSTAR_private_extract;
644
  lev->l.private_dispatch = EDFSTAR_private_dispatch;
645
  lev->l.private_epilogue = EDFSTAR_private_epilogue;
646
 
647
  lev->l.public_guarantee = NULL;
648
  lev->l.public_eligible  = EDFSTAR_public_eligible;
649
  lev->l.public_create    = EDFSTAR_public_create;
650
  lev->l.public_end       = EDFSTAR_public_end;
651
  lev->l.public_dispatch  = EDFSTAR_public_dispatch;
652
  lev->l.public_epilogue  = EDFSTAR_public_epilogue;
653
  lev->l.public_activate  = EDFSTAR_public_activate;
654
  lev->l.public_unblock   = EDFSTAR_public_unblock;
655
  lev->l.public_block     = EDFSTAR_public_block;
656
  lev->l.public_message   = EDFSTAR_public_message;
657
 
658
  /* fill the EDFSTAR descriptor part */
659
  for(i=0; i<MAX_PROC; i++) {
660
    lev->period[i]         = 0;
661
    lev->deadline_timer[i] = -1;
662
    lev->flag[i]           = 0;
663
    lev->dline_miss[i]     = 0;
664
    lev->wcet_miss[i]      = 0;
665
    lev->nact[i]           = 0;
666
    lev->budget[i]         = NIL;
667
  }
668
 
669
  iq_init(&lev->ready, NULL, IQUEUE_NO_PRIORITY);
670
  lev->activated = NIL;
671
 
672
  lev->scheduling_level = master;
296 trimarchi 673
  lev->cap_lev=NIL;
674
  NULL_TIMESPEC(&lev->cap_lasttime);
221 giacomo 675
 
676
  return l;
677
}
678
 
679
int EDFSTAR_get_dline_miss(PID p)
680
{
681
  LEVEL l = proc_table[p].task_level;
682
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
683
 
684
  return lev->dline_miss[p];
685
}
686
 
687
int EDFSTAR_get_wcet_miss(PID p)
688
{
689
  LEVEL l = proc_table[p].task_level;
690
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
691
 
692
  return lev->wcet_miss[p];
693
}
694
 
695
int EDFSTAR_get_nact(PID p)
696
{
697
  LEVEL l = proc_table[p].task_level;
698
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
699
 
700
  return lev->nact[p];
701
}
702
 
703
int EDFSTAR_reset_dline_miss(PID p)
704
{
705
  LEVEL l = proc_table[p].task_level;
706
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
707
 
708
  lev->dline_miss[p] = 0;
709
  return 0;
710
}
711
 
712
int EDFSTAR_reset_wcet_miss(PID p)
713
{
714
  LEVEL l = proc_table[p].task_level;
715
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
716
 
717
  lev->wcet_miss[p] = 0;
718
  return 0;
719
}
720
 
721
int EDFSTAR_setbudget(LEVEL l, PID p, int budget)
722
{
723
 
724
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
725
 
726
  lev->budget[p] = budget;
727
 
728
  return 0;
729
 
730
}
731
 
732
int EDFSTAR_getbudget(LEVEL l, PID p)
733
{
734
 
735
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
736
 
737
  return lev->budget[p];
738
 
739
}
236 giacomo 740
 
741
int EDFSTAR_budget_has_thread(LEVEL l, int budget)
742
{
743
 
744
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
745
  int i;
746
 
747
  for(i = 0; i< MAX_PROC; i++)
748
    if (lev->budget[i] == budget) return 1;
749
 
750
  return 0;
751
 
752
}