Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1085 → Rev 1124

/demos/tags/rel_0_3/cbs_ft/cbs_ft.c
15,11 → 15,11
 
/**
------------
CVS : $Id: cbs_ft.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
CVS : $Id: cbs_ft.c,v 1.4 2003-01-07 17:10:16 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:41 $
Revision: $Revision: 1.4 $
Last update: $Date: 2003-01-07 17:10:16 $
------------
 
This file contains the server CBS_FT
50,22 → 50,9
 
#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 +*/
#define CBS_FT_DELAY APER_STATUS_BASE+2 /*+ waiting the delay end +*/
 
/* structure of an element of the capacity queue */
struct cap_queue {
141,7 → 128,7
new = (struct cap_queue *)kern_alloc(sizeof(struct cap_queue));
if (new == NULL) {
kern_printf("\nNew cash_queue element failed\n");
kern_raise(XUNVALID_TASK, p);
kern_raise(XINVALID_TASK, p);
return -1;
}
new->next = NULL;
242,7 → 229,7
/* If the budget is still less than 0, an exception is raised */
if (proc_table[p].avail_time <= 0) {
kern_printf("\nnegative value for the budget!\n");
kern_raise(XUNVALID_TASK, p);
kern_raise(XINVALID_TASK, p);
return;
}
 
276,33 → 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";
case CBS_FT_DELAY : return "CBS_FT_Delay";
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];
 
311,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 */
319,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;
 
352,7 → 322,7
else {
/* this situation cannot occur */
kern_printf("\nTrying to reactivate a primary task which is not IDLE!\n");
kern_raise(XUNVALID_TASK,p);
kern_raise(XINVALID_TASK,p);
}
}
 
435,7 → 405,7
 
/* we finally put the task in the FREE status */
proc_table[p].status = FREE;
q_insertfirst(p,&freedesc);
iq_insertfirst(p,&freedesc);
 
 
/* and free the allocated bandwidth */
442,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...
512,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]);
 
533,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;
 
585,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
600,37 → 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 */
}
 
#ifdef __TEST1__
extern int testactive;
extern struct timespec s_stime[];
extern TIME s_curr[];
extern TIME s_PID[];
extern int useds;
#endif
 
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);
 
#ifdef __TEST1__
if (testactive)
{
TIMESPEC_ASSIGN(&s_stime[useds], &schedule_time);
s_curr[useds] = proc_table[p].avail_time;
s_PID[useds] = p;
useds++;
}
#endif
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]);
 
643,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;
}
 
653,11 → 552,11
/* The budget must be greater than 0! */
if (proc_table[p].avail_time <= 0) {
kern_printf("\nBackup task starting with exhausted budget\n");
kern_raise(XUNVALID_TASK, p);
kern_raise(XINVALID_TASK, p);
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;
}
}
665,21 → 564,20
/* 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(XUNVALID_TASK, p);
kern_raise(XINVALID_TASK, p);
}
else {
689,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;
709,7 → 607,7
}
}
CBS_FT_activation(lev, p, &proc_table[p].request_time);
CBS_FT_activation(lev, p, &t);
/* Set the reactivation timer */
722,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(XUNVALID_TASK,p);
}
 
 
static void CBS_FT_task_extract(LEVEL l, PID p)
{
printk("CBS_FT_task_extract\n");
kern_raise(XUNVALID_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;
763,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!! */
787,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]);
 
798,7 → 684,7
in a new release */
if (lev->P_or_B[p] == BACKUP) {
kern_printf("\nKilling a BACKUP task!\n");
kern_raise(XUNVALID_TASK, p);
kern_raise(XINVALID_TASK, p);
return;
}
 
812,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;
 
828,62 → 714,11
(void *)p);
}
 
 
static void CBS_FT_task_sleep(LEVEL l, PID p)
{
printk("CBS_FT_task_sleep\n");
kern_raise(XUNVALID_TASK,p);
}
 
 
static void CBS_FT_task_delay(LEVEL l, PID p, TIME usdelay)
{
printk("CBS_FT_task_delay\n");
kern_raise(XUNVALID_TASK,p);
}
 
 
static int CBS_FT_guest_create(LEVEL l, PID p, TASK_MODEL *m)
{ kern_raise(XUNVALID_GUEST,exec_shadow); return 0; }
 
static void CBS_FT_guest_detach(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_dispatch(LEVEL l, PID p, int nostop)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_epilogue(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_activate(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_insert(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_extract(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_endcycle(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_end(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_sleep(LEVEL l, PID p)
{ kern_raise(XUNVALID_GUEST,exec_shadow); }
 
static void CBS_FT_guest_delay(LEVEL l, PID p,DWORD tickdelay)
{ kern_raise(XUNVALID_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 */
892,58 → 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.task_delay = CBS_FT_task_delay;
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;
lev->l.guest_delay = CBS_FT_guest_delay;
 
/* fill the CBS_FT descriptor part */
for (i=0; i<MAX_PROC; i++) {
NULL_TIMESPEC(&lev->cbs_ft_dline[i]);
963,6 → 768,8
lev->scheduling_level = master;
 
lev->flags = flags & 0x07;
 
return l;
}
 
 
969,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;
}
 
 
/demos/tags/rel_0_3/cbs_ft/cbs_ft.h
15,11 → 15,11
 
/**
------------
CVS : $Id: cbs_ft.h,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
CVS : $Id: cbs_ft.h,v 1.2 2003-01-07 17:10:16 pj Exp $
 
File: $File$
Revision: $Revision: 1.1.1.1 $
Last update: $Date: 2002-09-02 09:37:41 $
Revision: $Revision: 1.2 $
Last update: $Date: 2003-01-07 17:10:16 $
------------
 
This file contains the server CBS_FT
57,6 → 57,7
#include <kernel/descr.h>
#include <kernel/var.h>
#include <kernel/func.h>
#include <kernel/trace.h>
 
 
 
133,7 → 134,7
#define ft_task_def_primary_exec(m,b) (m).execP = b
 
/************************************************************************/
void CBS_FT_register_level(int flags, LEVEL master);
LEVEL CBS_FT_register_level(int flags, LEVEL master);
 
 
bandwidth_t CBS_FT_usedbandwidth(LEVEL l);