Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 28 → Rev 29

/shark/trunk/kernel/modules/rrsoft.c
20,11 → 20,11
 
/**
------------
CVS : $Id: rrsoft.c,v 1.2 2002-10-28 07:55:55 pj Exp $
CVS : $Id: rrsoft.c,v 1.3 2002-11-11 08:32:07 pj Exp $
 
File: $File$
Revision: $Revision: 1.2 $
Last update: $Date: 2002-10-28 07:55:55 $
Revision: $Revision: 1.3 $
Last update: $Date: 2002-11-11 08:32:07 $
------------
 
This file contains the scheduling module RRSOFT (Round Robin)
63,7 → 63,6
 
/*+ Status used in the level +*/
#define RRSOFT_READY MODULE_STATUS_BASE
#define RRSOFT_DELAY MODULE_STATUS_BASE+1
#define RRSOFT_IDLE MODULE_STATUS_BASE+2
 
/*+ the level redefinition for the Round Robin level +*/
72,7 → 71,7
 
int nact[MAX_PROC]; /*+ number of pending activations +*/
 
QQUEUE ready; /*+ the ready queue +*/
IQUEUE ready; /*+ the ready queue +*/
 
int slice; /*+ the level's time slice +*/
 
100,7 → 99,6
 
switch (status) {
case RRSOFT_READY: return "RRSOFT_Ready";
case RRSOFT_DELAY: return "RRSOFT_Delay";
case RRSOFT_IDLE : return "RRSOFT_Idle";
default : return "RRSOFT_Unknown";
}
121,7 → 119,7
/* the task has finished the current activation and must be
reactivated */
proc_table[p].status = RRSOFT_READY;
qq_insertlast(p,&lev->ready);
iq_insertlast(p,&lev->ready);
 
event_need_reschedule();
}
140,25 → 138,6
}
 
 
/*+ this function is called when a task finish his delay +*/
static void RRSOFT_timer_delay(void *par)
{
PID p = (PID) par;
RRSOFT_level_des *lev;
 
lev = (RRSOFT_level_des *)level_table[proc_table[p].task_level];
 
proc_table[p].status = RRSOFT_READY;
qq_insertlast(p,&lev->ready);
 
proc_table[p].delay_timer = NIL; /* Paranoia */
 
// kern_printf(" DELAY TIMER %d ", p);
 
event_need_reschedule();
}
 
 
static int RRSOFT_level_accept_task_model(LEVEL l, TASK_MODEL *m)
{
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]);
181,7 → 160,7
static void RRSOFT_level_status(LEVEL l)
{
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]);
PID p = qq_queryfirst(&lev->ready);
PID p = iq_query_first(&lev->ready);
 
kern_printf("Slice: %d \n", lev->slice);
 
188,7 → 167,7
while (p != NIL) {
kern_printf("Pid: %d\t Name: %20s Status: %s\n",p,proc_table[p].name,
RRSOFT_status_to_a(proc_table[p].status));
p = proc_table[p].next;
p = iq_query_next(p, &lev->ready);
}
 
for (p=0; p<MAX_PROC; p++)
211,7 → 190,7
PID p;
 
for (;;) {
p = qq_queryfirst(&lev->ready);
p = iq_query_first(&lev->ready);
if (p == -1)
return p;
//{kern_printf("(s%d)",p); return p;}
219,8 → 198,8
// kern_printf("(p=%d l=%d avail=%d wcet =%d)\n",p,l,proc_table[p].avail_time, proc_table[p].wcet);
if (proc_table[p].avail_time <= 0) {
proc_table[p].avail_time += proc_table[p].wcet;
qq_extract(p,&lev->ready);
qq_insertlast(p,&lev->ready);
iq_extract(p,&lev->ready);
iq_insertlast(p,&lev->ready);
}
else
//{kern_printf("(s%d)",p); return p;}
322,14 → 301,6
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 RRSOFT_task_dispatch(LEVEL l, PID p, int nostop)
{
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]);
338,18 → 309,7
/* the task state is set EXE by the scheduler()
we extract the task from the ready queue
NB: we can't assume that p is the first task in the queue!!! */
qq_extract(p, &lev->ready);
 
 
#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
iq_extract(p, &lev->ready);
}
 
static void RRSOFT_task_epilogue(LEVEL l, PID p)
360,11 → 320,11
qqueue position */
if (proc_table[p].avail_time <= 0) {
proc_table[p].avail_time += proc_table[p].wcet;
qq_insertlast(p,&lev->ready);
iq_insertlast(p,&lev->ready);
}
else
/* curr is >0, so the running task have to run for another cuRRSOFT usec */
qq_insertfirst(p,&lev->ready);
iq_insertfirst(p,&lev->ready);
 
proc_table[p].status = RRSOFT_READY;
}
385,7 → 345,7
 
/* Insert task in the coRRSOFTect position */
proc_table[p].status = RRSOFT_READY;
qq_insertlast(p,&lev->ready);
iq_insertlast(p,&lev->ready);
 
/* Set the reactivation timer */
if (lev->periodic[p])
408,7 → 368,7
 
/* Insert task in the coRRSOFTect position */
proc_table[p].status = RRSOFT_READY;
qq_insertlast(p,&lev->ready);
iq_insertlast(p,&lev->ready);
}
 
static void RRSOFT_task_extract(LEVEL l, PID p)
432,7 → 392,7
ll_gettime(TIME_EXACT, &proc_table[p].request_time);
lev->nact[p]--;
// qq_insertlast(p,&lev->ready);
qq_insertfirst(p,&lev->ready);
iq_insertfirst(p,&lev->ready);
proc_table[p].status = RRSOFT_READY;
}
else
453,7 → 413,7
 
/* then, we insert the task in the free queue */
proc_table[p].status = FREE;
q_insert(p,&freedesc);
iq_insertlast(p,&freedesc);
}
 
static void RRSOFT_task_sleep(LEVEL l, PID p)
471,23 → 431,6
proc_table[p].status = SLEEP;
}
 
static void RRSOFT_task_delay(LEVEL l, PID p, TIME usdelay)
{
// RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]);
struct timespec wakeuptime;
 
/* equal to RRSOFT_task_endcycle */
proc_table[p].status = RRSOFT_DELAY;
 
/* we need to delete this event if we kill the task while it is sleeping */
ll_gettime(TIME_EXACT,&wakeuptime);
ADDUSEC2TIMESPEC(usdelay,&wakeuptime);
proc_table[p].delay_timer = kern_event_post(&wakeuptime,
RRSOFT_timer_delay,
(void *)p);
}
 
 
static int RRSOFT_guest_create(LEVEL l, PID p, TASK_MODEL *m)
{ kern_raise(XINVALID_GUEST,exec_shadow); return 0; }
 
518,12 → 461,8
static void RRSOFT_guest_sleep(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void RRSOFT_guest_delay(LEVEL l, PID p,DWORD tickdelay)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
 
 
 
/* Registration functions */
 
/*+ This init function install the "main" task +*/
603,7 → 542,6
lev->l.task_endcycle = RRSOFT_task_endcycle;
lev->l.task_end = RRSOFT_task_end;
lev->l.task_sleep = RRSOFT_task_sleep;
lev->l.task_delay = RRSOFT_task_delay;
 
lev->l.guest_create = RRSOFT_guest_create;
lev->l.guest_detach = RRSOFT_guest_detach;
615,7 → 553,6
lev->l.guest_endcycle = RRSOFT_guest_endcycle;
lev->l.guest_end = RRSOFT_guest_end;
lev->l.guest_sleep = RRSOFT_guest_sleep;
lev->l.guest_delay = RRSOFT_guest_delay;
 
/* fill the RRSOFT descriptor part */
for (i = 0; i < MAX_PROC; i++) {
626,7 → 563,7
lev->period[i] = 0;
}
 
qq_init(&lev->ready);
iq_init(&lev->ready, &freedesc, 0);
 
if (slice < RRSOFT_MINIMUM_SLICE) slice = RRSOFT_MINIMUM_SLICE;
if (slice > RRSOFT_MAXIMUM_SLICE) slice = RRSOFT_MAXIMUM_SLICE;