Subversion Repositories shark

Rev

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