Subversion Repositories shark

Rev

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

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