Subversion Repositories shark

Rev

Rev 1036 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
961 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
 *   Anton Cervin
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
 ------------
23
 CVS :        $Id: edf.c,v 1.1 2005-02-25 10:53:41 pj Exp $
24
 
25
 File:        $File$
26
 Revision:    $Revision: 1.1 $
27
 Last update: $Date: 2005-02-25 10:53:41 $
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,2002 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 <edf/edf/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 <tracer.h>
64
 
65
//#define EDF_DEBUG
66
#define edf_printf kern_printf
67
#ifdef EDF_DEBUG
68
char *pnow() {
69
  static char buf[40];
70
  struct timespec t;
71
  sys_gettime(&t);
72
  sprintf(buf, "%ld.%06ld", t.tv_sec, t.tv_nsec/1000);
73
  return buf;
74
}
75
char *ptime1(struct timespec *t) {
76
  static char buf[40];
77
  sprintf(buf, "%ld.%06ld", t->tv_sec, t->tv_nsec/1000);
78
  return buf;
79
}
80
char *ptime2(struct timespec *t) {
81
  static char buf[40];
82
  sprintf(buf, "%ld.%06ld", t->tv_sec, t->tv_nsec/1000);
83
  return buf;
84
}
85
#endif
86
 
87
/* Statuses used in the level */
88
#define EDF_READY      MODULE_STATUS_BASE    /* ready */
89
#define EDF_IDLE       MODULE_STATUS_BASE+1  /* idle, waiting for offset/eop */
90
#define EDF_WAIT       MODULE_STATUS_BASE+2  /* to sleep, waiting for eop */
91
#define EDF_ZOMBIE     MODULE_STATUS_BASE+3  /* to free, waiting for eop */
92
 
93
/* Task flags */
94
#define EDF_FLAG_SPORADIC    1   /* the task is sporadic */
95
#define EDF_FLAG_SPOR_LATE   2   /* sporadic task with period overrun */ 
96
 
97
 
98
/* Task descriptor */
99
typedef struct {
100
  int flags;                    /* task flags                         */
101
  TIME period;                  /* period (or inter-arrival interval) */
102
  TIME rdeadline;               /* relative deadline                  */
103
  TIME offset;                  /* release offset                     */
104
  struct timespec release;      /* release time of current instance   */
105
  struct timespec adeadline;    /* latest assigned deadline           */
106
  int dl_timer;                 /* deadline timer                     */
107
  int eop_timer;                /* end of period timer                */
108
  int off_timer;                /* timer offset                       */
109
  int dl_miss;                  /* deadline miss counter              */
110
  int wcet_miss;                /* WCET miss counter                  */
111
  int act_miss;                 /* activation miss counter            */
112
  int nact;                     /* number of pending periodic jobs    */
113
} EDF_task_des;
114
 
115
 
116
/* Level descriptor */
117
typedef struct {
118
  level_des l;                  /* standard level descriptor          */
119
  int flags;                    /* level flags                        */
120
  IQUEUE ready;                 /* the ready queue                    */
121
  bandwidth_t U;                /* used bandwidth                     */
122
  EDF_task_des tvec[MAX_PROC];  /* vector of task descriptors         */
123
} EDF_level_des;
124
 
125
 
126
/* Module function cross-references */
127
static void EDF_intern_release(PID p, EDF_level_des *lev);
128
 
129
 
130
/**** Timer event handler functions ****/
131
 
132
/* This timer event handler is called at the end of the period */
133
static void EDF_timer_endperiod(void *par)
134
{
135
  PID p = (PID) par;
136
  EDF_level_des *lev = (EDF_level_des *)level_table[proc_table[p].task_level];
137
  EDF_task_des *td = &lev->tvec[p];
138
 
139
  td->eop_timer = -1;
140
 
141
  if (proc_table[p].status == EDF_ZOMBIE) {
142
    /* put the task in the FREE state */
143
    proc_table[p].status = FREE;
144
    iq_insertfirst(p,&freedesc);
145
    /* free the allocated bandwidth */
146
    lev->U -= (MAX_BANDWIDTH/td->rdeadline) * proc_table[p].wcet;
147
    return;
148
  }
149
 
150
  if (proc_table[p].status == EDF_WAIT) {
151
    proc_table[p].status = SLEEP;
152
    return;
153
  }
154
 
155
  if (td->flags & EDF_FLAG_SPORADIC) {
156
    /* the task is sporadic and still busy, mark it as late */
157
    td->flags |= EDF_FLAG_SPOR_LATE;
158
  } else {
159
    /* the task is periodic, release/queue another instance */
160
    EDF_intern_release(p, lev);
161
  }
162
}
163
 
164
/* This timer event handler is called when a task misses its deadline */
165
static void EDF_timer_deadline(void *par)
166
{
167
  PID p = (PID) par;
168
  EDF_level_des *lev = (EDF_level_des *)level_table[proc_table[p].task_level];
169
  EDF_task_des *td = &lev->tvec[p];
170
 
171
  td->dl_timer = -1;
172
 
173
  TRACER_LOGEVENT(FTrace_EVT_task_deadline_miss,
174
                  (unsigned short int)proc_table[p].context,0);
175
 
176
  if (lev->flags & EDF_ENABLE_DL_EXCEPTION) {
177
    kern_raise(XDEADLINE_MISS,p);
178
  } else {
179
    td->dl_miss++;
180
  }
181
}
182
 
183
/* This timer event handler is called after waiting for an offset */
184
static void EDF_timer_offset(void *par)
185
{
186
  PID p = (PID) par;
187
  EDF_level_des *lev;
188
  lev = (EDF_level_des *)level_table[proc_table[p].task_level];
189
  EDF_task_des *td = &lev->tvec[p];
190
 
191
  td->off_timer = -1;
192
 
193
  /* release the task now */
194
  EDF_intern_release(p, lev);
195
 
196
}
197
 
198
/* This function is called when a guest task misses its deadline */
199
static void EDF_timer_guest_deadline(void *par)
200
{
201
  PID p = (PID) par;
202
  EDF_level_des *lev = (EDF_level_des *)level_table[proc_table[p].task_level];
203
  EDF_task_des *td = &lev->tvec[p];
204
 
205
  td->dl_timer = -1;
206
 
207
  TRACER_LOGEVENT(FTrace_EVT_task_deadline_miss,
208
                  (unsigned short int)proc_table[p].context,0);
209
 
210
  kern_raise(XDEADLINE_MISS,p);
211
 
212
}
213
 
214
 
215
/**** Internal utility functions ****/
216
 
217
/* Release (or queue) a task, post deadline and endperiod timers */
218
static void EDF_intern_release(PID p, EDF_level_des *lev)
219
{
220
  struct timespec temp;
221
  EDF_task_des *td = &lev->tvec[p];
222
 
223
  /* post deadline timer */
224
  if (lev->flags & EDF_ENABLE_DL_CHECK) {
225
    temp = td->release;
226
    ADDUSEC2TIMESPEC(td->rdeadline, &temp);
227
    if (td->dl_timer != -1) {
228
        kern_event_delete(td->dl_timer);
229
        td->dl_timer = -1;
230
    }
231
    td->dl_timer = kern_event_post(&temp,EDF_timer_deadline,(void *)p);
232
  }
233
 
234
  /* release or queue next job */
235
  if (proc_table[p].status == EDF_IDLE) {
236
    /* assign deadline, insert task in the ready queue */
237
    proc_table[p].status = EDF_READY;
238
    *iq_query_timespec(p,&lev->ready) = td->adeadline;
239
    iq_timespec_insert(p,&lev->ready);
240
#ifdef EDF_DEBUG
241
    edf_printf("At %s: releasing %s with deadline %s\n", pnow(),
242
       proc_table[p].name, ptime1(&td->adeadline));
243
#endif
244
    /* increase assigned deadline */
245
    ADDUSEC2TIMESPEC(td->period, &td->adeadline);
246
    /* reschedule */
247
    event_need_reschedule();
248
  } else {
249
    /* queue */
250
    td->nact++;
251
  }
252
 
253
  /* increase release time */
254
  ADDUSEC2TIMESPEC(td->period, &td->release);
255
  /* post end of period timer */
256
  if (td->eop_timer != -1) {
257
    kern_event_delete(td->eop_timer);
258
    td->eop_timer = -1;
259
  }
260
 
261
  td->eop_timer = kern_event_post(&td->release, EDF_timer_endperiod,(void *)p);
262
 
263
  TRACER_LOGEVENT(FTrace_EVT_task_timer,
264
                  (unsigned short int)proc_table[p].context,
265
                  (unsigned int)proc_table[p].task_level);
266
}
267
 
268
 
269
/**** Public generic kernel interface functions ****/
270
 
271
/* Returns the first task in the ready queue */
272
static PID EDF_public_scheduler(LEVEL l)
273
{
274
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
275
  return iq_query_first(&lev->ready);
276
}
277
 
278
/* Checks and decreases the available system bandwidth */
279
static int EDF_public_guarantee(LEVEL l, bandwidth_t *freebandwidth)
280
{
281
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
282
 
283
  if (*freebandwidth >= lev->U) {
284
    *freebandwidth -= lev->U;
285
    return 1;
286
  }
287
  else
288
    return 0;
289
}
290
 
291
/* Called by task_create: Checks task model and creates a task */
292
static int EDF_public_create(LEVEL l, PID p, TASK_MODEL *m)
293
{
294
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
295
  EDF_task_des *td = &lev->tvec[p];
296
  HARD_TASK_MODEL *h;
297
 
298
  if (m->pclass != HARD_PCLASS) return -1;
299
  if (m->level != 0 && m->level != l) return -1;
300
  h = (HARD_TASK_MODEL *)m;
301
  if (!h->wcet || !h->mit) return -1;
302
  if (h->drel > h->mit) return -1;  /* only D <= T supported */
303
 
304
  if (!h->drel) {
305
    td->rdeadline = h->mit;
306
  } else {
307
    td->rdeadline = h->drel;
308
  }
309
 
310
  /* check the free bandwidth... */
311
  if (lev->flags & EDF_ENABLE_GUARANTEE) {
312
    bandwidth_t b;
313
    b = (MAX_BANDWIDTH / td->rdeadline) * h->wcet;
314
 
315
    /* really update lev->U, checking an overflow... */
316
    if (MAX_BANDWIDTH - lev->U > b) {
317
      lev->U += b;
318
    } else {
319
      return -1;
320
    }
321
  }
322
 
323
  td->flags = 0;
324
  if (h->periodicity == APERIODIC) {
325
    td->flags |= EDF_FLAG_SPORADIC;
326
  }
327
  td->period = h->mit;
328
  if (td->rdeadline == td->period) {
329
    /* Ensure that D <= T-eps to make dl_timer trigger before eop_timer */
330
    td->rdeadline = td->period - 1;
331
  }
332
  td->offset = h->offset;
333
  td->dl_timer = -1;
334
  td->eop_timer = -1;
335
  td->off_timer = -1;
336
  td->dl_miss = 0;
337
  td->wcet_miss = 0;
338
  td->act_miss = 0;
339
  td->nact = 0;
340
 
341
  /* Enable wcet check */
342
  if (lev->flags & EDF_ENABLE_WCET_CHECK) {
343
    proc_table[p].avail_time = h->wcet;
344
    proc_table[p].wcet       = h->wcet;
345
    proc_table[p].control |= CONTROL_CAP; /* turn on measurement */
346
  }
347
 
348
  return 0; /* OK, also if the task cannot be guaranteed... */
349
}
350
 
351
/* Reclaim the bandwidth used by the task */
352
static void EDF_public_detach(LEVEL l, PID p)
353
{
354
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
355
  EDF_task_des *td = &lev->tvec[p];
356
 
357
  if (lev->flags & EDF_ENABLE_GUARANTEE) {
358
    lev->U -= (MAX_BANDWIDTH / td->rdeadline) * proc_table[p].wcet;
359
  }
360
}
361
 
362
/* Extracts the running task from the ready queue */
363
static void EDF_public_dispatch(LEVEL l, PID p, int nostop)
364
{
365
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
366
  iq_extract(p, &lev->ready);
367
}
368
 
369
/* Called when the task is preempted or when its budget is exhausted */
370
static void EDF_public_epilogue(LEVEL l, PID p)
371
{
372
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
373
  EDF_task_des *td = &lev->tvec[p];
374
 
375
  /* check if the wcet is finished... */
376
  if (lev->flags & EDF_ENABLE_WCET_CHECK) {
377
    if (proc_table[p].avail_time <= 0) {
378
      TRACER_LOGEVENT(FTrace_EVT_task_wcet_violation,
379
                      (unsigned short int)proc_table[p].context,0);
380
      if (lev->flags & EDF_ENABLE_WCET_EXCEPTION) {
381
        kern_raise(XWCET_VIOLATION,p);
382
      } else {
383
        proc_table[p].control &= ~CONTROL_CAP;
384
        td->wcet_miss++;
385
      }
386
    }
387
  }
388
 
389
  /* the task returns to the ready queue */
390
  iq_timespec_insert(p,&lev->ready);
391
  proc_table[p].status = EDF_READY;
392
 
393
}
394
 
395
/* Called by task_activate or group_activate: Activates the task at time t */
396
static void EDF_public_activate(LEVEL l, PID p, struct timespec *t)
397
{
398
  struct timespec clocktime;
399
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
400
  EDF_task_des *td = &lev->tvec[p];
401
 
402
  kern_gettime(&clocktime);
403
 
404
  /* check if we are not in the SLEEP state */
405
  if (proc_table[p].status != SLEEP) {
406
    if (lev->flags & EDF_ENABLE_ACT_EXCEPTION) {
407
      /* too frequent or wrongful activation: raise exception */
408
      kern_raise(XACTIVATION,p);
409
    } else {
410
      /* skip the sporadic job, but increase a counter */
411
#ifdef EDF_DEBUG
412
      edf_printf("At %s: activation of %s skipped\n", pnow(),
413
                 proc_table[p].name);
414
#endif
415
      td->act_miss++;
416
    }
417
    return;
418
  }
419
 
420
  /* set the release time to the activation time + offset */
421
  td->release = *t;
422
  ADDUSEC2TIMESPEC(td->offset, &td->release);
423
 
424
  /* set the absolute deadline to the activation time + offset + rdeadline */
425
  td->adeadline = td->release;
426
  ADDUSEC2TIMESPEC(td->rdeadline, &td->adeadline);
427
 
428
  /* Check if release > clocktime. If yes, release it later,
429
     otherwise release it now. */
430
 
431
  proc_table[p].status = EDF_IDLE;
432
 
433
  if (TIMESPEC_A_GT_B(&td->release, &clocktime)) {
434
    /* release later, post an offset timer */
435
    if (td->off_timer != -1) {
436
        kern_event_delete(td->off_timer);
437
        td->off_timer = -1;
438
    }
439
    td->off_timer = kern_event_post(&td->release,EDF_timer_offset,(void *)p);
440
  } else {
441
    /* release now */
442
    EDF_intern_release(p, lev);
443
  }
444
}
445
 
446
/* Reinserts a task that has been blocked into the ready queue */
447
static void EDF_public_unblock(LEVEL l, PID p)
448
{
449
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
450
 
451
  /* Insert task in the correct position */
452
  proc_table[p].status = EDF_READY;
453
  iq_timespec_insert(p,&lev->ready);
454
}
455
 
456
/* Called when a task experiences a synchronization block */
457
static void EDF_public_block(LEVEL l, PID p)
458
{
459
  /* Extract the running task from the level
460
     . we have already extract it from the ready queue at the dispatch time.
461
     . the capacity event have to be removed by the generic kernel
462
     . the wcet don't need modification...
463
     . the state of the task is set by the calling function
464
     . the deadline must remain...
465
 
466
     So, we do nothing!!!
467
  */
468
}
469
 
470
/* Called by task_endcycle or task_sleep: Ends the current instance */
471
static int EDF_public_message(LEVEL l, PID p, void *m)
472
{
473
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
474
  EDF_task_des *td = &lev->tvec[p];
475
 
476
  switch((long)(m)) {
477
    /* task_endcycle() */
478
  case 0:
479
    /* if there are no pending jobs */
480
    if (td->nact == 0) {
481
      /* remove deadline timer, if any */
482
      if (td->dl_timer != -1) {
483
        kern_event_delete(td->dl_timer);
484
        td->dl_timer = -1;
485
      }
486
      if (td->flags & EDF_FLAG_SPORADIC) {
487
        /* sporadic task */
488
        if (!(td->flags & EDF_FLAG_SPOR_LATE)) {
489
          proc_table[p].status = EDF_WAIT;
490
        } else {
491
          /* it's late, move it directly to SLEEP */
492
          proc_table[p].status = SLEEP;
493
          td->flags &= ~EDF_FLAG_SPOR_LATE;
494
        }
495
      } else {
496
        /* periodic task */
497
        proc_table[p].status = EDF_IDLE;
498
      }
499
    } else {
500
      /* we are late / there are pending jobs */
501
      td->nact--;
502
      /* compute and assign absolute deadline */
503
      *iq_query_timespec(p,&lev->ready) = td->adeadline;
504
      iq_timespec_insert(p,&lev->ready);
505
      /* increase assigned deadline */
506
      ADDUSEC2TIMESPEC(td->period, &td->adeadline);
507
#ifdef EDF_DEBUG
508
      edf_printf("(Late) At %s: releasing %s with deadline %s\n",
509
         pnow(),proc_table[p].name,ptime1(&td->adeadline));
510
#endif
511
    }
512
    break;
513
 
514
    /* task_sleep() */
515
  case 1:
516
    /* remove deadline timer, if any */
517
    if (td->dl_timer != -1) {
518
      kern_event_delete(td->dl_timer);
519
      td->dl_timer = -1;
520
    }
521
    if (td->flags & EDF_FLAG_SPORADIC) {
522
      /* sporadic task */
523
      if (!(td->flags & EDF_FLAG_SPOR_LATE)) {
524
        proc_table[p].status = EDF_WAIT;
525
      } else {
526
        /* it's late, move it directly to SLEEP */
527
        proc_table[p].status = SLEEP;
528
        td->flags &= ~EDF_FLAG_SPOR_LATE;
529
      }
530
    } else {
531
      /* periodic task */
532
      if (!(td->nact > 0)) {
533
        /* we are on time. go to the EDF_WAIT state */
534
        proc_table[p].status = EDF_WAIT;
535
      } else {
536
        /* we are late. delete pending activations and go to SLEEP */
537
        td->nact = 0;
538
        proc_table[p].status = SLEEP;
539
        /* remove end of period timer */
540
        if (td->eop_timer != -1) {
541
          kern_event_delete(td->eop_timer);
542
          td->eop_timer = -1;
543
        }
544
      }
545
    }
546
    break;
547
  }
548
 
549
  if (lev->flags & EDF_ENABLE_WCET_CHECK) {
550
    proc_table[p].control |= CONTROL_CAP;
551
  }
552
  jet_update_endcycle(); /* Update the Jet data... */
553
  proc_table[p].avail_time = proc_table[p].wcet;
554
  TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,
555
                  (unsigned short int)proc_table[p].context,(unsigned int)l);
556
 
557
  return 0;
558
 
559
}
560
 
561
/* End the task and free the resources at the end of the period */
562
static void EDF_public_end(LEVEL l, PID p)
563
{
564
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
565
  EDF_task_des *td = &lev->tvec[p];
566
 
567
  if (!(td->flags & EDF_FLAG_SPOR_LATE)) {
568
    /* remove the deadline timer (if any) */
569
    if (td->dl_timer != -1) {
570
      kern_event_delete(td->dl_timer);
571
      td->dl_timer = -1;
572
    }
573
    proc_table[p].status = EDF_ZOMBIE;
574
  } else {
575
    /* no endperiod timer will be fired, free the task now! */
576
    proc_table[p].status = FREE;
577
    iq_insertfirst(p,&freedesc);
578
    /* free the allocated bandwidth */
579
    lev->U -= (MAX_BANDWIDTH/td->rdeadline) * proc_table[p].wcet;
580
  }
581
}
582
 
583
/**** Private generic kernel interface functions (guest calls) ****/
584
 
585
/* Insert a guest task */
586
static void EDF_private_insert(LEVEL l, PID p, TASK_MODEL *m)
587
{
588
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
589
  EDF_task_des *td = &lev->tvec[p];
590
  JOB_TASK_MODEL *job;
591
 
592
  if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) {
593
    kern_raise(XINVALID_TASK, p);
594
    return;
595
  }
596
 
597
  job = (JOB_TASK_MODEL *)m;
598
 
599
  /* Insert task in the correct position */
600
  *iq_query_timespec(p, &lev->ready) = job->deadline;
601
  iq_timespec_insert(p,&lev->ready);
602
  proc_table[p].status = EDF_READY;
603
 
604
  if (td->dl_timer != -1) {
605
        kern_event_delete(td->dl_timer);
606
        td->dl_timer = -1;
607
  }
608
 
609
  td->period = job->period;
610
 
611
  if (!job->noraiseexc) {
612
    td->dl_timer = kern_event_post(iq_query_timespec(p, &lev->ready),
613
                                       EDF_timer_guest_deadline,(void *)p);
614
  }
615
}
616
 
617
/* Dispatch a guest task */
618
static void EDF_private_dispatch(LEVEL l, PID p, int nostop)
619
{
620
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
621
 
622
  /* the task state is set to EXE by the scheduler()
623
     we extract the task from the ready queue
624
     NB: we can't assume that p is the first task in the queue!!! */
625
  iq_extract(p, &lev->ready);
626
}
627
 
628
/* Called when a guest task is preempted/out of budget */
629
static void EDF_private_epilogue(LEVEL l, PID p)
630
{
631
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
632
 
633
  /* the task has been preempted. it returns into the ready queue... */
634
  iq_timespec_insert(p,&lev->ready);
635
  proc_table[p].status = EDF_READY;
636
}
637
 
638
/* Extract a guest task */
639
static void EDF_private_extract(LEVEL l, PID p)
640
{
641
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
642
  EDF_task_des *td = &lev->tvec[p];
643
 
644
  if (proc_table[p].status == EDF_READY)
645
    iq_extract(p, &lev->ready);
646
 
647
  /* we remove the deadline timer, because the slice is finished */
648
  if (td->dl_timer != -1) {
649
    kern_event_delete(td->dl_timer);
650
    td->dl_timer = -1;
651
  }
652
 
653
}
654
 
655
 
656
/**** Level registration function ****/
657
 
658
LEVEL EDF_register_level(int flags)
659
{
660
  LEVEL l;            /* the level that we register */
661
  EDF_level_des *lev;  /* for readableness only */
662
  int i;
663
 
664
  printk("EDF_register_level\n");
665
 
666
  /* request an entry in the level_table */
667
  l = level_alloc_descriptor(sizeof(EDF_level_des));
668
 
669
  lev = (EDF_level_des *)level_table[l];
670
 
671
  /* fill the standard descriptor */
672
  lev->l.private_insert   = EDF_private_insert;
673
  lev->l.private_extract  = EDF_private_extract;
674
  lev->l.private_dispatch = EDF_private_dispatch;
675
  lev->l.private_epilogue = EDF_private_epilogue;
676
 
677
  lev->l.public_scheduler = EDF_public_scheduler;
678
  if (flags & EDF_ENABLE_GUARANTEE)
679
    lev->l.public_guarantee = EDF_public_guarantee;
680
  else
681
    lev->l.public_guarantee = NULL;
682
 
683
  lev->l.public_create    = EDF_public_create;
684
  lev->l.public_detach    = EDF_public_detach;
685
  lev->l.public_end       = EDF_public_end;
686
  lev->l.public_dispatch  = EDF_public_dispatch;
687
  lev->l.public_epilogue  = EDF_public_epilogue;
688
  lev->l.public_activate  = EDF_public_activate;
689
  lev->l.public_unblock   = EDF_public_unblock;
690
  lev->l.public_block     = EDF_public_block;
691
  lev->l.public_message   = EDF_public_message;
692
 
693
  iq_init(&lev->ready, &freedesc, 0);
694
 
695
  lev->flags = flags;
696
  if (lev->flags & EDF_ENABLE_WCET_EXCEPTION) {
697
    lev->flags |= EDF_ENABLE_WCET_CHECK;
698
  }
699
  if (lev->flags & EDF_ENABLE_DL_EXCEPTION) {
700
    lev->flags |= EDF_ENABLE_DL_CHECK;
701
  }
702
 
703
  lev->U = 0;
704
 
705
  for (i=0;i<MAX_PROC;i++) {
706
    EDF_task_des *td = &lev->tvec[i];
707
    td->flags = 0;
708
    td->dl_timer = -1;
709
    td->eop_timer = -1;
710
    td->off_timer = -1;
711
    td->dl_miss = 0;
712
    td->wcet_miss = 0;
713
    td->act_miss = 0;
714
    td->nact = 0;
715
  }
716
 
717
  return l;
718
}
719
 
720
 
721
/**** Public utility functions ****/
722
 
723
/* Get the bandwidth used by the level */
724
bandwidth_t EDF_usedbandwidth(LEVEL l)
725
{
726
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
727
 
728
  return lev->U;
729
}
730
 
731
/* Get the number of missed deadlines for a task */
732
int EDF_get_dl_miss(PID p)
733
{
734
  LEVEL l = proc_table[p].task_level;
735
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
736
  EDF_task_des *td = &lev->tvec[p];
737
 
738
  return td->dl_miss;
739
}
740
 
741
/* Get the number of execution overruns for a task */
742
int EDF_get_wcet_miss(PID p)
743
{
744
  LEVEL l = proc_table[p].task_level;
745
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
746
  EDF_task_des *td = &lev->tvec[p];
747
 
748
  return td->wcet_miss;
749
}
750
 
751
/* Get the number of skipped activations for a task */
752
int EDF_get_act_miss(PID p)
753
{
754
  LEVEL l = proc_table[p].task_level;
755
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
756
  EDF_task_des *td = &lev->tvec[p];
757
 
758
  return td->act_miss;
759
}
760
 
761
/* Get the current number of queued activations for a task */
762
int EDF_get_nact(PID p)
763
{
764
  LEVEL l = proc_table[p].task_level;
765
 
766
  EDF_level_des *lev = (EDF_level_des *)(level_table[l]);
767
  EDF_task_des *td = &lev->tvec[p];
768
 
769
  return td->nact;
770
}
771