20,11 → 20,11 |
|
/** |
------------ |
CVS : $Id: posix.c,v 1.3 2002-11-11 08:32:06 pj Exp $ |
CVS : $Id: posix.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 compatible with POSIX |
63,6 → 63,7 |
#include <kernel/descr.h> |
#include <kernel/var.h> |
#include <kernel/func.h> |
#include <kernel/trace.h> |
|
/*+ Status used in the level +*/ |
#define POSIX_READY MODULE_STATUS_BASE |
88,53 → 89,11 |
|
} POSIX_level_des; |
|
static char *POSIX_status_to_a(WORD status) |
{ |
if (status < MODULE_STATUS_BASE) |
return status_to_a(status); |
|
switch (status) { |
case POSIX_READY: return "POSIX_Ready"; |
default : return "POSIX_Unknown"; |
} |
} |
|
static int POSIX_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 POSIX_level_accept_guest_model(LEVEL l, TASK_MODEL *m) |
{ |
return -1; |
} |
|
static void POSIX_level_status(LEVEL l) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
PID p; |
|
kern_printf("Slice: %d \n", lev->slice); |
|
for (p=0; p<MAX_PROC; p++) |
if (proc_table[p].task_level == l && proc_table[p].status != POSIX_READY |
&& proc_table[p].status != FREE ) |
kern_printf("Pid: %d\t Name: %20s Prio: %3d Status: %s\n", |
p,proc_table[p].name, |
lev->priority[p], |
POSIX_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 POSIX_level_scheduler(LEVEL l) |
static PID POSIX_public_scheduler(LEVEL l) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
166,19 → 125,15 |
} |
} |
|
static int POSIX_level_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
static int POSIX_public_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
/* the POSIX level always guarantee... the function is defined because |
there can be an aperiodic server at a level with less priority than |
the POSIX that need guarantee (e.g., a TBS server) */ |
return 1; |
} |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
NRT_TASK_MODEL *nrt; |
|
if (m->pclass != NRT_PCLASS) return -1; |
if (m->level != 0 && m->level != l) return -1; |
|
static int POSIX_task_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
NRT_TASK_MODEL *nrt = (NRT_TASK_MODEL *)m; |
nrt = (NRT_TASK_MODEL *)m; |
|
/* the task state is set at SLEEP by the general task_create */ |
|
223,20 → 178,8 |
return 0; /* OK */ |
} |
|
static void POSIX_task_detach(LEVEL l, PID p) |
static void POSIX_public_dispatch(LEVEL l, PID p, int nostop) |
{ |
/* the POSIX 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 POSIX_task_eligible(LEVEL l, PID p) |
{ |
return 0; /* if the task p is chosen, it is always eligible */ |
} |
|
static void POSIX_task_dispatch(LEVEL l, PID p, int nostop) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
/* the task state is set EXE by the scheduler() |
245,7 → 188,7 |
iq_extract(p, &lev->ready[lev->priority[p]]); |
} |
|
static void POSIX_task_epilogue(LEVEL l, PID p) |
static void POSIX_public_epilogue(LEVEL l, PID p) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
266,7 → 209,7 |
proc_table[p].status = POSIX_READY; |
} |
|
static void POSIX_task_activate(LEVEL l, PID p) |
static void POSIX_public_activate(LEVEL l, PID p) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
278,19 → 221,17 |
return; |
} |
|
ll_gettime(TIME_EXACT, &proc_table[p].request_time); |
|
/* Insert task in the correct position */ |
proc_table[p].status = POSIX_READY; |
iq_insertlast(p,&lev->ready[lev->priority[p]]); |
} |
|
static void POSIX_task_insert(LEVEL l, PID p) |
static void POSIX_public_unblock(LEVEL l, PID p) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
/* Similar to POSIX_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 coPOSIXect position */ |
proc_table[p].status = POSIX_READY; |
297,7 → 238,7 |
iq_insertlast(p,&lev->ready[lev->priority[p]]); |
} |
|
static void POSIX_task_extract(LEVEL l, PID p) |
static void POSIX_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. |
309,13 → 250,12 |
*/ |
} |
|
static void POSIX_task_endcycle(LEVEL l, PID p) |
static int POSIX_public_message(LEVEL l, PID p, void *m) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
if (lev->nact[p] > 0) { |
/* continue!!!! */ |
ll_gettime(TIME_EXACT, &proc_table[p].request_time); |
lev->nact[p]--; |
iq_insertfirst(p,&lev->ready[lev->priority[p]]); |
proc_table[p].status = POSIX_READY; |
322,9 → 262,14 |
} |
else |
proc_table[p].status = SLEEP; |
|
jet_update_endcycle(); /* Update the Jet data... */ |
trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */ |
|
return 0; |
} |
|
static void POSIX_task_end(LEVEL l, PID p) |
static void POSIX_public_end(LEVEL l, PID p) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
335,46 → 280,6 |
iq_priority_insert(p,&freedesc); |
} |
|
static void POSIX_task_sleep(LEVEL l, PID p) |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
lev->nact[p] = 0; |
proc_table[p].status = SLEEP; |
} |
|
|
|
static int POSIX_guest_create(LEVEL l, PID p, TASK_MODEL *m) |
{ kern_raise(XINVALID_GUEST,exec_shadow); return 0; } |
|
static void POSIX_guest_detach(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void POSIX_guest_dispatch(LEVEL l, PID p, int nostop) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void POSIX_guest_epilogue(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void POSIX_guest_activate(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void POSIX_guest_insert(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void POSIX_guest_extract(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void POSIX_guest_endcycle(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void POSIX_guest_end(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void POSIX_guest_sleep(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
|
/* Registration functions */ |
|
/*+ This init function install the "main" task +*/ |
405,7 → 310,7 |
if (p == NIL) |
printk("\nPanic!!! can't create main task...\n"); |
|
POSIX_task_activate(lev,p); |
POSIX_public_activate(lev,p); |
} |
|
|
413,7 → 318,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 POSIX_register_level(TIME slice, |
LEVEL POSIX_register_level(TIME slice, |
int createmain, |
struct multiboot_info *mb, |
int prioritylevels) |
425,53 → 330,23 |
|
printk("POSIX_register_level\n"); |
|
/* request an entry in the level_table */ |
l = level_alloc_descriptor(); |
l = level_alloc_descriptor(sizeof(POSIX_level_des)); |
|
printk(" alloco descrittore %d %d\n",l,(int)sizeof(POSIX_level_des)); |
lev = (POSIX_level_des *)level_table[l]; |
|
/* alloc the space needed for the POSIX_level_des */ |
lev = (POSIX_level_des *)kern_alloc(sizeof(POSIX_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, POSIX_LEVELNAME, MAX_LEVELNAME); |
lev->l.level_code = POSIX_LEVEL_CODE; |
lev->l.level_version = POSIX_LEVEL_VERSION; |
lev->l.public_scheduler = POSIX_public_scheduler; |
lev->l.public_create = POSIX_public_create; |
lev->l.public_end = POSIX_public_end; |
lev->l.public_dispatch = POSIX_public_dispatch; |
lev->l.public_epilogue = POSIX_public_epilogue; |
lev->l.public_activate = POSIX_public_activate; |
lev->l.public_unblock = POSIX_public_unblock; |
lev->l.public_block = POSIX_public_block; |
lev->l.public_message = POSIX_public_message; |
|
lev->l.level_accept_task_model = POSIX_level_accept_task_model; |
lev->l.level_accept_guest_model = POSIX_level_accept_guest_model; |
lev->l.level_status = POSIX_level_status; |
lev->l.level_scheduler = POSIX_level_scheduler; |
lev->l.level_guarantee = POSIX_level_guarantee; |
|
lev->l.task_create = POSIX_task_create; |
lev->l.task_detach = POSIX_task_detach; |
lev->l.task_eligible = POSIX_task_eligible; |
lev->l.task_dispatch = POSIX_task_dispatch; |
lev->l.task_epilogue = POSIX_task_epilogue; |
lev->l.task_activate = POSIX_task_activate; |
lev->l.task_insert = POSIX_task_insert; |
lev->l.task_extract = POSIX_task_extract; |
lev->l.task_endcycle = POSIX_task_endcycle; |
lev->l.task_end = POSIX_task_end; |
lev->l.task_sleep = POSIX_task_sleep; |
|
lev->l.guest_create = POSIX_guest_create; |
lev->l.guest_detach = POSIX_guest_detach; |
lev->l.guest_dispatch = POSIX_guest_dispatch; |
lev->l.guest_epilogue = POSIX_guest_epilogue; |
lev->l.guest_activate = POSIX_guest_activate; |
lev->l.guest_insert = POSIX_guest_insert; |
lev->l.guest_extract = POSIX_guest_extract; |
lev->l.guest_endcycle = POSIX_guest_endcycle; |
lev->l.guest_end = POSIX_guest_end; |
lev->l.guest_sleep = POSIX_guest_sleep; |
|
/* fill the POSIX descriptor part */ |
for (i = 0; i < MAX_PROC; i++) |
lev->nact[i] = -1; |
491,6 → 366,8 |
|
if (createmain) |
sys_atrunlevel(POSIX_call_main,(void *) l, RUNLEVEL_INIT); |
|
return l; |
} |
|
/*+ this function forces the running task to go to his queue tail; |
499,13 → 376,6 |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
if (l < 0 || l >= sched_levels) |
return -1; |
|
if (level_table[l]->level_code != POSIX_LEVEL_CODE || |
level_table[l]->level_version != POSIX_LEVEL_VERSION ) |
return -1; |
|
if (proc_table[exec_shadow].task_level != l) |
return -1; |
|
536,13 → 406,6 |
returns ENOSYS or ESRCH if there are problems +*/ |
int POSIX_getschedparam(LEVEL l, PID p, int *policy, int *priority) |
{ |
if (l < 0 || l >= sched_levels) |
return ENOSYS; |
|
if (level_table[l]->level_code != POSIX_LEVEL_CODE || |
level_table[l]->level_version != POSIX_LEVEL_VERSION ) |
return ENOSYS; |
|
if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE) |
return ESRCH; |
|
564,13 → 427,6 |
{ |
POSIX_level_des *lev = (POSIX_level_des *)(level_table[l]); |
|
if (l < 0 || l >= sched_levels) |
return ENOSYS; |
|
if (level_table[l]->level_code != POSIX_LEVEL_CODE || |
level_table[l]->level_version != POSIX_LEVEL_VERSION ) |
return ENOSYS; |
|
if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE) |
return ESRCH; |
|