Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1123 → Rev 1115

/demos/trunk/cbs_ft/cbs_ft.c
15,11 → 15,11
 
/**
------------
CVS : $Id: cbs_ft.c,v 1.4 2003-01-07 17:10:16 pj Exp $
CVS : $Id: cbs_ft.c,v 1.3 2002-11-11 08:14:22 pj Exp $
 
File: $File$
Revision: $Revision: 1.4 $
Last update: $Date: 2003-01-07 17:10:16 $
Revision: $Revision: 1.3 $
Last update: $Date: 2002-11-11 08:14:22 $
------------
 
This file contains the server CBS_FT
50,6 → 50,18
 
#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 +*/
263,16 → 275,32
job_task_default_model(job, lev->cbs_ft_dline[p]);
job_task_def_yesexc(job);
level_table[ lev->scheduling_level ]->
private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job);
guest_create(lev->scheduling_level, p, (TASK_MODEL *)&job);
level_table[ lev->scheduling_level ]->
guest_activate(lev->scheduling_level, p);
}
 
 
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];
 
281,7 → 309,7
reactivated */
/* request_time represents the time of the last instance release!! */
TIMESPEC_ASSIGN(&t, &lev->reactivation_time[p]);
TIMESPEC_ASSIGN(&proc_table[p].request_time, &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 */
289,7 → 317,7
TIME interval;
struct timespec delta;
lev->idle = 0;
SUBTIMESPEC(&t, &lev->start_idle, &delta);
SUBTIMESPEC(&proc_table[p].request_time, &lev->start_idle, &delta);
/* length of the idle interval expressed in usec! */
interval = TIMESPEC2NANOSEC(&delta) / 1000;
 
412,14 → 440,67
lev->U -= (MAX_BANDWIDTH / lev->period[p]) * (TIME)lev->maxcap[p];
}
 
static PID CBS_FT_public_scheduler(LEVEL l)
 
static int CBS_FT_level_accept_task_model(LEVEL l, TASK_MODEL *m)
{
 
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;
kern_gettime(&lev->start_idle);
ll_gettime(TIME_EXACT, &lev->start_idle);
 
/* the CBS_FT don't schedule anything...
429,7 → 510,7
 
 
/* The on-line guarantee is enabled only if the appropriate flag is set... */
static int CBS_FT_public_guarantee(LEVEL l, bandwidth_t *freebandwidth)
static int CBS_FT_level_guarantee(LEVEL l, bandwidth_t *freebandwidth)
{
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]);
 
450,22 → 531,17
}
 
 
static int CBS_FT_public_create(LEVEL l, PID p, TASK_MODEL *m)
static int CBS_FT_task_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 (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 */
/* if the CBS_FT_task_create is called, then the pclass must be a
valid pclass. */
FT_TASK_MODEL *s = (FT_TASK_MODEL *)m;
 
/* Enable budget check */
proc_table[p].control |= CONTROL_CAP;
 
507,7 → 583,7
}
 
 
static void CBS_FT_public_detach(LEVEL l, PID p)
static void CBS_FT_task_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
522,14 → 598,19
}
 
 
static void CBS_FT_public_dispatch(LEVEL l, PID p, int nostop)
static int CBS_FT_task_eligible(LEVEL l, PID p)
{
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 ]->
private_dispatch(lev->scheduling_level,p,nostop);
guest_dispatch(lev->scheduling_level,p,nostop);
}
 
static void CBS_FT_public_epilogue(LEVEL l, PID p)
static void CBS_FT_task_epilogue(LEVEL l, PID p)
{
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]);
 
542,7 → 623,7
kern_raise(XWCET_VIOLATION,p);
/* we kill the current activation */
level_table[ lev->scheduling_level ]->
private_extract(lev->scheduling_level, p);
guest_end(lev->scheduling_level, p);
return;
}
 
556,7 → 637,7
lev->CP[p] = 0;
/* we kill the current activation */
level_table[ lev->scheduling_level ]->
private_extract(lev->scheduling_level, p);
guest_end(lev->scheduling_level, p);
return;
}
}
564,17 → 645,18
/* the task returns into the ready queue by
calling the guest_epilogue... */
level_table[ lev->scheduling_level ]->
private_epilogue(lev->scheduling_level,p);
guest_epilogue(lev->scheduling_level,p);
}
 
 
static void CBS_FT_public_activate(LEVEL l, PID p)
static void CBS_FT_task_activate(LEVEL l, PID p)
{
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]);
struct timespec t;
 
kern_gettime(&t);
ll_gettime(TIME_EXACT, &proc_table[p].request_time);
 
 
if (lev->P_or_B[p] == BACKUP) {
kern_printf("\nTrying to activate a BACKUP task!\n");
kern_raise(XINVALID_TASK, p);
587,7 → 669,7
TIME interval;
struct timespec delta;
lev->idle = 0;
SUBTIMESPEC(&t, &lev->start_idle, &delta);
SUBTIMESPEC(&proc_table[p].request_time, &lev->start_idle, &delta);
/* length of the idle interval expressed in usec! */
interval = TIMESPEC2NANOSEC(&delta) / 1000;
607,7 → 689,7
}
}
CBS_FT_activation(lev, p, &t);
CBS_FT_activation(lev, p, &proc_table[p].request_time);
/* Set the reactivation timer */
620,13 → 702,28
}
}
 
static int CBS_FT_public_message(LEVEL l, PID p, void *m)
 
static void CBS_FT_task_insert(LEVEL l, PID p)
{
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 ]->
private_extract(lev->scheduling_level,p);
guest_end(lev->scheduling_level,p);
 
proc_table[p].status = CBS_FT_IDLE;
646,8 → 743,10
job_task_default_model(job, lev->cbs_ft_dline[p]);
job_task_def_yesexc(job);
level_table[ lev->scheduling_level ]->
private_insert(lev->scheduling_level, lev->backup[p],
guest_create(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!! */
668,15 → 767,10
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_public_end(LEVEL l, PID p)
static void CBS_FT_task_end(LEVEL l, PID p)
{
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]);
 
698,11 → 792,11
}
level_table[ lev->scheduling_level ]->
private_extract(lev->scheduling_level,p);
guest_end(lev->scheduling_level,p);
 
 
/* we delete the reactivation timer */
kern_event_delete(lev->reactivation_timer[p]);
event_delete(lev->reactivation_timer[p]);
lev->reactivation_timer[p] = -1;
 
714,11 → 808,52
(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 +*/
LEVEL CBS_FT_register_level(int flags, LEVEL master)
void CBS_FT_register_level(int flags, LEVEL master)
{
LEVEL l; /* the level that we register */
CBS_FT_level_des *lev; /* for readableness only */
727,28 → 862,56
printk("CBS_FT_register_level\n");
 
/* request an entry in the level_table */
l = level_alloc_descriptor(sizeof(CBS_FT_level_des));
l = level_alloc_descriptor();
 
lev = (CBS_FT_level_des *)level_table[l];
printk(" alloco descrittore %d %d\n",l,sizeof(CBS_FT_level_des));
 
/* 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 */
lev->l.public_scheduler = CBS_FT_public_scheduler;
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.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.public_guarantee = CBS_FT_public_guarantee;
lev->l.level_guarantee = CBS_FT_level_guarantee;
else
lev->l.public_guarantee = NULL;
lev->l.level_guarantee = NULL;
 
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.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.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]);
768,8 → 931,6
lev->scheduling_level = master;
 
lev->flags = flags & 0x07;
 
return l;
}
 
 
776,9 → 937,13
 
bandwidth_t CBS_FT_usedbandwidth(LEVEL l)
{
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]);
 
return lev->U;
if (lev->l.level_code == CBS_FT_LEVEL_CODE &&
lev->l.level_version == CBS_FT_LEVEL_VERSION)
return lev->U;
else
return 0;
}
 
 
/demos/trunk/cbs_ft/cbs_ft.h
15,11 → 15,11
 
/**
------------
CVS : $Id: cbs_ft.h,v 1.2 2003-01-07 17:10:16 pj Exp $
CVS : $Id: cbs_ft.h,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
 
File: $File$
Revision: $Revision: 1.2 $
Last update: $Date: 2003-01-07 17:10:16 $
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:41 $
------------
 
This file contains the server CBS_FT
57,7 → 57,6
#include <kernel/descr.h>
#include <kernel/var.h>
#include <kernel/func.h>
#include <kernel/trace.h>
 
 
 
134,7 → 133,7
#define ft_task_def_primary_exec(m,b) (m).execP = b
 
/************************************************************************/
LEVEL CBS_FT_register_level(int flags, LEVEL master);
void CBS_FT_register_level(int flags, LEVEL master);
 
 
bandwidth_t CBS_FT_usedbandwidth(LEVEL l);