Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 234 → Rev 235

/shark/trunk/ports/first/include/fsf_contract.h
21,6 → 21,7
#include "posix.h"
#include "cbsstar.h"
#include "edfstar.h"
#include "rmstar.h"
#include "posixstar.h"
 
#ifndef _FSF_CONTRACT_H_
/shark/trunk/ports/first/include/rmstar.h
0,0 → 1,131
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: rmstar.h,v 1.1 2003-09-17 09:13:50 giacomo Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2003-09-17 09:13:50 $
------------
 
Title:
RMSTAR
 
Task Models Accepted:
HARD_TASK_MODEL - Hard Tasks (only Periodic)
wcet field and mit field must be != 0. They are used to set the wcet
and period of the tasks.
periodicity field can be only PERIODIC
drel field is ignored
Guest Models Accepted:
JOB_TASK_MODEL - a single guest task activation
Identified by an absolute deadline and a period.
period field is ignored
 
Description:
 
This module schedule his tasks following the classic RM
scheme.
 
Note: This module is derived from the EDFSTAR Scheduling Module. I
have just changed RM in EDF and iq_timespec_insert with
iq_priority_insert...
 
Exceptions raised:
XUNVALID_GUEST XUNVALID_TASK
some primitives are not implemented:
task_sleep, task_delay, guest_endcycle, guest_sleep, guest_delay
 
XACTIVATION
If a task is actiated through task_activate or guest_activate more than
one time
Restrictions & special features:
see edfstar.h
 
**/
 
/*
* Copyright (C) 2001 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
 
#ifndef __RMSTAR_H__
#define __RMSTAR_H__
 
#include <ll/ll.h>
#include <kernel/config.h>
#include <sys/types.h>
#include <kernel/types.h>
 
 
 
/* flags... */
#define RMSTAR_ENABLE_GUARANTEE 1 /* Task Guarantee enabled */
#define RMSTAR_ENABLE_ALL 1
 
#define RMSTAR_FAILED_GUARANTEE 8 /* used in the module, unsettabl
in RM_register_level... */
 
 
 
#define RMSTAR_LEVELNAME "RMSTAR base"
#define RMSTAR_LEVEL_CODE 166
#define RMSTAR_LEVEL_VERSION 1
 
 
/* Registration function:
int budget The budget used by this module (see CBSSTAR.h)
int master The master module used by RMSTAR
*/
LEVEL RMSTAR_register_level(int master);
 
/* returns respectively the number of dline, wcet or nact; -1 if error */
int RMSTAR_get_dline_miss(PID p);
int RMSTAR_get_wcet_miss(PID p);
int RMSTAR_get_nact(PID p);
 
/* resets respectively the number of dline, wcet miss; -1 if error */
int RMSTAR_reset_dline_miss(PID p);
int RMSTAR_reset_wcet_miss(PID p);
int RMSTAR_getbudget(LEVEL l, PID p);
int RMSTAR_setbudget(LEVEL l, PID p, int budget);
int RMSTAR_budget_has_thread(LEVEL l, int budget);
 
#endif
 
/shark/trunk/ports/first/modules/rmstar.c
0,0 → 1,780
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/**
------------
CVS : $Id: rmstar.c,v 1.1 2003-09-17 09:13:50 giacomo Exp $
 
File: $File$
Revision: $Revision: 1.1 $
Last update: $Date: 2003-09-17 09:13:50 $
------------
**/
 
/*
* Copyright (C) 2001 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
#include "rmstar.h"
#include <ll/stdio.h>
#include <ll/string.h>
#include <kernel/model.h>
#include <kernel/descr.h>
#include <kernel/var.h>
#include <kernel/func.h>
#include <kernel/trace.h>
 
 
#define RMSTAR_CHANGE_LEVEL 1
 
/* for iqueues */
/* #include "iqueue.h" Now iqueues are the only queue type into the kernel */
 
/* for BUDGET_TASK_MODEL */
#include "cbsstar.h"
#include <comm_message.h>
 
/*
* DEBUG stuffs begin
*/
 
//#define RMSTAR_DEBUG
 
#ifdef RMSTAR_DEBUG
 
static __inline__ fake_printf(char *fmt, ...) {}
 
#define rmstar_printf fake_printf
#define rmstar_printf2 fake_printf
#define rmstar_printf3 fake_printf
 
//#define rmstar_printf kern_printf
//#define rmstar_printf2 kern_printf
//#define rmstar_printf3 kern_printf
#endif
 
/*
* DEBUG stuffs end
*/
 
/* Status used in the level */
#define RMSTAR_READY MODULE_STATUS_BASE /* - Ready status */
#define RMSTAR_IDLE MODULE_STATUS_BASE+4 /* to wait the deadline */
 
/* flags */
#define RMSTAR_FLAG_NORAISEEXC 2
 
/* the level redefinition for the Earliest Deadline First level */
typedef struct {
level_des l; /* the standard level descriptor */
 
TIME period[MAX_PROC]; /* The task periods; the deadlines are
stored in the priority field */
int deadline_timer[MAX_PROC];
/* The task deadline timers */
 
struct timespec deadline_timespec[MAX_PROC];
 
int dline_miss[MAX_PROC]; /* Deadline miss counter */
int wcet_miss[MAX_PROC]; /* Wcet miss counter */
 
int nact[MAX_PROC]; /* Wcet miss counter */
 
int flag[MAX_PROC];
/* used to manage the JOB_TASK_MODEL and the
periodicity */
 
IQUEUE ready; /* the ready queue */
 
PID activated; /* the task that has been inserted into the
master module */
 
int budget[MAX_PROC];
 
int new_level[MAX_PROC];
int wcet[MAX_PROC]; /* save the wcet fields */
 
int scheduling_level;
 
} RMSTAR_level_des;
 
static void RMSTAR_check_preemption(RMSTAR_level_des *lev)
{
PID first;
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:chk)");
#endif
 
if ((first = iq_query_first(&lev->ready)) != lev->activated) {
if (lev->activated != NIL)
level_table[ lev->scheduling_level ]->
private_extract(lev->scheduling_level, lev->activated);
 
lev->activated = first;
 
if (first != NIL) {
BUDGET_TASK_MODEL b;
budget_task_default_model(b, lev->budget[first]);
 
level_table[ lev->scheduling_level ]->
private_insert(lev->scheduling_level, first, (TASK_MODEL *)&b);
}
}
}
 
static void RMSTAR_timer_deadline(void *par);
 
static void RMSTAR_internal_activate(RMSTAR_level_des *lev, PID p,
struct timespec *t)
{
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:iact)");
#endif
 
ADDUSEC2TIMESPEC(lev->period[p], t);
 
*iq_query_timespec(p, &lev->ready) = *t;
lev->deadline_timespec[p] = *t;
 
/* Insert task in the correct position */
proc_table[p].status = RMSTAR_READY;
iq_priority_insert(p,&lev->ready);
 
/* needed because when there is a wcet miss I disable CONTROL_CAP */
proc_table[p].control |= CONTROL_CAP;
 
/* check for preemption */
RMSTAR_check_preemption(lev);
}
 
static void RMSTAR_timer_deadline(void *par)
{
PID p = (PID) par;
RMSTAR_level_des *lev;
 
#ifdef RMSTAR_DEBUG
// rmstar_printf("(E:tdl ");
#endif
 
lev = (RMSTAR_level_des *)level_table[proc_table[p].task_level];
 
switch (proc_table[p].status) {
case RMSTAR_IDLE:
#ifdef RMSTAR_DEBUG
// rmstar_printf2("I%d",p);
#endif
/* set the request time */
RMSTAR_internal_activate(lev,p,iq_query_timespec(p, &lev->ready));
 
event_need_reschedule();
break;
 
default:
#ifdef RMSTAR_DEBUG
// rmstar_printf2("D%d",p);
#endif
/* else, a deadline miss occurred!!! */
lev->dline_miss[p]++;
 
/* the task is into another state */
lev->nact[p]++;
 
/* Set the deadline timer */
ADDUSEC2TIMESPEC(lev->period[p], &lev->deadline_timespec[p]);
}
 
/* Set the deadline timer */
lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
RMSTAR_timer_deadline,
(void *)p);
 
#ifdef RMSTAR_DEBUG
// rmstar_printf(")");
#endif
}
 
static int RMSTAR_private_change_level(LEVEL l, PID p)
{
 
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
/* Change task level */
if (lev->flag[p] & RMSTAR_CHANGE_LEVEL) {
STD_command_message msg;
proc_table[p].status = SLEEP;
level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p);
iq_extract(p,&lev->ready);
if (lev->deadline_timer[p] != -1)
kern_event_delete(lev->deadline_timer[p]);
RMSTAR_check_preemption(lev);
lev->nact[p] = 0;
lev->budget[p] = -1;
proc_table[p].task_level = lev->new_level[p];
/* Send change level command to local scheduler */
 
msg.command = STD_ACTIVATE_TASK;
msg.param = NULL;
 
level_table[ lev->new_level[p] ]->public_message(lev->new_level[p],p,&msg);
return 1;
 
}
 
return 0;
 
}
static void RMSTAR_timer_guest_deadline(void *par)
{
PID p = (PID) par;
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:gdl)");
#endif
 
kern_raise(XDEADLINE_MISS,p);
}
 
static int RMSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
/* if the RMSTAR_task_create is called, then the pclass must be a
valid pclass. */
HARD_TASK_MODEL *h;
 
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 */
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:tcr)");
#endif
 
lev->period[p] = h->mit;
*iq_query_priority(p, &lev->ready) = h->mit;
 
lev->flag[p] = 0;
lev->deadline_timer[p] = -1;
lev->dline_miss[p] = 0;
lev->wcet_miss[p] = 0;
lev->nact[p] = 0;
 
/* Enable wcet check */
proc_table[p].avail_time = h->wcet;
proc_table[p].wcet = h->wcet;
proc_table[p].control |= CONTROL_CAP;
 
return 0; /* OK, also if the task cannot be guaranteed... */
}
 
static void RMSTAR_public_dispatch(LEVEL l, PID p, int nostop)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:dis)");
 
rmstar_printf3("(%d %d)",
iq_query_timespec(p, &lev->ready)->tv_nsec/1000000,
schedule_time.tv_nsec/1000000);
#endif
 
level_table[ lev->scheduling_level ]->
private_dispatch(lev->scheduling_level,p,nostop);
}
 
static void RMSTAR_public_epilogue(LEVEL l, PID p)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:epi ");
#endif
 
if (RMSTAR_private_change_level(l, p)) return;
 
/* check if the wcet is finished... */
if (proc_table[p].avail_time <= 0 && proc_table[p].control&CONTROL_CAP) {
/* wcet finished: disable wcet event and count wcet miss */
#ifdef RMSTAR_DEBUG
rmstar_printf2("W%d",p);
#endif
proc_table[p].control &= ~CONTROL_CAP;
lev->wcet_miss[p]++;
}
#ifdef RMSTAR_DEBUG
rmstar_printf(")");
#endif
 
level_table[ lev->scheduling_level ]->
private_epilogue(lev->scheduling_level,p);
 
proc_table[p].status = RMSTAR_READY;
}
 
static void RMSTAR_public_activate(LEVEL l, PID p)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
struct timespec t;
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:act)");
#endif
 
/* Test if we are trying to activate a non sleeping task */
/* save activation (only if needed... */
if (proc_table[p].status != SLEEP) {
/* a periodic task cannot be activated when it is already active */
kern_raise(XACTIVATION,p);
return;
}
 
kern_gettime(&t);
 
RMSTAR_internal_activate(lev,p, &t);
 
/* Set the deadline timer */
lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p],
RMSTAR_timer_deadline,
(void *)p);
 
}
 
static void RMSTAR_public_unblock(LEVEL l, PID p)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:ins)");
#endif
 
/* Insert task in the correct position */
proc_table[p].status = RMSTAR_READY;
iq_priority_insert(p,&lev->ready);
 
/* and check for preemption! */
RMSTAR_check_preemption(lev);
}
 
static void RMSTAR_public_block(LEVEL l, PID p)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:ext)");
#endif
 
/* the task is blocked on a synchronization primitive. we have to
remove it from the master module -and- from the local queue! */
iq_extract(p,&lev->ready);
 
/* and finally, a preemption check! (it will also call guest_end) */
RMSTAR_check_preemption(lev);
}
 
static int RMSTAR_public_message(LEVEL l, PID p, void *m)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
struct timespec temp;
STD_command_message *msg;
HARD_TASK_MODEL *h;
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:ecy ");
#endif
 
switch ((long)(m))
{
/* Task EndCycle */
case (long)(NULL):
 
if (RMSTAR_private_change_level(l,p)) return 0;
/* we call guest_end directly here because the same task may
be reinserted in the queue before calling the preemption check! */
level_table[ lev->scheduling_level ]->
private_extract(lev->scheduling_level,p); lev->activated = NIL;
iq_extract(p,&lev->ready);
/* we reset the capacity counters... */
proc_table[p].avail_time = proc_table[p].wcet;
if (lev->nact[p] > 0) {
#ifdef RMSTAR_DEBUG
rmstar_printf2("E%d",p);
#endif
/* Pending activation: reactivate the thread!!! */
lev->nact[p]--;
/* see also RMSTAR_timer_deadline */
kern_gettime(&temp);
RMSTAR_internal_activate(lev,p,&temp);
/* check if the deadline has already expired */
temp = *iq_query_timespec(p, &lev->ready);
if (TIMESPEC_A_LT_B(&temp, &schedule_time)) {
/* count the deadline miss */
lev->dline_miss[p]++;
kern_event_delete(lev->deadline_timer[p]);
}
}
else {
#ifdef RMSTAR_DEBUG
rmstar_printf("e%d",p);
#endif
/* the task has terminated his job before it consume the wcet. All OK! */
proc_table[p].status = RMSTAR_IDLE;
/* and finally, a preemption check! */
RMSTAR_check_preemption(lev);
/* when the deadline timer fire, it recognize the situation and set
correctly all the stuffs (like reactivation, etc... ) */
}
#ifdef RMSTAR_DEBUG
rmstar_printf(")");
#endif
jet_update_endcycle(); /* Update the Jet data... */
trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */
break;
default:
 
msg = (STD_command_message *)m;
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:MSG %d)",msg->command);
#endif
switch(msg->command) {
case STD_SET_NEW_MODEL:
/* if the RMSTAR_task_create is called, then the pclass must be a
valid pclass. */
h=(HARD_TASK_MODEL *)(msg->param);
/* now we know that m is a valid model */
lev->wcet[p] = h->wcet;
lev->period[p] = h->mit;
lev->flag[p] = 0;
lev->deadline_timer[p] = -1;
lev->dline_miss[p] = 0;
lev->wcet_miss[p] = 0;
lev->nact[p] = 0;
break;
 
case STD_SET_NEW_LEVEL:
lev->flag[p] |= RMSTAR_CHANGE_LEVEL;
lev->new_level[p] = (int)(msg->param);
break;
case STD_ACTIVATE_TASK:
/* Enable wcet check */
proc_table[p].avail_time = lev->wcet[p];
proc_table[p].wcet = lev->wcet[p];
proc_table[p].control |= CONTROL_CAP;
RMSTAR_public_activate(l, p);
break;
}
}
return 0;
}
 
static void RMSTAR_public_end(LEVEL l, PID p)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
#ifdef RMSTAR_DEBUG
rmstar_printf("(E:end)");
#endif
 
iq_extract(p,&lev->ready);
 
/* we finally put the task in the ready queue */
proc_table[p].status = FREE;
iq_insertfirst(p,&freedesc);
if (lev->deadline_timer[p] != -1) {
kern_event_delete(lev->deadline_timer[p]);
}
 
/* and finally, a preemption check! (it will also call guest_end) */
RMSTAR_check_preemption(lev);
}
 
 
/* Guest Functions
These functions manages a JOB_TASK_MODEL, that is used to put
a guest task in the RMSTAR ready queue. */
 
static void RMSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
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;
 
*iq_query_timespec(p, &lev->ready) = job->deadline;
lev->deadline_timer[p] = -1;
lev->dline_miss[p] = 0;
lev->wcet_miss[p] = 0;
lev->nact[p] = 0;
 
if (job->noraiseexc)
lev->flag[p] = RMSTAR_FLAG_NORAISEEXC;
else {
lev->flag[p] = 0;
lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready),
RMSTAR_timer_guest_deadline,
(void *)p);
}
 
lev->period[p] = job->period;
*iq_query_priority(p, &lev->ready) = job->period;
 
/* there is no bandwidth guarantee at this level, it is performed
by the level that inserts guest tasks... */
 
/* Insert task in the correct position */
iq_priority_insert(p,&lev->ready);
proc_table[p].status = RMSTAR_READY;
 
/* check for preemption */
RMSTAR_check_preemption(lev);
}
 
 
static void RMSTAR_private_dispatch(LEVEL l, PID p, int nostop)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
level_table[ lev->scheduling_level ]->
private_dispatch(lev->scheduling_level,p,nostop);
}
 
static void RMSTAR_private_epilogue(LEVEL l, PID p)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
/* the task has been preempted. it returns into the ready queue... */
level_table[ lev->scheduling_level ]->
private_epilogue(lev->scheduling_level,p);
 
proc_table[p].status = RMSTAR_READY;
}
 
static void RMSTAR_private_extract(LEVEL l, PID p)
{
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
#ifdef RMSTAR_DEBUG
//kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
#endif
 
iq_extract(p, &lev->ready);
 
/* we remove the deadline timer, because the slice is finished */
if (lev->deadline_timer[p] != NIL) {
#ifdef RMSTAR_DEBUG
// kern_printf("RMSTAR_guest_end: dline timer %d\n",lev->deadline_timer[p]);
#endif
kern_event_delete(lev->deadline_timer[p]);
lev->deadline_timer[p] = NIL;
}
 
/* and finally, a preemption check! (it will also call guest_end() */
RMSTAR_check_preemption(lev);
}
 
/* Registration functions */
 
/* Registration function:
int flags the init flags ... see RMSTAR.h */
LEVEL RMSTAR_register_level(int master)
{
LEVEL l; /* the level that we register */
RMSTAR_level_des *lev; /* for readableness only */
PID i; /* a counter */
 
#ifdef RMSTAR_DEBUG
printk("RMSTAR_register_level\n");
#endif
 
/* request an entry in the level_table */
l = level_alloc_descriptor(sizeof(RMSTAR_level_des));
 
lev = (RMSTAR_level_des *)level_table[l];
 
printk(" lev=%d\n",(int)lev);
 
/* fill the standard descriptor */
lev->l.private_insert = RMSTAR_private_insert;
lev->l.private_extract = RMSTAR_private_extract;
lev->l.private_dispatch = RMSTAR_private_dispatch;
lev->l.private_epilogue = RMSTAR_private_epilogue;
 
lev->l.public_guarantee = NULL;
lev->l.public_create = RMSTAR_public_create;
lev->l.public_end = RMSTAR_public_end;
lev->l.public_dispatch = RMSTAR_public_dispatch;
lev->l.public_epilogue = RMSTAR_public_epilogue;
lev->l.public_activate = RMSTAR_public_activate;
lev->l.public_unblock = RMSTAR_public_unblock;
lev->l.public_block = RMSTAR_public_block;
lev->l.public_message = RMSTAR_public_message;
 
/* fill the RMSTAR descriptor part */
for(i=0; i<MAX_PROC; i++) {
lev->period[i] = 0;
lev->deadline_timer[i] = -1;
lev->flag[i] = 0;
lev->dline_miss[i] = 0;
lev->wcet_miss[i] = 0;
lev->nact[i] = 0;
lev->budget[i] = NIL;
lev->wcet[i] = 0;
}
 
iq_init(&lev->ready, NULL, 0);
lev->activated = NIL;
 
lev->scheduling_level = master;
 
return l;
}
 
int RMSTAR_get_dline_miss(PID p)
{
LEVEL l = proc_table[p].task_level;
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
return lev->dline_miss[p];
}
 
int RMSTAR_get_wcet_miss(PID p)
{
LEVEL l = proc_table[p].task_level;
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
return lev->wcet_miss[p];
}
 
int RMSTAR_get_nact(PID p)
{
LEVEL l = proc_table[p].task_level;
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
return lev->nact[p];
}
 
int RMSTAR_reset_dline_miss(PID p)
{
LEVEL l = proc_table[p].task_level;
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
lev->dline_miss[p] = 0;
return 0;
}
 
int RMSTAR_reset_wcet_miss(PID p)
{
LEVEL l = proc_table[p].task_level;
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
lev->wcet_miss[p] = 0;
return 0;
}
 
 
int RMSTAR_setbudget(LEVEL l, PID p, int budget)
{
 
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
lev->budget[p] = budget;
 
return 0;
 
}
 
int RMSTAR_getbudget(LEVEL l, PID p)
{
 
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
 
return lev->budget[p];
 
}
 
int RMSTAR_budget_has_thread(LEVEL l, int budget)
{
 
RMSTAR_level_des *lev = (RMSTAR_level_des *)(level_table[l]);
int i;
 
for(i = 0; i< MAX_PROC; i++)
if (lev->budget[i] == budget) return 1;
 
return 0;
 
}
/shark/trunk/ports/first/first-server.c
14,6 → 14,7
#include "fsf_contract.h"
#include "cbsstar.h"
#include "posixstar.h"
#include "rmstar.h"
#include "edfstar.h"
#include "posix.h"
#include "comm_message.h"
56,6 → 57,7
local_scheduler_level = EDFSTAR_register_level(fsf_cbsstar_level);
break;
case FSF_SCHEDULER_RM:
local_scheduler_level = RMSTAR_register_level(fsf_cbsstar_level);
break;
}
210,7 → 212,30
free(msg);
 
break;
 
case FSF_SCHEDULER_RM:
 
if (RMSTAR_getbudget(local_scheduler_level,thread) != -1)
return FSF_ERR_BIND_THREAD;
 
/* Set server on local scheduler */
RMSTAR_setbudget(local_scheduler_level,thread,(int)(server));
 
/* Send change level command to posix level */
msg = (STD_command_message *)malloc(sizeof(STD_command_message));
 
#ifdef FSF_DEBUG
kern_printf("(MSG RMSTAR LEV %d SEV %d THR %d)",local_scheduler_level,server,thread);
#endif
 
msg->command = STD_SET_NEW_MODEL;
msg->param = (void *)(rt_arg);
level_table[local_scheduler_level]->public_message(local_scheduler_level,thread,msg);
 
msg->command = STD_SET_NEW_LEVEL;
msg->param = (void *)(local_scheduler_level);
task_message(msg,thread,0);
 
default:
return FSF_ERR_BIND_THREAD;
break;
296,6 → 321,32
break;
 
case FSF_SCHEDULER_RM:
 
if (RMSTAR_getbudget(local_scheduler_level,thread) == -1)
return FSF_ERR_UNBIND_THREAD;
else {
 
STD_command_message *msg;
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_save_arrivals(nrt);
 
/* Send change level command to local scheduler */
msg = (STD_command_message *)malloc(sizeof(STD_command_message));
 
msg->command = STD_SET_NEW_MODEL;
msg->param = (void *)(&nrt);
level_table[fsf_posix_level]->public_message(fsf_posix_level,thread,msg);
 
msg->command = STD_SET_NEW_LEVEL;
msg->param = (void *)(fsf_posix_level);
task_message(msg,thread,0);
 
free(msg);
 
}
 
break;
}
 
365,7 → 416,10
case FSF_SCHEDULER_POSIX:
return POSIXSTAR_getbudget(local_scheduler_level,thread);
case FSF_SCHEDULER_EDF:
return EDFSTAR_getbudget(local_scheduler_level,thread);
case FSF_SCHEDULER_RM:
return RMSTAR_getbudget(local_scheduler_level,thread);
default:
return -1;
}
 
399,7 → 453,16
break;
case FSF_SCHEDULER_EDF:
/* Check if some thread use the server */
if(EDFSTAR_budget_has_thread(local_scheduler_level,*server))
return FSF_ERR_SERVER_USED;
break;
 
case FSF_SCHEDULER_RM:
/* Check if some thread use the server */
if(RMSTAR_budget_has_thread(local_scheduler_level,*server))
return FSF_ERR_SERVER_USED;
 
break;
}
 
/shark/trunk/ports/first/makefile
12,7 → 12,7
 
FIRST = first-contract.o first-server.o first-sync.o \
./modules/cbsstar.o ./modules/posixstar.o ./modules/posix.o \
./modules/edfstar.o
./modules/edfstar.o ./modules/rmstar.o
 
OBJS = $(FIRST)