20,11 → 20,11 |
|
/** |
------------ |
CVS : $Id: rr.c,v 1.1.1.1 2002-03-29 14:12:52 pj Exp $ |
CVS : $Id: rr.c,v 1.3 2002-11-11 08:32:06 pj Exp $ |
|
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2002-03-29 14:12:52 $ |
Revision: $Revision: 1.3 $ |
Last update: $Date: 2002-11-11 08:32:06 $ |
------------ |
|
This file contains the scheduling module RR (Round Robin) |
63,13 → 63,12 |
|
/*+ Status used in the level +*/ |
#define RR_READY MODULE_STATUS_BASE |
#define RR_DELAY MODULE_STATUS_BASE+1 |
|
/*+ the level redefinition for the Round Robin level +*/ |
typedef struct { |
level_des l; /*+ the standard level descriptor +*/ |
|
QQUEUE ready; /*+ the ready queue +*/ |
IQUEUE ready; /*+ the ready queue +*/ |
|
int slice; /*+ the level's time slice +*/ |
|
85,30 → 84,10 |
|
switch (status) { |
case RR_READY: return "RR_Ready"; |
case RR_DELAY: return "RR_Delay"; |
default : return "RR_Unknown"; |
} |
} |
|
/*+ this function is called when a task finish his delay +*/ |
static void RR_timer_delay(void *par) |
{ |
PID p = (PID) par; |
RR_level_des *lev; |
|
lev = (RR_level_des *)level_table[proc_table[p].task_level]; |
|
proc_table[p].status = RR_READY; |
qq_insertlast(p,&lev->ready); |
|
proc_table[p].delay_timer = NIL; /* Paranoia */ |
|
// kern_printf(" DELAY TIMER %d ", p); |
|
event_need_reschedule(); |
} |
|
|
static int RR_level_accept_task_model(LEVEL l, TASK_MODEL *m) |
{ |
if (m->pclass == NRT_PCLASS || m->pclass == (NRT_PCLASS | l)) |
125,7 → 104,7 |
static void RR_level_status(LEVEL l) |
{ |
RR_level_des *lev = (RR_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); |
|
132,7 → 111,7 |
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 = proc_table[p].next; |
p = iq_query_next(p,&lev->ready); |
} |
|
for (p=0; p<MAX_PROC; p++) |
155,14 → 134,14 |
PID p; |
|
for (;;) { |
p = qq_queryfirst(&lev->ready); |
p = iq_query_first(&lev->ready); |
if (p == -1) |
return p; |
|
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 |
return p; |
215,14 → 194,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 RR_task_dispatch(LEVEL l, PID p, int nostop) |
{ |
RR_level_des *lev = (RR_level_des *)(level_table[l]); |
230,20 → 201,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 |
// if (nostop) kern_printf("Û"); |
// kern_printf("(RR d %d)",nostop); |
iq_extract(p, &lev->ready); |
} |
|
static void RR_task_epilogue(LEVEL l, PID p) |
254,11 → 212,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 curr usec */ |
qq_insertfirst(p,&lev->ready); |
iq_insertfirst(p,&lev->ready); |
|
proc_table[p].status = RR_READY; |
} |
276,7 → 234,7 |
|
/* Insert task in the correct position */ |
proc_table[p].status = RR_READY; |
qq_insertlast(p,&lev->ready); |
iq_insertlast(p,&lev->ready); |
} |
|
static void RR_task_insert(LEVEL l, PID p) |
288,7 → 246,7 |
|
/* Insert task in the correct position */ |
proc_table[p].status = RR_READY; |
qq_insertlast(p,&lev->ready); |
iq_insertlast(p,&lev->ready); |
} |
|
static void RR_task_extract(LEVEL l, PID p) |
318,7 → 276,7 |
|
/* we insert the task in the free queue */ |
proc_table[p].status = FREE; |
q_insert(p,&freedesc); |
iq_insertlast(p,&freedesc); |
} |
|
static void RR_task_sleep(LEVEL l, PID p) |
326,59 → 284,39 |
proc_table[p].status = SLEEP; |
} |
|
static void RR_task_delay(LEVEL l, PID p, TIME usdelay) |
{ |
// RR_level_des *lev = (RR_level_des *)(level_table[l]); |
struct timespec wakeuptime; |
|
/* equal to RR_task_endcycle */ |
proc_table[p].status = RR_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, |
RR_timer_delay, |
(void *)p); |
} |
|
|
static int RR_guest_create(LEVEL l, PID p, TASK_MODEL *m) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); return 0; } |
{ kern_raise(XINVALID_GUEST,exec_shadow); return 0; } |
|
static void RR_guest_detach(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_dispatch(LEVEL l, PID p, int nostop) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_epilogue(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_activate(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_insert(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_extract(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_endcycle(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_end(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_sleep(LEVEL l, PID p) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void RR_guest_delay(LEVEL l, PID p,DWORD tickdelay) |
{ kern_raise(XUNVALID_GUEST,exec_shadow); } |
|
|
|
|
/* Registration functions */ |
|
/*+ This init function install the "main" task +*/ |
456,7 → 394,6 |
lev->l.task_endcycle = RR_task_endcycle; |
lev->l.task_end = RR_task_end; |
lev->l.task_sleep = RR_task_sleep; |
lev->l.task_delay = RR_task_delay; |
|
lev->l.guest_create = RR_guest_create; |
lev->l.guest_detach = RR_guest_detach; |
468,10 → 405,9 |
lev->l.guest_endcycle = RR_guest_endcycle; |
lev->l.guest_end = RR_guest_end; |
lev->l.guest_sleep = RR_guest_sleep; |
lev->l.guest_delay = RR_guest_delay; |
|
/* fill the RR descriptor part */ |
qq_init(&lev->ready); |
iq_init(&lev->ready, &freedesc, 0); |
|
if (slice < RR_MINIMUM_SLICE) slice = RR_MINIMUM_SLICE; |
if (slice > RR_MAXIMUM_SLICE) slice = RR_MAXIMUM_SLICE; |