Subversion Repositories shark

Rev

Rev 799 | 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 */
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];
799 giacomo 188
  lev->deadline_timer[p] = NIL;
235 giacomo 189
 
190
  switch (proc_table[p].status) {
191
    case RMSTAR_IDLE:
192
#ifdef RMSTAR_DEBUG
193
//      rmstar_printf2("I%d",p);
194
#endif
195
      /* set the request time */
394 trimarchi 196
      if (!(lev->flag[p] & RMSTAR_FLAG_SPORADIC))
197
          RMSTAR_internal_activate(lev,p,iq_query_timespec(p, &lev->ready));
235 giacomo 198
 
199
      event_need_reschedule();
200
      break;
201
 
202
    default:
203
#ifdef RMSTAR_DEBUG
204
//      rmstar_printf2("D%d",p);
205
#endif
206
      /* else, a deadline miss occurred!!! */
207
      lev->dline_miss[p]++;
783 giacomo 208
      TRACER_LOGEVENT(FTrace_EVT_task_deadline_miss,proc_table[p].context,proc_table[p].task_level);
209
 
394 trimarchi 210
      if (!(lev->flag[p] & RMSTAR_FLAG_SPORADIC)) {
211
         lev->nact[p]++;
212
         ADDUSEC2TIMESPEC(lev->period[p], &lev->deadline_timespec[p]);
213
      }
235 giacomo 214
  }
215
 
216
  /* Set the deadline timer */
394 trimarchi 217
  if (!(lev->flag[p] & RMSTAR_FLAG_SPORADIC))
218
     lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
219
                                              RMSTAR_timer_deadline,
220
                                              (void *)p);
235 giacomo 221
 
222
#ifdef RMSTAR_DEBUG
223
//  rmstar_printf(")");
224
#endif
225
}
226
 
227
static void RMSTAR_timer_guest_deadline(void *par)
228
{
229
  PID p = (PID) par;
230
 
231
#ifdef RMSTAR_DEBUG
232
  rmstar_printf("(E:gdl)");
233
#endif
234
 
235
  kern_raise(XDEADLINE_MISS,p);
236
}
237
 
394 trimarchi 238
static void RMSTAR_account_capacity(RMSTAR_level_des *lev, PID p)
239
{
240
  struct timespec ty;
241
  TIME tx;
242
 
243
  SUBTIMESPEC(&schedule_time, &lev->cap_lasttime, &ty);
244
  tx = TIMESPEC2USEC(&ty);
245
 
246
  proc_table[p].avail_time -= tx;
247
}
248
 
249
 
235 giacomo 250
static int RMSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m)
251
{
252
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
394 trimarchi 253
 
235 giacomo 254
  /* if the RMSTAR_task_create is called, then the pclass must be a
255
     valid pclass. */
256
  HARD_TASK_MODEL *h;
394 trimarchi 257
 
235 giacomo 258
  if (m->pclass != HARD_PCLASS) return -1;
259
  if (m->level != 0 && m->level != l) return -1;
260
  h = (HARD_TASK_MODEL *)m;
394 trimarchi 261
  if (!h->wcet || !h->mit) return -1;
235 giacomo 262
  /* now we know that m is a valid model */
263
 
394 trimarchi 264
  if (h->periodicity == APERIODIC)
265
        lev->flag[p] |= RMSTAR_FLAG_SPORADIC;
266
 
235 giacomo 267
#ifdef RMSTAR_DEBUG
268
  rmstar_printf("(E:tcr)");
269
#endif
270
 
271
  lev->period[p] = h->mit;
272
  *iq_query_priority(p, &lev->ready) = h->mit;
273
 
274
  lev->flag[p] = 0;
275
  lev->deadline_timer[p] = -1;
276
  lev->dline_miss[p]     = 0;
277
  lev->wcet_miss[p]      = 0;
278
  lev->nact[p]           = 0;
279
 
280
  /* Enable wcet check */
281
  proc_table[p].avail_time = h->wcet;
282
  proc_table[p].wcet       = h->wcet;
394 trimarchi 283
  //proc_table[p].control |= CONTROL_CAP;
235 giacomo 284
 
285
  return 0; /* OK, also if the task cannot be guaranteed... */
286
}
287
 
288
static void RMSTAR_public_dispatch(LEVEL l, PID p, int nostop)
289
{
290
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
394 trimarchi 291
  struct timespec ty;
235 giacomo 292
 
293
#ifdef RMSTAR_DEBUG
294
  rmstar_printf("(E:dis)");
295
 
296
  rmstar_printf3("(%d %d)",
297
                  iq_query_timespec(p, &lev->ready)->tv_nsec/1000000,
298
                  schedule_time.tv_nsec/1000000);
299
#endif
300
 
394 trimarchi 301
  if (!nostop || proc_table[exec].task_level==l) {
302
      TIMESPEC_ASSIGN(&ty, &schedule_time);
303
      TIMESPEC_ASSIGN(&lev->cap_lasttime, &schedule_time);
304
 
305
      /* ...and finally, we have to post a capacity event on exec task because the shadow_task consume
306
       *      *        capacity on exe task always */
786 trimarchi 307
      if (proc_table[exec].avail_time > 0) {
308
        ADDUSEC2TIMESPEC(proc_table[exec].avail_time ,&ty);
309
        lev->cap_lev = kern_event_post(&ty,capacity_handler, lev);
310
      }
394 trimarchi 311
      level_table[lev->scheduling_level]->private_dispatch(lev->scheduling_level, p, nostop);
312
  }
313
  else
314
      level_table[proc_table[exec].task_level]->public_dispatch(proc_table[exec].task_level, p, nostop);
315
 
235 giacomo 316
}
317
 
318
static void RMSTAR_public_epilogue(LEVEL l, PID p)
319
{
320
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
321
 
322
#ifdef RMSTAR_DEBUG
323
  rmstar_printf("(E:epi ");
324
#endif
325
 
394 trimarchi 326
  if (lev->cap_lev!=NIL) {
327
    kern_event_delete(lev->cap_lev);
328
    lev->cap_lev=NIL;
329
  }
330
 
331
 
332
  if ( proc_table[exec].task_level==l ) {
333
 
786 trimarchi 334
    if (proc_table[exec].avail_time > 0) RMSTAR_account_capacity(lev,exec);
394 trimarchi 335
 
336
    /* check if the wcet is finished... */
786 trimarchi 337
    if (proc_table[exec].avail_time) {
394 trimarchi 338
      /* wcet finished: disable wcet event and count wcet miss */
235 giacomo 339
#ifdef RMSTAR_DEBUG
394 trimarchi 340
      rmstar_printf2("W%d",p);
235 giacomo 341
#endif
394 trimarchi 342
      //proc_table[p].control &= ~CONTROL_CAP;
783 giacomo 343
      TRACER_LOGEVENT(FTrace_EVT_task_wcet_violation,proc_table[p].context,proc_table[p].task_level);
394 trimarchi 344
      lev->wcet_miss[p]++;
345
    }
235 giacomo 346
#ifdef RMSTAR_DEBUG
394 trimarchi 347
    rmstar_printf(")");
235 giacomo 348
#endif
394 trimarchi 349
 
350
    level_table[ lev->scheduling_level ]->
351
      private_epilogue(lev->scheduling_level,p);
352
 
353
    proc_table[p].status = RMSTAR_READY;
354
  } else
355
    level_table[proc_table[exec].task_level]->public_epilogue(proc_table[exec].task_level,p);
235 giacomo 356
}
357
 
783 giacomo 358
static void RMSTAR_public_activate(LEVEL l, PID p, struct timespec *o)
235 giacomo 359
{
360
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
361
  struct timespec t;
362
 
363
#ifdef RMSTAR_DEBUG
364
  rmstar_printf("(E:act)");
365
#endif
394 trimarchi 366
 /* Test if we are trying to activate a non sleeping task    */
367
 /* save activation (only if needed... */
235 giacomo 368
 
394 trimarchi 369
 if (proc_table[p].status != SLEEP) {
370
     /* a periodic task cannot be activated when it is already active */
371
     /* but aperiodic task can be reactivate before */
802 giacomo 372
     if (lev->flag[p] & RMSTAR_FLAG_SPORADIC) {
373
        if (proc_table[p].status != RMSTAR_IDLE) {
374
          lev->nact[p]++;
375
          return;
376
        }
377
     } else {
378
        kern_raise(XACTIVATION,p);
394 trimarchi 379
     }
380
  }
381
 
235 giacomo 382
  /* Test if we are trying to activate a non sleeping task    */
383
  /* save activation (only if needed... */
384
 
385
  kern_gettime(&t);
386
 
387
  RMSTAR_internal_activate(lev,p, &t);
388
 
389
  /* Set the deadline timer */
390
  lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
391
                                           RMSTAR_timer_deadline,
392
                                           (void *)p);
393
 
394
}
395
 
396
static void RMSTAR_public_unblock(LEVEL l, PID p)
397
{
398
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
399
 
400
#ifdef RMSTAR_DEBUG
401
  rmstar_printf("(E:ins)");
402
#endif
403
 
404
  /* Insert task in the correct position */
405
  proc_table[p].status = RMSTAR_READY;
406
  iq_priority_insert(p,&lev->ready);
407
 
408
  /* and check for preemption! */
409
  RMSTAR_check_preemption(lev);
410
}
411
 
412
static void RMSTAR_public_block(LEVEL l, PID p)
413
{
414
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
415
 
416
#ifdef RMSTAR_DEBUG
417
  rmstar_printf("(E:ext)");
418
#endif
419
 
420
  /* the task is blocked on a synchronization primitive. we have to
421
     remove it from the master module -and- from the local queue! */
422
  iq_extract(p,&lev->ready);
423
 
424
  /* and finally, a preemption check! (it will also call guest_end) */
425
  RMSTAR_check_preemption(lev);
426
}
427
 
428
static int RMSTAR_public_message(LEVEL l, PID p, void *m)
429
{
430
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
431
  struct timespec temp;
432
 
433
#ifdef RMSTAR_DEBUG
434
  rmstar_printf("(E:ecy ");
435
#endif
436
 
437
  switch ((long)(m))
438
    {
439
 
440
      /* Task EndCycle */
441
    case (long)(NULL):
442
 
443
      /* we call guest_end directly here because the same task may
444
         be reinserted in the queue before calling the preemption check! */
445
      level_table[ lev->scheduling_level ]->
446
        private_extract(lev->scheduling_level,p);  lev->activated = NIL;
447
 
448
      iq_extract(p,&lev->ready);
449
 
450
      /* we reset the capacity counters... */
451
      proc_table[p].avail_time = proc_table[p].wcet;
452
 
453
      if (lev->nact[p] > 0) {
454
#ifdef RMSTAR_DEBUG
455
        rmstar_printf2("E%d",p);
456
#endif
457
 
458
        /* Pending activation: reactivate the thread!!! */
459
        lev->nact[p]--;
460
 
461
        /* see also RMSTAR_timer_deadline */
462
        kern_gettime(&temp);
463
 
464
        RMSTAR_internal_activate(lev,p,&temp);
465
 
466
        /* check if the deadline has already expired */
467
        temp = *iq_query_timespec(p, &lev->ready);
468
        if (TIMESPEC_A_LT_B(&temp, &schedule_time)) {
469
          /* count the deadline miss */
470
          lev->dline_miss[p]++;
471
          kern_event_delete(lev->deadline_timer[p]);
799 giacomo 472
          lev->deadline_timer[p] = NIL;
235 giacomo 473
        }
474
 
475
      }
476
      else {
477
#ifdef RMSTAR_DEBUG
478
        rmstar_printf("e%d",p);
479
#endif
799 giacomo 480
        if (lev->flag[p] & RMSTAR_FLAG_SPORADIC && lev->deadline_timer[p] != NIL) {
394 trimarchi 481
            kern_event_delete(lev->deadline_timer[p]);
799 giacomo 482
            lev->deadline_timer[p] = NIL;
483
        }
394 trimarchi 484
 
235 giacomo 485
        /* the task has terminated his job before it consume the wcet. All OK! */
799 giacomo 486
        if (lev->flag[p] & RMSTAR_FLAG_SPORADIC)
487
                proc_table[p].status = SLEEP;
488
         else
489
                proc_table[p].status = RMSTAR_IDLE;
235 giacomo 490
 
491
        /* and finally, a preemption check! */
492
        RMSTAR_check_preemption(lev);
493
 
494
        /* when the deadline timer fire, it recognize the situation and set
495
           correctly all the stuffs (like reactivation, etc... ) */
496
      }
497
#ifdef RMSTAR_DEBUG
498
      rmstar_printf(")");
499
#endif
783 giacomo 500
      TRACER_LOGEVENT(FTrace_EVT_task_end_cycle,proc_table[p].context,proc_table[p].task_level);      
235 giacomo 501
      jet_update_endcycle(); /* Update the Jet data... */
502
      break;
503
    default:
504
 
505
      break;
506
 
507
    }
508
  return 0;
509
}
510
 
511
static void RMSTAR_public_end(LEVEL l, PID p)
512
{
513
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
514
 
515
#ifdef RMSTAR_DEBUG
516
  rmstar_printf("(E:end)");
517
#endif
518
 
519
  iq_extract(p,&lev->ready);
520
 
521
  /* we finally put the task in the ready queue */
522
  proc_table[p].status = FREE;
523
 
524
  iq_insertfirst(p,&freedesc);
525
 
526
  if (lev->deadline_timer[p] != -1) {
527
    kern_event_delete(lev->deadline_timer[p]);
799 giacomo 528
    lev->deadline_timer[p] = NIL;
235 giacomo 529
  }
530
 
531
  /* and finally, a preemption check! (it will also call guest_end) */
532
  RMSTAR_check_preemption(lev);
533
}
534
 
535
 
536
/* Guest Functions
537
   These functions manages a JOB_TASK_MODEL, that is used to put
538
   a guest task in the RMSTAR ready queue. */
539
 
540
static void RMSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m)
541
{
542
  RMSTAR_level_des *lev = (RMSTAR_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
  *iq_query_timespec(p, &lev->ready) = job->deadline;
553
 
554
  lev->deadline_timer[p] = -1;
555
  lev->dline_miss[p]     = 0;
556
  lev->wcet_miss[p]      = 0;
557
  lev->nact[p]           = 0;
558
 
559
  if (job->noraiseexc)
560
    lev->flag[p] = RMSTAR_FLAG_NORAISEEXC;
561
  else {
562
    lev->flag[p] = 0;
563
    lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
564
                                             RMSTAR_timer_guest_deadline,
565
                                             (void *)p);
566
   }
567
 
568
  lev->period[p] = job->period;
569
  *iq_query_priority(p, &lev->ready) = job->period;
570
 
571
  /* there is no bandwidth guarantee at this level, it is performed
572
     by the level that inserts guest tasks... */
573
 
574
  /* Insert task in the correct position */
575
  iq_priority_insert(p,&lev->ready);
576
  proc_table[p].status = RMSTAR_READY;
577
 
578
  /* check for preemption */
579
  RMSTAR_check_preemption(lev);
580
}
581
 
582
 
583
static void RMSTAR_private_dispatch(LEVEL l, PID p, int nostop)
584
{
585
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
586
 
587
  level_table[ lev->scheduling_level ]->
588
    private_dispatch(lev->scheduling_level,p,nostop);
589
}
590
 
591
static void RMSTAR_private_epilogue(LEVEL l, PID p)
592
{
593
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
594
 
595
  /* the task has been preempted. it returns into the ready queue... */
596
  level_table[ lev->scheduling_level ]->
597
    private_epilogue(lev->scheduling_level,p);
598
 
599
  proc_table[p].status = RMSTAR_READY;
600
}
601
 
602
static void RMSTAR_private_extract(LEVEL l, PID p)
603
{
604
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
605
 
606
#ifdef RMSTAR_DEBUG
607
  //kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
608
#endif
609
 
610
  iq_extract(p, &lev->ready);
611
 
612
  /* we remove the deadline timer, because the slice is finished */
613
  if (lev->deadline_timer[p] != NIL) {
614
#ifdef RMSTAR_DEBUG
615
//    kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
616
#endif
617
    kern_event_delete(lev->deadline_timer[p]);
618
    lev->deadline_timer[p] = NIL;
619
  }
620
 
621
  /* and finally, a preemption check! (it will also call guest_end() */
622
  RMSTAR_check_preemption(lev);
623
}
624
 
625
/* Registration functions */
626
 
627
/* Registration function:
628
    int flags                 the init flags ... see RMSTAR.h */
629
LEVEL RMSTAR_register_level(int master)
630
{
631
  LEVEL l;            /* the level that we register */
632
  RMSTAR_level_des *lev;  /* for readableness only */
633
  PID i;              /* a counter */
634
 
635
#ifdef RMSTAR_DEBUG
636
  printk("RMSTAR_register_level\n");
637
#endif
638
 
639
  /* request an entry in the level_table */
640
  l = level_alloc_descriptor(sizeof(RMSTAR_level_des));
641
 
642
  lev = (RMSTAR_level_des *)level_table[l];
643
 
644
  /* fill the standard descriptor */
645
  lev->l.private_insert   = RMSTAR_private_insert;
646
  lev->l.private_extract  = RMSTAR_private_extract;
647
  lev->l.private_dispatch = RMSTAR_private_dispatch;
648
  lev->l.private_epilogue = RMSTAR_private_epilogue;
649
 
650
  lev->l.public_guarantee = NULL;
651
  lev->l.public_create    = RMSTAR_public_create;
652
  lev->l.public_end       = RMSTAR_public_end;
653
  lev->l.public_dispatch  = RMSTAR_public_dispatch;
654
  lev->l.public_epilogue  = RMSTAR_public_epilogue;
655
  lev->l.public_activate  = RMSTAR_public_activate;
656
  lev->l.public_unblock   = RMSTAR_public_unblock;
657
  lev->l.public_block     = RMSTAR_public_block;
658
  lev->l.public_message   = RMSTAR_public_message;
659
 
660
  /* fill the RMSTAR descriptor part */
661
  for(i=0; i<MAX_PROC; i++) {
662
    lev->period[i]         = 0;
663
    lev->deadline_timer[i] = -1;
664
    lev->flag[i]           = 0;
665
    lev->dline_miss[i]     = 0;
666
    lev->wcet_miss[i]      = 0;
667
    lev->nact[i]           = 0;
668
    lev->budget[i]         = NIL;
669
  }
670
 
671
  iq_init(&lev->ready, NULL, 0);
672
  lev->activated = NIL;
673
 
674
  lev->scheduling_level = master;
675
 
394 trimarchi 676
  lev->cap_lev = NIL;
677
  NULL_TIMESPEC(&lev->cap_lasttime);
678
 
235 giacomo 679
  return l;
680
}
681
 
682
int RMSTAR_get_dline_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->dline_miss[p];
688
}
689
 
690
int RMSTAR_get_wcet_miss(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->wcet_miss[p];
696
}
697
 
698
int RMSTAR_get_nact(PID p)
699
{
700
  LEVEL l = proc_table[p].task_level;
701
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
702
 
703
  return lev->nact[p];
704
}
705
 
706
int RMSTAR_reset_dline_miss(PID p)
707
{
708
  LEVEL l = proc_table[p].task_level;
709
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
710
 
711
  lev->dline_miss[p] = 0;
712
  return 0;
713
}
714
 
715
int RMSTAR_reset_wcet_miss(PID p)
716
{
717
  LEVEL l = proc_table[p].task_level;
718
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
719
 
720
  lev->wcet_miss[p] = 0;
721
  return 0;
722
}
723
 
724
 
725
int RMSTAR_setbudget(LEVEL l, PID p, int budget)
726
{
727
 
728
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
729
 
730
  lev->budget[p] = budget;
731
 
732
  return 0;
733
 
734
}
735
 
736
int RMSTAR_getbudget(LEVEL l, PID p)
737
{
738
 
739
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
740
 
741
  return lev->budget[p];
742
 
743
}
744
 
745
int RMSTAR_budget_has_thread(LEVEL l, int budget)
746
{
747
 
748
  RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
749
  int i;
750
 
751
  for(i = 0; i< MAX_PROC; i++)
752
    if (lev->budget[i] == budget) return 1;
753
 
754
  return 0;
755
 
756
}