Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1107 → Rev 1123

/demos/trunk/edfact/edfact.c
18,11 → 18,11
 
/**
------------
CVS : $Id: edfact.c,v 1.3 2002-11-11 07:55:55 pj Exp $
CVS : $Id: edfact.c,v 1.4 2003-01-07 17:10:16 pj Exp $
 
File: $File$
Revision: $Revision: 1.3 $
Last update: $Date: 2002-11-11 07:55:55 $
Revision: $Revision: 1.4 $
Last update: $Date: 2003-01-07 17:10:16 $
------------
**/
 
95,14 → 95,14
 
static void EDFACT_timer_deadline(void *par);
 
static void EDFACT_internal_activate(EDFACT_level_des *lev, PID p)
static void EDFACT_internal_activate(EDFACT_level_des *lev, PID p,
struct timespec *t)
{
struct timespec *temp;
 
temp = iq_query_timespec(p, &lev->ready);
 
TIMESPEC_ASSIGN(temp,
&proc_table[p].request_time);
TIMESPEC_ASSIGN(temp,t);
ADDUSEC2TIMESPEC(lev->period[p], temp);
 
TIMESPEC_ASSIGN(&lev->deadline_timespec[p],
116,18 → 116,6
proc_table[p].control |= CONTROL_CAP;
}
 
static char *EDFACT_status_to_a(WORD status)
{
if (status < MODULE_STATUS_BASE)
return status_to_a(status);
 
switch (status) {
case EDFACT_READY : return "EDFACT_Ready";
case EDFACT_IDLE : return "EDFACT_Idle";
default : return "EDFACT_Unknown";
}
}
 
static void EDFACT_timer_deadline(void *par)
{
PID p = (PID) par;
139,10 → 127,8
case EDFACT_IDLE:
edfact_printf("I%d",p);
 
*iq_query_timespec(p, &lev->ready) = proc_table[p].request_time;
EDFACT_internal_activate(lev,p, &lev->deadline_timespec[p]);
 
EDFACT_internal_activate(lev,p);
 
event_need_reschedule();
break;
 
173,93 → 159,17
kern_raise(XDEADLINE_MISS,p);
}
 
static int EDFACT_level_accept_task_model(LEVEL l, TASK_MODEL *m)
{
if (m->pclass == HARD_PCLASS || m->pclass == (HARD_PCLASS | l)) {
HARD_TASK_MODEL *h = (HARD_TASK_MODEL *)m;
 
if (h->wcet && h->mit && h->periodicity == PERIODIC)
return 0;
}
 
return -1;
}
 
static int EDFACT_level_accept_guest_model(LEVEL l, TASK_MODEL *m)
{
if (m->pclass == JOB_PCLASS || m->pclass == (JOB_PCLASS | l))
return 0;
else
return -1;
}
 
 
static char *onoff(int i)
{
if (i)
return "On ";
else
return "Off";
}
 
static void EDFACT_level_status(LEVEL l)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
PID p = iq_query_first(&lev->ready);
 
kern_printf("On-line guarantee : %s\n",
onoff(lev->flags & EDFACT_ENABLE_GUARANTEE));
kern_printf("Used Bandwidth : %u/%u\n",
lev->U, MAX_BANDWIDTH);
 
while (p != NIL) {
if ((proc_table[p].pclass) == JOB_PCLASS)
kern_printf("Pid: %2d (GUEST)\n", p);
else
kern_printf("Pid: %2d Name: %10s %s: %9d Dline: %9d.%6d Stat: %s\n",
p,
proc_table[p].name,
"Period ",
lev->period[p],
iq_query_timespec(p, &lev->ready)->tv_sec,
iq_query_timespec(p, &lev->ready)->tv_nsec/1000,
EDFACT_status_to_a(proc_table[p].status));
p = iq_query_next(p, &lev->ready);
}
 
for (p=0; p<MAX_PROC; p++)
if (proc_table[p].task_level == l && proc_table[p].status != EDFACT_READY
&& proc_table[p].status != FREE )
kern_printf("Pid: %2d Name: %10s %s: %9d Dline: %9d.%6d Stat: %s\n",
p,
proc_table[p].name,
"Period ",
lev->period[p],
iq_query_timespec(p, &lev->ready)->tv_sec,
iq_query_timespec(p, &lev->ready)->tv_nsec/1000,
EDFACT_status_to_a(proc_table[p].status));
}
 
/* The scheduler only gets the first task in the queue */
static PID EDFACT_level_scheduler(LEVEL l)
static PID EDFACT_public_scheduler(LEVEL l)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
/* { // print 4 dbg the ready queue
PID p= lev->ready;
kern_printf("(s");
while (p != NIL) {
kern_printf("%d ",p);
p = proc_table[p].next;
}
kern_printf(") ");
}
*/
return iq_query_first(&lev->ready);
}
 
/* The on-line guarantee is enabled only if the appropriate flag is set... */
static int EDFACT_level_guarantee(LEVEL l, bandwidth_t *freebandwidth)
static int EDFACT_public_guarantee(LEVEL l, bandwidth_t *freebandwidth)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
277,14 → 187,17
 
}
 
static int EDFACT_task_create(LEVEL l, PID p, TASK_MODEL *m)
static int EDFACT_public_create(LEVEL l, PID p, TASK_MODEL *m)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
/* if the EDFACT_task_create is called, then the pclass must be a
valid pclass. */
HARD_TASK_MODEL *h;
 
HARD_TASK_MODEL *h = (HARD_TASK_MODEL *)m;
if (m->pclass != HARD_PCLASS) return -1;
if (m->level != 0 && m->level != l) return -1;
h = (HARD_TASK_MODEL *)m;
if (!h->wcet || !h->mit || h->periodicity != PERIODIC) return -1;
/* now we know that m is a valid model */
 
lev->period[p] = h->mit;
 
326,7 → 239,7
return 0; /* OK, also if the task cannot be guaranteed... */
}
 
static void EDFACT_task_detach(LEVEL l, PID p)
static void EDFACT_public_detach(LEVEL l, PID p)
{
/* the EDFACT level doesn't introduce any dinamic allocated new field.
we have only to reset the NO_GUARANTEE FIELD and decrement the allocated
340,13 → 253,8
lev->U -= (MAX_BANDWIDTH / lev->period[p]) * proc_table[p].wcet;
}
 
static int EDFACT_task_eligible(LEVEL l, PID p)
static void EDFACT_public_dispatch(LEVEL l, PID p, int nostop)
{
return 0; /* if the task p is chosen, it is always eligible */
}
 
static void EDFACT_task_dispatch(LEVEL l, PID p, int nostop)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
/* the task state is set EXE by the scheduler()
355,7 → 263,7
iq_extract(p, &lev->ready);
}
 
static void EDFACT_task_epilogue(LEVEL l, PID p)
static void EDFACT_public_epilogue(LEVEL l, PID p)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
372,9 → 280,10
proc_table[p].status = EDFACT_READY;
}
 
static void EDFACT_task_activate(LEVEL l, PID p)
static void EDFACT_public_activate(LEVEL l, PID p)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
struct timespec t;
 
/* Test if we are trying to activate a non sleeping task */
/* save activation (only if needed... */
384,10 → 293,9
return;
}
 
ll_gettime(TIME_EXACT, &proc_table[p].request_time);
kern_gettime(&t);
EDFACT_internal_activate(lev,p, &t);
 
EDFACT_internal_activate(lev,p);
 
/* Set the deadline timer */
lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
EDFACT_timer_deadline,
395,7 → 303,7
 
}
 
static void EDFACT_task_insert(LEVEL l, PID p)
static void EDFACT_public_unblock(LEVEL l, PID p)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
404,15 → 312,15
iq_timespec_insert(p,&lev->ready);
}
 
static void EDFACT_task_extract(LEVEL l, PID p)
static void EDFACT_public_block(LEVEL l, PID p)
{
}
 
static void EDFACT_task_endcycle(LEVEL l, PID p)
static int EDFACT_public_message(LEVEL l, PID p, void *m)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
struct timespec t;
 
 
/* we reset the capacity counters... */
proc_table[p].avail_time = proc_table[p].wcet;
 
423,15 → 331,14
lev->nact[p]--;
 
/* see also EDFACT_timer_deadline */
ll_gettime(TIME_EXACT, &proc_table[p].request_time);
kern_gettime(&t);
EDFACT_internal_activate(lev,p, &t);
 
EDFACT_internal_activate(lev,p);
 
/* check if the deadline has already expired */
if (TIMESPEC_A_LT_B(iq_query_timespec(p, &lev->ready), &schedule_time)) {
/* count the deadline miss */
lev->dline_miss[p]++;
event_delete(lev->deadline_timer[p]);
kern_event_delete(lev->deadline_timer[p]);
}
 
}
442,11 → 349,16
proc_table[p].status = EDFACT_IDLE;
 
/* when the deadline timer fire, it recognize the situation and set
correctly all the stuffs (like reactivation, request_time, etc... ) */
correctly all the stuffs (like reactivation, etc... ) */
}
 
jet_update_endcycle(); /* Update the Jet data... */
trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */
 
return 0;
}
 
static void EDFACT_task_end(LEVEL l, PID p)
static void EDFACT_public_end(LEVEL l, PID p)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
460,26 → 372,28
 
if (lev->deadline_timer[p] != -1) {
edfact_printf("²%d",p);
event_delete(lev->deadline_timer[p]);
kern_event_delete(lev->deadline_timer[p]);
}
}
 
static void EDFACT_task_sleep(LEVEL l, PID p)
{ kern_raise(XINVALID_TASK,exec_shadow); }
 
 
/* Guest Functions
These functions manages a JOB_TASK_MODEL, that is used to put
a guest task in the EDFACT ready queue. */
 
static int EDFACT_guest_create(LEVEL l, PID p, TASK_MODEL *m)
static void EDFACT_private_insert(LEVEL l, PID p, TASK_MODEL *m)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
JOB_TASK_MODEL *job = (JOB_TASK_MODEL *)m;
 
/* if the EDFACT_guest_create is called, then the pclass must be a
valid pclass. */
JOB_TASK_MODEL *job;
 
if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) {
kern_raise(XINVALID_TASK, p);
return;
}
 
job = (JOB_TASK_MODEL *)m;
 
TIMESPEC_ASSIGN(iq_query_timespec(p, &lev->ready), &job->deadline);
lev->deadline_timer[p] = -1;
489,26 → 403,25
 
if (job->noraiseexc)
lev->flag[p] = EDFACT_FLAG_NORAISEEXC;
else
else {
lev->flag[p] = 0;
lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
EDFACT_timer_guest_deadline,
(void *)p);
}
 
lev->period[p] = job->period;
 
/* Insert task in the correct position */
iq_timespec_insert(p,&lev->ready);
proc_table[p].status = EDFACT_READY;
 
/* there is no bandwidth guarantee at this level, it is performed
by the level that inserts guest tasks... */
 
return 0; /* OK, also if the task cannot be guaranteed... */
}
 
static void EDFACT_guest_detach(LEVEL l, PID p)
static void EDFACT_private_dispatch(LEVEL l, PID p, int nostop)
{
/* the EDFACT level doesn't introduce any dinamic allocated new field.
No guarantee is performed on guest tasks... so we don't have to reset
the NO_GUARANTEE FIELD */
}
 
static void EDFACT_guest_dispatch(LEVEL l, PID p, int nostop)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
/* the task state is set to EXE by the scheduler()
517,7 → 430,7
iq_extract(p, &lev->ready);
}
 
static void EDFACT_guest_epilogue(LEVEL l, PID p)
static void EDFACT_private_epilogue(LEVEL l, PID p)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
526,42 → 439,10
proc_table[p].status = EDFACT_READY;
}
 
static void EDFACT_guest_activate(LEVEL l, PID p)
static void EDFACT_private_extract(LEVEL l, PID p)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
/* Insert task in the correct position */
iq_timespec_insert(p,&lev->ready);
proc_table[p].status = EDFACT_READY;
 
/* Set the deadline timer */
if (!(lev->flag[p] & EDFACT_FLAG_NORAISEEXC))
lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
EDFACT_timer_guest_deadline,
(void *)p);
 
}
 
static void EDFACT_guest_insert(LEVEL l, PID p)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
/* Insert task in the correct position */
iq_timespec_insert(p,&lev->ready);
proc_table[p].status = EDFACT_READY;
}
 
static void EDFACT_guest_extract(LEVEL l, PID p)
{
}
 
static void EDFACT_guest_endcycle(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
static void EDFACT_guest_end(LEVEL l, PID p)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
 
//kern_printf("EDFACT_guest_end: dline timer %d\n",lev->deadline_timer[p]);
if (proc_table[p].status == EDFACT_READY)
{
572,20 → 453,17
/* we remove the deadline timer, because the slice is finished */
if (lev->deadline_timer[p] != NIL) {
// kern_printf("EDFACT_guest_end: dline timer %d\n",lev->deadline_timer[p]);
event_delete(lev->deadline_timer[p]);
kern_event_delete(lev->deadline_timer[p]);
lev->deadline_timer[p] = NIL;
}
 
}
 
static void EDFACT_guest_sleep(LEVEL l, PID p)
{ kern_raise(XINVALID_GUEST,exec_shadow); }
 
/* Registration functions */
 
/*+ Registration function:
int flags the init flags ... see EDFACT.h +*/
void EDFACT_register_level(int flags)
LEVEL EDFACT_register_level(int flags)
{
LEVEL l; /* the level that we register */
EDFACT_level_des *lev; /* for readableness only */
594,56 → 472,33
printk("EDFACT_register_level\n");
 
/* request an entry in the level_table */
l = level_alloc_descriptor();
l = level_alloc_descriptor(sizeof(EDFACT_level_des));
 
printk(" alloco descrittore %d %d\n",l,(int)sizeof(EDFACT_level_des));
lev = (EDFACT_level_des *)level_table[l];
 
/* alloc the space needed for the EDFACT_level_des */
lev = (EDFACT_level_des *)kern_alloc(sizeof(EDFACT_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, EDFACT_LEVELNAME, MAX_LEVELNAME);
lev->l.level_code = EDFACT_LEVEL_CODE;
lev->l.level_version = EDFACT_LEVEL_VERSION;
lev->l.private_insert = EDFACT_private_insert;
lev->l.private_extract = EDFACT_private_extract;
lev->l.private_dispatch = EDFACT_private_dispatch;
lev->l.private_epilogue = EDFACT_private_epilogue;
 
lev->l.level_accept_task_model = EDFACT_level_accept_task_model;
lev->l.level_accept_guest_model = EDFACT_level_accept_guest_model;
lev->l.level_status = EDFACT_level_status;
lev->l.level_scheduler = EDFACT_level_scheduler;
 
lev->l.public_scheduler = EDFACT_public_scheduler;
if (flags & EDFACT_ENABLE_GUARANTEE)
lev->l.level_guarantee = EDFACT_level_guarantee;
lev->l.public_guarantee = EDFACT_public_guarantee;
else
lev->l.level_guarantee = NULL;
lev->l.public_guarantee = NULL;
lev->l.public_create = EDFACT_public_create;
lev->l.public_detach = EDFACT_public_detach;
lev->l.public_end = EDFACT_public_end;
lev->l.public_dispatch = EDFACT_public_dispatch;
lev->l.public_epilogue = EDFACT_public_epilogue;
lev->l.public_activate = EDFACT_public_activate;
lev->l.public_unblock = EDFACT_public_unblock;
lev->l.public_block = EDFACT_public_block;
lev->l.public_message = EDFACT_public_message;
 
lev->l.task_create = EDFACT_task_create;
lev->l.task_detach = EDFACT_task_detach;
lev->l.task_eligible = EDFACT_task_eligible;
lev->l.task_dispatch = EDFACT_task_dispatch;
lev->l.task_epilogue = EDFACT_task_epilogue;
lev->l.task_activate = EDFACT_task_activate;
lev->l.task_insert = EDFACT_task_insert;
lev->l.task_extract = EDFACT_task_extract;
lev->l.task_endcycle = EDFACT_task_endcycle;
lev->l.task_end = EDFACT_task_end;
lev->l.task_sleep = EDFACT_task_sleep;
 
lev->l.guest_create = EDFACT_guest_create;
lev->l.guest_detach = EDFACT_guest_detach;
lev->l.guest_dispatch = EDFACT_guest_dispatch;
lev->l.guest_epilogue = EDFACT_guest_epilogue;
lev->l.guest_activate = EDFACT_guest_activate;
lev->l.guest_insert = EDFACT_guest_insert;
lev->l.guest_extract = EDFACT_guest_extract;
lev->l.guest_endcycle = EDFACT_guest_endcycle;
lev->l.guest_end = EDFACT_guest_end;
lev->l.guest_sleep = EDFACT_guest_sleep;
 
/* fill the EDFACT descriptor part */
for(i=0; i<MAX_PROC; i++) {
lev->period[i] = 0;
657,16 → 512,15
iq_init(&lev->ready,&freedesc, 0);
lev->flags = flags & 0x07;
lev->U = 0;
 
return l;
}
 
bandwidth_t EDFACT_usedbandwidth(LEVEL l)
{
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
if (lev->l.level_code == EDFACT_LEVEL_CODE &&
lev->l.level_version == EDFACT_LEVEL_VERSION)
return lev->U;
else
return 0;
return lev->U;
}
 
int EDFACT_get_dline_miss(PID p)
673,11 → 527,8
{
LEVEL l = proc_table[p].task_level;
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
if (lev->l.level_code == EDFACT_LEVEL_CODE &&
lev->l.level_version == EDFACT_LEVEL_VERSION)
return lev->dline_miss[p];
else
return -1;
 
return lev->dline_miss[p];
}
 
int EDFACT_get_wcet_miss(PID p)
684,11 → 535,8
{
LEVEL l = proc_table[p].task_level;
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
if (lev->l.level_code == EDFACT_LEVEL_CODE &&
lev->l.level_version == EDFACT_LEVEL_VERSION)
return lev->wcet_miss[p];
else
return -1;
 
return lev->wcet_miss[p];
}
 
int EDFACT_get_nact(PID p)
695,11 → 543,8
{
LEVEL l = proc_table[p].task_level;
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
if (lev->l.level_code == EDFACT_LEVEL_CODE &&
lev->l.level_version == EDFACT_LEVEL_VERSION)
return lev->nact[p];
else
return -1;
return lev->nact[p];
}
 
int EDFACT_reset_dline_miss(PID p)
706,14 → 551,9
{
LEVEL l = proc_table[p].task_level;
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
if (lev->l.level_code == EDFACT_LEVEL_CODE &&
lev->l.level_version == EDFACT_LEVEL_VERSION)
{
lev->dline_miss[p] = 0;
return 0;
}
else
return -1;
 
lev->dline_miss[p] = 0;
return 0;
}
 
int EDFACT_reset_wcet_miss(PID p)
720,13 → 560,8
{
LEVEL l = proc_table[p].task_level;
EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]);
if (lev->l.level_code == EDFACT_LEVEL_CODE &&
lev->l.level_version == EDFACT_LEVEL_VERSION)
{
lev->wcet_miss[p] = 0;
return 0;
}
else
return -1;
 
lev->wcet_miss[p] = 0;
return 0;
}