15,11 → 15,11 |
|
/** |
------------ |
CVS : $Id: cbs_ft.c,v 1.3 2002-11-11 08:14:22 pj Exp $ |
CVS : $Id: cbs_ft.c,v 1.4 2003-01-07 17:10:16 pj Exp $ |
|
File: $File$ |
Revision: $Revision: 1.3 $ |
Last update: $Date: 2002-11-11 08:14:22 $ |
Revision: $Revision: 1.4 $ |
Last update: $Date: 2003-01-07 17:10:16 $ |
------------ |
|
This file contains the server CBS_FT |
50,18 → 50,6 |
|
#include "cbs_ft.h" |
|
/*+ 4 debug purposes +*/ |
#undef CBS_FT_TEST |
|
#ifdef TESTG |
#include "drivers/glib.h" |
TIME x,oldx; |
extern TIME starttime; |
#endif |
|
|
|
|
/*+ Status used in the level +*/ |
#define CBS_FT_IDLE APER_STATUS_BASE /*+ waiting the activation +*/ |
#define CBS_FT_ZOMBIE APER_STATUS_BASE+1 /*+ waiting the period end +*/ |
275,32 → 263,16 |
job_task_default_model(job, lev->cbs_ft_dline[p]); |
job_task_def_yesexc(job); |
level_table[ lev->scheduling_level ]-> |
guest_create(lev->scheduling_level, p, (TASK_MODEL *)&job); |
level_table[ lev->scheduling_level ]-> |
guest_activate(lev->scheduling_level, p); |
private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
} |
|
|
static char *CBS_FT_status_to_a(WORD status) |
{ |
if (status < MODULE_STATUS_BASE) |
return status_to_a(status); |
|
switch (status) { |
case CBS_FT_IDLE : return "CBS_FT_Idle"; |
case CBS_FT_ZOMBIE : return "CBS_FT_Zombie"; |
default : return "CBS_FT_Unknown"; |
} |
} |
|
|
|
|
/* this is the periodic reactivation of the task... */ |
static void CBS_FT_timer_reactivate(void *par) |
{ |
PID p = (PID) par; |
CBS_FT_level_des *lev; |
struct timespec t; |
|
lev = (CBS_FT_level_des *)level_table[proc_table[p].task_level]; |
|
309,7 → 281,7 |
reactivated */ |
|
/* request_time represents the time of the last instance release!! */ |
TIMESPEC_ASSIGN(&proc_table[p].request_time, &lev->reactivation_time[p]); |
TIMESPEC_ASSIGN(&t, &lev->reactivation_time[p]); |
|
/* If idle=1, then we have to discharge the capacities stored in |
the capacity queue up to the length of the idle interval */ |
317,7 → 289,7 |
TIME interval; |
struct timespec delta; |
lev->idle = 0; |
SUBTIMESPEC(&proc_table[p].request_time, &lev->start_idle, &delta); |
SUBTIMESPEC(&t, &lev->start_idle, &delta); |
/* length of the idle interval expressed in usec! */ |
interval = TIMESPEC2NANOSEC(&delta) / 1000; |
|
440,67 → 412,14 |
lev->U -= (MAX_BANDWIDTH / lev->period[p]) * (TIME)lev->maxcap[p]; |
} |
|
|
static int CBS_FT_level_accept_task_model(LEVEL l, TASK_MODEL *m) |
static PID CBS_FT_public_scheduler(LEVEL l) |
{ |
|
if (m->pclass == FT_PCLASS || m->pclass == |
(FT_PCLASS | l)) { |
FT_TASK_MODEL *f = (FT_TASK_MODEL *) m; |
|
//kern_printf("accept :FAULT TOLERANT TASK found!!!!!!\n"); */ |
if (f->type == PRIMARY && f->execP > 0 && f->budget < (int)f->period |
&& f->backup != NIL) return 0; |
if (f->type == BACKUP && f->wcetB > 0) |
return 0; |
} |
return -1; |
} |
|
|
|
static int CBS_FT_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 CBS_FT_level_status(LEVEL l) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
PID p; |
|
kern_printf("On-line guarantee : %s\n", |
onoff(lev->flags & CBS_FT_ENABLE_GUARANTEE)); |
kern_printf("Used Bandwidth : %u/%u\n", |
lev->U, MAX_BANDWIDTH); |
|
for (p=0; p<MAX_PROC; p++) |
if (proc_table[p].task_level == l && proc_table[p].status != FREE ) |
kern_printf("Pid: %2d Name: %10s Period: %9ld Dline: %9ld.%6ld Stat: %s\n", |
p, |
proc_table[p].name, |
lev->period[p], |
lev->cbs_ft_dline[p].tv_sec, |
lev->cbs_ft_dline[p].tv_nsec/1000, |
CBS_FT_status_to_a(proc_table[p].status)); |
} |
|
static PID CBS_FT_level_scheduler(LEVEL l) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
|
/* it stores the actual time and set the IDLE flag in order to handle |
the capacity queue discharging!!! */ |
lev->idle = 1; |
ll_gettime(TIME_EXACT, &lev->start_idle); |
kern_gettime(&lev->start_idle); |
|
|
/* the CBS_FT don't schedule anything... |
510,7 → 429,7 |
|
|
/* The on-line guarantee is enabled only if the appropriate flag is set... */ |
static int CBS_FT_level_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
static int CBS_FT_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
|
531,17 → 450,22 |
} |
|
|
static int CBS_FT_task_create(LEVEL l, PID p, TASK_MODEL *m) |
static int CBS_FT_public_create(LEVEL l, PID p, TASK_MODEL *m) |
|
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
FT_TASK_MODEL *s; |
|
/* if the CBS_FT_task_create is called, then the pclass must be a |
valid pclass. */ |
FT_TASK_MODEL *s = (FT_TASK_MODEL *)m; |
|
if (m->pclass != FT_PCLASS) return -1; |
if (m->level != 0 && m->level != l) return -1; |
s = (FT_TASK_MODEL *) m; |
//kern_printf("accept :FAULT TOLERANT TASK found!!!!!!\n"); */ |
if (!(s->type == PRIMARY && s->execP > 0 && s->budget < (int)s->period |
&& s->backup != NIL)) return -1; |
if (!(s->type == BACKUP && s->wcetB > 0)) |
return -1; |
/* now we know that m is a valid model */ |
|
|
/* Enable budget check */ |
proc_table[p].control |= CONTROL_CAP; |
|
583,7 → 507,7 |
} |
|
|
static void CBS_FT_task_detach(LEVEL l, PID p) |
static void CBS_FT_public_detach(LEVEL l, PID p) |
{ |
/* the CBS_FT level doesn't introduce any dynamic allocated new field. |
we have only to reset the NO_GUARANTEE FIELD and decrement the allocated |
598,19 → 522,14 |
} |
|
|
static int CBS_FT_task_eligible(LEVEL l, PID p) |
static void CBS_FT_public_dispatch(LEVEL l, PID p, int nostop) |
{ |
return 0; /* if the task p is chosen, it is always eligible */ |
} |
|
static void CBS_FT_task_dispatch(LEVEL l, PID p, int nostop) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
level_table[ lev->scheduling_level ]-> |
guest_dispatch(lev->scheduling_level,p,nostop); |
private_dispatch(lev->scheduling_level,p,nostop); |
} |
|
static void CBS_FT_task_epilogue(LEVEL l, PID p) |
static void CBS_FT_public_epilogue(LEVEL l, PID p) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
|
623,7 → 542,7 |
kern_raise(XWCET_VIOLATION,p); |
/* we kill the current activation */ |
level_table[ lev->scheduling_level ]-> |
guest_end(lev->scheduling_level, p); |
private_extract(lev->scheduling_level, p); |
return; |
} |
|
637,7 → 556,7 |
lev->CP[p] = 0; |
/* we kill the current activation */ |
level_table[ lev->scheduling_level ]-> |
guest_end(lev->scheduling_level, p); |
private_extract(lev->scheduling_level, p); |
return; |
} |
} |
645,18 → 564,17 |
/* the task 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 CBS_FT_task_activate(LEVEL l, PID p) |
static void CBS_FT_public_activate(LEVEL l, PID p) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
struct timespec t; |
|
ll_gettime(TIME_EXACT, &proc_table[p].request_time); |
kern_gettime(&t); |
|
|
|
if (lev->P_or_B[p] == BACKUP) { |
kern_printf("\nTrying to activate a BACKUP task!\n"); |
kern_raise(XINVALID_TASK, p); |
669,7 → 587,7 |
TIME interval; |
struct timespec delta; |
lev->idle = 0; |
SUBTIMESPEC(&proc_table[p].request_time, &lev->start_idle, &delta); |
SUBTIMESPEC(&t, &lev->start_idle, &delta); |
/* length of the idle interval expressed in usec! */ |
interval = TIMESPEC2NANOSEC(&delta) / 1000; |
|
689,7 → 607,7 |
} |
} |
|
CBS_FT_activation(lev, p, &proc_table[p].request_time); |
CBS_FT_activation(lev, p, &t); |
|
|
/* Set the reactivation timer */ |
702,28 → 620,13 |
} |
} |
|
|
static void CBS_FT_task_insert(LEVEL l, PID p) |
static int CBS_FT_public_message(LEVEL l, PID p, void *m) |
{ |
printk("CBS_FT_task_insert\n"); |
kern_raise(XINVALID_TASK,p); |
} |
|
|
static void CBS_FT_task_extract(LEVEL l, PID p) |
{ |
printk("CBS_FT_task_extract\n"); |
kern_raise(XINVALID_TASK,p); |
} |
|
|
static void CBS_FT_task_endcycle(LEVEL l, PID p) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
|
|
level_table[ lev->scheduling_level ]-> |
guest_end(lev->scheduling_level,p); |
private_extract(lev->scheduling_level,p); |
|
|
proc_table[p].status = CBS_FT_IDLE; |
743,10 → 646,8 |
job_task_default_model(job, lev->cbs_ft_dline[p]); |
job_task_def_yesexc(job); |
level_table[ lev->scheduling_level ]-> |
guest_create(lev->scheduling_level, lev->backup[p], |
private_insert(lev->scheduling_level, lev->backup[p], |
(TASK_MODEL *)&job); |
level_table[ lev->scheduling_level ]-> |
guest_activate(lev->scheduling_level, lev->backup[p]); |
} |
else { |
/* A spare capacity is inserted in the capacity queue!! */ |
767,10 → 668,15 |
proc_table[p].avail_time = 0; |
} |
} |
|
jet_update_endcycle(); /* Update the Jet data... */ |
trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */ |
|
return 0; |
} |
|
|
static void CBS_FT_task_end(LEVEL l, PID p) |
static void CBS_FT_public_end(LEVEL l, PID p) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
|
792,11 → 698,11 |
} |
|
level_table[ lev->scheduling_level ]-> |
guest_end(lev->scheduling_level,p); |
private_extract(lev->scheduling_level,p); |
|
|
/* we delete the reactivation timer */ |
event_delete(lev->reactivation_timer[p]); |
kern_event_delete(lev->reactivation_timer[p]); |
lev->reactivation_timer[p] = -1; |
|
|
808,52 → 714,11 |
(void *)p); |
} |
|
|
static void CBS_FT_task_sleep(LEVEL l, PID p) |
{ |
printk("CBS_FT_task_sleep\n"); |
kern_raise(XINVALID_TASK,p); |
} |
|
|
static int CBS_FT_guest_create(LEVEL l, PID p, TASK_MODEL *m) |
{ kern_raise(XINVALID_GUEST,exec_shadow); return 0; } |
|
static void CBS_FT_guest_detach(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void CBS_FT_guest_dispatch(LEVEL l, PID p, int nostop) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void CBS_FT_guest_epilogue(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void CBS_FT_guest_activate(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void CBS_FT_guest_insert(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void CBS_FT_guest_extract(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void CBS_FT_guest_endcycle(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void CBS_FT_guest_end(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
static void CBS_FT_guest_sleep(LEVEL l, PID p) |
{ kern_raise(XINVALID_GUEST,exec_shadow); } |
|
|
|
|
/* Registration functions */ |
|
/*+ Registration function: |
int flags the init flags ... see CBS.h +*/ |
void CBS_FT_register_level(int flags, LEVEL master) |
LEVEL CBS_FT_register_level(int flags, LEVEL master) |
{ |
LEVEL l; /* the level that we register */ |
CBS_FT_level_des *lev; /* for readableness only */ |
862,56 → 727,28 |
printk("CBS_FT_register_level\n"); |
|
/* request an entry in the level_table */ |
l = level_alloc_descriptor(); |
l = level_alloc_descriptor(sizeof(CBS_FT_level_des)); |
|
printk(" alloco descrittore %d %d\n",l,sizeof(CBS_FT_level_des)); |
lev = (CBS_FT_level_des *)level_table[l]; |
|
/* alloc the space needed for the CBS_FT_level_des */ |
lev = (CBS_FT_level_des *)kern_alloc(sizeof(CBS_FT_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, CBS_FT_LEVELNAME, MAX_LEVELNAME); |
lev->l.level_code = CBS_FT_LEVEL_CODE; |
lev->l.level_version = CBS_FT_LEVEL_VERSION; |
lev->l.public_scheduler = CBS_FT_public_scheduler; |
|
lev->l.level_accept_task_model = CBS_FT_level_accept_task_model; |
lev->l.level_accept_guest_model = CBS_FT_level_accept_guest_model; |
lev->l.level_status = CBS_FT_level_status; |
lev->l.level_scheduler = CBS_FT_level_scheduler; |
|
if (flags & CBS_FT_ENABLE_GUARANTEE) |
lev->l.level_guarantee = CBS_FT_level_guarantee; |
lev->l.public_guarantee = CBS_FT_public_guarantee; |
else |
lev->l.level_guarantee = NULL; |
lev->l.public_guarantee = NULL; |
|
lev->l.task_create = CBS_FT_task_create; |
lev->l.task_detach = CBS_FT_task_detach; |
lev->l.task_eligible = CBS_FT_task_eligible; |
lev->l.task_dispatch = CBS_FT_task_dispatch; |
lev->l.task_epilogue = CBS_FT_task_epilogue; |
lev->l.task_activate = CBS_FT_task_activate; |
lev->l.task_insert = CBS_FT_task_insert; |
lev->l.task_extract = CBS_FT_task_extract; |
lev->l.task_endcycle = CBS_FT_task_endcycle; |
lev->l.task_end = CBS_FT_task_end; |
lev->l.task_sleep = CBS_FT_task_sleep; |
lev->l.public_create = CBS_FT_public_create; |
lev->l.public_detach = CBS_FT_public_detach; |
lev->l.public_end = CBS_FT_public_end; |
lev->l.public_dispatch = CBS_FT_public_dispatch; |
lev->l.public_epilogue = CBS_FT_public_epilogue; |
lev->l.public_activate = CBS_FT_public_activate; |
lev->l.public_message = CBS_FT_public_message; |
|
lev->l.guest_create = CBS_FT_guest_create; |
lev->l.guest_detach = CBS_FT_guest_detach; |
lev->l.guest_dispatch = CBS_FT_guest_dispatch; |
lev->l.guest_epilogue = CBS_FT_guest_epilogue; |
lev->l.guest_activate = CBS_FT_guest_activate; |
lev->l.guest_insert = CBS_FT_guest_insert; |
lev->l.guest_extract = CBS_FT_guest_extract; |
lev->l.guest_endcycle = CBS_FT_guest_endcycle; |
lev->l.guest_end = CBS_FT_guest_end; |
lev->l.guest_sleep = CBS_FT_guest_sleep; |
|
/* fill the CBS_FT descriptor part */ |
for (i=0; i<MAX_PROC; i++) { |
NULL_TIMESPEC(&lev->cbs_ft_dline[i]); |
931,6 → 768,8 |
lev->scheduling_level = master; |
|
lev->flags = flags & 0x07; |
|
return l; |
} |
|
|
937,13 → 776,9 |
|
bandwidth_t CBS_FT_usedbandwidth(LEVEL l) |
{ |
|
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
if (lev->l.level_code == CBS_FT_LEVEL_CODE && |
lev->l.level_version == CBS_FT_LEVEL_VERSION) |
return lev->U; |
else |
return 0; |
|
return lev->U; |
} |
|
|