Subversion Repositories shark

Rev

Rev 975 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
221 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Trimarchi Michael   <trimarchi@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) 2000 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 WARR2ANTY; without even the implied waRR2anty 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
 
1689 fabio 39
#include <arch/stdio.h>
40
#include <arch/string.h>
221 giacomo 41
#include <kernel/model.h>
42
#include <kernel/descr.h>
43
#include <kernel/var.h>
44
#include <kernel/func.h>
45
#include "posixstar.h"
867 trimarchi 46
#include "fsf_configuration_parameters.h"
47
#include "fsf_core.h"
241 giacomo 48
#include "fsf_server.h"
975 trimarchi 49
#include <posix/posix/comm_message.h>
221 giacomo 50
 
822 trimarchi 51
//#define POSIXSTAR_DEBUG
221 giacomo 52
 
53
/*+ Status used in the level +*/
54
#define POSIXSTAR_READY   MODULE_STATUS_BASE
55
 
56
#define POSIXSTAR_CHANGE_LEVEL 1
57
 
815 trimarchi 58
/* flags */
59
#define POSIXSTAR_FLAG_NOPREEMPT   4 
60
 
221 giacomo 61
/*+ the level redefinition for the Round Robin level +*/
62
typedef struct {
63
  level_des l;          /*+ the standard level descriptor          +*/
64
 
65
  int nact[MAX_PROC];   /*+ number of pending activations          +*/
66
 
67
  int priority[MAX_PROC]; /*+ priority of each task                +*/
68
 
69
  IQUEUE *ready;        /*+ the ready queue array                  +*/
70
 
71
  int slice;            /*+ the level's time slice                 +*/
72
 
73
  int maxpriority;      /*+ the priority are from 0 to maxpriority
74
                            (i.e 0 to 31)                          +*/
75
 
76
  int yielding;         /*+ equal to 1 when a sched_yield is called +*/
77
 
78
  int budget[MAX_PROC];
79
 
815 trimarchi 80
  int flag[MAX_PROC];
81
 
876 trimarchi 82
  int new_level[MAX_PROC];
83
  int new_slice[MAX_PROC];
84
  int new_control[MAX_PROC];
85
 
221 giacomo 86
  PID activated;
87
  int scheduling_level;
296 trimarchi 88
  int cap_lev;
89
  struct timespec cap_lasttime;
221 giacomo 90
 
91
} POSIXSTAR_level_des;
92
 
296 trimarchi 93
static void capacity_handler(void *l)
94
{
95
  POSIXSTAR_level_des *lev = l;
96
  lev->cap_lev = NIL;
97
  event_need_reschedule();
98
}
221 giacomo 99
/* the private scheduler choice a task and insert in cbsstar module */
100
/* This is not efficient but very fair :-)
101
   The need of all this stuff is because if a task execute a long time
102
   due to (shadow!) priority inheritance, then the task shall go to the
103
   tail of the queue many times... */
104
 
105
static void POSIXSTAR_private_scheduler(POSIXSTAR_level_des * lev)
106
{
107
  /* the old posix scheduler select the private job for CBS */
108
  PID p = NIL;
109
 
110
  int prio;
111
 
815 trimarchi 112
 
221 giacomo 113
  prio = lev->maxpriority;
114
 
115
  for (;;) {
116
    p = iq_query_first(&lev->ready[prio]);
117
    if (p == NIL) {
118
      if (prio) {
119
        prio--;
120
        continue;
121
      }
122
      else {
123
        p=NIL;
124
        break;
125
      }
126
    }
127
 
393 giacomo 128
    if (proc_table[p].avail_time <= 0) {
298 giacomo 129
      while (proc_table[p].avail_time<=0)
221 giacomo 130
        proc_table[p].avail_time += proc_table[p].wcet;
131
      iq_extract(p,&lev->ready[prio]);
132
      iq_insertlast(p,&lev->ready[prio]);
133
    }
134
    else {
135
      break;
136
    }
137
  }
828 trimarchi 138
 
139
  /* check if the task is preempteble or not */
835 trimarchi 140
  if (lev->activated != NIL && (lev->flag[lev->activated] & POSIXSTAR_FLAG_NOPREEMPT)) return;
828 trimarchi 141
 
221 giacomo 142
  if (p!=lev->activated) {
143
    if (lev->activated != NIL )  {
144
     level_table[ lev->scheduling_level ]->
145
       private_extract(lev->scheduling_level, lev->activated);
146
   }
147
   lev->activated = p;
148
 
149
   if (p != NIL) {
150
     BUDGET_TASK_MODEL b;
151
     budget_task_default_model(b, lev->budget[p]);
152
     #ifdef POSIXSTAR_DEBUG
153
       kern_printf("(PS:SchAct:%d:%d)",p,lev->budget[p]);
154
     #endif
155
     level_table[ lev->scheduling_level ]->
156
       private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b);
157
   }
158
 }
159
}
160
 
161
static int POSIXSTAR_public_eligible(LEVEL l, PID p)
162
{
163
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
296 trimarchi 164
  return level_table[ lev->scheduling_level ]->
221 giacomo 165
      private_eligible(lev->scheduling_level,p);
296 trimarchi 166
 
221 giacomo 167
  return 0;
168
}
169
 
296 trimarchi 170
 
171
static void POSIXSTAR_account_capacity(POSIXSTAR_level_des *lev, PID p)
172
{
393 giacomo 173
  struct timespec ty;
174
  TIME tx;
296 trimarchi 175
 
393 giacomo 176
  SUBTIMESPEC(&schedule_time, &lev->cap_lasttime, &ty);
177
  tx = TIMESPEC2USEC(&ty);
296 trimarchi 178
 
393 giacomo 179
  proc_table[p].avail_time -= tx;
296 trimarchi 180
 
181
}
182
 
221 giacomo 183
static int POSIXSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m)
184
{
185
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
186
  NRT_TASK_MODEL *nrt;
187
 
188
  /* DEBUG */
189
  #ifdef POSIXSTAR_DEBUG
190
    kern_printf("(PS:Crt:%d)",p);
191
  #endif
192
 
193
  if (m->pclass != NRT_PCLASS) return -1;
194
  if (m->level != 0 && m->level != l) return -1;
195
 
196
  nrt = (NRT_TASK_MODEL *)m;
197
 
198
  /* the task state is set at SLEEP by the general task_create */
199
 
200
  /* I used the wcet field because using wcet can account if a task
201
     consume more than the timeslice... */
202
 
203
  if (nrt->inherit == NRT_INHERIT_SCHED &&
204
      proc_table[exec_shadow].task_level == l) {
205
    /* We inherit the scheduling properties if the scheduling level
206
       *is* the same */
207
    lev->priority[p] = lev->priority[exec_shadow];
208
 
209
    proc_table[p].avail_time = proc_table[exec_shadow].avail_time;
210
    proc_table[p].wcet       = proc_table[exec_shadow].wcet;
211
 
212
    lev->nact[p] = (lev->nact[exec_shadow] == -1) ? -1 : 0;
213
  }
214
  else {
215
    if (nrt->weight<=lev->maxpriority)
216
      lev->priority[p] = nrt->weight;
217
    else lev->priority[p]=lev->maxpriority;
218
 
219
    if (nrt->slice) {
220
      proc_table[p].avail_time = nrt->slice;
221
      proc_table[p].wcet       = nrt->slice;
222
    }
223
    else {
224
      proc_table[p].avail_time = lev->slice;
225
      proc_table[p].wcet       = lev->slice;
226
    }
815 trimarchi 227
 
392 trimarchi 228
    #if defined POSIXSTAR_DEBUG
229
        kern_printf("(slice %d)", proc_table[p].wcet);
230
    #endif 
221 giacomo 231
    if (nrt->arrivals == SAVE_ARRIVALS)
232
      lev->nact[p] = 0;
233
    else
234
      lev->nact[p] = -1;
235
 
236
  }
237
 
834 trimarchi 238
  lev->flag[p] = 0;
393 giacomo 239
  proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP);
240
 
241
  return 0;
242
 
221 giacomo 243
}
244
 
245
static void POSIXSTAR_public_dispatch(LEVEL l, PID p, int nostop)
246
{
247
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
296 trimarchi 248
  struct timespec ty;
221 giacomo 249
  /* the task state is set EXE by the scheduler()
250
     we extract the task from the ready queue
251
     NB: we can't assume that p is the first task in the queue!!! */
252
 
253
  #ifdef POSIXSTAR_DEBUG
296 trimarchi 254
     if( !nostop) kern_printf("(PS:Dsp:%d)",p); else
255
         kern_printf("(PS:Dsp_shad:%d)",p);
221 giacomo 256
  #endif
383 trimarchi 257
 
384 trimarchi 258
  if (!nostop || proc_table[exec].task_level==l) {
259
    TIMESPEC_ASSIGN(&ty, &schedule_time);
260
    TIMESPEC_ASSIGN(&lev->cap_lasttime, &schedule_time);
383 trimarchi 261
 
262
  /* ...and finally, we have to post a capacity event on exec task because the shadow_task consume
263
   *        capacity on exe task always */
392 trimarchi 264
    ADDUSEC2TIMESPEC(proc_table[exec].avail_time, &ty);
384 trimarchi 265
 
266
    lev->cap_lev = kern_event_post(&ty,capacity_handler, lev);
221 giacomo 267
    level_table[lev->scheduling_level]->private_dispatch(lev->scheduling_level, p, nostop);
296 trimarchi 268
  }
269
  else
384 trimarchi 270
    level_table[proc_table[exec].task_level]->public_dispatch(proc_table[exec].task_level, p, nostop);
271
 
221 giacomo 272
}
273
 
876 trimarchi 274
static int POSIXSTAR_private_change_level(LEVEL l, PID p)
275
{
276
 
277
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
278
 
279
  /* Change task level */
280
  if (lev->flag[p] & POSIXSTAR_CHANGE_LEVEL) {
281
 
282
    STD_command_message msg;
283
 
284
    proc_table[p].status = SLEEP;
877 trimarchi 285
    lev->flag[p] &= ~POSIXSTAR_CHANGE_LEVEL;
876 trimarchi 286
 
287
    level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p);
288
    iq_extract(p,&lev->ready[lev->priority[p]]);
289
 
290
    POSIXSTAR_private_scheduler(lev);
291
 
292
    lev->nact[p] = 0;
293
    lev->budget[p] = -1;
294
 
295
    proc_table[p].task_level = lev->new_level[p];
296
    msg.command = STD_ACTIVATE_TASK;
297
    level_table[lev->new_level[p]] -> public_message(lev->new_level[p],p,&msg);
298
 
299
    return 1;
300
 
301
  }
302
 
303
  return 0;
304
 
305
}
306
 
226 giacomo 307
static void POSIXSTAR_public_epilogue(LEVEL l, PID p)
308
{
309
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
402 giacomo 310
 
226 giacomo 311
  #ifdef POSIXSTAR_DEBUG
312
    kern_printf("(PS:Epi:%d)",p);
313
  #endif 
314
 
296 trimarchi 315
 if (lev->cap_lev!=NIL) {
393 giacomo 316
   kern_event_delete(lev->cap_lev);
317
   lev->cap_lev=NIL;
296 trimarchi 318
 }
319
 
393 giacomo 320
 if (proc_table[exec].task_level==l ) {
321
 
828 trimarchi 322
   POSIXSTAR_account_capacity(lev,exec);
876 trimarchi 323
 
324
   if (POSIXSTAR_private_change_level(l,p)) return;
221 giacomo 325
 
393 giacomo 326
   if (lev->yielding) {
327
     lev->yielding = 0;
328
     iq_extract(p,&lev->ready[lev->priority[exec]]);
329
     iq_insertlast(p,&lev->ready[lev->priority[exec]]);
402 giacomo 330
   } else {
331
 
332
     if (proc_table[exec].avail_time <= 0) {
333
 
334
       POSIXSTAR_private_scheduler(lev);
838 giacomo 335
 
836 trimarchi 336
       if (exec==lev->activated) {
402 giacomo 337
         level_table[lev->scheduling_level]->private_epilogue(lev->scheduling_level,p);  
338
       }
339
 
340
     } else  {
341
 
342
       level_table[lev->scheduling_level]->private_epilogue(lev->scheduling_level,p);
343
 
344
     }
345
 
393 giacomo 346
   }
347
 
402 giacomo 348
   proc_table[exec].status = POSIXSTAR_READY;
221 giacomo 349
 
402 giacomo 350
 } else {
351
 
352
   level_table[proc_table[exec].task_level]->public_epilogue(proc_table[exec].task_level,p);
353
 
354
 }
355
 
221 giacomo 356
}
357
 
358
static void POSIXSTAR_internal_activate(POSIXSTAR_level_des *lev, PID p)
359
{
360
 
361
  /* Insert task in the correct position */
362
  proc_table[p].status = POSIXSTAR_READY;
363
  iq_insertlast(p,&lev->ready[lev->priority[p]]);
364
 
365
}
366
 
367
 
783 giacomo 368
static void POSIXSTAR_public_activate(LEVEL l, PID p, struct timespec *t)
221 giacomo 369
{
370
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
371
 
372
  /* Test if we are trying to activate a non sleeping task    */
373
  /* save activation (only if needed...) */
374
  if (proc_table[p].status != SLEEP) {
375
    if (lev->nact[p] != -1)
376
      lev->nact[p]++;
377
    return;
378
  }
379
 
380
  #ifdef POSIXSTAR_DEBUG 
381
    kern_printf("(PS:Act:%d)",p);
382
  #endif
383
 
384
  POSIXSTAR_internal_activate(lev, p);
385
  POSIXSTAR_private_scheduler(lev);
386
 
387
}
388
 
389
 
390
static void POSIXSTAR_public_unblock(LEVEL l, PID p)
391
{
392
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
393
 
394
  /* Similar to POSIX_task_activate, but we don't check in what state
395
     the task is */
396
 
397
  #ifdef POSIXSTAR_DEBUG
398
    kern_printf("(PS:UnBlk:%d)",p);
399
  #endif
400
  /* Insert task in the coPOSIXect position */
401
  proc_table[p].status = POSIXSTAR_READY;
402
  iq_insertlast(p,&lev->ready[lev->priority[p]]);
403
  POSIXSTAR_private_scheduler(lev);
404
 
405
}
406
 
407
static void POSIXSTAR_public_block(LEVEL l, PID p)
408
{  
409
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
410
 
411
  /* Extract the running task from the level
412
     . we have already extract it from the ready queue at the dispatch time.
413
     . the capacity event have to be removed by the generic kernel
414
     . the wcet don't need modification...
415
     . the state of the task is set by the calling function
416
 
417
     So, we do nothing!!!
418
  */
419
 
420
  #ifdef POSIXSTAR_DEBUG
421
    kern_printf("(PS:Blk:%d)", p);     
422
  #endif
423
 
424
  iq_extract(p,&lev->ready[lev->priority[p]]);
425
  POSIXSTAR_private_scheduler(lev);
426
 
427
}
428
 
429
static int POSIXSTAR_public_message(LEVEL l, PID p, void *m)
430
{
431
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
876 trimarchi 432
  STD_command_message *msg;
433
  NRT_TASK_MODEL *nrt;
221 giacomo 434
 
435
  #ifdef POSIXSTAR_DEBUG
436
    kern_printf("(PS:Msg:%d)",p);
437
  #endif
438
 
439
  switch ((long)(m)) {
440
 
441
    /* Task EndCycle */
442
    case (long)(NULL):
443
 
876 trimarchi 444
      if (POSIXSTAR_private_change_level(l,p)) return 0;
445
 
221 giacomo 446
      if (lev->nact[p] > 0) {
447
        /* continue!!!! */
448
        lev->nact[p]--;
449
        iq_extract(p,&lev->ready[lev->priority[p]]);
450
        iq_insertfirst(p,&lev->ready[lev->priority[p]]);
451
        proc_table[p].status = POSIXSTAR_READY;
452
      }
453
      else {
454
        proc_table[p].status = SLEEP;
455
        iq_extract(p,&lev->ready[lev->priority[p]]);
456
      }
457
 
458
      jet_update_endcycle(); /* Update the Jet data... */
459
      POSIXSTAR_private_scheduler(lev);
460
 
461
      break;
462
 
463
    /* Task Disable */
464
    case (long)(1):
465
 
466
      break;
467
 
468
    default:
469
 
876 trimarchi 470
      msg = (STD_command_message *)m;
471
 
472
      switch(msg->command) {
473
        case STD_SET_NEW_LEVEL:
474
 
475
          lev->flag[p] |= POSIXSTAR_CHANGE_LEVEL;
476
          lev->new_level[p] = (int)(msg->param);
477
 
478
          break;
479
        case STD_SET_NEW_MODEL:
480
 
481
          nrt = (NRT_TASK_MODEL *)(msg->param);
482
 
483
          lev->priority[p] = nrt->weight;
484
 
485
          if (nrt->slice) {
486
            lev->new_slice[p] = nrt->slice;
487
          } else {
488
            lev->new_slice[p] = 0;
489
          }
490
 
491
          if (nrt->policy == NRT_RR_POLICY)
492
            lev->new_control[p] &= ~CONTROL_CAP;
493
 
494
          if (nrt->arrivals == SAVE_ARRIVALS)
495
            lev->nact[p] = 0;
496
          else
497
            lev->nact[p] = -1;
498
 
499
          lev->flag[p] = 0;
500
 
501
          break;
502
       case STD_ACTIVATE_TASK:
503
 
504
         if (lev->new_slice[p]) {
505
           proc_table[p].avail_time = lev->new_slice[p];
506
           proc_table[p].wcet = lev->new_slice[p];
507
         } else {
508
           proc_table[p].avail_time = lev->slice;
509
           proc_table[p].wcet = lev->slice;
510
         }
511
 
512
         proc_table[p].control |= lev->new_control[p];
513
 
514
         POSIXSTAR_public_activate(l,p,NULL);
515
 
516
         break;
517
 
518
      }
519
 
241 giacomo 520
      break;
221 giacomo 521
 
522
  }
523
 
524
  return 0;
525
 
526
}
527
 
528
static void POSIXSTAR_public_end(LEVEL l, PID p)
529
{
530
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
531
 
532
  #ifdef POSIXSTAR_DEBUG
533
    kern_printf("(PS:End:%d)", p);
534
  #endif
535
 
536
  lev->nact[p] = -1;
348 trimarchi 537
  /* extract task from the queue */
538
  iq_extract(p,&lev->ready[lev->priority[p]]);
221 giacomo 539
 
540
  /* then, we insert the task in the free queue */
541
  proc_table[p].status = FREE;
542
  iq_priority_insert(p,NULL);
543
  POSIXSTAR_private_scheduler(lev);
544
 
545
}
546
 
547
/* Registration functions */
548
 
549
/*+ Registration function:
550
    TIME slice                the slice for the Round Robin queue +*/
551
LEVEL POSIXSTAR_register_level(int master, TIME slice,
552
                       int prioritylevels)
553
{
554
  LEVEL l;            /* the level that we register */
555
  POSIXSTAR_level_des *lev;  /* for readableness only */
556
  PID i;              /* a counter */
557
  int x;              /* a counter */
558
 
559
  #ifdef POSIXSTRA_DEBUG
560
    kern_printf("POSIXSTAR_register_level\n");
561
  #endif
562
 
563
  l = level_alloc_descriptor(sizeof(POSIXSTAR_level_des));
564
 
565
  lev = (POSIXSTAR_level_des *)level_table[l];
566
 
270 giacomo 567
  lev->l.public_guarantee = NULL;
221 giacomo 568
  lev->l.public_create    = POSIXSTAR_public_create;
569
  lev->l.public_end       = POSIXSTAR_public_end;
570
  lev->l.public_dispatch  = POSIXSTAR_public_dispatch;
571
  lev->l.public_epilogue  = POSIXSTAR_public_epilogue;
572
  lev->l.public_activate  = POSIXSTAR_public_activate;
573
  lev->l.public_unblock   = POSIXSTAR_public_unblock;
574
  lev->l.public_block     = POSIXSTAR_public_block;
575
  lev->l.public_message   = POSIXSTAR_public_message;
576
  lev->l.public_eligible  = POSIXSTAR_public_eligible;
577
 
578
  /* fill the POSIX descriptor part */
579
  for (i = 0; i < MAX_PROC; i++) {
580
    lev->nact[i] = -1;
581
    lev->budget[i] = -1;
876 trimarchi 582
 
583
    lev->flag[i] = 0;
584
 
585
    lev->new_level[i] = 0;
586
    lev->new_slice[i] = 0;
587
    lev->new_control[i] = 0;
221 giacomo 588
  }
589
 
590
  lev->maxpriority = prioritylevels - 1;
591
 
592
  lev->ready = (IQUEUE *)kern_alloc(sizeof(IQUEUE) * prioritylevels);
593
 
594
  for (x = 0; x < prioritylevels; x++)
595
    iq_init(&lev->ready[x], NULL, 0);
596
 
597
  if (slice < POSIXSTAR_MINIMUM_SLICE) slice = POSIXSTAR_MINIMUM_SLICE;
598
  if (slice > POSIXSTAR_MAXIMUM_SLICE) slice = POSIXSTAR_MAXIMUM_SLICE;
599
  lev->slice = slice;
600
  lev->activated = NIL;
601
  lev->scheduling_level = master;
298 giacomo 602
  lev->cap_lev = NIL;
838 giacomo 603
  lev->yielding = 0;
296 trimarchi 604
  NULL_TIMESPEC(&lev->cap_lasttime);
605
 
221 giacomo 606
  return l;
607
 
608
}
609
 
610
int POSIXSTAR_setbudget(LEVEL l, PID p, int budget)
611
{
612
 
613
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
614
 
615
  lev->budget[p] = budget;
616
 
617
  return 0;
618
 
619
}
620
 
621
int POSIXSTAR_getbudget(LEVEL l, PID p)
622
{
623
 
624
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
625
 
626
  return lev->budget[p];
627
 
628
}
629
 
630
int POSIXSTAR_budget_has_thread(LEVEL l, int budget)
631
{
632
 
633
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
634
  int i;
635
 
636
  for(i = 0; i< MAX_PROC; i++)
637
    if (lev->budget[i] == budget) return 1;
638
 
639
  return 0;
640
 
641
}
642
 
643
/*+ this function forces the running task to go to his queue tail;
644
    (it works only on the POSIX level) +*/
645
int POSIXSTAR_sched_yield(LEVEL l)
646
{
647
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
648
 
649
  if (proc_table[exec_shadow].task_level != l)
650
    return -1;
651
 
652
  proc_table[exec_shadow].context = kern_context_save();
653
  lev->yielding = 1;
654
  scheduler();
655
  kern_context_load(proc_table[exec_shadow].context);
656
  return 0;
657
}
658
 
659
/*+ this function returns the maximum level allowed for the POSIX level +*/
660
int POSIXSTAR_get_priority_max(LEVEL l)
661
{
662
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
663
  return lev->maxpriority;
664
}
665
 
666
/*+ this function returns the default timeslice for the POSIX level +*/
667
int POSIXSTAR_rr_get_interval(LEVEL l)
668
{
669
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
670
  return lev->slice;
671
}
672
 
673
/*+ this functions returns some paramaters of a task;
674
    policy must be NRT_RR_POLICY or NRT_FIFO_POLICY;
675
    priority must be in the range [0..prioritylevels]
676
    returns ENOSYS or ESRCH if there are problems +*/
677
int POSIXSTAR_getschedparam(LEVEL l, PID p, int *policy, int *priority)
678
{
679
  if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE)
680
    return ESRCH;
681
 
682
  if (proc_table[p].task_level != l)
683
    return ENOSYS;
684
 
393 giacomo 685
  *policy = NRT_RR_POLICY;
221 giacomo 686
  *priority = ((POSIXSTAR_level_des *)(level_table[l]))->priority[p];
687
 
688
  return 0;
689
}
690
 
691
/*+ this functions sets paramaters of a task +*/
692
int POSIXSTAR_setschedparam(LEVEL l, PID p, int policy, int priority)
693
{
694
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
695
 
696
  if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE)
697
    return ESRCH;
698
 
699
  if (proc_table[p].task_level != l)
700
    return ENOSYS;
701
  if (lev->priority[p] != priority) {
702
    if (proc_table[p].status == POSIXSTAR_READY) {
703
      iq_extract(p,&lev->ready[lev->priority[p]]);
704
      lev->priority[p] = priority;
705
      iq_insertlast(p,&lev->ready[priority]);
706
    }
707
    else
708
      lev->priority[p] = priority;
709
  }
710
 
711
  return 0;
712
}
713
 
815 trimarchi 714
 
715
void POSIXSTAR_set_nopreemtive_current(LEVEL l) {
716
 
717
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
718
 
719
  lev->flag[lev->activated]|=POSIXSTAR_FLAG_NOPREEMPT;
720
}
721
 
722
void POSIXSTAR_unset_nopreemtive_current(LEVEL l) {
723
 
724
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
725
 
726
  lev->flag[lev->activated]&=~POSIXSTAR_FLAG_NOPREEMPT;
727
}