Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 37 → Rev 38

/shark/trunk/kernel/modules/rr.c
20,11 → 20,11
 
/**
------------
CVS : $Id: rr.c,v 1.3 2002-11-11 08:32:06 pj Exp $
CVS : $Id: rr.c,v 1.4 2003-01-07 17:07:50 pj Exp $
 
File: $File$
Revision: $Revision: 1.3 $
Last update: $Date: 2002-11-11 08:32:06 $
Revision: $Revision: 1.4 $
Last update: $Date: 2003-01-07 17:07:50 $
------------
 
This file contains the scheduling module RR (Round Robin)
60,7 → 60,12
#include <kernel/descr.h>
#include <kernel/var.h>
#include <kernel/func.h>
#include <kernel/trace.h>
 
//#define RRDEBUG
 
#define rr_printf kern_printf
 
/*+ Status used in the level +*/
#define RR_READY MODULE_STATUS_BASE
 
76,67 → 81,29
the main task +*/
} RR_level_des;
 
 
static char *RR_status_to_a(WORD status)
{
if (status < MODULE_STATUS_BASE)
return status_to_a(status);
 
switch (status) {
case RR_READY: return "RR_Ready";
default : return "RR_Unknown";
}
}
 
static int RR_level_accept_task_model(LEVEL l, TASK_MODEL *m)
{
if (m->pclass == NRT_PCLASS || m->pclass == (NRT_PCLASS | l))
return 0;
else
return -1;
}
 
static int RR_level_accept_guest_model(LEVEL l, TASK_MODEL *m)
{
return -1;
}
 
static void RR_level_status(LEVEL l)
{
RR_level_des *lev = (RR_level_des *)(level_table[l]);
PID p = iq_query_first(&lev->ready);
 
kern_printf("Slice: %d \n", lev->slice);
 
while (p != NIL) {
kern_printf("Pid: %d\t Name: %20s Status: %s\n",p,proc_table[p].name,
RR_status_to_a(proc_table[p].status));
p = iq_query_next(p,&lev->ready);
}
 
for (p=0; p<MAX_PROC; p++)
if (proc_table[p].task_level == l && proc_table[p].status != RR_READY
&& proc_table[p].status != FREE )
kern_printf("Pid: %d\t Name: %20s Status: %s\n",p,proc_table[p].name,
RR_status_to_a(proc_table[p].status));
 
}
 
 
/* This is not efficient but very fair :-)
The need of all this stuff is because if a task execute a long time
due to (shadow!) priority inheritance, then the task shall go to the
tail of the queue many times... */
static PID RR_level_scheduler(LEVEL l)
static PID RR_public_scheduler(LEVEL l)
{
RR_level_des *lev = (RR_level_des *)(level_table[l]);
 
PID p;
 
#ifdef RRDEBUG
rr_printf("(RRs",p);
#endif
 
for (;;) {
p = iq_query_first(&lev->ready);
if (p == -1)
 
if (p == -1) {
#ifdef RRDEBUG
rr_printf(" %d)",p);
#endif
return p;
}
 
if (proc_table[p].avail_time <= 0) {
proc_table[p].avail_time += proc_table[p].wcet;
143,25 → 110,28
iq_extract(p,&lev->ready);
iq_insertlast(p,&lev->ready);
}
else
else {
#ifdef RRDEBUG
rr_printf(" %d)",p);
#endif
return p;
}
}
}
 
static int RR_level_guarantee(LEVEL l, bandwidth_t *freebandwidth)
static int RR_public_create(LEVEL l, PID p, TASK_MODEL *m)
{
/* the RR level always guarantee... the function is defined because
there can be an aperiodic server at a level with less priority than
the RR that need guarantee (e.g., a TBS server) */
return 1;
}
RR_level_des *lev = (RR_level_des *)(level_table[l]);
NRT_TASK_MODEL *nrt;
 
#ifdef RRDEBUG
rr_printf("(create %d!!!!)",p);
#endif
 
static int RR_task_create(LEVEL l, PID p, TASK_MODEL *m)
{
RR_level_des *lev = (RR_level_des *)(level_table[l]);
NRT_TASK_MODEL *nrt = (NRT_TASK_MODEL *)m;
if (m->pclass != NRT_PCLASS) return -1;
if (m->level != 0 && m->level != l) return -1;
 
nrt = (NRT_TASK_MODEL *)m;
/* the task state is set at SLEEP by the general task_create
the only thing to set remains the capacity stuffs that are set
to the values passed in the model... */
179,23 → 149,14
}
proc_table[p].control |= CONTROL_CAP;
 
#ifdef RRDEBUG
rr_printf("(c%d av%d w%d )",p,proc_table[p].avail_time,proc_table[p].wcet);
#endif
return 0; /* OK */
}
 
static void RR_task_detach(LEVEL l, PID p)
static void RR_public_dispatch(LEVEL l, PID p, int nostop)
{
/* the RR level doesn't introduce any new field in the TASK_MODEL
so, all detach stuffs are done by the task_create
The task state is set at FREE by the general task_create */
}
 
static int RR_task_eligible(LEVEL l, PID p)
{
return 0; /* if the task p is chosen, it is always eligible */
}
 
static void RR_task_dispatch(LEVEL l, PID p, int nostop)
{
RR_level_des *lev = (RR_level_des *)(level_table[l]);
 
/* the task state is set EXE by the scheduler()
202,9 → 163,13
we extract the task from the ready queue
NB: we can't assume that p is the first task in the queue!!! */
iq_extract(p, &lev->ready);
 
#ifdef RRDEBUG
rr_printf("(dis%d)",p);
#endif
}
 
static void RR_task_epilogue(LEVEL l, PID p)
static void RR_public_epilogue(LEVEL l, PID p)
{
RR_level_des *lev = (RR_level_des *)(level_table[l]);
 
219,9 → 184,13
iq_insertfirst(p,&lev->ready);
 
proc_table[p].status = RR_READY;
 
#ifdef RRDEBUG
rr_printf("(epi%d)",p);
#endif
}
 
static void RR_task_activate(LEVEL l, PID p)
static void RR_public_activate(LEVEL l, PID p)
{
RR_level_des *lev = (RR_level_des *)(level_table[l]);
 
230,26 → 199,33
if (proc_table[p].status != SLEEP)
return;
 
ll_gettime(TIME_EXACT, &proc_table[p].request_time);
 
/* Insert task in the correct position */
proc_table[p].status = RR_READY;
iq_insertlast(p,&lev->ready);
 
#ifdef RRDEBUG
rr_printf("(act%d)",p);
#endif
 
}
 
static void RR_task_insert(LEVEL l, PID p)
static void RR_public_unblock(LEVEL l, PID p)
{
RR_level_des *lev = (RR_level_des *)(level_table[l]);
 
/* Similar to RR_task_activate, but we don't check in what state
the task is and we don't set the request_time */
/* Similar to RR_task_activate,
but we don't check in what state the task is */
 
/* Insert task in the correct position */
proc_table[p].status = RR_READY;
iq_insertlast(p,&lev->ready);
 
#ifdef RRDEBUG
rr_printf("(ubl%d)",p);
#endif
}
 
static void RR_task_extract(LEVEL l, PID p)
static void RR_public_block(LEVEL l, PID p)
{
/* Extract the running task from the level
. we have already extract it from the ready queue at the dispatch time.
259,64 → 235,36
 
So, we do nothing!!!
*/
#ifdef RRDEBUG
rr_printf("(bl%d)",p);
#endif
}
 
static void RR_task_endcycle(LEVEL l, PID p)
static int RR_public_message(LEVEL l, PID p, void *m)
{
// RR_level_des *lev = (RR_level_des *)(level_table[l]);
proc_table[p].status = SLEEP;
 
/* this function is equal to the RR_task_extract, except that
the task fall asleep... */
proc_table[p].status = SLEEP;
jet_update_endcycle(); /* Update the Jet data... */
trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */
 
#ifdef RRDEBUG
rr_printf("(msg%d)",p);
#endif
return 0;
}
 
static void RR_task_end(LEVEL l, PID p)
static void RR_public_end(LEVEL l, PID p)
{
// RR_level_des *lev = (RR_level_des *)(level_table[l]);
 
/* we insert the task in the free queue */
proc_table[p].status = FREE;
iq_insertlast(p,&freedesc);
}
 
static void RR_task_sleep(LEVEL l, PID p)
{
proc_table[p].status = SLEEP;
#ifdef RRDEBUG
rr_printf("(end%d)",p);
#endif
}
 
static int RR_guest_create(LEVEL l, PID p, TASK_MODEL *m)
{ kern_raise(XINVALID_GUEST,exec_shadow); return 0; }
 
static void RR_guest_detach(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RR_guest_dispatch(LEVEL l, PID p, int nostop)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RR_guest_epilogue(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RR_guest_activate(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RR_guest_insert(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RR_guest_extract(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RR_guest_endcycle(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RR_guest_end(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RR_guest_sleep(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
 
 
 
/* Registration functions */
 
/*+ This init function install the "main" task +*/
342,9 → 290,13
p = task_create("Main", __init__, (TASK_MODEL *)&m, NULL);
 
if (p == NIL)
kern_printf("\nPanic!!! can't create main task... errno =%d\n",errno);
printk(KERN_EMERG "Panic!!! can't create main task... errno =%d\n",errno);
 
RR_task_activate(lev,p);
RR_public_activate(lev,p);
 
#ifdef RRDEBUG
rr_printf("(main created %d)",p);
#endif
}
 
 
352,7 → 304,7
TIME slice the slice for the Round Robin queue
int createmain 1 if the level creates the main task 0 otherwise
struct multiboot_info *mb used if createmain specified +*/
void RR_register_level(TIME slice,
LEVEL RR_register_level(TIME slice,
int createmain,
struct multiboot_info *mb)
{
362,50 → 314,23
printk("RR_register_level\n");
 
/* request an entry in the level_table */
l = level_alloc_descriptor();
l = level_alloc_descriptor(sizeof(RR_level_des));
 
/* alloc the space needed for the RR_level_des */
lev = (RR_level_des *)kern_alloc(sizeof(RR_level_des));
lev = (RR_level_des *)level_table[l];
 
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, RR_LEVELNAME, MAX_LEVELNAME);
lev->l.level_code = RR_LEVEL_CODE;
lev->l.level_version = RR_LEVEL_VERSION;
lev->l.public_scheduler = RR_public_scheduler;
lev->l.public_create = RR_public_create;
lev->l.public_end = RR_public_end;
lev->l.public_dispatch = RR_public_dispatch;
lev->l.public_epilogue = RR_public_epilogue;
lev->l.public_activate = RR_public_activate;
lev->l.public_unblock = RR_public_unblock;
lev->l.public_block = RR_public_block;
lev->l.public_message = RR_public_message;
 
lev->l.level_accept_task_model = RR_level_accept_task_model;
lev->l.level_accept_guest_model = RR_level_accept_guest_model;
lev->l.level_status = RR_level_status;
lev->l.level_scheduler = RR_level_scheduler;
lev->l.level_guarantee = RR_level_guarantee;
 
lev->l.task_create = RR_task_create;
lev->l.task_detach = RR_task_detach;
lev->l.task_eligible = RR_task_eligible;
lev->l.task_dispatch = RR_task_dispatch;
lev->l.task_epilogue = RR_task_epilogue;
lev->l.task_activate = RR_task_activate;
lev->l.task_insert = RR_task_insert;
lev->l.task_extract = RR_task_extract;
lev->l.task_endcycle = RR_task_endcycle;
lev->l.task_end = RR_task_end;
lev->l.task_sleep = RR_task_sleep;
 
lev->l.guest_create = RR_guest_create;
lev->l.guest_detach = RR_guest_detach;
lev->l.guest_dispatch = RR_guest_dispatch;
lev->l.guest_epilogue = RR_guest_epilogue;
lev->l.guest_activate = RR_guest_activate;
lev->l.guest_insert = RR_guest_insert;
lev->l.guest_extract = RR_guest_extract;
lev->l.guest_endcycle = RR_guest_endcycle;
lev->l.guest_end = RR_guest_end;
lev->l.guest_sleep = RR_guest_sleep;
 
/* fill the RR descriptor part */
iq_init(&lev->ready, &freedesc, 0);
 
417,6 → 342,6
 
if (createmain)
sys_atrunlevel(RR_call_main,(void *) l, RUNLEVEL_INIT);
 
return l;
}