Subversion Repositories shark

Rev

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