20,11 → 20,11 |
|
/** |
------------ |
CVS : $Id: rrsoft.c,v 1.1.1.1 2002-03-29 14:12:52 pj Exp $ |
CVS : $Id: rrsoft.c,v 1.4 2003-01-07 17:07:51 pj Exp $ |
|
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2002-03-29 14:12:52 $ |
Revision: $Revision: 1.4 $ |
Last update: $Date: 2003-01-07 17:07:51 $ |
------------ |
|
This file contains the scheduling module RRSOFT (Round Robin) |
60,10 → 60,10 |
#include <kernel/descr.h> |
#include <kernel/var.h> |
#include <kernel/func.h> |
#include <kernel/trace.h> |
|
/*+ 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 → 72,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 +*/ |
|
93,20 → 93,6 |
} RRSOFT_level_des; |
|
|
static char *RRSOFT_status_to_a(WORD status) |
{ |
if (status < MODULE_STATUS_BASE) |
return status_to_a(status); |
|
switch (status) { |
case RRSOFT_READY: return "RRSOFT_Ready"; |
case RRSOFT_DELAY: return "RRSOFT_Delay"; |
case RRSOFT_IDLE : return "RRSOFT_Idle"; |
default : return "RRSOFT_Unknown"; |
} |
} |
|
|
/* this is the periodic reactivation of the task... it is posted only |
if the task is a periodic task */ |
static void RRSOFT_timer_reactivate(void *par) |
121,7 → 107,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(); |
} |
139,72 → 125,11 |
// trc_logevent(TRC_INTACTIVATION,&p); |
} |
|
|
/*+ 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]); |
|
if ((m->pclass == NRT_PCLASS || m->pclass == (NRT_PCLASS | l)) && lev->models & RRSOFT_ONLY_NRT) |
return 0; |
else if ((m->pclass == SOFT_PCLASS || m->pclass == (SOFT_PCLASS | l)) && lev->models & RRSOFT_ONLY_SOFT) |
return 0; |
else if ((m->pclass == HARD_PCLASS || m->pclass == (HARD_PCLASS | l)) && lev->models & RRSOFT_ONLY_HARD) |
return 0; |
else |
return -1; |
} |
|
static int RRSOFT_level_accept_guest_model(LEVEL l, TASK_MODEL *m) |
{ |
return -1; |
} |
|
static void RRSOFT_level_status(LEVEL l) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
PID p = qq_queryfirst(&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, |
RRSOFT_status_to_a(proc_table[p].status)); |
p = proc_table[p].next; |
} |
|
for (p=0; p<MAX_PROC; p++) |
if (proc_table[p].task_level == l && proc_table[p].status != RRSOFT_READY |
&& proc_table[p].status != FREE ) |
kern_printf("Pid: %d\t Name: %20s Status: %s\n",p,proc_table[p].name, |
RRSOFT_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 RRSOFT_level_scheduler(LEVEL l) |
static PID RRSOFT_public_scheduler(LEVEL l) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
|
211,7 → 136,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 → 144,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;} |
229,17 → 154,8 |
} |
} |
|
static int RRSOFT_level_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
static int RRSOFT_public_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
/* the RRSOFT level always guarantee... the function is defined because |
there can be an aperiodic server at a level with less priority than |
the RRSOFT that need guarantee (e.g., a TBS server) */ |
return 1; |
} |
|
|
static int RRSOFT_task_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
|
// kern_printf("create %d mod %d\n",p,m->pclass); |
247,6 → 163,11 |
the only thing to set remains the capacity stuffs that are set |
to the values passed in the model... */ |
|
if ( !(m->pclass==NRT_PCLASS && lev->models & RRSOFT_ONLY_NRT ) ) return -1; |
if ( !(m->pclass==SOFT_PCLASS && lev->models & RRSOFT_ONLY_SOFT) ) return -1; |
if ( !(m->pclass==HARD_PCLASS && lev->models & RRSOFT_ONLY_HARD) ) return -1; |
if (m->level != 0 && m->level != l) return -1; |
|
/* I used the wcet field because using wcet can account if a task |
consume more than the timeslice... */ |
|
310,49 → 231,17 |
return 0; /* OK */ |
} |
|
static void RRSOFT_task_detach(LEVEL l, PID p) |
static void RRSOFT_public_dispatch(LEVEL l, PID p, int nostop) |
{ |
/* the RRSOFT 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 RRSOFT_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 RRSOFT_task_dispatch(LEVEL l, PID p, int nostop) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
//static int p2count=0; |
|
/* 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) |
static void RRSOFT_public_epilogue(LEVEL l, PID p) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
|
360,16 → 249,16 |
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; |
} |
|
static void RRSOFT_task_activate(LEVEL l, PID p) |
static void RRSOFT_public_activate(LEVEL l, PID p) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
|
381,18 → 270,15 |
return; |
} |
|
ll_gettime(TIME_EXACT, &proc_table[p].request_time); |
|
/* Insert task in the coRRSOFTect position */ |
/* Insert task in the correct 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]) |
{ |
TIMESPEC_ASSIGN(&lev->reactivation_time[p], &proc_table[p].request_time); |
kern_gettime(&lev->reactivation_time[p]); |
ADDUSEC2TIMESPEC(lev->period[p], &lev->reactivation_time[p]); |
// TIMESPEC_ASSIGN(&lev->reactivation_time[p], &lev->cbs_dline[p]); |
lev->reactivation_timer[p] = kern_event_post(&lev->reactivation_time[p], |
RRSOFT_timer_reactivate, |
(void *)p); |
399,19 → 285,19 |
} |
} |
|
static void RRSOFT_task_insert(LEVEL l, PID p) |
static void RRSOFT_public_unblock(LEVEL l, PID p) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
|
/* Similar to RRSOFT_task_activate, but we don't check in what state |
the task is and we don't set the request_time */ |
the task is */ |
|
/* 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) |
static void RRSOFT_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. |
423,23 → 309,27 |
*/ |
} |
|
static void RRSOFT_task_endcycle(LEVEL l, PID p) |
static int RRSOFT_public_message(LEVEL l, PID p, void *m) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
|
if (lev->nact[p] > 0) { |
/* continue!!!! */ |
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 |
proc_table[p].status = RRSOFT_IDLE; |
|
jet_update_endcycle(); /* Update the Jet data... */ |
trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */ |
|
return 0; |
} |
|
static void RRSOFT_task_end(LEVEL l, PID p) |
static void RRSOFT_public_end(LEVEL l, PID p) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
|
447,83 → 337,15 |
|
/* we delete the reactivation timer */ |
if (lev->periodic[p]) { |
event_delete(lev->reactivation_timer[p]); |
kern_event_delete(lev->reactivation_timer[p]); |
lev->reactivation_timer[p] = -1; |
} |
|
/* 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) |
{ |
RRSOFT_level_des *lev = (RRSOFT_level_des *)(level_table[l]); |
|
if (lev->nact[p] >= 0) lev->nact[p] = 0; |
|
/* we delete the reactivation timer */ |
if (lev->periodic[p]) { |
event_delete(lev->reactivation_timer[p]); |
lev->reactivation_timer[p] = -1; |
} |
|
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(XUNVALID_GUEST,exec_shadow); return 0; } |
|
static void RRSOFT_guest_detach(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_dispatch(LEVEL l, PID p, int nostop) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_epilogue(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_activate(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_insert(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_extract(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_endcycle(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_end(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_sleep(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
static void RRSOFT_guest_delay(LEVEL l, PID p,DWORD tickdelay) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
|
|
|
/* Registration functions */ |
|
/*+ This init function install the "main" task +*/ |
551,7 → 373,7 |
if (p == NIL) |
printk("\nPanic!!! can't create main task...\n"); |
|
RRSOFT_task_activate(lev,p); |
RRSOFT_public_activate(lev,p); |
} |
|
|
559,7 → 381,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 RRSOFT_register_level(TIME slice, |
LEVEL RRSOFT_register_level(TIME slice, |
int createmain, |
struct multiboot_info *mb, |
BYTE models) |
571,52 → 393,23 |
printk("RRSOFT_register_level\n"); |
|
/* request an entry in the level_table */ |
l = level_alloc_descriptor(); |
l = level_alloc_descriptor(sizeof(RRSOFT_level_des)); |
|
/* alloc the space needed for the RRSOFT_level_des */ |
lev = (RRSOFT_level_des *)kern_alloc(sizeof(RRSOFT_level_des)); |
lev = (RRSOFT_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, RRSOFT_LEVELNAME, MAX_LEVELNAME); |
lev->l.level_code = RRSOFT_LEVEL_CODE; |
lev->l.level_version = RRSOFT_LEVEL_VERSION; |
lev->l.public_scheduler = RRSOFT_public_scheduler; |
lev->l.public_create = RRSOFT_public_create; |
lev->l.public_end = RRSOFT_public_end; |
lev->l.public_dispatch = RRSOFT_public_dispatch; |
lev->l.public_epilogue = RRSOFT_public_epilogue; |
lev->l.public_activate = RRSOFT_public_activate; |
lev->l.public_unblock = RRSOFT_public_unblock; |
lev->l.public_block = RRSOFT_public_block; |
lev->l.public_message = RRSOFT_public_message; |
|
lev->l.level_accept_task_model = RRSOFT_level_accept_task_model; |
lev->l.level_accept_guest_model = RRSOFT_level_accept_guest_model; |
lev->l.level_status = RRSOFT_level_status; |
lev->l.level_scheduler = RRSOFT_level_scheduler; |
lev->l.level_guarantee = RRSOFT_level_guarantee; |
|
lev->l.task_create = RRSOFT_task_create; |
lev->l.task_detach = RRSOFT_task_detach; |
lev->l.task_eligible = RRSOFT_task_eligible; |
lev->l.task_dispatch = RRSOFT_task_dispatch; |
lev->l.task_epilogue = RRSOFT_task_epilogue; |
lev->l.task_activate = RRSOFT_task_activate; |
lev->l.task_insert = RRSOFT_task_insert; |
lev->l.task_extract = RRSOFT_task_extract; |
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; |
lev->l.guest_dispatch = RRSOFT_guest_dispatch; |
lev->l.guest_epilogue = RRSOFT_guest_epilogue; |
lev->l.guest_activate = RRSOFT_guest_activate; |
lev->l.guest_insert = RRSOFT_guest_insert; |
lev->l.guest_extract = RRSOFT_guest_extract; |
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++) { |
lev->nact[i] = -1; |
626,7 → 419,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; |
638,6 → 431,8 |
|
if (createmain) |
sys_atrunlevel(RRSOFT_call_main,(void *) l, RUNLEVEL_INIT); |
|
return l; |
} |
|
|