Subversion Repositories shark

Rev

Rev 226 | Rev 241 | 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
 ------------
236 giacomo 21
 CVS :        $Id: edfstar.c,v 1.4 2003-09-17 09:43:47 giacomo Exp $
221 giacomo 22
 
23
 File:        $File$
236 giacomo 24
 Revision:    $Revision: 1.4 $
25
 Last update: $Date: 2003-09-17 09:43:47 $
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
 
226 giacomo 303
static int EDFSTAR_private_change_level(LEVEL l, PID p)
221 giacomo 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) {
226 giacomo 310
 
221 giacomo 311
    STD_command_message msg;
226 giacomo 312
 
221 giacomo 313
    proc_table[p].status = SLEEP;
226 giacomo 314
 
315
    level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p);
221 giacomo 316
    iq_extract(p,&lev->ready);
226 giacomo 317
 
221 giacomo 318
    if (lev->deadline_timer[p] != -1)
319
      kern_event_delete(lev->deadline_timer[p]);
226 giacomo 320
 
221 giacomo 321
    EDFSTAR_check_preemption(lev);
226 giacomo 322
 
221 giacomo 323
    lev->nact[p] = 0;
324
    lev->budget[p] = -1;
325
    proc_table[p].task_level = lev->new_level[p];
326
 
327
    /* Send change level command to local scheduler */
328
 
329
    msg.command = STD_ACTIVATE_TASK;
330
    msg.param = NULL;
331
 
332
    level_table[ lev->new_level[p] ]->public_message(lev->new_level[p],p,&msg);
333
 
334
    return 1;
335
 
336
  }
337
 
338
  return 0;
339
 
340
}
341
 
342
static void EDFSTAR_public_epilogue(LEVEL l, PID p)
343
{
344
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
345
 
346
#ifdef EDFSTAR_DEBUG
347
  edfstar_printf("(E:epi ");
348
#endif
349
 
226 giacomo 350
  if (EDFSTAR_private_change_level(l, p)) return;
221 giacomo 351
 
352
  /* check if the wcet is finished... */
353
  if (proc_table[p].avail_time <= 0 && proc_table[p].control&CONTROL_CAP) {
354
    /* wcet finished: disable wcet event and count wcet miss */
355
#ifdef EDFSTAR_DEBUG
356
    edfstar_printf2("W%d",p);
357
#endif
358
    proc_table[p].control &= ~CONTROL_CAP;
359
    lev->wcet_miss[p]++;
360
  }
361
#ifdef EDFSTAR_DEBUG
362
  edfstar_printf(")");
363
#endif
364
 
365
  level_table[ lev->scheduling_level ]->
366
    private_epilogue(lev->scheduling_level,p);
367
 
368
  proc_table[p].status = EDFSTAR_READY;
369
}
370
 
371
static void EDFSTAR_public_activate(LEVEL l, PID p)
372
{
373
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
374
  struct timespec t;
375
 
376
  #ifdef EDFSTAR_DEBUG
377
    edfstar_printf("(E:act:%d)",p);
378
  #endif
379
 
380
  /* Test if we are trying to activate a non sleeping task    */
381
  /* save activation (only if needed... */
382
  if (proc_table[p].status != SLEEP) {
383
    /* a periodic task cannot be activated when it is already active */
384
    kern_raise(XACTIVATION,p);
385
    return;
386
  }
387
 
388
  kern_gettime(&t);
389
 
390
  EDFSTAR_internal_activate(lev,p, &t);
391
 
392
  /* Set the deadline timer */
393
  lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
394
                                           EDFSTAR_timer_deadline,
395
                                           (void *)p);
396
 
397
}
398
 
399
static void EDFSTAR_public_unblock(LEVEL l, PID p)
400
{
401
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
402
 
403
#ifdef EDFSTAR_DEBUG
404
  edfstar_printf("(E:ins)");
405
#endif
406
 
407
  /* Insert task in the correct position */
408
  proc_table[p].status = EDFSTAR_READY;
409
  iq_timespec_insert(p,&lev->ready);
410
 
411
  /* and check for preemption! */
412
  EDFSTAR_check_preemption(lev);
413
}
414
 
415
static void EDFSTAR_public_block(LEVEL l, PID p)
416
{
417
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
418
 
419
#ifdef EDFSTAR_DEBUG
420
  edfstar_printf("(E:ext)");
421
#endif
422
 
423
  /* the task is blocked on a synchronization primitive. we have to
424
     remove it from the master module -and- from the local queue! */
425
  iq_extract(p,&lev->ready);
426
 
427
  /* and finally, a preemption check! (it will also call guest_end) */
428
  EDFSTAR_check_preemption(lev);
429
}
430
 
431
static int EDFSTAR_public_message(LEVEL l, PID p, void *m)
432
{
433
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
434
  struct timespec temp;
435
  STD_command_message *msg;
436
  HARD_TASK_MODEL *h;
437
 
438
#ifdef EDFSTAR_DEBUG
439
  edfstar_printf("(E:ecy ");
440
#endif
441
 
442
  switch ((long)(m)) {
443
 
444
    /* Task EndCycle */
445
  case (long)(NULL):
446
 
226 giacomo 447
    if (EDFSTAR_private_change_level(l,p)) return 0;
448
 
221 giacomo 449
    /* we call guest_end directly here because the same task may
450
       be reinserted in the queue before calling the preemption check! */
451
    level_table[ lev->scheduling_level ]->
452
      private_extract(lev->scheduling_level,p);
453
    lev->activated = NIL;
454
 
455
    iq_extract(p,&lev->ready);
456
 
457
    /* we reset the capacity counters... */
458
    proc_table[p].avail_time = proc_table[p].wcet;
459
 
460
    if (lev->nact[p] > 0) {
461
 
462
      #ifdef EDFSTAR_DEBUG
463
        edfstar_printf2("E%d",p);
464
      #endif
465
 
466
      /* Pending activation: reactivate the thread!!! */
467
      lev->nact[p]--;
468
 
469
      /* see also EDFSTAR_timer_deadline */
470
      kern_gettime(&temp);
471
 
472
      EDFSTAR_internal_activate(lev,p, &temp);
473
 
474
      /* check if the deadline has already expired */
475
      temp = *iq_query_timespec(p, &lev->ready);
476
      if (TIMESPEC_A_LT_B(&temp, &schedule_time)) {
477
          /* count the deadline miss */
478
          lev->dline_miss[p]++;
479
          kern_event_delete(lev->deadline_timer[p]);
480
      }
481
 
482
    } else {
483
 
484
      #ifdef EDFSTAR_DEBUG
485
        edfstar_printf("e%d",p);
486
      #endif
487
 
488
      /* the task has terminated his job before it consume the wcet. All OK! */
489
      proc_table[p].status = EDFSTAR_IDLE;
490
 
491
      /* and finally, a preemption check! */
492
      EDFSTAR_check_preemption(lev);
493
 
494
      /* when the deadline timer fire, it recognize the situation and set
495
         correctly all the stuffs (like reactivation, etc... ) */
496
    }
497
#ifdef EDFSTAR_DEBUG
498
    edfstar_printf(")");
499
#endif
500
 
501
    jet_update_endcycle(); /* Update the Jet data... */
502
    trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */
503
    break;
504
 
505
  default:
506
 
507
    msg = (STD_command_message *)m;
226 giacomo 508
 
509
    #ifdef EDFSTAR_DEBUG
510
       edfstar_printf("(E:MSG %d)",msg->command);
511
    #endif   
512
 
221 giacomo 513
    switch(msg->command) {
514
    case STD_SET_NEW_MODEL:
515
      /* if the EDFSTAR_task_create is called, then the pclass must be a
516
         valid pclass. */
517
      h=(HARD_TASK_MODEL *)(msg->param);
518
 
519
      /* now we know that m is a valid model */
226 giacomo 520
      lev->wcet[p] = h->wcet;
221 giacomo 521
      lev->period[p] = h->mit;
522
 
523
      lev->flag[p] = 0;
524
      lev->deadline_timer[p] = -1;
525
      lev->dline_miss[p]     = 0;
526
      lev->wcet_miss[p]      = 0;
527
      lev->nact[p]           = 0;
528
 
529
      break;
530
 
531
    case STD_SET_NEW_LEVEL:
532
 
533
      lev->flag[p] |= EDFSTAR_CHANGE_LEVEL;
534
      lev->new_level[p] = (int)(msg->param);
535
 
536
      break;
537
 
538
    case STD_ACTIVATE_TASK:
539
 
540
      /* Enable wcet check */
541
      proc_table[p].avail_time = lev->wcet[p];
542
      proc_table[p].wcet       = lev->wcet[p];
543
      proc_table[p].control |= CONTROL_CAP;
226 giacomo 544
 
221 giacomo 545
      EDFSTAR_public_activate(l, p);
546
 
547
      break;
548
 
549
 
550
    }
551
  }
552
  return 0;
553
}
554
 
555
static void EDFSTAR_public_end(LEVEL l, PID p)
556
{
557
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
558
 
559
#ifdef EDFSTAR_DEBUG
560
  edfstar_printf("(E:end)");
561
#endif
562
 
563
  iq_extract(p,&lev->ready);
564
 
565
  /* we finally put the task in the ready queue */
566
  proc_table[p].status = FREE;
567
 
568
  iq_insertfirst(p,&freedesc);
569
 
570
  if (lev->deadline_timer[p] != -1) {
571
    kern_event_delete(lev->deadline_timer[p]);
572
  }
573
 
574
  /* and finally, a preemption check! (it will also call guest_end) */
575
  EDFSTAR_check_preemption(lev);
576
}
577
 
578
/* Guest Functions
579
   These functions manages a JOB_TASK_MODEL, that is used to put
580
   a guest task in the EDFSTAR ready queue. */
581
 
582
static void EDFSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m)
583
{
584
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
585
  JOB_TASK_MODEL *job;
586
 
587
  if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) {
588
    kern_raise(XINVALID_TASK, p);
589
    return;
590
  }
591
 
592
  job = (JOB_TASK_MODEL *)m;
593
 
594
  /* if the EDFSTAR_guest_create is called, then the pclass must be a
595
     valid pclass. */
596
 
597
  *iq_query_timespec(p, &lev->ready) = job->deadline;
598
 
599
  lev->deadline_timer[p] = -1;
600
  lev->dline_miss[p]     = 0;
601
  lev->wcet_miss[p]      = 0;
602
  lev->nact[p]           = 0;
603
 
604
  if (job->noraiseexc)
605
    lev->flag[p] |= EDFSTAR_FLAG_NORAISEEXC;
606
  else {
607
    lev->flag[p] &= ~EDFSTAR_FLAG_NORAISEEXC;
608
    lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
609
                                             EDFSTAR_timer_guest_deadline,
610
                                             (void *)p);
611
  }
612
 
613
  lev->period[p] = job->period;
614
 
615
  /* Insert task in the correct position */
616
  iq_timespec_insert(p,&lev->ready);
617
  proc_table[p].status = EDFSTAR_READY;
618
 
619
  /* check for preemption */
620
  EDFSTAR_check_preemption(lev);
621
 
622
  /* there is no bandwidth guarantee at this level, it is performed
623
     by the level that inserts guest tasks... */
624
}
625
 
626
static void EDFSTAR_private_dispatch(LEVEL l, PID p, int nostop)
627
{
628
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
629
 
630
  level_table[ lev->scheduling_level ]->
631
    private_dispatch(lev->scheduling_level,p,nostop);
632
}
633
 
634
static void EDFSTAR_private_epilogue(LEVEL l, PID p)
635
{
636
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
637
 
638
  /* the task has been preempted. it returns into the ready queue... */
639
  level_table[ lev->scheduling_level ]->
640
    private_epilogue(lev->scheduling_level,p);
641
 
642
  proc_table[p].status = EDFSTAR_READY;
643
}
644
 
645
static void EDFSTAR_private_extract(LEVEL l, PID p)
646
{
647
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
648
 
649
#ifdef EDFSTAR_DEBUG
650
  //kern_printf("EDFSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
651
#endif
652
 
653
  iq_extract(p, &lev->ready);
654
 
655
  /* we remove the deadline timer, because the slice is finished */
656
  if (lev->deadline_timer[p] != NIL) {
657
#ifdef EDFSTAR_DEBUG
658
//    kern_printf("EDFSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
659
#endif
660
    kern_event_delete(lev->deadline_timer[p]);
661
    lev->deadline_timer[p] = NIL;
662
  }
663
 
664
  /* and finally, a preemption check! (it will also call guest_end() */
665
  EDFSTAR_check_preemption(lev);
666
}
667
 
668
/* Registration functions */
669
 
670
/* Registration function:
671
    int flags                 the init flags ... see EDFSTAR.h */
672
 
673
LEVEL EDFSTAR_register_level(int master)
674
{
675
  LEVEL l;            /* the level that we register */
676
  EDFSTAR_level_des *lev;  /* for readableness only */
677
  PID i;              /* a counter */
678
 
679
#ifdef EDFSTAR_DEBUG
680
  printk("EDFSTAR_register_level\n");
681
#endif
682
 
683
  /* request an entry in the level_table */
684
  l = level_alloc_descriptor(sizeof(EDFSTAR_level_des));
685
 
686
  lev = (EDFSTAR_level_des *)level_table[l];
687
 
688
  printk("    lev=%d\n",(int)lev);
689
 
690
  /* fill the standard descriptor */
691
  lev->l.private_insert   = EDFSTAR_private_insert;
692
  lev->l.private_extract  = EDFSTAR_private_extract;
693
  lev->l.private_dispatch = EDFSTAR_private_dispatch;
694
  lev->l.private_epilogue = EDFSTAR_private_epilogue;
695
 
696
  lev->l.public_guarantee = NULL;
697
  lev->l.public_eligible  = EDFSTAR_public_eligible;
698
  lev->l.public_create    = EDFSTAR_public_create;
699
  lev->l.public_end       = EDFSTAR_public_end;
700
  lev->l.public_dispatch  = EDFSTAR_public_dispatch;
701
  lev->l.public_epilogue  = EDFSTAR_public_epilogue;
702
  lev->l.public_activate  = EDFSTAR_public_activate;
703
  lev->l.public_unblock   = EDFSTAR_public_unblock;
704
  lev->l.public_block     = EDFSTAR_public_block;
705
  lev->l.public_message   = EDFSTAR_public_message;
706
 
707
  /* fill the EDFSTAR descriptor part */
708
  for(i=0; i<MAX_PROC; i++) {
709
    lev->period[i]         = 0;
710
    lev->deadline_timer[i] = -1;
711
    lev->flag[i]           = 0;
712
    lev->dline_miss[i]     = 0;
713
    lev->wcet_miss[i]      = 0;
714
    lev->nact[i]           = 0;
715
    lev->budget[i]         = NIL;
716
    lev->wcet[i]           = 0;
717
  }
718
 
719
  iq_init(&lev->ready, NULL, IQUEUE_NO_PRIORITY);
720
  lev->activated = NIL;
721
 
722
  lev->scheduling_level = master;
723
 
724
  return l;
725
}
726
 
727
int EDFSTAR_get_dline_miss(PID p)
728
{
729
  LEVEL l = proc_table[p].task_level;
730
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
731
 
732
  return lev->dline_miss[p];
733
}
734
 
735
int EDFSTAR_get_wcet_miss(PID p)
736
{
737
  LEVEL l = proc_table[p].task_level;
738
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
739
 
740
  return lev->wcet_miss[p];
741
}
742
 
743
int EDFSTAR_get_nact(PID p)
744
{
745
  LEVEL l = proc_table[p].task_level;
746
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
747
 
748
  return lev->nact[p];
749
}
750
 
751
int EDFSTAR_reset_dline_miss(PID p)
752
{
753
  LEVEL l = proc_table[p].task_level;
754
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
755
 
756
  lev->dline_miss[p] = 0;
757
  return 0;
758
}
759
 
760
int EDFSTAR_reset_wcet_miss(PID p)
761
{
762
  LEVEL l = proc_table[p].task_level;
763
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
764
 
765
  lev->wcet_miss[p] = 0;
766
  return 0;
767
}
768
 
769
int EDFSTAR_setbudget(LEVEL l, PID p, int budget)
770
{
771
 
772
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
773
 
774
  lev->budget[p] = budget;
775
 
776
  return 0;
777
 
778
}
779
 
780
int EDFSTAR_getbudget(LEVEL l, PID p)
781
{
782
 
783
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
784
 
785
  return lev->budget[p];
786
 
787
}
236 giacomo 788
 
789
int EDFSTAR_budget_has_thread(LEVEL l, int budget)
790
{
791
 
792
  EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]);
793
  int i;
794
 
795
  for(i = 0; i< MAX_PROC; i++)
796
    if (lev->budget[i] == budget) return 1;
797
 
798
  return 0;
799
 
800
}