Subversion Repositories shark

Rev

Rev 867 | Rev 877 | Go to most recent revision | 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
 
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
#include "posixstar.h"
867 trimarchi 46
#include "fsf_configuration_parameters.h"
47
#include "fsf_core.h"
241 giacomo 48
#include "fsf_server.h"
876 trimarchi 49
#include <modules/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;
285
 
286
    level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p);
287
    iq_extract(p,&lev->ready[lev->priority[p]]);
288
 
289
    POSIXSTAR_private_scheduler(lev);
290
 
291
    lev->nact[p] = 0;
292
    lev->budget[p] = -1;
293
 
294
    proc_table[p].task_level = lev->new_level[p];
295
    msg.command = STD_ACTIVATE_TASK;
296
    level_table[lev->new_level[p]] -> public_message(lev->new_level[p],p,&msg);
297
 
298
    return 1;
299
 
300
  }
301
 
302
  return 0;
303
 
304
}
305
 
226 giacomo 306
static void POSIXSTAR_public_epilogue(LEVEL l, PID p)
307
{
308
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
402 giacomo 309
 
226 giacomo 310
  #ifdef POSIXSTAR_DEBUG
311
    kern_printf("(PS:Epi:%d)",p);
312
  #endif 
313
 
296 trimarchi 314
 if (lev->cap_lev!=NIL) {
393 giacomo 315
   kern_event_delete(lev->cap_lev);
316
   lev->cap_lev=NIL;
296 trimarchi 317
 }
318
 
393 giacomo 319
 if (proc_table[exec].task_level==l ) {
320
 
828 trimarchi 321
   POSIXSTAR_account_capacity(lev,exec);
876 trimarchi 322
 
323
   if (POSIXSTAR_private_change_level(l,p)) return;
221 giacomo 324
 
393 giacomo 325
   if (lev->yielding) {
326
     lev->yielding = 0;
327
     iq_extract(p,&lev->ready[lev->priority[exec]]);
328
     iq_insertlast(p,&lev->ready[lev->priority[exec]]);
402 giacomo 329
   } else {
330
 
331
     if (proc_table[exec].avail_time <= 0) {
332
 
333
       POSIXSTAR_private_scheduler(lev);
838 giacomo 334
 
836 trimarchi 335
       if (exec==lev->activated) {
402 giacomo 336
         level_table[lev->scheduling_level]->private_epilogue(lev->scheduling_level,p);  
337
       }
338
 
339
     } else  {
340
 
341
       level_table[lev->scheduling_level]->private_epilogue(lev->scheduling_level,p);
342
 
343
     }
344
 
393 giacomo 345
   }
346
 
402 giacomo 347
   proc_table[exec].status = POSIXSTAR_READY;
221 giacomo 348
 
402 giacomo 349
 } else {
350
 
351
   level_table[proc_table[exec].task_level]->public_epilogue(proc_table[exec].task_level,p);
352
 
353
 }
354
 
221 giacomo 355
}
356
 
357
static void POSIXSTAR_internal_activate(POSIXSTAR_level_des *lev, PID p)
358
{
359
 
360
  /* Insert task in the correct position */
361
  proc_table[p].status = POSIXSTAR_READY;
362
  iq_insertlast(p,&lev->ready[lev->priority[p]]);
363
 
364
}
365
 
366
 
783 giacomo 367
static void POSIXSTAR_public_activate(LEVEL l, PID p, struct timespec *t)
221 giacomo 368
{
369
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
370
 
371
  /* Test if we are trying to activate a non sleeping task    */
372
  /* save activation (only if needed...) */
373
  if (proc_table[p].status != SLEEP) {
374
    if (lev->nact[p] != -1)
375
      lev->nact[p]++;
376
    return;
377
  }
378
 
379
  #ifdef POSIXSTAR_DEBUG 
380
    kern_printf("(PS:Act:%d)",p);
381
  #endif
382
 
383
  POSIXSTAR_internal_activate(lev, p);
384
  POSIXSTAR_private_scheduler(lev);
385
 
386
}
387
 
388
 
389
static void POSIXSTAR_public_unblock(LEVEL l, PID p)
390
{
391
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
392
 
393
  /* Similar to POSIX_task_activate, but we don't check in what state
394
     the task is */
395
 
396
  #ifdef POSIXSTAR_DEBUG
397
    kern_printf("(PS:UnBlk:%d)",p);
398
  #endif
399
  /* Insert task in the coPOSIXect position */
400
  proc_table[p].status = POSIXSTAR_READY;
401
  iq_insertlast(p,&lev->ready[lev->priority[p]]);
402
  POSIXSTAR_private_scheduler(lev);
403
 
404
}
405
 
406
static void POSIXSTAR_public_block(LEVEL l, PID p)
407
{  
408
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
409
 
410
  /* Extract the running task from the level
411
     . we have already extract it from the ready queue at the dispatch time.
412
     . the capacity event have to be removed by the generic kernel
413
     . the wcet don't need modification...
414
     . the state of the task is set by the calling function
415
 
416
     So, we do nothing!!!
417
  */
418
 
419
  #ifdef POSIXSTAR_DEBUG
420
    kern_printf("(PS:Blk:%d)", p);     
421
  #endif
422
 
423
  iq_extract(p,&lev->ready[lev->priority[p]]);
424
  POSIXSTAR_private_scheduler(lev);
425
 
426
}
427
 
428
static int POSIXSTAR_public_message(LEVEL l, PID p, void *m)
429
{
430
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
876 trimarchi 431
  STD_command_message *msg;
432
  NRT_TASK_MODEL *nrt;
221 giacomo 433
 
434
  #ifdef POSIXSTAR_DEBUG
435
    kern_printf("(PS:Msg:%d)",p);
436
  #endif
437
 
438
  switch ((long)(m)) {
439
 
440
    /* Task EndCycle */
441
    case (long)(NULL):
442
 
876 trimarchi 443
      if (POSIXSTAR_private_change_level(l,p)) return 0;
444
 
221 giacomo 445
      if (lev->nact[p] > 0) {
446
        /* continue!!!! */
447
        lev->nact[p]--;
448
        iq_extract(p,&lev->ready[lev->priority[p]]);
449
        iq_insertfirst(p,&lev->ready[lev->priority[p]]);
450
        proc_table[p].status = POSIXSTAR_READY;
451
      }
452
      else {
453
        proc_table[p].status = SLEEP;
454
        iq_extract(p,&lev->ready[lev->priority[p]]);
455
      }
456
 
457
      jet_update_endcycle(); /* Update the Jet data... */
458
      POSIXSTAR_private_scheduler(lev);
459
 
460
      break;
461
 
462
    /* Task Disable */
463
    case (long)(1):
464
 
465
      break;
466
 
467
    default:
468
 
876 trimarchi 469
      msg = (STD_command_message *)m;
470
 
471
      switch(msg->command) {
472
        case STD_SET_NEW_LEVEL:
473
 
474
          lev->flag[p] |= POSIXSTAR_CHANGE_LEVEL;
475
          lev->new_level[p] = (int)(msg->param);
476
 
477
          break;
478
        case STD_SET_NEW_MODEL:
479
 
480
          nrt = (NRT_TASK_MODEL *)(msg->param);
481
 
482
          lev->priority[p] = nrt->weight;
483
 
484
          if (nrt->slice) {
485
            lev->new_slice[p] = nrt->slice;
486
          } else {
487
            lev->new_slice[p] = 0;
488
          }
489
 
490
          if (nrt->policy == NRT_RR_POLICY)
491
            lev->new_control[p] &= ~CONTROL_CAP;
492
 
493
          if (nrt->arrivals == SAVE_ARRIVALS)
494
            lev->nact[p] = 0;
495
          else
496
            lev->nact[p] = -1;
497
 
498
          lev->flag[p] = 0;
499
 
500
          break;
501
       case STD_ACTIVATE_TASK:
502
 
503
         if (lev->new_slice[p]) {
504
           proc_table[p].avail_time = lev->new_slice[p];
505
           proc_table[p].wcet = lev->new_slice[p];
506
         } else {
507
           proc_table[p].avail_time = lev->slice;
508
           proc_table[p].wcet = lev->slice;
509
         }
510
 
511
         proc_table[p].control |= lev->new_control[p];
512
 
513
         POSIXSTAR_public_activate(l,p,NULL);
514
 
515
         break;
516
 
517
      }
518
 
241 giacomo 519
      break;
221 giacomo 520
 
521
  }
522
 
523
  return 0;
524
 
525
}
526
 
527
static void POSIXSTAR_public_end(LEVEL l, PID p)
528
{
529
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
530
 
531
  #ifdef POSIXSTAR_DEBUG
532
    kern_printf("(PS:End:%d)", p);
533
  #endif
534
 
535
  lev->nact[p] = -1;
348 trimarchi 536
  /* extract task from the queue */
537
  iq_extract(p,&lev->ready[lev->priority[p]]);
221 giacomo 538
 
539
  /* then, we insert the task in the free queue */
540
  proc_table[p].status = FREE;
541
  iq_priority_insert(p,NULL);
542
  POSIXSTAR_private_scheduler(lev);
543
 
544
}
545
 
546
/* Registration functions */
547
 
548
/*+ Registration function:
549
    TIME slice                the slice for the Round Robin queue +*/
550
LEVEL POSIXSTAR_register_level(int master, TIME slice,
551
                       int prioritylevels)
552
{
553
  LEVEL l;            /* the level that we register */
554
  POSIXSTAR_level_des *lev;  /* for readableness only */
555
  PID i;              /* a counter */
556
  int x;              /* a counter */
557
 
558
  #ifdef POSIXSTRA_DEBUG
559
    kern_printf("POSIXSTAR_register_level\n");
560
  #endif
561
 
562
  l = level_alloc_descriptor(sizeof(POSIXSTAR_level_des));
563
 
564
  lev = (POSIXSTAR_level_des *)level_table[l];
565
 
270 giacomo 566
  lev->l.public_guarantee = NULL;
221 giacomo 567
  lev->l.public_create    = POSIXSTAR_public_create;
568
  lev->l.public_end       = POSIXSTAR_public_end;
569
  lev->l.public_dispatch  = POSIXSTAR_public_dispatch;
570
  lev->l.public_epilogue  = POSIXSTAR_public_epilogue;
571
  lev->l.public_activate  = POSIXSTAR_public_activate;
572
  lev->l.public_unblock   = POSIXSTAR_public_unblock;
573
  lev->l.public_block     = POSIXSTAR_public_block;
574
  lev->l.public_message   = POSIXSTAR_public_message;
575
  lev->l.public_eligible  = POSIXSTAR_public_eligible;
576
 
577
  /* fill the POSIX descriptor part */
578
  for (i = 0; i < MAX_PROC; i++) {
579
    lev->nact[i] = -1;
580
    lev->budget[i] = -1;
876 trimarchi 581
 
582
    lev->flag[i] = 0;
583
 
584
    lev->new_level[i] = 0;
585
    lev->new_slice[i] = 0;
586
    lev->new_control[i] = 0;
221 giacomo 587
  }
588
 
589
  lev->maxpriority = prioritylevels - 1;
590
 
591
  lev->ready = (IQUEUE *)kern_alloc(sizeof(IQUEUE) * prioritylevels);
592
 
593
  for (x = 0; x < prioritylevels; x++)
594
    iq_init(&lev->ready[x], NULL, 0);
595
 
596
  if (slice < POSIXSTAR_MINIMUM_SLICE) slice = POSIXSTAR_MINIMUM_SLICE;
597
  if (slice > POSIXSTAR_MAXIMUM_SLICE) slice = POSIXSTAR_MAXIMUM_SLICE;
598
  lev->slice = slice;
599
  lev->activated = NIL;
600
  lev->scheduling_level = master;
298 giacomo 601
  lev->cap_lev = NIL;
838 giacomo 602
  lev->yielding = 0;
296 trimarchi 603
  NULL_TIMESPEC(&lev->cap_lasttime);
604
 
221 giacomo 605
  return l;
606
 
607
}
608
 
609
int POSIXSTAR_setbudget(LEVEL l, PID p, int budget)
610
{
611
 
612
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
613
 
614
  lev->budget[p] = budget;
615
 
616
  return 0;
617
 
618
}
619
 
620
int POSIXSTAR_getbudget(LEVEL l, PID p)
621
{
622
 
623
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
624
 
625
  return lev->budget[p];
626
 
627
}
628
 
629
int POSIXSTAR_budget_has_thread(LEVEL l, int budget)
630
{
631
 
632
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
633
  int i;
634
 
635
  for(i = 0; i< MAX_PROC; i++)
636
    if (lev->budget[i] == budget) return 1;
637
 
638
  return 0;
639
 
640
}
641
 
642
/*+ this function forces the running task to go to his queue tail;
643
    (it works only on the POSIX level) +*/
644
int POSIXSTAR_sched_yield(LEVEL l)
645
{
646
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
647
 
648
  if (proc_table[exec_shadow].task_level != l)
649
    return -1;
650
 
651
  proc_table[exec_shadow].context = kern_context_save();
652
  lev->yielding = 1;
653
  scheduler();
654
  kern_context_load(proc_table[exec_shadow].context);
655
  return 0;
656
}
657
 
658
/*+ this function returns the maximum level allowed for the POSIX level +*/
659
int POSIXSTAR_get_priority_max(LEVEL l)
660
{
661
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
662
  return lev->maxpriority;
663
}
664
 
665
/*+ this function returns the default timeslice for the POSIX level +*/
666
int POSIXSTAR_rr_get_interval(LEVEL l)
667
{
668
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
669
  return lev->slice;
670
}
671
 
672
/*+ this functions returns some paramaters of a task;
673
    policy must be NRT_RR_POLICY or NRT_FIFO_POLICY;
674
    priority must be in the range [0..prioritylevels]
675
    returns ENOSYS or ESRCH if there are problems +*/
676
int POSIXSTAR_getschedparam(LEVEL l, PID p, int *policy, int *priority)
677
{
678
  if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE)
679
    return ESRCH;
680
 
681
  if (proc_table[p].task_level != l)
682
    return ENOSYS;
683
 
393 giacomo 684
  *policy = NRT_RR_POLICY;
221 giacomo 685
  *priority = ((POSIXSTAR_level_des *)(level_table[l]))->priority[p];
686
 
687
  return 0;
688
}
689
 
690
/*+ this functions sets paramaters of a task +*/
691
int POSIXSTAR_setschedparam(LEVEL l, PID p, int policy, int priority)
692
{
693
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
694
 
695
  if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE)
696
    return ESRCH;
697
 
698
  if (proc_table[p].task_level != l)
699
    return ENOSYS;
700
  if (lev->priority[p] != priority) {
701
    if (proc_table[p].status == POSIXSTAR_READY) {
702
      iq_extract(p,&lev->ready[lev->priority[p]]);
703
      lev->priority[p] = priority;
704
      iq_insertlast(p,&lev->ready[priority]);
705
    }
706
    else
707
      lev->priority[p] = priority;
708
  }
709
 
710
  return 0;
711
}
712
 
815 trimarchi 713
 
714
void POSIXSTAR_set_nopreemtive_current(LEVEL l) {
715
 
716
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
717
 
718
  lev->flag[lev->activated]|=POSIXSTAR_FLAG_NOPREEMPT;
719
}
720
 
721
void POSIXSTAR_unset_nopreemtive_current(LEVEL l) {
722
 
723
  POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]);
724
 
725
  lev->flag[lev->activated]&=~POSIXSTAR_FLAG_NOPREEMPT;
726
}