Subversion Repositories shark

Rev

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