20,11 → 20,11 |
|
/** |
------------ |
CVS : $Id: tbs.c,v 1.3 2002-11-11 08:32:07 pj Exp $ |
CVS : $Id: tbs.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 server TBS (Total Bandwidth Server) |
60,6 → 60,7 |
#include <kernel/descr.h> |
#include <kernel/var.h> |
#include <kernel/func.h> |
#include <kernel/trace.h> |
|
/*+ 4 debug purposes +*/ |
#undef TBS_TEST |
97,19 → 98,6 |
|
} TBS_level_des; |
|
|
static char *TBS_status_to_a(WORD status) |
{ |
if (status < MODULE_STATUS_BASE) |
return status_to_a(status); |
|
switch (status) { |
case TBS_WCET_VIOLATED: return "TBS_Wcet_Violated"; |
case TBS_WAIT : return "TBS_Wait"; |
default : return "TBS_Unknown"; |
} |
} |
|
#ifdef TESTG |
#include "drivers/glib.h" |
#endif |
131,9 → 119,6 |
/* we compute a suitable deadline for the task */ |
drel = (proc_table[p].wcet * lev->band_den) / lev->band_num; |
|
if (TIMESPEC_A_GT_B(&proc_table[p].request_time, &lev->lastdline)) |
TIMESPEC_ASSIGN(&lev->lastdline, &proc_table[p].request_time ); |
|
ADDUSEC2TIMESPEC(drel, &lev->lastdline); |
|
#ifdef TESTG |
147,8 → 132,7 |
/* and we insert the task in another level */ |
m = lev->scheduling_level; |
job_task_default_model(j,lev->lastdline); |
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 TBS_TEST |
kern_printf("TBS_activation: lastdline %ds %dns\n",lev->lastdline.tv_sec,lev->lastdline.tv_nsec); |
176,74 → 160,8 |
#endif |
} |
|
|
|
static int TBS_level_accept_task_model(LEVEL l, TASK_MODEL *m) |
{ |
if (m->pclass == SOFT_PCLASS || m->pclass == (SOFT_PCLASS | l) ) { |
SOFT_TASK_MODEL *s = (SOFT_TASK_MODEL *)m; |
|
if (s->wcet && s->periodicity == APERIODIC) |
return 0; |
} |
|
return -1; |
} |
|
static int TBS_level_accept_guest_model(LEVEL l, TASK_MODEL *m) |
{ |
return -1; |
} |
|
static char *onoff(int i) |
{ |
if (i) |
return "On "; |
else |
return "Off"; |
} |
|
static void TBS_level_status(LEVEL l) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
PID p = iq_query_first(&lev->wait); |
|
kern_printf("Wcet Check : %s\n", |
onoff(lev->flags & TBS_ENABLE_WCET_CHECK)); |
kern_printf("On-line guarantee : %s\n", |
onoff(lev->flags & TBS_ENABLE_GUARANTEE)); |
kern_printf("Used Bandwidth : %u/%u\n", |
lev->U, MAX_BANDWIDTH); |
kern_printf("Last deadline : %lds %ldns\n",lev->lastdline.tv_sec, |
lev->lastdline.tv_nsec); |
|
if (lev->activated != -1) |
kern_printf("Activated: Pid: %2d Name: %10s Dl: %ld.%9ld nact: %d Stat: %s\n", |
lev->activated, |
proc_table[lev->activated].name, |
iq_query_timespec(lev->activated, &lev->wait)->tv_sec, |
iq_query_timespec(lev->activated, &lev->wait)->tv_nsec, |
lev->nact[lev->activated], |
TBS_status_to_a(proc_table[lev->activated].status)); |
|
while (p != NIL) { |
kern_printf("Pid: %2d Name: %10s Stat: %s\n", |
p, |
proc_table[p].name, |
TBS_status_to_a(proc_table[p].status)); |
p = iq_query_next(p, &lev->wait); |
} |
} |
|
static PID TBS_level_scheduler(LEVEL l) |
{ |
/* the TBS don't schedule anything... |
it's an EDF level or similar that do it! */ |
return NIL; |
} |
|
/* The on-line guarantee is enabled only if the appropriate flag is set... */ |
static int TBS_level_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
static int TBS_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
|
255,14 → 173,19 |
return 0; |
} |
|
static int TBS_task_create(LEVEL l, PID p, TASK_MODEL *m) |
static int TBS_public_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
|
/* if the TBS_task_create is called, then the pclass must be a |
valid pclass. */ |
SOFT_TASK_MODEL *s = (SOFT_TASK_MODEL *)m; |
SOFT_TASK_MODEL *s; |
|
if (m->pclass != SOFT_PCLASS) return -1; |
if (m->level != 0 && m->level != l) return -1; |
s = (SOFT_TASK_MODEL *)m; |
if (!(s->wcet && s->periodicity == APERIODIC)) return -1; |
|
proc_table[p].wcet = s->wcet; |
|
/* Enable wcet check */ |
278,18 → 201,8 |
return 0; /* OK, also if the task cannot be guaranteed... */ |
} |
|
static void TBS_task_detach(LEVEL l, PID p) |
static void TBS_public_dispatch(LEVEL l, PID p, int nostop) |
{ |
/* the TBS level doesn't introduce any dinamic allocated new field. */ |
} |
|
static int TBS_task_eligible(LEVEL l, PID p) |
{ |
return 0; /* if the task p is chosen, it is always eligible */ |
} |
|
static void TBS_task_dispatch(LEVEL l, PID p, int nostop) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
|
/* there is at least one task ready inserted in an EDF or similar |
296,10 → 209,10 |
level */ |
|
level_table[ lev->scheduling_level ]-> |
guest_dispatch(lev->scheduling_level,p,nostop); |
private_dispatch(lev->scheduling_level,p,nostop); |
} |
|
static void TBS_task_epilogue(LEVEL l, PID p) |
static void TBS_public_epilogue(LEVEL l, PID p) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
|
313,7 → 226,7 |
have to be put in place... this code is identical to the |
TBS_task_end */ |
level_table[ lev->scheduling_level ]-> |
guest_end(lev->scheduling_level,p); |
private_extract(lev->scheduling_level,p); |
|
/* we reclaim an avail time that can be <0 due to the timer |
approximations -> we have to postpone the deadline a little! |
335,18 → 248,22 |
/* the task has been preempted. it returns into the ready queue by |
calling the guest_epilogue... */ |
level_table[ lev->scheduling_level ]-> |
guest_epilogue(lev->scheduling_level,p); |
private_epilogue(lev->scheduling_level,p); |
} |
|
static void TBS_task_activate(LEVEL l, PID p) |
static void TBS_public_activate(LEVEL l, PID p) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
struct timespec t; |
|
if (proc_table[p].status == SLEEP || |
proc_table[p].status == TBS_WCET_VIOLATED) { |
|
ll_gettime(TIME_EXACT, &proc_table[p].request_time); |
|
kern_gettime(&t); |
if (TIMESPEC_A_GT_B(&t, &lev->lastdline)) |
TIMESPEC_ASSIGN(&lev->lastdline, &t ); |
|
|
if (lev->activated == NIL) { |
/* This is the first task in the level, so we activate it immediately */ |
lev->activated = p; |
363,23 → 280,25 |
kern_printf("TBSREJ!!!");*/ |
} |
|
static void TBS_task_insert(LEVEL l, PID p) |
static void TBS_public_unblock(LEVEL l, PID p) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
JOB_TASK_MODEL j; |
|
level_table[ lev->scheduling_level ]-> |
guest_insert(lev->scheduling_level,p); |
job_task_default_model(j,lev->lastdline); |
level_table[lev->scheduling_level]-> |
private_insert(lev->scheduling_level,p,(TASK_MODEL *)&j); |
} |
|
static void TBS_task_extract(LEVEL l, PID p) |
static void TBS_public_block(LEVEL l, PID p) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
|
level_table[ lev->scheduling_level ]-> |
guest_extract(lev->scheduling_level,p); |
private_extract(lev->scheduling_level,p); |
} |
|
static void TBS_task_endcycle(LEVEL l, PID p) |
static int TBS_public_message(LEVEL l, PID p, void *m) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
|
387,7 → 306,7 |
that implements a single activation, so we have to call |
the guest_end, that representsa single activation... */ |
level_table[ lev->scheduling_level ]-> |
guest_end(lev->scheduling_level,p); |
private_extract(lev->scheduling_level,p); |
|
TBS_bandwidth_reclaiming(lev,p); |
|
408,14 → 327,18 |
if (lev->activated != NIL) |
TBS_activation(lev); |
|
jet_update_endcycle(); /* Update the Jet data... */ |
trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */ |
|
return 0; |
} |
|
static void TBS_task_end(LEVEL l, PID p) |
static void TBS_public_end(LEVEL l, PID p) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
|
level_table[ lev->scheduling_level ]-> |
guest_end(lev->scheduling_level,p); |
private_extract(lev->scheduling_level,p); |
|
TBS_bandwidth_reclaiming(lev,p); |
|
427,65 → 350,6 |
TBS_activation(lev); |
} |
|
static void TBS_task_sleep(LEVEL l, PID p) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
|
/* a task activation is finished, but we are using a JOB_TASK_MODEL |
that implements a single activation, so we have to call |
the guest_end, that representsa single activation... */ |
level_table[ lev->scheduling_level ]-> |
guest_end(lev->scheduling_level,p); |
|
TBS_bandwidth_reclaiming(lev,p); |
|
/* we reset the capacity counters... */ |
if (lev->flags & TBS_ENABLE_WCET_CHECK) |
proc_table[p].avail_time = proc_table[p].wcet; |
|
proc_table[p].status = SLEEP; |
|
lev->nact[p] = 0; |
|
lev->activated = iq_getfirst(&lev->wait); |
if (lev->activated != NIL) |
TBS_activation(lev); |
|
} |
|
static int TBS_guest_create(LEVEL l, PID p, TASK_MODEL *m) |
{ kern_raise(XINVALID_GUEST,exec_shadow); return 0; } |
|
static void TBS_guest_detach(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void TBS_guest_dispatch(LEVEL l, PID p, int nostop) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void TBS_guest_epilogue(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void TBS_guest_activate(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void TBS_guest_insert(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void TBS_guest_extract(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void TBS_guest_endcycle(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void TBS_guest_end(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void TBS_guest_sleep(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
|
|
|
/* Registration functions */ |
|
/*+ Registration function: |
499,56 → 363,28 |
printk("TBS_register_level\n"); |
|
/* request an entry in the level_table */ |
l = level_alloc_descriptor(); |
l = level_alloc_descriptor(sizeof(TBS_level_des)); |
|
printk(" alloco descrittore %d %d\n",l,(int)sizeof(TBS_level_des)); |
lev = (TBS_level_des *)level_table[l]; |
|
/* alloc the space needed for the TBS_level_des */ |
lev = (TBS_level_des *)kern_alloc(sizeof(TBS_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, TBS_LEVELNAME, MAX_LEVELNAME); |
lev->l.level_code = TBS_LEVEL_CODE; |
lev->l.level_version = TBS_LEVEL_VERSION; |
|
lev->l.level_accept_task_model = TBS_level_accept_task_model; |
lev->l.level_accept_guest_model = TBS_level_accept_guest_model; |
lev->l.level_status = TBS_level_status; |
lev->l.level_scheduler = TBS_level_scheduler; |
|
if (flags & TBS_ENABLE_GUARANTEE) |
lev->l.level_guarantee = TBS_level_guarantee; |
lev->l.public_guarantee = TBS_public_guarantee; |
else |
lev->l.level_guarantee = NULL; |
lev->l.public_guarantee = NULL; |
|
lev->l.task_create = TBS_task_create; |
lev->l.task_detach = TBS_task_detach; |
lev->l.task_eligible = TBS_task_eligible; |
lev->l.task_dispatch = TBS_task_dispatch; |
lev->l.task_epilogue = TBS_task_epilogue; |
lev->l.task_activate = TBS_task_activate; |
lev->l.task_insert = TBS_task_insert; |
lev->l.task_extract = TBS_task_extract; |
lev->l.task_endcycle = TBS_task_endcycle; |
lev->l.task_end = TBS_task_end; |
lev->l.task_sleep = TBS_task_sleep; |
lev->l.public_guarantee = TBS_public_guarantee; |
lev->l.public_create = TBS_public_create; |
lev->l.public_end = TBS_public_end; |
lev->l.public_dispatch = TBS_public_dispatch; |
lev->l.public_epilogue = TBS_public_epilogue; |
lev->l.public_activate = TBS_public_activate; |
lev->l.public_unblock = TBS_public_unblock; |
lev->l.public_block = TBS_public_block; |
lev->l.public_message = TBS_public_message; |
|
lev->l.guest_create = TBS_guest_create; |
lev->l.guest_detach = TBS_guest_detach; |
lev->l.guest_dispatch = TBS_guest_dispatch; |
lev->l.guest_epilogue = TBS_guest_epilogue; |
lev->l.guest_activate = TBS_guest_activate; |
lev->l.guest_insert = TBS_guest_insert; |
lev->l.guest_extract = TBS_guest_extract; |
lev->l.guest_endcycle = TBS_guest_endcycle; |
lev->l.guest_end = TBS_guest_end; |
lev->l.guest_sleep = TBS_guest_sleep; |
|
/* fill the TBS descriptor part */ |
|
for (i = 0; i < MAX_PROC; i++) { |
573,20 → 409,14 |
bandwidth_t TBS_usedbandwidth(LEVEL l) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
if (lev->l.level_code == TBS_LEVEL_CODE && |
lev->l.level_version == TBS_LEVEL_VERSION) |
return lev->U; |
else |
return 0; |
|
return lev->U; |
} |
|
int TBS_get_nact(LEVEL l, PID p) |
{ |
TBS_level_des *lev = (TBS_level_des *)(level_table[l]); |
if (lev->l.level_code == TBS_LEVEL_CODE && |
lev->l.level_version == TBS_LEVEL_VERSION) |
return lev->nact[p]; |
else |
return -1; |
|
return lev->nact[p]; |
} |
|