Subversion Repositories shark

Rev

Rev 394 | Rev 786 | 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 */
306
      ADDUSEC2TIMESPEC(proc_table[exec].avail_time ,&ty);
307
      lev->cap_lev = kern_event_post(&ty,capacity_handler, lev);
308
      level_table[lev->scheduling_level]->private_dispatch(lev->scheduling_level, p, nostop);
309
  }
310
  else
311
      level_table[proc_table[exec].task_level]->public_dispatch(proc_table[exec].task_level, p, nostop);
312
 
235 giacomo 313
}
314
 
315
static void RMSTAR_public_epilogue(LEVEL l, PID p)
316
{
317
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
318
 
319
#ifdef RMSTAR_DEBUG
320
  rmstar_printf("(E:epi ");
321
#endif
322
 
394 trimarchi 323
  if (lev->cap_lev!=NIL) {
324
    kern_event_delete(lev->cap_lev);
325
    lev->cap_lev=NIL;
326
  }
327
 
328
 
329
  if ( proc_table[exec].task_level==l ) {
330
 
331
    RMSTAR_account_capacity(lev,exec);
332
 
333
    /* check if the wcet is finished... */
334
    if (proc_table[p].avail_time) {
335
      /* wcet finished: disable wcet event and count wcet miss */
235 giacomo 336
#ifdef RMSTAR_DEBUG
394 trimarchi 337
      rmstar_printf2("W%d",p);
235 giacomo 338
#endif
394 trimarchi 339
      //proc_table[p].control &= ~CONTROL_CAP;
783 giacomo 340
      TRACER_LOGEVENT(FTrace_EVT_task_wcet_violation,proc_table[p].context,proc_table[p].task_level);
394 trimarchi 341
      lev->wcet_miss[p]++;
342
    }
235 giacomo 343
#ifdef RMSTAR_DEBUG
394 trimarchi 344
    rmstar_printf(")");
235 giacomo 345
#endif
394 trimarchi 346
 
347
    level_table[ lev->scheduling_level ]->
348
      private_epilogue(lev->scheduling_level,p);
349
 
350
    proc_table[p].status = RMSTAR_READY;
351
  } else
352
    level_table[proc_table[exec].task_level]->public_epilogue(proc_table[exec].task_level,p);
235 giacomo 353
}
354
 
783 giacomo 355
static void RMSTAR_public_activate(LEVEL l, PID p, struct timespec *o)
235 giacomo 356
{
357
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
358
  struct timespec t;
359
 
360
#ifdef RMSTAR_DEBUG
361
  rmstar_printf("(E:act)");
362
#endif
394 trimarchi 363
 /* Test if we are trying to activate a non sleeping task    */
364
 /* save activation (only if needed... */
235 giacomo 365
 
394 trimarchi 366
 if (proc_table[p].status != SLEEP) {
367
     /* a periodic task cannot be activated when it is already active */
368
     /* but aperiodic task can be reactivate before */
369
     if (lev->flag[p] & RMSTAR_FLAG_SPORADIC) {
370
            if (proc_table[p].status != RMSTAR_IDLE) {
371
              lev->nact[p]++;
372
              return;
373
            }
374
     } else {
375
       kern_raise(XACTIVATION,p);
376
     }
377
  }
378
 
235 giacomo 379
  /* Test if we are trying to activate a non sleeping task    */
380
  /* save activation (only if needed... */
381
 
382
  kern_gettime(&t);
383
 
384
  RMSTAR_internal_activate(lev,p, &t);
385
 
386
  /* Set the deadline timer */
387
  lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
388
                                           RMSTAR_timer_deadline,
389
                                           (void *)p);
390
 
391
}
392
 
393
static void RMSTAR_public_unblock(LEVEL l, PID p)
394
{
395
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
396
 
397
#ifdef RMSTAR_DEBUG
398
  rmstar_printf("(E:ins)");
399
#endif
400
 
401
  /* Insert task in the correct position */
402
  proc_table[p].status = RMSTAR_READY;
403
  iq_priority_insert(p,&lev->ready);
404
 
405
  /* and check for preemption! */
406
  RMSTAR_check_preemption(lev);
407
}
408
 
409
static void RMSTAR_public_block(LEVEL l, PID p)
410
{
411
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
412
 
413
#ifdef RMSTAR_DEBUG
414
  rmstar_printf("(E:ext)");
415
#endif
416
 
417
  /* the task is blocked on a synchronization primitive. we have to
418
     remove it from the master module -and- from the local queue! */
419
  iq_extract(p,&lev->ready);
420
 
421
  /* and finally, a preemption check! (it will also call guest_end) */
422
  RMSTAR_check_preemption(lev);
423
}
424
 
425
static int RMSTAR_public_message(LEVEL l, PID p, void *m)
426
{
427
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
428
  struct timespec temp;
429
 
430
#ifdef RMSTAR_DEBUG
431
  rmstar_printf("(E:ecy ");
432
#endif
433
 
434
  switch ((long)(m))
435
    {
436
 
437
      /* Task EndCycle */
438
    case (long)(NULL):
439
 
440
      /* we call guest_end directly here because the same task may
441
         be reinserted in the queue before calling the preemption check! */
442
      level_table[ lev->scheduling_level ]->
443
        private_extract(lev->scheduling_level,p);  lev->activated = NIL;
444
 
445
      iq_extract(p,&lev->ready);
446
 
447
      /* we reset the capacity counters... */
448
      proc_table[p].avail_time = proc_table[p].wcet;
449
 
450
      if (lev->nact[p] > 0) {
451
#ifdef RMSTAR_DEBUG
452
        rmstar_printf2("E%d",p);
453
#endif
454
 
455
        /* Pending activation: reactivate the thread!!! */
456
        lev->nact[p]--;
457
 
458
        /* see also RMSTAR_timer_deadline */
459
        kern_gettime(&temp);
460
 
461
        RMSTAR_internal_activate(lev,p,&temp);
462
 
463
        /* check if the deadline has already expired */
464
        temp = *iq_query_timespec(p, &lev->ready);
465
        if (TIMESPEC_A_LT_B(&temp, &schedule_time)) {
466
          /* count the deadline miss */
467
          lev->dline_miss[p]++;
468
          kern_event_delete(lev->deadline_timer[p]);
469
        }
470
 
471
      }
472
      else {
473
#ifdef RMSTAR_DEBUG
474
        rmstar_printf("e%d",p);
475
#endif
394 trimarchi 476
        if (lev->flag[p] & RMSTAR_FLAG_SPORADIC && lev->deadline_timer[p] != NIL)
477
            kern_event_delete(lev->deadline_timer[p]);
478
 
235 giacomo 479
        /* the task has terminated his job before it consume the wcet. All OK! */
480
        proc_table[p].status = RMSTAR_IDLE;
481
 
482
        /* and finally, a preemption check! */
483
        RMSTAR_check_preemption(lev);
484
 
485
        /* when the deadline timer fire, it recognize the situation and set
486
           correctly all the stuffs (like reactivation, etc... ) */
487
      }
488
#ifdef RMSTAR_DEBUG
489
      rmstar_printf(")");
490
#endif
783 giacomo 491
      TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,proc_table[p].context,proc_table[p].task_level);      
235 giacomo 492
      jet_update_endcycle(); /* Update the Jet data... */
493
      break;
494
    default:
495
 
496
      break;
497
 
498
    }
499
  return 0;
500
}
501
 
502
static void RMSTAR_public_end(LEVEL l, PID p)
503
{
504
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
505
 
506
#ifdef RMSTAR_DEBUG
507
  rmstar_printf("(E:end)");
508
#endif
509
 
510
  iq_extract(p,&lev->ready);
511
 
512
  /* we finally put the task in the ready queue */
513
  proc_table[p].status = FREE;
514
 
515
  iq_insertfirst(p,&freedesc);
516
 
517
  if (lev->deadline_timer[p] != -1) {
518
    kern_event_delete(lev->deadline_timer[p]);
519
  }
520
 
521
  /* and finally, a preemption check! (it will also call guest_end) */
522
  RMSTAR_check_preemption(lev);
523
}
524
 
525
 
526
/* Guest Functions
527
   These functions manages a JOB_TASK_MODEL, that is used to put
528
   a guest task in the RMSTAR ready queue. */
529
 
530
static void RMSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m)
531
{
532
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
533
  JOB_TASK_MODEL *job;
534
 
535
  if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) {
536
    kern_raise(XINVALID_TASK, p);
537
    return;
538
  }
539
 
540
  job = (JOB_TASK_MODEL *)m;
541
 
542
  *iq_query_timespec(p, &lev->ready) = job->deadline;
543
 
544
  lev->deadline_timer[p] = -1;
545
  lev->dline_miss[p]     = 0;
546
  lev->wcet_miss[p]      = 0;
547
  lev->nact[p]           = 0;
548
 
549
  if (job->noraiseexc)
550
    lev->flag[p] = RMSTAR_FLAG_NORAISEEXC;
551
  else {
552
    lev->flag[p] = 0;
553
    lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
554
                                             RMSTAR_timer_guest_deadline,
555
                                             (void *)p);
556
   }
557
 
558
  lev->period[p] = job->period;
559
  *iq_query_priority(p, &lev->ready) = job->period;
560
 
561
  /* there is no bandwidth guarantee at this level, it is performed
562
     by the level that inserts guest tasks... */
563
 
564
  /* Insert task in the correct position */
565
  iq_priority_insert(p,&lev->ready);
566
  proc_table[p].status = RMSTAR_READY;
567
 
568
  /* check for preemption */
569
  RMSTAR_check_preemption(lev);
570
}
571
 
572
 
573
static void RMSTAR_private_dispatch(LEVEL l, PID p, int nostop)
574
{
575
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
576
 
577
  level_table[ lev->scheduling_level ]->
578
    private_dispatch(lev->scheduling_level,p,nostop);
579
}
580
 
581
static void RMSTAR_private_epilogue(LEVEL l, PID p)
582
{
583
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
584
 
585
  /* the task has been preempted. it returns into the ready queue... */
586
  level_table[ lev->scheduling_level ]->
587
    private_epilogue(lev->scheduling_level,p);
588
 
589
  proc_table[p].status = RMSTAR_READY;
590
}
591
 
592
static void RMSTAR_private_extract(LEVEL l, PID p)
593
{
594
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
595
 
596
#ifdef RMSTAR_DEBUG
597
  //kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
598
#endif
599
 
600
  iq_extract(p, &lev->ready);
601
 
602
  /* we remove the deadline timer, because the slice is finished */
603
  if (lev->deadline_timer[p] != NIL) {
604
#ifdef RMSTAR_DEBUG
605
//    kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
606
#endif
607
    kern_event_delete(lev->deadline_timer[p]);
608
    lev->deadline_timer[p] = NIL;
609
  }
610
 
611
  /* and finally, a preemption check! (it will also call guest_end() */
612
  RMSTAR_check_preemption(lev);
613
}
614
 
615
/* Registration functions */
616
 
617
/* Registration function:
618
    int flags                 the init flags ... see RMSTAR.h */
619
LEVEL RMSTAR_register_level(int master)
620
{
621
  LEVEL l;            /* the level that we register */
622
  RMSTAR_level_des *lev;  /* for readableness only */
623
  PID i;              /* a counter */
624
 
625
#ifdef RMSTAR_DEBUG
626
  printk("RMSTAR_register_level\n");
627
#endif
628
 
629
  /* request an entry in the level_table */
630
  l = level_alloc_descriptor(sizeof(RMSTAR_level_des));
631
 
632
  lev = (RMSTAR_level_des *)level_table[l];
633
 
634
  /* fill the standard descriptor */
635
  lev->l.private_insert   = RMSTAR_private_insert;
636
  lev->l.private_extract  = RMSTAR_private_extract;
637
  lev->l.private_dispatch = RMSTAR_private_dispatch;
638
  lev->l.private_epilogue = RMSTAR_private_epilogue;
639
 
640
  lev->l.public_guarantee = NULL;
641
  lev->l.public_create    = RMSTAR_public_create;
642
  lev->l.public_end       = RMSTAR_public_end;
643
  lev->l.public_dispatch  = RMSTAR_public_dispatch;
644
  lev->l.public_epilogue  = RMSTAR_public_epilogue;
645
  lev->l.public_activate  = RMSTAR_public_activate;
646
  lev->l.public_unblock   = RMSTAR_public_unblock;
647
  lev->l.public_block     = RMSTAR_public_block;
648
  lev->l.public_message   = RMSTAR_public_message;
649
 
650
  /* fill the RMSTAR descriptor part */
651
  for(i=0; i<MAX_PROC; i++) {
652
    lev->period[i]         = 0;
653
    lev->deadline_timer[i] = -1;
654
    lev->flag[i]           = 0;
655
    lev->dline_miss[i]     = 0;
656
    lev->wcet_miss[i]      = 0;
657
    lev->nact[i]           = 0;
658
    lev->budget[i]         = NIL;
659
  }
660
 
661
  iq_init(&lev->ready, NULL, 0);
662
  lev->activated = NIL;
663
 
664
  lev->scheduling_level = master;
665
 
394 trimarchi 666
  lev->cap_lev = NIL;
667
  NULL_TIMESPEC(&lev->cap_lasttime);
668
 
235 giacomo 669
  return l;
670
}
671
 
672
int RMSTAR_get_dline_miss(PID p)
673
{
674
  LEVEL l = proc_table[p].task_level;
675
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
676
 
677
  return lev->dline_miss[p];
678
}
679
 
680
int RMSTAR_get_wcet_miss(PID p)
681
{
682
  LEVEL l = proc_table[p].task_level;
683
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
684
 
685
  return lev->wcet_miss[p];
686
}
687
 
688
int RMSTAR_get_nact(PID p)
689
{
690
  LEVEL l = proc_table[p].task_level;
691
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
692
 
693
  return lev->nact[p];
694
}
695
 
696
int RMSTAR_reset_dline_miss(PID p)
697
{
698
  LEVEL l = proc_table[p].task_level;
699
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
700
 
701
  lev->dline_miss[p] = 0;
702
  return 0;
703
}
704
 
705
int RMSTAR_reset_wcet_miss(PID p)
706
{
707
  LEVEL l = proc_table[p].task_level;
708
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
709
 
710
  lev->wcet_miss[p] = 0;
711
  return 0;
712
}
713
 
714
 
715
int RMSTAR_setbudget(LEVEL l, PID p, int budget)
716
{
717
 
718
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
719
 
720
  lev->budget[p] = budget;
721
 
722
  return 0;
723
 
724
}
725
 
726
int RMSTAR_getbudget(LEVEL l, PID p)
727
{
728
 
729
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
730
 
731
  return lev->budget[p];
732
 
733
}
734
 
735
int RMSTAR_budget_has_thread(LEVEL l, int budget)
736
{
737
 
738
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
739
  int i;
740
 
741
  for(i = 0; i< MAX_PROC; i++)
742
    if (lev->budget[i] == budget) return 1;
743
 
744
  return 0;
745
 
746
}