Subversion Repositories shark

Rev

Rev 14 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 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
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/**
22
 ------------
29 pj 23
 CVS :        $Id: edf.c,v 1.3 2002-11-11 08:32:06 pj Exp $
2 pj 24
 
25
 File:        $File$
29 pj 26
 Revision:    $Revision: 1.3 $
27
 Last update: $Date: 2002-11-11 08:32:06 $
2 pj 28
 ------------
29
 
30
 This file contains the scheduling module EDF (Earliest Deadline First)
31
 
32
 Read edf.h for further details.
33
 
34
**/
35
 
36
/*
37
 * Copyright (C) 2000 Paolo Gai
38
 *
39
 * This program is free software; you can redistribute it and/or modify
40
 * it under the terms of the GNU General Public License as published by
41
 * the Free Software Foundation; either version 2 of the License, or
42
 * (at your option) any later version.
43
 *
44
 * This program is distributed in the hope that it will be useful,
45
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47
 * GNU General Public License for more details.
48
 *
49
 * You should have received a copy of the GNU General Public License
50
 * along with this program; if not, write to the Free Software
51
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
52
 *
53
 */
54
 
55
 
56
#include <modules/edf.h>
57
#include <ll/stdio.h>
58
#include <ll/string.h>
59
#include <kernel/model.h>
60
#include <kernel/descr.h>
61
#include <kernel/var.h>
62
#include <kernel/func.h>
63
#include <kernel/trace.h>
64
 
65
//#define edf_printf kern_printf
66
#define edf_printf printk
67
 
68
/*+ Status used in the level +*/
69
#define EDF_READY         MODULE_STATUS_BASE    /*+ - Ready status        +*/
70
#define EDF_WCET_VIOLATED MODULE_STATUS_BASE+2  /*+ when wcet is finished +*/
71
#define EDF_WAIT          MODULE_STATUS_BASE+3  /*+ to wait the deadline  +*/
72
#define EDF_IDLE          MODULE_STATUS_BASE+4  /*+ to wait the deadline  +*/
73
#define EDF_ZOMBIE        MODULE_STATUS_BASE+5  /*+ to wait the free time +*/
74
 
75
/*+ flags +*/
76
#define EDF_FLAG_SPORADIC    1
77
#define EDF_FLAG_NORAISEEXC  2
78
 
79
/*+ the level redefinition for the Earliest Deadline First level +*/
80
typedef struct {
81
  level_des l;     /*+ the standard level descriptor          +*/
82
 
83
  TIME period[MAX_PROC]; /*+ The task periods; the deadlines are
84
                       stored in the priority field           +*/
85
  int deadline_timer[MAX_PROC];
86
                   /*+ The task deadline timers               +*/
87
 
88
  int flag[MAX_PROC];
89
                   /*+ used to manage the JOB_TASK_MODEL and the
90
                       periodicity                            +*/
91
 
29 pj 92
  IQUEUE ready;     /*+ the ready queue                        +*/
2 pj 93
 
94
  int flags;       /*+ the init flags...                      +*/
95
 
96
  bandwidth_t U;   /*+ the used bandwidth                     +*/
97
 
98
} EDF_level_des;
99
 
100
 
101
static char *EDF_status_to_a(WORD status)
102
{
103
  if (status < MODULE_STATUS_BASE)
104
    return status_to_a(status);
105
 
106
  switch (status) {
107
    case EDF_READY        : return "EDF_Ready";
108
    case EDF_WCET_VIOLATED: return "EDF_Wcet_Violated";
109
    case EDF_WAIT         : return "EDF_Sporadic_Wait";
110
    case EDF_IDLE         : return "EDF_Idle";
111
    case EDF_ZOMBIE       : return "EDF_Zombie";
112
    default               : return "EDF_Unknown";
113
  }
114
}
115
 
116
static void EDF_timer_deadline(void *par)
117
{
118
  PID p = (PID) par;
119
  EDF_level_des *lev;
29 pj 120
  struct timespec *temp;
2 pj 121
 
122
  edf_printf("$");
123
 
124
  lev = (EDF_level_des *)level_table[proc_table[p].task_level];
125
 
126
  switch (proc_table[p].status) {
127
    case EDF_ZOMBIE:
128
      /* we finally put the task in the ready queue */
129
      proc_table[p].status = FREE;
29 pj 130
      iq_insertfirst(p,&freedesc);
2 pj 131
      /* and free the allocated bandwidth */
132
      lev->U -= (MAX_BANDWIDTH/lev->period[p]) * proc_table[p].wcet;
133
      break;
134
 
135
    case EDF_IDLE:
136
      /* tracer stuff */
137
      trc_logevent(TRC_INTACTIVATION,&p);
138
      /* similar to EDF_task_activate */
29 pj 139
      temp = iq_query_timespec(p,&lev->ready);
2 pj 140
      TIMESPEC_ASSIGN(&proc_table[p].request_time,
29 pj 141
                      temp);
142
      ADDUSEC2TIMESPEC(lev->period[p], temp);
2 pj 143
      proc_table[p].status = EDF_READY;
29 pj 144
      iq_timespec_insert(p,&lev->ready);
145
      lev->deadline_timer[p] = kern_event_post(temp,
2 pj 146
                                               EDF_timer_deadline,
147
                                               (void *)p);
29 pj 148
      edf_printf("(dline p%d ev%d %d.%d)",(int)p,(int)lev->deadline_timer[p],(int)temp->tv_sec,(int)temp->tv_nsec/1000);
2 pj 149
      //printk("(d%d idle priority set to %d)",p,proc_table[p].priority );
150
      event_need_reschedule();
151
      printk("el%d|",p);
152
      break;
153
 
154
    case EDF_WAIT:
155
      /* Without this, the task cannot be reactivated!!! */
156
      proc_table[p].status = SLEEP;
157
      break;
158
 
159
    default:
160
      /* else, a deadline miss occurred!!! */
161
      edf_printf("\nstatus %d\n", (int)proc_table[p].status);
162
      edf_printf("timer_deadline:AAARRRGGGHHH!!!");
163
      kern_raise(XDEADLINE_MISS,p);
164
  }
165
}
166
 
167
static void EDF_timer_guest_deadline(void *par)
168
{
169
  PID p = (PID) par;
170
 
171
  edf_printf("AAARRRGGGHHH!!!");
172
  kern_raise(XDEADLINE_MISS,p);
173
}
174
 
175
static int EDF_level_accept_task_model(LEVEL l, TASK_MODEL *m)
176
{
177
  if (m->pclass == HARD_PCLASS || m->pclass == (HARD_PCLASS | l)) {
178
    HARD_TASK_MODEL *h = (HARD_TASK_MODEL *)m;
179
 
180
    if (h->wcet && h->mit)
181
      return 0;
182
  }
183
 
184
  return -1;
185
}
186
 
187
static int EDF_level_accept_guest_model(LEVEL l, TASK_MODEL *m)
188
{
189
  if (m->pclass == JOB_PCLASS || m->pclass == (JOB_PCLASS | l))
190
    return 0;
191
  else
192
    return -1;
193
}
194
 
195
 
196
static char *onoff(int i)
197
{
198
  if (i)
199
    return "On ";
200
  else
201
    return "Off";
202
}
203
 
204
static void EDF_level_status(LEVEL l)
205
{
206
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
29 pj 207
  PID p = iq_query_first(&lev->ready);
2 pj 208
 
209
  kern_printf("Wcet     Check    : %s\n",
210
            onoff(lev->flags & EDF_ENABLE_WCET_CHECK));
211
  kern_printf("On-line guarantee : %s\n",
212
            onoff(lev->flags & EDF_ENABLE_GUARANTEE));
213
  kern_printf("Used Bandwidth    : %u/%u\n",
214
            lev->U, MAX_BANDWIDTH);
215
 
216
  while (p != NIL) {
217
    if ((proc_table[p].pclass) == JOB_PCLASS)
218
      kern_printf("Pid: %2d (GUEST)\n", p);
219
    else
220
      kern_printf("Pid: %2d Name: %10s %s: %9ld Dline: %9ld.%6ld Stat: %s\n",
221
              p,
222
              proc_table[p].name,
223
              lev->flag[p] & EDF_FLAG_SPORADIC ? "MinITime" : "Period  ",
224
              lev->period[p],
29 pj 225
              iq_query_timespec(p, &lev->ready)->tv_sec,
226
              iq_query_timespec(p, &lev->ready)->tv_nsec/1000,
2 pj 227
              EDF_status_to_a(proc_table[p].status));
29 pj 228
    p = iq_query_next(p, &lev->ready);
2 pj 229
  }
230
 
231
  for (p=0; p<MAX_PROC; p++)
232
    if (proc_table[p].task_level == l && proc_table[p].status != EDF_READY
233
        && proc_table[p].status != FREE )
234
      kern_printf("Pid: %2d Name: %10s %s: %9ld Dline: %9ld.%6ld Stat: %s\n",
235
                p,
236
                proc_table[p].name,
237
                lev->flag[p] & EDF_FLAG_SPORADIC ? "MinITime" : "Period  ",
238
                lev->period[p],
29 pj 239
                iq_query_timespec(p, &lev->ready)->tv_sec,
240
                iq_query_timespec(p, &lev->ready)->tv_nsec/1000,
2 pj 241
                EDF_status_to_a(proc_table[p].status));
242
}
243
 
244
/* The scheduler only gets the first task in the queue */
245
static PID EDF_level_scheduler(LEVEL l)
246
{
247
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
248
 
249
/*  {  // print 4 dbg the ready queue
250
    PID p= lev->ready;
251
    kern_printf("(s");
252
    while (p != NIL) {
253
      kern_printf("%d ",p);
254
      p = proc_table[p].next;
255
    }
256
    kern_printf(") ");
257
  }
258
  */
29 pj 259
  return iq_query_first(&lev->ready);
2 pj 260
}
261
 
262
/* The on-line guarantee is enabled only if the appropriate flag is set... */
263
static int EDF_level_guarantee(LEVEL l, bandwidth_t *freebandwidth)
264
{
265
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
266
 
267
  if (lev->flags & EDF_FAILED_GUARANTEE) {
268
    *freebandwidth = 0;
269
    return 0;
270
  }
271
  else
272
    if (*freebandwidth >= lev->U) {
273
      *freebandwidth -= lev->U;
274
      return 1;
275
    }
276
    else
277
      return 0;
278
 
279
}
280
 
281
static int EDF_task_create(LEVEL l, PID p, TASK_MODEL *m)
282
{
283
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
284
 
285
  /* if the EDF_task_create is called, then the pclass must be a
286
     valid pclass. */
287
 
288
  HARD_TASK_MODEL *h = (HARD_TASK_MODEL *)m;
289
 
290
  lev->period[p] = h->mit;
291
 
292
  if (h->periodicity == APERIODIC)
293
    lev->flag[p] = EDF_FLAG_SPORADIC;
294
  else
295
    lev->flag[p] = 0;
296
  lev->deadline_timer[p] = -1;
297
 
298
  /* Enable wcet check */
299
  if (lev->flags & EDF_ENABLE_WCET_CHECK) {
300
    proc_table[p].avail_time = h->wcet;
301
    proc_table[p].wcet       = h->wcet;
302
    proc_table[p].control |= CONTROL_CAP;
303
  }
304
 
305
  /* update the bandwidth... */
306
  if (lev->flags & EDF_ENABLE_GUARANTEE) {
307
    bandwidth_t b;
308
    b = (MAX_BANDWIDTH / h->mit) * h->wcet;
309
 
310
    /* really update lev->U, checking an overflow... */
311
    if (MAX_BANDWIDTH - lev->U > b)
312
      lev->U += b;
313
    else
314
      /* The task can NOT be guaranteed (U>MAX_BANDWIDTH)...
315
         in this case, we don't raise an exception... in fact, after the
316
         EDF_task_create the task_create will call level_guarantee that return
317
         -1... return -1 in EDF_task_create isn't correct, because:
318
           . generally, the guarantee must be done when also the resources
319
             are registered
320
           . returning -1 will cause the task_create to return with an errno
321
             ETASK_CREATE instead of ENO_GUARANTEE!!!
322
 
323
         Why I use the flag??? because if the lev->U overflows, if i.e. I set
324
         it to MAX_BANDWIDTH, I lose the correct allocated bandwidth...
325
      */
326
      lev->flags |= EDF_FAILED_GUARANTEE;
327
  }
328
 
329
  return 0; /* OK, also if the task cannot be guaranteed... */
330
}
331
 
332
static void EDF_task_detach(LEVEL l, PID p)
333
{
334
  /* the EDF level doesn't introduce any dinamic allocated new field.
335
     we have only to reset the NO_GUARANTEE FIELD and decrement the allocated
336
     bandwidth */
337
 
338
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
339
 
340
  if (lev->flags & EDF_FAILED_GUARANTEE)
341
    lev->flags &= ~EDF_FAILED_GUARANTEE;
342
  else
343
    lev->U -= (MAX_BANDWIDTH / lev->period[p]) * proc_table[p].wcet;
344
}
345
 
346
static int EDF_task_eligible(LEVEL l, PID p)
347
{
348
  return 0; /* if the task p is chosen, it is always eligible */
349
}
350
 
351
static void EDF_task_dispatch(LEVEL l, PID p, int nostop)
352
{
353
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
354
 
355
  edf_printf("(disp p%d %d.%d)",(int)p,(int)schedule_time.tv_sec,(int)schedule_time.tv_nsec/1000);
356
 
357
  /* the task state is set EXE by the scheduler()
358
     we extract the task from the ready queue
359
     NB: we can't assume that p is the first task in the queue!!! */
29 pj 360
  iq_extract(p, &lev->ready);
2 pj 361
}
362
 
363
static void EDF_task_epilogue(LEVEL l, PID p)
364
{
365
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
366
 
367
  edf_printf("(epil p%d %d.%d)",p,(int)schedule_time.tv_sec,(int)schedule_time.tv_nsec/1000);
368
 
369
  /* check if the wcet is finished... */
370
  if ((lev->flags & EDF_ENABLE_WCET_CHECK) && proc_table[p].avail_time <= 0) {
371
    /* if it is, raise a XWCET_VIOLATION exception */
372
    kern_raise(XWCET_VIOLATION,p);
373
    proc_table[p].status = EDF_WCET_VIOLATED;
374
  }
375
  else {
376
    /* the task has been preempted. it returns into the ready queue... */
29 pj 377
    iq_timespec_insert(p,&lev->ready);
2 pj 378
    proc_table[p].status = EDF_READY;
379
  }
380
}
381
 
382
static void EDF_task_activate(LEVEL l, PID p)
383
{
384
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
29 pj 385
  struct timespec *temp;
2 pj 386
 
387
  if (proc_table[p].status == EDF_WAIT) {
388
    kern_raise(XACTIVATION,p);
389
    return;
390
  }
391
 
392
  /* Test if we are trying to activate a non sleeping task    */
393
  /* Ignore this; the task is already active                  */
394
  if (proc_table[p].status != SLEEP &&
395
      proc_table[p].status != EDF_WCET_VIOLATED)
396
    return;
397
 
398
 
399
  /* see also EDF_timer_deadline */
400
  ll_gettime(TIME_EXACT, &proc_table[p].request_time);
401
 
29 pj 402
  temp = iq_query_timespec(p, &lev->ready);
403
  TIMESPEC_ASSIGN(temp, &proc_table[p].request_time);
404
  ADDUSEC2TIMESPEC(lev->period[p], temp);
2 pj 405
 
406
  /* Insert task in the correct position */
407
  proc_table[p].status = EDF_READY;
29 pj 408
  iq_timespec_insert(p,&lev->ready);
2 pj 409
 
410
  /* Set the deadline timer */
29 pj 411
  lev->deadline_timer[p] = kern_event_post(temp,
2 pj 412
                                           EDF_timer_deadline,
413
                                           (void *)p);
29 pj 414
  edf_printf("(dline p%d ev%d %d.%d)",p,(int)lev->deadline_timer[p],(int)temp->tv_sec,(int)temp->tv_nsec/1000);
2 pj 415
}
416
 
417
static void EDF_task_insert(LEVEL l, PID p)
418
{
419
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
420
 
421
  /* Similar to EDF_task_activate, but we don't check in what state
422
     the task is and we don't set the request_time*/
423
 
424
  /* Insert task in the coEDFect position */
425
  proc_table[p].status = EDF_READY;
29 pj 426
  iq_timespec_insert(p,&lev->ready);
2 pj 427
}
428
 
429
static void EDF_task_extract(LEVEL l, PID p)
430
{
431
  /* Extract the running task from the level
432
     . we have already extract it from the ready queue at the dispatch time.
433
     . the capacity event have to be removed by the generic kernel
434
     . the wcet don't need modification...
435
     . the state of the task is set by the calling function
436
     . the deadline must remain...
437
 
438
     So, we do nothing!!!
439
  */
440
}
441
 
442
static void EDF_task_endcycle(LEVEL l, PID p)
443
{
444
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
445
 
446
  edf_printf("(ecyc p%d %d.%d)",p,(int)schedule_time.tv_sec,(int)schedule_time.tv_nsec/1000);
447
 
448
  /* the task has terminated his job before it consume the wcet. All OK! */
449
  if (lev->flag[p] & EDF_FLAG_SPORADIC)
450
    proc_table[p].status = EDF_WAIT;
451
  else /* pclass = sporadic_pclass */
452
    proc_table[p].status = EDF_IDLE;
453
 
454
  /* we reset the capacity counters... */
455
  if (lev->flags & EDF_ENABLE_WCET_CHECK)
456
    proc_table[p].avail_time = proc_table[p].wcet;
457
 
458
  /* when the deadline timer fire, it recognize the situation and set
459
     correctly all the stuffs (like reactivation, request_time, etc... ) */
460
}
461
 
462
static void EDF_task_end(LEVEL l, PID p)
463
{
464
//  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
465
 
466
  proc_table[p].status = EDF_ZOMBIE;
467
 
468
  /* When the deadline timer fire, it put the task descriptor in
469
     the free queue, and free the allocated bandwidth... */
470
}
471
 
472
static void EDF_task_sleep(LEVEL l, PID p)
473
{
474
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
475
 
476
  /* the task has terminated his job before it consume the wcet. All OK! */
477
  proc_table[p].status = EDF_WAIT;
478
 
479
  /* we reset the capacity counters... */
480
  if (lev->flags & EDF_ENABLE_WCET_CHECK)
481
    proc_table[p].avail_time = proc_table[p].wcet;
482
 
483
  /* when the deadline timer fire, it recognize the situation and set
484
     correctly the task state to sleep... */
485
}
486
 
487
 
488
/* Guest Functions
489
   These functions manages a JOB_TASK_MODEL, that is used to put
490
   a guest task in the EDF ready queue. */
491
 
492
static int EDF_guest_create(LEVEL l, PID p, TASK_MODEL *m)
493
{
494
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
495
  JOB_TASK_MODEL *job = (JOB_TASK_MODEL *)m;
496
 
497
  /* if the EDF_guest_create is called, then the pclass must be a
498
     valid pclass. */
499
 
29 pj 500
  *iq_query_timespec(p, &lev->ready) = job->deadline;
2 pj 501
 
502
  lev->deadline_timer[p] = -1;
503
 
504
  if (job->noraiseexc)
505
    lev->flag[p] = EDF_FLAG_NORAISEEXC;
506
  else
507
    lev->flag[p] = 0;
508
 
509
  lev->period[p] = job->period;
510
 
511
  /* there is no bandwidth guarantee at this level, it is performed
512
     by the level that inserts guest tasks... */
513
 
514
  return 0; /* OK, also if the task cannot be guaranteed... */
515
}
516
 
517
static void EDF_guest_detach(LEVEL l, PID p)
518
{
519
  /* the EDF level doesn't introduce any dinamic allocated new field.
520
     No guarantee is performed on guest tasks... so we don't have to reset
521
     the NO_GUARANTEE FIELD */
522
}
523
 
524
static void EDF_guest_dispatch(LEVEL l, PID p, int nostop)
525
{
526
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
527
 
528
  /* the task state is set to EXE by the scheduler()
529
     we extract the task from the ready queue
530
     NB: we can't assume that p is the first task in the queue!!! */
29 pj 531
  iq_extract(p, &lev->ready);
2 pj 532
}
533
 
534
static void EDF_guest_epilogue(LEVEL l, PID p)
535
{
536
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
537
 
538
  /* the task has been preempted. it returns into the ready queue... */
29 pj 539
  iq_timespec_insert(p,&lev->ready);
2 pj 540
  proc_table[p].status = EDF_READY;
541
}
542
 
543
static void EDF_guest_activate(LEVEL l, PID p)
544
{
545
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
546
 
547
  /* Insert task in the correct position */
29 pj 548
  iq_timespec_insert(p,&lev->ready);
2 pj 549
  proc_table[p].status = EDF_READY;
550
 
551
  /* Set the deadline timer */
552
  if (!(lev->flag[p] & EDF_FLAG_NORAISEEXC))
29 pj 553
    lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
2 pj 554
                                             EDF_timer_guest_deadline,
555
                                             (void *)p);
556
 
557
}
558
 
559
static void EDF_guest_insert(LEVEL l, PID p)
560
{
561
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
562
 
563
  /* Insert task in the correct position */
29 pj 564
  iq_timespec_insert(p,&lev->ready);
2 pj 565
  proc_table[p].status = EDF_READY;
566
}
567
 
568
static void EDF_guest_extract(LEVEL l, PID p)
569
{
570
  /* Extract the running task from the level
571
     . we have already extract it from the ready queue at the dispatch time.
572
     . the state of the task is set by the calling function
573
     . the deadline must remain...
574
 
575
     So, we do nothing!!!
576
  */
577
}
578
 
579
static void EDF_guest_endcycle(LEVEL l, PID p)
14 pj 580
{ kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 581
 
582
static void EDF_guest_end(LEVEL l, PID p)
583
{
584
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
585
 
586
  //kern_printf("EDF_guest_end: dline timer %d\n",lev->deadline_timer[p]);
587
  if (proc_table[p].status == EDF_READY)
588
  {
29 pj 589
    iq_extract(p, &lev->ready);
2 pj 590
    //kern_printf("(g_end rdy extr)");
591
  }
592
 
593
  /* we remove the deadline timer, because the slice is finished */
594
  if (lev->deadline_timer[p] != NIL) {
595
//    kern_printf("EDF_guest_end: dline timer %d\n",lev->deadline_timer[p]);
596
    event_delete(lev->deadline_timer[p]);
597
    lev->deadline_timer[p] = NIL;
598
  }
599
 
600
}
601
 
602
static void EDF_guest_sleep(LEVEL l, PID p)
14 pj 603
{ kern_raise(XINVALID_GUEST,exec_shadow); }
2 pj 604
 
605
 
606
 
607
/* Registration functions */
608
 
609
/*+ Registration function:
610
    int flags                 the init flags ... see edf.h +*/
611
void EDF_register_level(int flags)
612
{
613
  LEVEL l;            /* the level that we register */
614
  EDF_level_des *lev;  /* for readableness only */
615
  PID i;              /* a counter */
616
 
617
  printk("EDF_register_level\n");
618
 
619
  /* request an entry in the level_table */
620
  l = level_alloc_descriptor();
621
 
622
  printk("    alloco descrittore %d %d\n",l,(int)sizeof(EDF_level_des));
623
 
624
  /* alloc the space needed for the EDF_level_des */
625
  lev = (EDF_level_des *)kern_alloc(sizeof(EDF_level_des));
626
 
627
  printk("    lev=%d\n",(int)lev);
628
 
629
  /* update the level_table with the new entry */
630
  level_table[l] = (level_des *)lev;
631
 
632
  /* fill the standard descriptor */
633
  strncpy(lev->l.level_name,  EDF_LEVELNAME, MAX_LEVELNAME);
634
  lev->l.level_code               = EDF_LEVEL_CODE;
635
  lev->l.level_version            = EDF_LEVEL_VERSION;
636
 
637
  lev->l.level_accept_task_model  = EDF_level_accept_task_model;
638
  lev->l.level_accept_guest_model = EDF_level_accept_guest_model;
639
  lev->l.level_status             = EDF_level_status;
640
  lev->l.level_scheduler          = EDF_level_scheduler;
641
 
642
  if (flags & EDF_ENABLE_GUARANTEE)
643
    lev->l.level_guarantee        = EDF_level_guarantee;
644
  else
645
    lev->l.level_guarantee        = NULL;
646
 
647
  lev->l.task_create              = EDF_task_create;
648
  lev->l.task_detach              = EDF_task_detach;
649
  lev->l.task_eligible            = EDF_task_eligible;
650
  lev->l.task_dispatch            = EDF_task_dispatch;
651
  lev->l.task_epilogue            = EDF_task_epilogue;
652
  lev->l.task_activate            = EDF_task_activate;
653
  lev->l.task_insert              = EDF_task_insert;
654
  lev->l.task_extract             = EDF_task_extract;
655
  lev->l.task_endcycle            = EDF_task_endcycle;
656
  lev->l.task_end                 = EDF_task_end;
657
  lev->l.task_sleep               = EDF_task_sleep;
658
 
659
  lev->l.guest_create             = EDF_guest_create;
660
  lev->l.guest_detach             = EDF_guest_detach;
661
  lev->l.guest_dispatch           = EDF_guest_dispatch;
662
  lev->l.guest_epilogue           = EDF_guest_epilogue;
663
  lev->l.guest_activate           = EDF_guest_activate;
664
  lev->l.guest_insert             = EDF_guest_insert;
665
  lev->l.guest_extract            = EDF_guest_extract;
666
  lev->l.guest_endcycle           = EDF_guest_endcycle;
667
  lev->l.guest_end                = EDF_guest_end;
668
  lev->l.guest_sleep              = EDF_guest_sleep;
669
 
670
  /* fill the EDF 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
  }
676
 
29 pj 677
  iq_init(&lev->ready, &freedesc, 0);
2 pj 678
  lev->flags = flags & 0x07;
679
  lev->U     = 0;
680
}
681
 
682
bandwidth_t EDF_usedbandwidth(LEVEL l)
683
{
684
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
685
  if (lev->l.level_code    == EDF_LEVEL_CODE &&
686
      lev->l.level_version == EDF_LEVEL_VERSION)
687
    return lev->U;
688
  else
689
    return 0;
690
}
691