20,11 → 20,11 |
|
/** |
------------ |
CVS : $Id: ss.c,v 1.3 2002-11-11 08:32:07 pj Exp $ |
CVS : $Id: ss.c,v 1.4 2003-01-07 17:07:51 pj Exp $ |
|
File: $File$ |
Revision: $Revision: 1.3 $ |
Last update: $Date: 2002-11-11 08:32:07 $ |
Revision: $Revision: 1.4 $ |
Last update: $Date: 2003-01-07 17:07:51 $ |
------------ |
|
This file contains the aperiodic Sporadic Server (SS). |
125,6 → 125,7 |
#include <kernel/descr.h> |
#include <kernel/var.h> |
#include <kernel/func.h> |
#include <kernel/trace.h> |
|
/* For debugging purpose */ |
//#define DEBUG 1 |
174,7 → 175,7 |
} SS_level_des; |
|
/*+ function prototypes +*/ |
void SS_level_status(LEVEL l); |
void SS_internal_status(LEVEL l); |
static void SS_replenish_timer(void *arg); |
/*-------------------------------------------------------------------*/ |
|
313,7 → 314,7 |
if(ssq_inslast(l, lev->replenish_amount) == NIL) { |
kern_printf("SS: no more space to post replenishment\n"); |
kern_printf("You should recompile setting higher SS_MAX_REPLENISH into include/modules/ss.h\n"); |
SS_level_status(l); |
SS_internal_status(l); |
kern_raise(XINVALID_SS_REPLENISH,exec_shadow); |
#ifdef DEBUG |
sys_abort(-1); |
324,7 → 325,7 |
} |
else { |
kern_printf("SS not active when posting R.A.\n"); |
SS_level_status(l); |
SS_internal_status(l); |
kern_raise(XINVALID_SS_REPLENISH,exec_shadow); |
#ifdef DEBUG |
sys_abort(-1); |
368,8 → 369,7 |
|
job_task_default_model(j,lev->lastdline); |
job_task_def_period(j,lev->period); |
level_table[m]->guest_create(m,p,(TASK_MODEL *)&j); |
level_table[m]->guest_activate(m,p); |
level_table[m]->private_insert(m,p,(TASK_MODEL *)&j); |
|
#ifdef DEBUG |
kern_printf("PID:%p lastdl:%d.%d ",p,lev->lastdline.tv_sec,lev->lastdline.tv_nsec); |
400,7 → 400,7 |
if(ssq_inslast(l, tx+lev->replenish_amount) == NIL) { |
kern_printf("SS: no more space to post replenishment\n"); |
kern_printf(" You should recompile setting higher SS_MAX_REPLENISH into include/modules/ss.h\n"); |
SS_level_status(l); |
SS_internal_status(l); |
kern_raise(XINVALID_SS_REPLENISH,exec_shadow); |
#ifdef DEBUG |
sys_abort(-1); |
456,7 → 456,7 |
else { |
/* replenish queue is empty */ |
kern_printf("Replenish Timer fires but no Replenish Amount defined\n"); |
SS_level_status(l); |
SS_internal_status(l); |
kern_raise(XINVALID_SS_REPLENISH,exec_shadow); |
#ifdef DEBUG |
sys_abort(-1); |
471,7 → 471,7 |
if (lev->server_active == SS_SERVER_NOTACTIVE) { |
lev->server_active = SS_SERVER_ACTIVE; |
/* set replenish time */ |
ll_gettime(TIME_EXACT, &ty); |
kern_gettime(&ty); |
ADDUSEC2TIMESPEC(lev->period, &ty); |
TIMESPEC_ASSIGN(&lev->lastdline, &ty); |
#ifdef DEBUG |
488,7 → 488,7 |
static char *SS_status_to_a(WORD status) |
{ |
if (status < MODULE_STATUS_BASE) |
return status_to_a(status); |
return "Unavailable"; //status_to_a(status); |
|
switch (status) { |
case SS_WAIT : return "SS_Wait"; |
501,40 → 501,8 |
|
/*** Level functions ***/ |
|
|
static int SS_level_accept_task_model(LEVEL l, TASK_MODEL *m) |
void SS_internal_status(LEVEL l) |
{ |
#ifdef DEBUG |
kern_printf("SS_levacctm cl=%d ",m->pclass); |
#endif |
|
if (m->pclass == SOFT_PCLASS || m->pclass == (SOFT_PCLASS | l) ) { |
SOFT_TASK_MODEL *s = (SOFT_TASK_MODEL *)m; |
|
if (s->periodicity == APERIODIC) { |
#ifdef DEBUG |
kern_printf("AcceptApe "); |
#endif |
return 0; |
} |
#ifdef DEBUG |
kern_printf("NAcceptApe "); |
#endif |
} |
#ifdef DEBUG |
kern_printf("NAccept "); |
#endif |
return -1; |
} |
|
static int SS_level_accept_guest_model(LEVEL l, TASK_MODEL *m) |
{ |
/* SS doesn't handles guest tasks */ |
return -1; |
} |
|
void SS_level_status(LEVEL l) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
PID p = iq_query_first(&lev->wait); |
|
568,19 → 536,8 |
} |
} |
|
static PID SS_level_scheduler(LEVEL l) |
static PID SS_public_schedulerbackground(LEVEL l) |
{ |
#ifdef DEBUG |
kern_printf("SS_levsch "); |
#endif |
|
/* the SS don't schedule anything... |
it's an RM level or similar that do it! */ |
return NIL; |
} |
|
static PID SS_level_schedulerbackground(LEVEL l) |
{ |
/* the SS catch the background time to exec aperiodic activities */ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
|
597,7 → 554,7 |
} |
|
/* The on-line guarantee is enabled only if the appropriate flag is set... */ |
static int SS_level_guaranteeEDF(LEVEL l, bandwidth_t *freebandwidth) |
static int SS_public_guaranteeEDF(LEVEL l, bandwidth_t *freebandwidth) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
|
613,7 → 570,7 |
return 0; |
} |
|
static int SS_level_guaranteeRM(LEVEL l, bandwidth_t *freebandwidth) |
static int SS_public_guaranteeRM(LEVEL l, bandwidth_t *freebandwidth) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
|
634,17 → 591,22 |
/*** Task functions ***/ |
|
|
static int SS_task_create(LEVEL l, PID p, TASK_MODEL *m) |
static int SS_public_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
SOFT_TASK_MODEL *s = (SOFT_TASK_MODEL *)m; /* if the SS_task_create is |
called, the pclass must |
be a valid pclass. */ |
SOFT_TASK_MODEL *s; |
|
#ifdef DEBUG |
kern_printf("SS_taskcre "); |
#endif |
|
if (m->pclass != SOFT_PCLASS) return -1; |
if (m->level != 0 && m->level != l) return -1; |
s = (SOFT_TASK_MODEL *)m; |
if (s->periodicity != APERIODIC) return -1; |
|
s = (SOFT_TASK_MODEL *)m; |
|
if (s->arrivals == SAVE_ARRIVALS) |
lev->nact[p] = 0; |
else |
653,19 → 615,8 |
return 0; /* OK, also if the task cannot be guaranteed */ |
} |
|
static void SS_task_detach(LEVEL l, PID p) |
static void SS_public_dispatch(LEVEL l, PID p, int nostop) |
{ |
/* No cleanups to do here. |
SS level doesn't introduce any dynamic allocated field. */ |
} |
|
static int SS_task_eligible(LEVEL l, PID p) |
{ |
return 0; /* If the task p is chosen, it is always eligible */ |
} |
|
static void SS_task_dispatch(LEVEL l, PID p, int nostop) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
struct timespec ty; |
|
706,7 → 657,7 |
if (nostop) kern_printf("(gd status=%d)",proc_table[p].status); |
#endif |
level_table[lev->scheduling_level]-> |
guest_dispatch(lev->scheduling_level,p,nostop); |
private_dispatch(lev->scheduling_level,p,nostop); |
} |
|
/* set capacity timer */ |
723,7 → 674,7 |
} |
} |
|
static void SS_task_epilogue(LEVEL l, PID p) { |
static void SS_public_epilogue(LEVEL l, PID p) { |
|
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
struct timespec ty; |
765,7 → 716,7 |
if(ssq_inslast(l, lev->replenish_amount) == NIL) { |
kern_printf("SS: no more space to post replenishment\n"); |
kern_printf("You should recompile setting higher SS_MAX_REPLENISH into include/modules/ss.h\n"); |
SS_level_status(l); |
SS_internal_status(l); |
kern_raise(XINVALID_SS_REPLENISH,exec_shadow); |
#ifdef DEBUG |
sys_abort(-1); |
777,7 → 728,7 |
} |
|
if (lev->activated == p) |
level_table[lev->scheduling_level]->guest_end(lev->scheduling_level,p); |
level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p); |
|
iq_insertfirst(p, &lev->wait); |
proc_table[p].status = SS_WAIT; |
786,11 → 737,11 |
else { |
/* The task has been preempted. |
It returns into the ready queue or to the |
wait queue by calling the guest_epilogue... */ |
wait queue by calling the private_epilogue... */ |
|
if (lev->activated == p) { /* goes into ready queue */ |
level_table[ lev->scheduling_level ]-> |
guest_epilogue(lev->scheduling_level,p); |
private_epilogue(lev->scheduling_level,p); |
} |
else { /* goes into wait queue */ |
iq_insertfirst(p, &lev->wait); |
799,7 → 750,7 |
} |
} |
|
static void SS_task_activate(LEVEL l, PID p) |
static void SS_public_activate(LEVEL l, PID p) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
struct timespec ty; |
812,8 → 763,6 |
if (lev->nact[p] != -1) lev->nact[p]++; |
} |
else if (proc_table[p].status == SLEEP) { |
ll_gettime(TIME_EXACT, &proc_table[p].request_time); |
// kern_printf("-%d.%d- ",proc_table[p].request_time.tv_sec,proc_table[p].request_time.tv_nsec); |
if (lev->activated == NIL && lev->availCs > 0) { |
if(!BACKGROUND_ON) { |
/* if server is active, replenish time already set */ |
820,7 → 769,7 |
if (lev->server_active == SS_SERVER_NOTACTIVE) { |
lev->server_active = SS_SERVER_ACTIVE; |
/* set replenish time */ |
TIMESPEC_ASSIGN(&ty, &proc_table[p].request_time); |
kern_gettime(&ty); |
ADDUSEC2TIMESPEC(lev->period, &ty); |
TIMESPEC_ASSIGN(&lev->lastdline, &ty); |
#ifdef DEBUG |
847,7 → 796,7 |
} |
} |
|
static void SS_task_insert(LEVEL l, PID p) |
static void SS_public_unblock(LEVEL l, PID p) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
|
864,7 → 813,7 |
proc_table[p].status = SS_WAIT; |
} |
|
static void SS_task_extract(LEVEL l, PID p) |
static void SS_public_block(LEVEL l, PID p) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
|
883,10 → 832,10 |
lev->flags |= SS_BACKGROUND_BLOCK; |
|
if (lev->activated == p) |
level_table[lev->scheduling_level]->guest_end(lev->scheduling_level,p); |
level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p); |
} |
|
static void SS_task_endcycle(LEVEL l, PID p) |
static int SS_public_message(LEVEL l, PID p, void *m) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
struct timespec ty; |
910,7 → 859,7 |
} |
|
if (lev->activated == p) |
level_table[lev->scheduling_level]->guest_end(lev->scheduling_level,p); |
level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p); |
else |
iq_extract(p, &lev->wait); |
|
933,9 → 882,14 |
SS_set_ra(l); |
} |
} |
|
jet_update_endcycle(); /* Update the Jet data... */ |
trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */ |
|
return 0; |
} |
|
static void SS_task_end(LEVEL l, PID p) |
static void SS_public_end(LEVEL l, PID p) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
struct timespec ty; |
959,7 → 913,7 |
} |
|
if (lev->activated == p) |
level_table[lev->scheduling_level]->guest_end(lev->scheduling_level,p); |
level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p); |
|
proc_table[p].status = FREE; |
iq_insertfirst(p,&freedesc); |
976,97 → 930,14 |
} |
} |
|
static void SS_task_sleep(LEVEL l, PID p) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
struct timespec ty; |
int tx; |
|
#ifdef DEBUG |
kern_printf("SS_tasksle "); |
#endif |
|
/* update the server capacity */ |
if (BACKGROUND_ON) |
lev->flags &= ~SS_BACKGROUND; |
else { |
SUBTIMESPEC(&schedule_time, &cap_lasttime, &ty); |
tx = TIMESPEC2USEC(&ty); |
lev->availCs -= tx; |
lev->replenish_amount += tx; |
#ifdef DEBUG |
kern_printf("PID:%d RA=%d ",p,lev->replenish_amount); |
#endif |
} |
|
lev->nact[p] = 0; |
|
if (lev->activated == p) |
level_table[lev->scheduling_level]->guest_end(lev->scheduling_level,p); |
else |
iq_extract(p, &lev->wait); |
|
proc_table[p].status = SLEEP; |
|
lev->activated = iq_getfirst(&lev->wait); |
if (lev->activated != NIL) { |
SS_activation(lev); |
} |
else { |
if(!(BACKGROUND_ON)){ |
/* No more task to schedule; set replenish amount */ |
SS_set_ra(l); |
} |
} |
} |
|
|
/*-------------------------------------------------------------------*/ |
|
/*** Guest functions ***/ |
|
|
/* SS doesn't handles guest tasks */ |
|
static int SS_guest_create(LEVEL l, PID p, TASK_MODEL *m) |
{ kern_raise(XINVALID_GUEST,exec_shadow); return 0; } |
|
static void SS_guest_detach(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void SS_guest_dispatch(LEVEL l, PID p, int nostop) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void SS_guest_epilogue(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void SS_guest_activate(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void SS_guest_insert(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void SS_guest_extract(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void SS_guest_endcycle(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void SS_guest_end(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void SS_guest_sleep(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
|
/*-------------------------------------------------------------------*/ |
|
/*** Registration functions ***/ |
|
|
/*+ Registration function: |
int flags the init flags ... see SS.h +*/ |
void SS_register_level(int flags, LEVEL master, int Cs, int per) |
LEVEL SS_register_level(int flags, LEVEL master, int Cs, int per) |
{ |
LEVEL l; /* the level that we register */ |
SS_level_des *lev; /* for readableness only */ |
1073,61 → 944,33 |
PID i; /* a counter */ |
|
/* request an entry in the level_table */ |
l = level_alloc_descriptor(); |
#ifdef DEBUG |
kern_printf("Alloc des %d ",l); |
#endif |
l = level_alloc_descriptor(sizeof(SS_level_des)); |
|
/* alloc the space needed for the SS_level_des */ |
lev = (SS_level_des *)kern_alloc(sizeof(SS_level_des)); |
lev = (SS_level_des *)level_table[l]; |
|
/* update the level_table with the new entry */ |
level_table[l] = (level_des *)lev; |
printk(" lev=%d\n",(int)lev); |
|
/* fill the standard descriptor */ |
strncpy(lev->l.level_name, SS_LEVELNAME, MAX_LEVELNAME); |
lev->l.level_code = SS_LEVEL_CODE; |
lev->l.level_version = SS_LEVEL_VERSION; |
|
lev->l.level_accept_task_model = SS_level_accept_task_model; |
lev->l.level_accept_guest_model = SS_level_accept_guest_model; |
lev->l.level_status = SS_level_status; |
|
if (flags & SS_ENABLE_BACKGROUND) |
lev->l.level_scheduler = SS_level_schedulerbackground; |
else |
lev->l.level_scheduler = SS_level_scheduler; |
lev->l.public_scheduler = SS_public_schedulerbackground; |
|
if (flags & SS_ENABLE_GUARANTEE_EDF) |
lev->l.level_guarantee = SS_level_guaranteeEDF; |
lev->l.public_guarantee = SS_public_guaranteeEDF; |
else if (flags & SS_ENABLE_GUARANTEE_RM) |
lev->l.level_guarantee = SS_level_guaranteeRM; |
lev->l.public_guarantee = SS_public_guaranteeRM; |
else |
lev->l.level_guarantee = NULL; |
lev->l.public_guarantee = NULL; |
|
lev->l.task_create = SS_task_create; |
lev->l.task_detach = SS_task_detach; |
lev->l.task_eligible = SS_task_eligible; |
lev->l.task_dispatch = SS_task_dispatch; |
lev->l.task_epilogue = SS_task_epilogue; |
lev->l.task_activate = SS_task_activate; |
lev->l.task_insert = SS_task_insert; |
lev->l.task_extract = SS_task_extract; |
lev->l.task_endcycle = SS_task_endcycle; |
lev->l.task_end = SS_task_end; |
lev->l.task_sleep = SS_task_sleep; |
lev->l.public_create = SS_public_create; |
lev->l.public_end = SS_public_end; |
lev->l.public_dispatch = SS_public_dispatch; |
lev->l.public_epilogue = SS_public_epilogue; |
lev->l.public_activate = SS_public_activate; |
lev->l.public_unblock = SS_public_unblock; |
lev->l.public_block = SS_public_block; |
lev->l.public_message = SS_public_message; |
|
lev->l.guest_create = SS_guest_create; |
lev->l.guest_detach = SS_guest_detach; |
lev->l.guest_dispatch = SS_guest_dispatch; |
lev->l.guest_epilogue = SS_guest_epilogue; |
lev->l.guest_activate = SS_guest_activate; |
lev->l.guest_insert = SS_guest_insert; |
lev->l.guest_extract = SS_guest_extract; |
lev->l.guest_endcycle = SS_guest_endcycle; |
lev->l.guest_end = SS_guest_end; |
lev->l.guest_sleep = SS_guest_sleep; |
|
/* fill the SS descriptor part */ |
|
for (i=0; i<MAX_PROC; i++) |
1156,23 → 999,19 |
lev->rcount=0; |
lev->replenish_amount=0; |
lev->server_active=SS_SERVER_NOTACTIVE; |
|
return l; |
} |
|
bandwidth_t SS_usedbandwidth(LEVEL l) |
{ |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
if (lev->l.level_code == SS_LEVEL_CODE && |
lev->l.level_version == SS_LEVEL_VERSION) |
return lev->U; |
else |
return 0; |
|
return lev->U; |
} |
|
int SS_availCs(LEVEL l) { |
SS_level_des *lev = (SS_level_des *)(level_table[l]); |
if (lev->l.level_code == SS_LEVEL_CODE && |
lev->l.level_version == SS_LEVEL_VERSION) |
return lev->availCs; |
else |
return 0; |
|
return lev->availCs; |
} |