Subversion Repositories shark

Rev

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