Subversion Repositories shark

Rev

Rev 799 | Rev 821 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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