Subversion Repositories shark

Rev

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