/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
/**
------------
CVS : $Id: ps.c,v 1.1.1.1 2002-03-29 14:12:52 pj Exp $
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-03-29 14:12:52 $
------------
This file contains the aperiodic server PS (Polling Server)
when scheduling in background the flags field has the PS_BACKGROUND bit set
when scheduling a task because it is pointed by another task via shadows,
the task have to be extracted from the wait queue or the master level. To
check this we have to look at the activated field; it is != NIL if a task
is inserted into the master level. Only a task at a time can be inserted
into the master level.
The capacity of the server must be updated
- when scheduling a task normally
- when scheduling a task because it is pointed by a shadow
but not when scheduling in background.
When a task is extracted from the system no scheduling has to be done
until the task reenter into the system. to implement this, when a task
is extracted we block the background scheduling (the scheduling with the
master level is already blocked because the activated field is not
reset to NIL) using the PS_BACKGROUNDBLOCK bit.
nact[p] is -1 if the task set the activations to SKIP, >= 0 otherwise
Note that if the period event fires and there aren't any task to schedule,
the server capacity is set to 0. This is correct, but there is a subtle
variant: the server capacity may be set to 0 later because if at the
period end the running task have priority > than the server, the capacity
may be set to zero the first time the server become the highest priority
running task and there aren't task to serve. The second implementation
is more efficient but more complicated, because normally we don't know the
priority of the running task.
An implementation can be done in this way: when there are not task to
schedule, we does not set the lev->activated field to nil, but to a "dummy"
task that is inserted into the master level queue.
When the master level scheduler try to schedule the "dummy" task (this is
the situation in witch there are not task to schedule and the PS is the
task with greater priority), it calls the PS_task_eligible, that set the
server capacity to 0, remove the dummy task from the queue with a guest_end
and ask to reschedule.
Because this implementation is more complex than the first, I don't
implement it... see (*), near line 169, 497 and 524
Read PS.h for further details.
**/
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <modules/ps.h>
#include <ll/stdio.h>
#include <ll/string.h>
#include <kernel/model.h>
#include <kernel/descr.h>
#include <kernel/var.h>
#include <kernel/func.h>
/*+ Status used in the level +*/
#define PS_WAIT APER_STATUS_BASE /*+ waiting the service +*/
/*+ the level redefinition for the Total Bandwidth Server level +*/
typedef struct {
level_des l
; /*+ the standard level descriptor +*/
/* The wcet are stored in the task descriptor's priority
field, so no other fields are needed */
int nact
[MAX_PROC
]; /*+ number of pending activations +*/
struct timespec lastdline
; /*+ the last deadline assigned to
a PS task +*/
int Cs
; /*+ server capacity +*/
int availCs
; /*+ server avail time +*/
QQUEUE wait
; /*+ the wait queue of the PS +*/
PID activated
; /*+ the task inserted in another queue +*/
int flags
; /*+ the init flags... +*/
bandwidth_t U
; /*+ the used bandwidth by the server +*/
int period
;
LEVEL scheduling_level
;
} PS_level_des
;
/* This static function activates the task pointed by lev->activated) */
static __inline__
void PS_activation
(PS_level_des
*lev
)
{
PID p
; /* for readableness */
JOB_TASK_MODEL j
; /* the guest model */
LEVEL m
; /* the master level... only for readableness*/
p
= lev
->activated
;
m
= lev
->scheduling_level
;
job_task_default_model
(j
,lev
->lastdline
);
job_task_def_period
(j
,lev
->period
);
level_table
[m
]->guest_create
(m
,p
,(TASK_MODEL
*)&j
);
level_table
[m
]->guest_activate
(m
,p
);
// kern_printf("(%d %d)",lev->lastdline.tv_sec,lev->lastdline.tv_nsec);
}
static void PS_deadline_timer
(void *a
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[(LEVEL
)a
]);
ADDUSEC2TIMESPEC
(lev
->period
, &lev
->lastdline
);
// kern_printf("(%d:%d %d)",lev->lastdline.tv_sec,lev->lastdline.tv_nsec, lev->period);
if (lev
->availCs
>= 0)
lev
->availCs
= lev
->Cs
;
else
lev
->availCs
+= lev
->Cs
;
/* availCs may be <0 because a task executed via a shadow fo many time
lev->activated == NIL only if the prec task was finished and there
was not any other task to be put in the ready queue
... we are now activating the next task */
if (lev
->availCs
> 0 && lev
->activated
== NIL
) {
if (qq_queryfirst
(&lev
->wait
) != NIL
) {
lev
->activated
= qq_getfirst
(&lev
->wait
);
PS_activation
(lev
);
event_need_reschedule
();
}
else
lev
->availCs
= 0; /* see note (*) at the begin of the file */
}
kern_event_post
(&lev
->lastdline
, PS_deadline_timer
, a
);
// kern_printf("!");
}
static char *PS_status_to_a
(WORD status
)
{
if (status
< MODULE_STATUS_BASE
)
return status_to_a
(status
);
switch (status
) {
case PS_WAIT
: return "PS_Wait";
default : return "PS_Unknown";
}
}
static int PS_level_accept_task_model
(LEVEL l
, TASK_MODEL
*m
)
{
if (m
->pclass
== SOFT_PCLASS
|| m
->pclass
== (SOFT_PCLASS
| l
) ) {
SOFT_TASK_MODEL
*s
= (SOFT_TASK_MODEL
*)m
;
if (s
->periodicity
== APERIODIC
)
return 0;
}
return -1;
}
static int PS_level_accept_guest_model
(LEVEL l
, TASK_MODEL
*m
)
{
return -1;
}
static char *onoff
(int i
)
{
if (i
)
return "On ";
else
return "Off";
}
static void PS_level_status
(LEVEL l
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
PID p
= qq_queryfirst
(&lev
->wait
);
kern_printf
("On-line guarantee : %s\n",
onoff
(lev
->flags
& PS_ENABLE_GUARANTEE_EDF
||
lev
->flags
& PS_ENABLE_GUARANTEE_RM
));
kern_printf
("Used Bandwidth : %u/%u\n",
lev
->U
, MAX_BANDWIDTH
);
if (lev
->activated
!= -1)
kern_printf
("Activated: Pid: %2d Name: %10s Dl: %ld.%ld Nact: %d Stat: %s\n",
lev
->activated
,
proc_table
[lev
->activated
].
name,
proc_table
[lev
->activated
].
timespec_priority.
tv_sec,
proc_table
[lev
->activated
].
timespec_priority.
tv_nsec,
lev
->nact
[lev
->activated
],
PS_status_to_a
(proc_table
[lev
->activated
].
status));
while (p
!= NIL
) {
kern_printf
("Pid: %2d Name: %10s Stat: %s\n",
p
,
proc_table
[p
].
name,
PS_status_to_a
(proc_table
[p
].
status));
p
= proc_table
[p
].
next;
}
}
static PID PS_level_scheduler
(LEVEL l
)
{
/* the PS don't schedule anything...
it's an EDF level or similar that do it! */
return NIL
;
}
static PID PS_level_schedulerbackground
(LEVEL l
)
{
/* the PS catch the background time to exec aperiodic activities */
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
lev
->flags
|= PS_BACKGROUND
;
if (lev
->flags
& PS_BACKGROUND_BLOCK
)
return NIL
;
else
return qq_queryfirst
(&lev
->wait
);
}
/* The on-line guarantee is enabled only if the appropriate flag is set... */
static int PS_level_guaranteeEDF
(LEVEL l
, bandwidth_t
*freebandwidth
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
if (*freebandwidth
>= lev
->U
) {
*freebandwidth
-= lev
->U
;
return 1;
}
else
return 0;
}
static int PS_level_guaranteeRM
(LEVEL l
, bandwidth_t
*freebandwidth
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
if (*freebandwidth
> lev
->U
+ RM_MINFREEBANDWIDTH
) {
*freebandwidth
-= lev
->U
;
return 1;
}
else
return 0;
}
static int PS_task_create
(LEVEL l
, PID p
, TASK_MODEL
*m
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
/* if the PS_task_create is called, then the pclass must be a
valid pclass. */
SOFT_TASK_MODEL
*s
= (SOFT_TASK_MODEL
*)m
;
if (s
->arrivals
== SAVE_ARRIVALS
)
lev
->nact
[p
] = 0;
else
lev
->nact
[p
] = -1;
return 0; /* OK, also if the task cannot be guaranteed... */
}
static void PS_task_detach
(LEVEL l
, PID p
)
{
/* the PS level doesn't introduce any dinamic allocated new field. */
}
static int PS_task_eligible
(LEVEL l
, PID p
)
{
return 0; /* if the task p is chosen, it is always eligible */
}
#ifdef __TEST1__
extern int testactive
;
extern struct timespec s_stime
[];
extern TIME s_curr
[];
extern TIME s_PID
[];
extern int useds
;
#endif
static void PS_task_dispatch
(LEVEL l
, PID p
, int nostop
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
struct timespec ty
;
// if (nostop) kern_printf("NOSTOP!!!!!!!!!!!!");
/* there is at least one task ready inserted in an EDF or similar
level note that we can't check the status because the scheduler set it
to exe before calling task_dispatch. we have to check
lev->activated != p instead */
if (lev
->activated
!= p
) {
qq_extract
(p
, &lev
->wait
);
//kern_printf("#%d#",p);
}
else {
//if (nostop) kern_printf("(gd status=%d)",proc_table[p].status);
level_table
[ lev
->scheduling_level
]->
guest_dispatch
(lev
->scheduling_level
,p
,nostop
);
}
/* set the capacity timer */
if (!nostop
) {
TIMESPEC_ASSIGN
(&ty
, &schedule_time
);
ADDUSEC2TIMESPEC
(lev
->availCs
,&ty
);
cap_timer
= kern_event_post
(&ty
, capacity_timer
, NULL
);
}
// kern_printf("(disp %d %d)",ty.tv_sec, ty.tv_nsec);
#ifdef __TEST1__
if (testactive
)
{
TIMESPEC_ASSIGN
(&s_stime
[useds
], &schedule_time
);
s_curr
[useds
] = proc_table
[p
].
avail_time;
s_PID
[useds
] = p
;
useds
++;
}
#endif
}
static void PS_task_epilogue
(LEVEL l
, PID p
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
struct timespec ty
;
TIME tx
;
/* update the server capacity */
if (lev
->flags
& PS_BACKGROUND
)
lev
->flags
&= ~PS_BACKGROUND
;
else {
SUBTIMESPEC
(&schedule_time
, &cap_lasttime
, &ty
);
tx
= TIMESPEC2USEC
(&ty
);
lev
->availCs
-= tx
;
}
// kern_printf("(epil %d %d)",lev->availCs, proc_table[p].avail_time);
/* check if the server capacity is finished... */
if (lev
->availCs
< 0) {
// kern_printf("(epil Cs%d %d:%d act%d p%d)",
// lev->availCs,proc_table[p].timespec_priority.tv_sec,
// proc_table[p].timespec_priority.tv_nsec,
// lev->activated,p);
/* the server slice has finished... do the task_end!!!
a first version of the module used the task_endcycle, but it was
not conceptually correct because the task didn't stop because it
finished all the work but because the server didn't have budget!
So, if the task_endcycle is called, the task remain into the
master level, and we can't wake him up if, for example, another
task point the shadow to it!!!*/
if (lev
->activated
== p
)
level_table
[ lev
->scheduling_level
]->
guest_end
(lev
->scheduling_level
,p
);
qq_insertfirst
(p
, &lev
->wait
);
proc_table
[p
].
status = PS_WAIT
;
lev
->activated
= NIL
;
}
else
/* the task has been preempted. it returns into the ready queue or to the
wait queue by calling the guest_epilogue... */
if (lev
->activated
== p
) {//kern_printf("Û1");
level_table
[ lev
->scheduling_level
]->
guest_epilogue
(lev
->scheduling_level
,p
);
} else { //kern_printf("Û2");
qq_insertfirst
(p
, &lev
->wait
);
proc_table
[p
].
status = PS_WAIT
;
}
}
static void PS_task_activate
(LEVEL l
, PID p
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
if (lev
->activated
== p
|| proc_table
[p
].
status == PS_WAIT
) {
if (lev
->nact
[p
] != -1)
lev
->nact
[p
]++;
}
else if (proc_table
[p
].
status == SLEEP
) {
ll_gettime
(TIME_EXACT
, &proc_table
[p
].
request_time);
if (lev
->activated
== NIL
&& lev
->availCs
> 0) {
lev
->activated
= p
;
PS_activation
(lev
);
}
else {
qq_insertlast
(p
, &lev
->wait
);
proc_table
[p
].
status = PS_WAIT
;
}
}
else
{ kern_printf
("PS_REJ%d %d %d %d ",p
, proc_table
[p
].
status, lev
->activated
, lev
->wait.
first);
return; }
}
static void PS_task_insert
(LEVEL l
, PID p
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
lev
->flags
&= ~PS_BACKGROUND_BLOCK
;
lev
->activated
= -1;
/* when we reinsert the task into the system, the server capacity
is always 0 because nobody executes with the PS before... */
qq_insertfirst
(p
, &lev
->wait
);
proc_table
[p
].
status = PS_WAIT
;
}
static void PS_task_extract
(LEVEL l
, PID p
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
/* update the server capacity */
lev
->availCs
= 0;
lev
->flags
|= PS_BACKGROUND_BLOCK
;
if (lev
->activated
== p
)
level_table
[ lev
->scheduling_level
]->
guest_end
(lev
->scheduling_level
,p
);
}
static void PS_task_endcycle
(LEVEL l
, PID p
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
struct timespec ty
;
TIME tx
;
/* update the server capacity */
if (lev
->flags
& PS_BACKGROUND
)
lev
->flags
&= ~PS_BACKGROUND
;
else {
SUBTIMESPEC
(&schedule_time
, &cap_lasttime
, &ty
);
tx
= TIMESPEC2USEC
(&ty
);
lev
->availCs
-= tx
;
}
if (lev
->activated
== p
)
level_table
[ lev
->scheduling_level
]->
guest_end
(lev
->scheduling_level
,p
);
else
qq_extract
(p
, &lev
->wait
);
if (lev
->nact
[p
] > 0)
{
lev
->nact
[p
]--;
qq_insertlast
(p
, &lev
->wait
);
proc_table
[p
].
status = PS_WAIT
;
}
else
proc_table
[p
].
status = SLEEP
;
lev
->activated
= qq_getfirst
(&lev
->wait
);
if (lev
->activated
== NIL
)
lev
->availCs
= 0; /* see note (*) at the begin of the file */
else
PS_activation
(lev
);
}
static void PS_task_end
(LEVEL l
, PID p
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
struct timespec ty
;
TIME tx
;
/* update the server capacity */
if (lev
->flags
& PS_BACKGROUND
)
lev
->flags
&= ~PS_BACKGROUND
;
else {
SUBTIMESPEC
(&schedule_time
, &cap_lasttime
, &ty
);
tx
= TIMESPEC2USEC
(&ty
);
lev
->availCs
-= tx
;
}
if (lev
->activated
== p
)
level_table
[ lev
->scheduling_level
]->
guest_end
(lev
->scheduling_level
,p
);
proc_table
[p
].
status = FREE
;
q_insertfirst
(p
,&freedesc
);
lev
->activated
= qq_getfirst
(&lev
->wait
);
if (lev
->activated
== NIL
)
lev
->availCs
= 0; /* see note (*) at the begin of the file */
else
PS_activation
(lev
);
}
static void PS_task_sleep
(LEVEL l
, PID p
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
struct timespec ty
;
TIME tx
;
/* update the server capacity */
if (lev
->flags
& PS_BACKGROUND
)
lev
->flags
&= ~PS_BACKGROUND
;
else {
SUBTIMESPEC
(&schedule_time
, &cap_lasttime
, &ty
);
tx
= TIMESPEC2USEC
(&ty
);
lev
->availCs
-= tx
;
}
if (lev
->nact
[p
] >= 0) lev
->nact
[p
] = 0;
if (lev
->activated
== p
)
level_table
[ lev
->scheduling_level
]->
guest_end
(lev
->scheduling_level
,p
);
else
qq_extract
(p
, &lev
->wait
);
proc_table
[p
].
status = SLEEP
;
lev
->activated
= qq_getfirst
(&lev
->wait
);
if (lev
->activated
== NIL
)
lev
->availCs
= 0; /* see note (*) at the begin of the file */
else
PS_activation
(lev
);
}
static void PS_task_delay
(LEVEL l
, PID p
, TIME usdelay
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
struct timespec ty
;
TIME tx
;
/* update the server capacity */
if (lev
->flags
& PS_BACKGROUND
)
lev
->flags
&= ~PS_BACKGROUND
;
else {
SUBTIMESPEC
(&schedule_time
, &cap_lasttime
, &ty
);
tx
= TIMESPEC2USEC
(&ty
);
lev
->availCs
-= tx
;
}
/* I hope no delay when owning a mutex... */
if (lev
->activated
== p
)
level_table
[ lev
->scheduling_level
]->
guest_delay
(lev
->scheduling_level
,p
,usdelay
);
}
static int PS_guest_create
(LEVEL l
, PID p
, TASK_MODEL
*m
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); return 0; }
static void PS_guest_detach
(LEVEL l
, PID p
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_dispatch
(LEVEL l
, PID p
, int nostop
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_epilogue
(LEVEL l
, PID p
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_activate
(LEVEL l
, PID p
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_insert
(LEVEL l
, PID p
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_extract
(LEVEL l
, PID p
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_endcycle
(LEVEL l
, PID p
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_end
(LEVEL l
, PID p
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_sleep
(LEVEL l
, PID p
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
static void PS_guest_delay
(LEVEL l
, PID p
,DWORD tickdelay
)
{ kern_raise
(XUNVALID_GUEST
,exec_shadow
); }
/* Registration functions */
/*+ This init function install the PS deadline timer
+*/
static void PS_dline_install
(void *l
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[(LEVEL
)l
]);
ll_gettime
(TIME_EXACT
,&lev
->lastdline
);
ADDUSEC2TIMESPEC
(lev
->period
, &lev
->lastdline
);
kern_event_post
(&lev
->lastdline
, PS_deadline_timer
, l
);
}
/*+ Registration function:
int flags the init flags ... see PS.h +*/
void PS_register_level
(int flags
, LEVEL master
, int Cs
, int per
)
{
LEVEL l
; /* the level that we register */
PS_level_des
*lev
; /* for readableness only */
PID i
; /* a counter */
printk
("PS_register_level\n");
/* request an entry in the level_table */
l
= level_alloc_descriptor
();
printk
(" alloco descrittore %d %d\n",l
,(int)sizeof(PS_level_des
));
/* alloc the space needed for the PS_level_des */
lev
= (PS_level_des
*)kern_alloc
(sizeof(PS_level_des
));
printk
(" lev=%d\n",(int)lev
);
/* update the level_table with the new entry */
level_table
[l
] = (level_des
*)lev
;
/* fill the standard descriptor */
strncpy(lev
->l.
level_name, PS_LEVELNAME
, MAX_LEVELNAME
);
lev
->l.
level_code = PS_LEVEL_CODE
;
lev
->l.
level_version = PS_LEVEL_VERSION
;
lev
->l.
level_accept_task_model = PS_level_accept_task_model
;
lev
->l.
level_accept_guest_model = PS_level_accept_guest_model
;
lev
->l.
level_status = PS_level_status
;
if (flags
& PS_ENABLE_BACKGROUND
)
lev
->l.
level_scheduler = PS_level_schedulerbackground
;
else
lev
->l.
level_scheduler = PS_level_scheduler
;
if (flags
& PS_ENABLE_GUARANTEE_EDF
)
lev
->l.
level_guarantee = PS_level_guaranteeEDF
;
else if (flags
& PS_ENABLE_GUARANTEE_RM
)
lev
->l.
level_guarantee = PS_level_guaranteeRM
;
else
lev
->l.
level_guarantee = NULL
;
lev
->l.
task_create = PS_task_create
;
lev
->l.
task_detach = PS_task_detach
;
lev
->l.
task_eligible = PS_task_eligible
;
lev
->l.
task_dispatch = PS_task_dispatch
;
lev
->l.
task_epilogue = PS_task_epilogue
;
lev
->l.
task_activate = PS_task_activate
;
lev
->l.
task_insert = PS_task_insert
;
lev
->l.
task_extract = PS_task_extract
;
lev
->l.
task_endcycle = PS_task_endcycle
;
lev
->l.
task_end = PS_task_end
;
lev
->l.
task_sleep = PS_task_sleep
;
lev
->l.
task_delay = PS_task_delay
;
lev
->l.
guest_create = PS_guest_create
;
lev
->l.
guest_detach = PS_guest_detach
;
lev
->l.
guest_dispatch = PS_guest_dispatch
;
lev
->l.
guest_epilogue = PS_guest_epilogue
;
lev
->l.
guest_activate = PS_guest_activate
;
lev
->l.
guest_insert = PS_guest_insert
;
lev
->l.
guest_extract = PS_guest_extract
;
lev
->l.
guest_endcycle = PS_guest_endcycle
;
lev
->l.
guest_end = PS_guest_end
;
lev
->l.
guest_sleep = PS_guest_sleep
;
lev
->l.
guest_delay = PS_guest_delay
;
/* fill the PS descriptor part */
for (i
=0; i
<MAX_PROC
; i
++)
lev
->nact
[i
] = -1;
lev
->Cs
= Cs
;
lev
->availCs
= 0;
lev
->period
= per
;
qq_init
(&lev
->wait
);
lev
->activated
= NIL
;
lev
->U
= (MAX_BANDWIDTH
/ per
) * Cs
;
lev
->scheduling_level
= master
;
lev
->flags
= flags
& 0x07;
sys_atrunlevel
(PS_dline_install
,(void *) l
, RUNLEVEL_INIT
);
}
bandwidth_t PS_usedbandwidth
(LEVEL l
)
{
PS_level_des
*lev
= (PS_level_des
*)(level_table
[l
]);
if (lev
->l.
level_code == PS_LEVEL_CODE
&&
lev
->l.
level_version == PS_LEVEL_VERSION
)
return lev
->U
;
else
return 0;
}