/unsupported/trunk/first/test1.c |
---|
0,0 → 1,247 |
/* |
* 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: test1.c,v 1.1 2004-06-01 11:42:45 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:45 $ |
------------ |
this test shows a set of 5 tasks (+main+dummy+keyboard driver). |
The first 4 tasks are scheduled by a EDFSTAR Module, whereas the |
fifth one is a standard traditional EDF task. The 4 tasks uses a |
budget of 10000/100000. |
if edfstar.c is compiled with edfstar_printf3 active, a couple |
(dline, curtime) is showed (in ms). |
if cbsstar.c is compiled with cbsstar_printf3 active, the budget |
replenishments are showed. |
*/ |
/* |
* Copyright (C) 2002 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "cbsstar.h" |
#include "edfstar.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "drivers/keyb.h" |
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
int cbsstar_level, edfstar_level, mybudget; |
EDF_register_level(EDF_ENABLE_ALL); |
cbsstar_level = CBSSTAR_register_level(3, 0); |
mybudget = CBSSTAR_setbudget(cbsstar_level, 10000, 100000); |
edfstar_level = EDFSTAR_register_level(mybudget, cbsstar_level); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
// for the keyboard... |
CBS_register_level(CBS_ENABLE_ALL, 0); |
SEM_register_module(); |
CABS_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
KEYB_PARMS kparms = BASE_KEYB; |
HARTPORT_init(); |
//keyb_def_ctrlC(kparms, NULL); |
//keyb_def_map(kparms,itaMap); |
KEYB_init(&kparms); |
__call_main__(mb); |
return (void *)0; |
} |
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
#include <kernel/kern.h> |
#include <drivers/keyb.h> |
void *star(void *arg) |
{ |
int i,j; |
for (i=0; i<5; i++) { |
for (j=0; j<100000; j++); |
cputc('°'); |
cputs((char *)arg); |
task_endcycle(); |
} |
return NULL; |
} |
void *edftask(void *arg) |
{ |
int i,j; |
for (i=0; i<5; i++) { |
for (j=0; j<100000; j++); |
cputc('°'); |
cputs((char *)arg); |
task_endcycle(); |
} |
return NULL; |
} |
void create1() |
{ |
HARD_TASK_MODEL m1, m2; |
PID p1a, p1b, p1c, p1d, p2; |
hard_task_default_model(m1); |
hard_task_def_wcet(m1, 5000); |
hard_task_def_level(m1,2); |
hard_task_def_group(m1,1); |
hard_task_def_periodic(m1); |
hard_task_def_arg(m1,(void *)"a"); |
hard_task_def_mit(m1,10000); |
p1a = task_create("a", star, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_def_arg(m1,(void *)"b"); |
hard_task_def_mit(m1,15000); |
p1b = task_create("b", star, &m1, NULL); |
if (p1b == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
hard_task_def_arg(m1,(void *)"c"); |
hard_task_def_mit(m1,20000); |
p1c = task_create("c", star, &m1, NULL); |
if (p1c == -1) { |
perror("Could not create task c ..."); |
sys_end(); |
} |
hard_task_def_arg(m1,(void *)"d"); |
hard_task_def_mit(m1,30000); |
p1d = task_create("d", star, &m1, NULL); |
if (p1d == -1) { |
perror("Could not create task d ..."); |
sys_end(); |
} |
hard_task_default_model(m2); |
hard_task_def_mit(m2,50000); // the budget has dline 100,000! |
hard_task_def_wcet(m2, 5000); |
hard_task_def_arg(m2,(void *)"Û"); |
hard_task_def_group(m2,1); |
hard_task_def_periodic(m2); |
p2 = task_create("2", edftask, &m2, NULL); |
if (p2 == -1) { |
perror("Could not create task edf ..."); |
sys_end(); |
} |
cprintf("stars=%d %d %d %d, star2=%d\n", p1a, p1b, p1c, p1d, p2); |
group_activate(1); |
} |
int main(int argc, char **argv) |
{ |
char c; |
clear(); |
cprintf("Hello, world!\nPress ESC to end the demo...\n"); |
create1(); |
do { |
c =keyb_getch(BLOCK); |
} while (c != ESC); |
cprintf("ESC pressed!"); |
sys_end(); |
return 0; |
} |
/unsupported/trunk/first/test2.c |
---|
0,0 → 1,241 |
/* |
* 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: test2.c,v 1.1 2004-06-01 11:42:45 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:45 $ |
------------ |
The purpose of this test is to show that two budgets with different |
period and capacity schedules correctly. |
4 periodic tasks are involved |
*/ |
/* |
* Copyright (C) 2002 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "cbsstar.h" |
#include "edfstar.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "drivers/keyb.h" |
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
int cbsstar_level, edfstar_level, edfstar_level2, mybudget, mybudget2; |
clear(); |
EDF_register_level(EDF_ENABLE_ALL); |
cbsstar_level = CBSSTAR_register_level(3, 0); |
mybudget = CBSSTAR_setbudget(cbsstar_level, 1000, 50000); |
edfstar_level = EDFSTAR_register_level(mybudget, cbsstar_level); |
mybudget2 = CBSSTAR_setbudget(cbsstar_level, 10000, 25000); |
edfstar_level2 = EDFSTAR_register_level(mybudget2, cbsstar_level); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
cprintf("edfstar_level=%d, edfstar_level2=%d\n", |
edfstar_level,edfstar_level2); |
// for the keyboard... |
CBS_register_level(CBS_ENABLE_ALL, 0); |
SEM_register_module(); |
CABS_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
KEYB_PARMS kparms = BASE_KEYB; |
HARTPORT_init(); |
KEYB_init(&kparms); |
__call_main__(mb); |
return (void *)0; |
} |
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
#include <kernel/kern.h> |
#include <drivers/keyb.h> |
void *star(void *arg) |
{ |
int i,j,z; |
for (i=0; i<100; i++) { |
for (z=0; z<5; z++) { |
for (j=0; j<60000; j++); |
cputs((char *)arg); |
} |
task_endcycle(); |
} |
return NULL; |
} |
// version for the "slow" budget |
void *slow(void *arg) |
{ |
int i,j,z; |
for (i=0; i<15; i++) { |
for (z=0; z<5; z++) { |
for (j=0; j<200000; j++); |
cputs((char *)arg); |
} |
task_endcycle(); |
} |
return NULL; |
} |
void create1() |
{ |
HARD_TASK_MODEL m1; |
PID p1a, p1b, p1c, p1d; |
hard_task_default_model(m1); |
hard_task_def_wcet(m1, 5000); |
hard_task_def_group(m1,1); |
hard_task_def_periodic(m1); |
hard_task_def_level(m1,2); |
hard_task_def_arg(m1,(void *)"."); |
hard_task_def_mit(m1,5000); |
p1a = task_create("a", slow, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_def_arg(m1,(void *)","); |
hard_task_def_mit(m1,5000); |
p1b = task_create("b", slow, &m1, NULL); |
if (p1b == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
hard_task_def_level(m1,3); |
hard_task_def_arg(m1,(void *)"o"); |
hard_task_def_mit(m1,5000); |
p1c = task_create("c", star, &m1, NULL); |
if (p1c == -1) { |
perror("Could not create task c ..."); |
sys_end(); |
} |
hard_task_def_arg(m1,(void *)"O"); |
hard_task_def_mit(m1,5000); |
p1d = task_create("d", star, &m1, NULL); |
if (p1d == -1) { |
perror("Could not create task d ..."); |
sys_end(); |
} |
group_activate(1); |
} |
int main(int argc, char **argv) |
{ |
char c; |
cprintf("Hello, world!"); |
create1(); |
do { |
c =keyb_getch(BLOCK); |
} while (c != ESC); |
cprintf("ESC pressed!"); |
sys_end(); |
return 0; |
} |
/unsupported/trunk/first/posixstar.h |
---|
0,0 → 1,142 |
/* |
* 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: posixstar.h,v 1.1 2004-06-01 11:42:44 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:44 $ |
------------ |
This file contains the scheduling module compatible with POSIX |
specifications |
Title: |
POSIX version 1 |
Task Models Accepted: |
NRT_TASK_MODEL - Non-Realtime Tasks |
weight field is ignored |
slice field is used to set the slice of a task, if it is !=0 |
policy field is ignored |
inherit field is ignored |
Description: |
This module schedule his tasks following the POSIX specifications... |
A task can be scheduled in a Round Robin way or in a FIFO way. |
The tasks have also a priority field. |
The slices can be different one task from one another. |
The module can SAVE or SKIP activations |
Exceptions raised: |
XUNVALID_GUEST |
This level doesn't support guests. When a guest operation |
is called, the exception is raised. |
Restrictions & special features: |
- if specified, it creates at init time a task, |
called "Main", attached to the function __init__(). |
- There must be only one module in the system that creates a task |
attached to the function __init__(). |
- The level tries to guarantee that a RR task uses a "full" timeslice |
before going to the queue tail. "full" means that a task can execute |
a maximum time of slice+sys_tick due to the approx. done by |
the Virtual Machine. If a task execute more time than the slice, |
the next time it execute less... |
**/ |
/* |
* Copyright (C) 2000 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 __POSIXSTAR_H__ |
#define __POSIXSTAR_H__ |
#include <ll/ll.h> |
#include <kernel/config.h> |
#include <sys/types.h> |
#include <kernel/types.h> |
//#define POSIXSTAR_DEBUG |
/*+ Const: +*/ |
#define POSIXSTAR_MINIMUM_SLICE 1000 /*+ Minimum Timeslice +*/ |
#define POSIXSTAR_MAXIMUM_SLICE 500000 /*+ Maximum Timeslice +*/ |
/*+ Registration function: |
TIME slice the slice for the Round Robin queue |
int createmain 1 if the level creates the main task 0 otherwise |
struct multiboot_info *mb used if createmain specified |
returns the level number at which the module has been registered. |
+*/ |
LEVEL POSIXSTAR_register_level(int budget, int master, TIME slice, |
int prioritylevels); |
/*+ this function forces the running task to go to his queue tail, |
then calls the scheduler and changes the context |
(it works only on the POSIX level) +*/ |
int POSIXSTAR_sched_yield(LEVEL l); |
/* the following functions have to be called with interruptions DISABLED! */ |
/*+ this function returns the maximum level allowed for the POSIX level +*/ |
int POSIXSTAR_get_priority_max(LEVEL l); |
/*+ this function returns the default timeslice for the POSIX level +*/ |
int POSIXSTAR_rr_get_interval(LEVEL l); |
/*+ this functions returns some paramaters of a task; |
policy must be NRT_RR_POLICY or NRT_FIFO_POLICY; |
priority must be in the range [0..prioritylevels] |
returns ENOSYS or ESRCH if there are problems +*/ |
int POSIXSTAR_getschedparam(LEVEL l, PID p, int *policy, int *priority); |
/*+ this functions sets paramaters of a task +*/ |
int POSIXSTAR_setschedparam(LEVEL l, PID p, int policy, int priority); |
#endif |
/* |
MANCANO |
13.3.6 GETPRIORITYMin da mettere a 0 |
*/ |
/unsupported/trunk/first/cbsstar.c |
---|
0,0 → 1,674 |
/* |
* 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: cbsstar.c,v 1.1 2004-06-01 11:42:43 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:43 $ |
------------ |
Read CBSSTAR.h for general details. |
Basically, a budget can be in 2 states: |
- Active -> the budget queue is not empty |
- Idle -> the budget queue is empty |
The fact that a task into a budget is inserted into the master module depends |
on the value of the remaining time the tasks can spend in the period. |
The module does handle only one oslib event, used to enforce the |
temporal isolation between buffers. Note that all is implemented |
without using the CONTROL_CAP field. |
Basically, for each budget there can be at most one task inserted |
into the master level. Its deadline is modified according to the |
usage of its capacity, that is, when a budget is exausted its |
deadline is postponed. |
*/ |
/* |
* Copyright (C) 2002 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 "cbsstar.h" |
#include <ll/string.h> |
#define ACTIVE 1 |
#define NOACTIVE 0 |
#define INIT 2 |
#define CBSSTAR_IDLE APER_STATUS_BASE |
/* |
* DEBUG stuffs begin |
*/ |
//#define CBSSTAR_DEBUG |
int event_monitor; |
#ifdef CBSSTAR_DEBUG |
static __inline__ void fake_printf(char *fmt, ...) {} |
//#define cbsstar_printf kern_printf |
//#define cbsstar_printf2 kern_printf |
//#define cbsstar_printf3 kern_printf |
#define cbsstar_printf fake_printf |
#define cbsstar_printf2 fake_printf |
#define cbsstar_printf3 fake_printf |
#if 0 |
void cbsstar_printq(QQUEUE *q) |
{ |
PID p; |
kern_printf("["); |
p = q->first; |
kern_printf("->%d",p); |
while (p != NIL) { |
p = proc_table[p].next; |
kern_printf("->%d",p); |
} |
kern_printf("]"); |
} |
#else |
static __inline__ void cbsstar_printq(QQUEUE *q) {} |
#endif |
#if 0 |
static __inline__ void cbsstar_printblob(int x) { if (x) cputc('±'); else cputc('Û'); } |
#else |
static __inline__ void cbsstar_printblob(int x) {} |
#endif |
#endif |
/* |
* DEBUG stuffs end |
*/ |
/*+ Status used in the level +*/ |
#define CBSSTAR_WAIT APER_STATUS_BASE /*+ waiting the service +*/ |
/* this structure contains the status for a single budget */ |
struct budget_struct { |
TIME Q; /* budget */ |
TIME T; /* period */ |
struct timespec dline; /* deadline */ |
int dline_timer; /* oslib event for budget reactivation*/ |
int avail; /* current budget */ |
PID current; /* the task currently put in execution */ |
int flags; |
IQUEUE tasks; /* a FIFO queue for the tasks handled |
using the budget */ |
}; |
typedef struct { |
level_des l; /* the standard level descriptor */ |
struct budget_struct *b; /* the budgets! */ |
int n; /* the maximum index for the budgets */ |
int freebudgets; /* number of free budgets; starts from n */ |
int tb[MAX_PROC]; /* link task->budget (used in guest_end) */ |
bandwidth_t U; /*+ the used bandwidth by the server +*/ |
int cap_lev; |
PID on_shadow; |
LEVEL scheduling_level; |
} CBSSTAR_level_des; |
static void CBSSTAR_deadline_timer_hardreservation(void *a) |
{ |
struct budget_struct *b = a; |
struct timespec t; |
//kern_printf("*********** %d", b->dline_timer); |
b->dline_timer=NIL; |
/* we modify the deadline according to rule 4 ... */ |
/* there is a while because if the wcet is << than the system tick |
we need to postpone the deadline many times */ |
if (b->avail<=0) { |
b->avail += b->Q; |
if (b->avail>b->Q) b->avail=b->Q; |
//kern_printf("budget recharge %d", b); |
} |
if (b->avail>0) b->flags=ACTIVE; |
/* avail may be <0 because a task executed via a shadow fo many time |
b->current == NIL only if the prec task was finished and there |
was not any other task to be put in the ready queue |
... we are now activating the next task */ |
if (b->current == NIL && b->flags) { |
if (iq_query_first(&(b->tasks)) != NIL) { |
//struct timespec t; |
CBSSTAR_level_des *lev; |
PID p; |
JOB_TASK_MODEL job; |
//kern_gettime(&t); |
//TIMESPEC_ASSIGN(&b->dline, &schedule_time); |
//ADDUSEC2TIMESPEC(b->T, &b->dline); |
kern_gettime(&t); |
TIMESPEC_ASSIGN(&b->dline, &t); |
ADDUSEC2TIMESPEC(b->T, &b->dline); |
p = iq_getfirst(&(b->tasks)); |
b->current=p; |
lev = (CBSSTAR_level_des *)(level_table[proc_table[p].task_level]); |
//kern_printf("reinsert task p = %d lev = %d ",p,proc_table[p].task_level); |
/* and, finally, we reinsert the task in the master level */ |
job_task_default_model(job, b->dline); |
job_task_def_noexc(job); |
//kern_printf("(CR:iact p%d %ld.%ld av=%d)",p,b->dline.tv_sec,b->dline.tv_nsec/1000, b->avail); |
//kern_printf("**"); |
level_table[ lev->scheduling_level ]-> |
private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
event_need_reschedule(); |
} |
} else |
if (b->current !=NIL && b->avail>0) { |
kern_printf("(cap&nil "); |
} |
if (b->flags==NOACTIVE && b->dline_timer!=NIL){ |
kern_gettime(&t); |
TIMESPEC_ASSIGN(&b->dline, &t); |
ADDUSEC2TIMESPEC(b->T, &b->dline); |
b->dline_timer=kern_event_post(&b->dline, CBSSTAR_deadline_timer_hardreservation, b); |
event_monitor=b->dline_timer; |
//kern_printf("(dline hard %ld.%ld ev %d)",b->dline.tv_sec,b->dline.tv_nsec/1000, b->dline_timer); |
} |
} |
static void CBSSTAR_activation(CBSSTAR_level_des *lev, |
PID p, |
struct timespec *acttime) |
{ |
JOB_TASK_MODEL job; |
struct budget_struct *b = &lev->b[lev->tb[p]]; |
/* we have to check if the deadline and the wcet are correct before |
activating a new task or an old task... */ |
/* check 1: if the deadline is before than the actual scheduling time */ |
/* check 2: if ( avail_time >= (cbs_dline - acttime)* (wcet/period) ) |
(rule 7 in the CBS article!) */ |
TIME t; |
struct timespec t2,t3; |
t = (b->T * b->avail) / b->Q; |
t3.tv_sec = t / 1000000; |
t3.tv_nsec = (t % 1000000) * 1000; |
SUBTIMESPEC(&b->dline, acttime, &t2); |
if (/* 1 */ TIMESPEC_A_LT_B(&b->dline, acttime) || |
/* 2 */ TIMESPEC_A_GT_B(&t3, &t2) ) { |
TIMESPEC_ASSIGN(&b->dline, acttime); |
ADDUSEC2TIMESPEC(b->T, &b->dline); |
} |
/* and the capacity */ |
if (b->flags==INIT) { |
b->avail = b->Q; |
b->flags=ACTIVE; |
} |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf3("±%d±",lev->tb[p]); |
cbsstar_printblob(lev->tb[p]); |
#endif |
//} |
//#endif |
/* record the current task inserted in the master module */ |
b->current = p; |
//#ifdef CBSSTAR_DEBUG |
//kern_printf("(CA:iact p%d %ld.%ld av=%d at=%ld.%ld)",p,b->dline.tv_sec,b->dline.tv_nsec/1000, b->avail, acttime->tv_sec, acttime->tv_nsec/1000); |
//#endif |
/* and, finally, we reinsert the task in the master level */ |
job_task_default_model(job, b->dline); |
job_task_def_noexc(job); |
level_table[ lev->scheduling_level ]-> |
private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
//b->dline_timer=kern_event_post(&b->dline, CBSSTAR_deadline_timer_hardreservation, b); |
} |
static void CBSSTAR_account_capacity(CBSSTAR_level_des *lev, PID p) |
{ |
struct timespec ty; |
TIME tx; |
struct budget_struct *b = &lev->b[lev->tb[p]]; |
TIME t; |
struct timespec t2,t3, acttime; |
if (lev->cap_lev!=NIL && b->current==p) { |
kern_event_delete(lev->cap_lev); |
lev->cap_lev=NIL; |
} |
kern_gettime(&acttime); |
t = (b->T * b->avail) / b->Q; |
t3.tv_sec = t / 1000000; |
t3.tv_nsec = (t % 1000000) * 1000; |
SUBTIMESPEC(&b->dline, &acttime, &t2); |
SUBTIMESPEC(&schedule_time, &cap_lasttime, &ty); |
tx = TIMESPEC2USEC(&ty); |
lev->b[lev->tb[p]].avail -= tx; |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf2("(C:cap p%d av=%d)", p, lev->b[lev->tb[p]].avail); |
#endif |
if (lev->b[lev->tb[p]].avail<=0 || TIMESPEC_A_GT_B(&t3, &t2)) lev->b[lev->tb[p]].flags=NOACTIVE; |
if ( TIMESPEC_A_LT_B(&b->dline, &schedule_time) ) { |
/* we modify the deadline ... */ |
TIMESPEC_ASSIGN(&b->dline, &schedule_time); |
ADDUSEC2TIMESPEC(b->T, &b->dline); |
} |
//if (b->flags==NOACTIVE && b->dline_timer!=NIL) |
// kern_printf("flags %d, dline_timer %d", b->flags, b->dline_timer); |
if (b->flags==NOACTIVE && b->dline_timer==NIL) { |
b->dline_timer=kern_event_post(&b->dline, CBSSTAR_deadline_timer_hardreservation, b); |
event_monitor=b->dline_timer; |
//kern_printf("(dline %ld.%ld ev %d)",b->dline.tv_sec,b->dline.tv_nsec/1000, b->dline_timer); |
} |
} |
/* The on-line guarantee is enabled only if the appropriate flag is set... */ |
static int CBSSTAR_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
{ |
CBSSTAR_level_des *lev = (CBSSTAR_level_des *)(level_table[l]); |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf("(C:gua)"); |
#endif |
if (*freebandwidth >= lev->U) { |
*freebandwidth -= lev->U; |
return 1; |
} |
else |
return 0; |
} |
static void capacity_handler(void *l) |
{ |
//kern_printf("!"); |
CBSSTAR_level_des *lev =l; |
lev->cap_lev=NIL; |
event_need_reschedule(); |
} |
static int CBSSTAR_private_eligible(LEVEL l, PID p) |
{ |
CBSSTAR_level_des *lev = (CBSSTAR_level_des *)(level_table[l]); |
struct budget_struct *b = &lev->b[lev->tb[p]]; |
JOB_TASK_MODEL job; |
#ifdef CBSSTAR_DEBUG |
//kern_printf("(C:eli %d",p); |
#endif |
/* we have to check if the deadline and the wcet are correct... |
if the CBSSTAR level schedules in background with respect to others |
levels, there can be the case in witch a task is scheduled by |
schedule_time > CBSSTAR_deadline; in this case (not covered in the |
article because if there is only the standard scheduling policy |
this never apply) we reassign the deadline */ |
if (b->current==p) { |
if ( TIMESPEC_A_LT_B(&b->dline, &schedule_time)) { |
if (lev->cap_lev!=NIL) { |
kern_event_delete(lev->cap_lev); |
lev->cap_lev=NIL; |
} |
/* we kill the current activation */ |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level, p); |
/* we modify the deadline ... */ |
TIMESPEC_ASSIGN(&b->dline, &schedule_time); |
ADDUSEC2TIMESPEC(b->T, &b->dline); |
/* and the capacity */ |
b->avail = b->Q; |
b->flags=ACTIVE; |
if (b->dline_timer!=NIL) { |
kern_event_delete(b->dline_timer); |
b->dline_timer=NIL; |
} |
//#ifdef CBSSTAR_DEBUG |
//kern_printf(" %ld.%ld av=%d)",b->dline.tv_sec,b->dline.tv_nsec/1000, b->Q); |
//cbsstar_printf3("±%d±",lev->tb[p]); |
//cbsstar_printblob(lev->tb[p]); |
//#endif |
/* and, finally, we reinsert the task in the master level */ |
job_task_default_model(job, b->dline); |
job_task_def_noexc(job); |
//kern_printf("(CE:iact p%d %ld.%ld av=%d)",p,b->dline.tv_sec,b->dline.tv_nsec/1000, b->avail); |
level_table[ lev->scheduling_level ]-> |
private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
//kern_printf("task %d, avail %d", p, b->avail); |
return -1; |
} |
} |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf(")"); |
#endif |
return 0; |
} |
static void CBSSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m) |
{ |
/* A task has been activated for some reason. Basically, the task is |
inserted in the queue if the queue is empty, otherwise the task is |
inserted into the master module, and an oslib event is posted. */ |
CBSSTAR_level_des *lev = (CBSSTAR_level_des *)(level_table[l]); |
BUDGET_TASK_MODEL *budget; |
if (m->pclass != BUDGET_PCLASS || |
(m->level != 0 && m->level != l)) { |
kern_raise(XINVALID_TASK, p); |
return; |
} |
budget = (BUDGET_TASK_MODEL *)m; |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf("(C:gcr %d b%d", p, budget->b); |
#endif |
lev->tb[p] = budget->b; |
if (lev->b[budget->b].current == NIL && lev->b[budget->b].flags ) { |
/* This is the first task in the budget, |
the task have to be inserted into the master module */ |
struct timespec t; |
kern_gettime(&t); |
CBSSTAR_activation(lev,p,&t); |
} else { |
/* The budget is not empty, another task is already into the |
master module, so the task is inserted at the end of the budget |
queue */ |
iq_insertlast(p,&lev->b[budget->b].tasks); |
//#ifdef CBSSTAR_DEBUG |
//kern_printf(" ilast flag %d task %d",lev->b[budget->b].flags,lev->b[budget->b].current); |
// cbsstar_printq(&lev->b[budget->b].tasks); |
//#endif |
} |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf(")"); |
#endif |
} |
static void CBSSTAR_private_extract(LEVEL l, PID p) |
{ |
CBSSTAR_level_des *lev = (CBSSTAR_level_des *)(level_table[l]); |
//#ifdef CBSSTAR_DEBUG |
//kern_printf("(C:gend p%d c%d av=%d)", p, lev->b[lev->tb[p]].current, lev->b[lev->tb[p]].avail); |
//cbsstar_printq(&lev->b[lev->tb[p]].tasks); |
//#endif |
/* a task is removed from execution for some reasons. It must be |
that it is the first in its budget queue (only the first task in |
a budget queue is put into execution!) */ |
/* remove the task from execution (or from the ready queue) */ |
if (lev->b[lev->tb[p]].current == p) { |
CBSSTAR_account_capacity(lev,p); |
/* remove the task from the master module */ |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level, p); |
#ifdef CBSSTAR_DEBUG |
cbsstar_printq(&lev->b[lev->tb[p]].tasks); |
#endif |
/* check if the buffer has someone else to schedule */ |
if (iq_query_first(&lev->b[lev->tb[p]].tasks) == NIL) { |
/* the buffer has no tasks! */ |
lev->b[lev->tb[p]].current = NIL; |
} |
else if (lev->b[lev->tb[p]].flags) { |
/* if so, insert the new task into the master module */ |
PID n; |
struct timespec t; |
kern_gettime(&t); |
n = iq_getfirst(&lev->b[lev->tb[p]].tasks); |
//#ifdef CBSSTAR_DEBUG |
//kern_printf("{p%d n%d}",p,n); |
//#endif |
CBSSTAR_activation(lev,n,&t); // it modifies b[lev->tb[p]].current |
} |
else |
lev->b[lev->tb[p]].current=NIL; |
} |
else { |
iq_extract(p, &lev->b[lev->tb[p]].tasks); |
} |
} |
static void CBSSTAR_private_dispatch(LEVEL l, PID p, int nostop) |
{ |
CBSSTAR_level_des *lev = (CBSSTAR_level_des *)(level_table[l]); |
struct timespec ty; |
//#ifdef CBSSTAR_DEBUG |
//kern_printf("(C:gdisp p%d c%d av=%d)", p, lev->b[lev->tb[p]].current, lev->b[lev->tb[p]].avail); |
// cbsstar_printq(&lev->b[lev->tb[p]].tasks); |
//#endif |
/* the current task (that is the only one inserted in the master module |
for the corresponding budget) is dispatched. Note that the current |
task is not inserted in any FIFO queue, so the task does not have to |
be extracted! */ |
/* ... then, we dispatch it to the master level */ |
level_table[ lev->scheduling_level ]-> |
private_dispatch(lev->scheduling_level,p,nostop); |
/* ...and finally, we have to post a capacity event */ |
if (!nostop) { |
TIMESPEC_ASSIGN(&ty, &schedule_time); |
ADDUSEC2TIMESPEC(lev->b[lev->tb[p]].avail,&ty); |
lev->cap_lev = kern_event_post(&ty,capacity_handler, lev); |
} |
} |
static void CBSSTAR_private_epilogue(LEVEL l, PID p) |
{ |
CBSSTAR_level_des *lev = (CBSSTAR_level_des *)(level_table[l]); |
struct budget_struct *b = &lev->b[lev->tb[p]]; |
//#ifdef CBSSTAR_DEBUG |
//kern_printf("(C:gepi %d %d",p, b->current); |
//#endif |
if (p==b->current) { |
CBSSTAR_account_capacity(lev,p); |
// L'evento di capacità va cancellato perchè sarà ripristinato nella successiva dispatch |
/* we have to check if the capacity is still available */ |
if (b->flags) { |
/* there is capacity available, maybe it is simply a preemption; |
the task have to return to the ready queue */ |
level_table[ lev->scheduling_level ]-> |
private_epilogue(lev->scheduling_level,p); |
#ifdef CBSSTAR_DEBUG |
//kern_printf("(ep *av=%d", b->avail); |
#endif |
} else { |
/* we kill the current activation */ |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level, p); |
//kern_printf("extract"); |
iq_insertfirst(p, &b->tasks); |
proc_table[p].status = CBSSTAR_IDLE; |
b->current = NIL; |
//kern_printf("budget finish %d", b); |
} |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf(")"); |
#endif |
} |
} |
/* Registration functions }*/ |
/*+ Registration function: |
int flags the init flags ... see CBSSTAR.h +*/ |
LEVEL CBSSTAR_register_level(int n, LEVEL master) |
{ |
LEVEL l; /* the level that we register */ |
CBSSTAR_level_des *lev; /* for readableness only */ |
PID i; /* a counter */ |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf("CBSSTAR_register_level\n"); |
#endif |
/* request an entry in the level_table */ |
l = level_alloc_descriptor(sizeof(CBSSTAR_level_des)); |
lev = (CBSSTAR_level_des *)level_table[l]; |
printk(" lev=%d\n",(int)lev); |
/* fill the standard descriptor */ |
lev->l.private_insert = CBSSTAR_private_insert; |
lev->l.private_extract = CBSSTAR_private_extract; |
lev->l.private_eligible = CBSSTAR_private_eligible; |
lev->l.private_dispatch = CBSSTAR_private_dispatch; |
lev->l.private_epilogue = CBSSTAR_private_epilogue; |
lev->l.public_guarantee = CBSSTAR_public_guarantee; |
/* fill the CBSSTAR descriptor part */ |
lev->b = (struct budget_struct *)kern_alloc(sizeof(struct budget_struct)*n); |
for (i=0; i<n; i++) { |
lev->b[i].Q = 0; |
lev->b[i].T = 0; |
NULL_TIMESPEC(&lev->b[i].dline); |
lev->b[i].dline_timer = NIL; |
lev->b[i].avail = 0; |
lev->b[i].current = -1; |
lev->b[i].flags=INIT; |
iq_init(&lev->b[i].tasks, &freedesc, 0); |
} |
lev->n = n; |
lev->freebudgets = 0; |
for (i=0; i<MAX_PROC; i++) |
lev->tb[i] = NIL; |
lev->U = 0; |
lev->cap_lev=NIL; |
lev->scheduling_level = master; |
lev->on_shadow=NIL; |
return l; |
} |
int CBSSTAR_setbudget(LEVEL l, TIME Q, TIME T) |
{ |
CBSSTAR_level_des *lev = (CBSSTAR_level_des *)(level_table[l]); |
#ifdef CBSSTAR_DEBUG |
cbsstar_printf("(C:sbud)"); |
#endif |
if (lev->freebudgets != lev->n) { |
bandwidth_t b; |
b = (MAX_BANDWIDTH / T) * Q; |
/* really update lev->U, checking an overflow... */ |
if (Q< T && MAX_BANDWIDTH - lev->U > b) { |
int r = lev->freebudgets; // the return value |
lev->U += b; |
lev->freebudgets++; |
lev->b[r].Q = Q; |
lev->b[r].T = T; |
return r; |
} |
else |
return -2; |
} |
else |
return -1; |
} |
/unsupported/trunk/first/iqueue.h |
---|
0,0 → 1,172 |
/* |
* 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: iqueue.h,v 1.1 2004-06-01 11:42:43 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:43 $ |
------------ |
*/ |
/* |
* Copyright (C) 2002 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 |
* |
*/ |
/* |
IQUEUEs |
This file contains functions that helps to manage task queues. |
These functions are different from the functions that manages the |
QUEUE and QQUEUE types. In particular, these functions no more relies |
on the prev & next fields of the task descriptor. In that way, tasks |
can be inserted in more than one queue at a time. |
Basically, an IQUEUE has an "I"nternal prev/next structure, that may |
be shared between one or more queue. Of course, the user MUST |
guarantee that the same task will not be inserted in two IQUEUEs that |
share the same prev/next buffer. |
The queue insertion is made by the following functions: |
iq_insert -> insertion based on the priority field. |
iq_timespec_insert -> same as above but use the timespec_priority field |
iq_insertfirst -> insert in the first position of the queue |
*/ |
#include <kernel/const.h> |
#include <kernel/types.h> |
#include <sys/types.h> |
#define IQUEUE_NO_PRIORITY 1 |
#define IQUEUE_NO_TIMESPEC 2 |
struct IQUEUE_shared { |
PID prev[MAX_PROC]; |
PID next[MAX_PROC]; |
struct timespec *timespec_priority; |
DWORD *priority; |
}; |
typedef struct { |
PID first; |
PID last; |
struct IQUEUE_shared *s; |
} IQUEUE; |
/* Internal queue initialization: |
share = &x -> the internal data structure of the IQUEUE x is used |
to enqueue the tasks. |
share = NULL -> an internal data structure to handle prev/next |
pairs is dynamically allocated (The amount of |
memory that is allocated can be reduced using the |
flags). |
flags can be used to reduce the memory usage of an IQUEUE when share=NULL: |
IQUEUE_NO_PRIORITY -> the iqueue do not provide internally a priority field |
IQUEUE_NO_TIMESPEC -> the iqueue do not provide internally a timespec field |
- note that, if these flags are used, the corresponding insert |
functions will not work! |
- the default value for the flags is, of course, 0 |
*/ |
void iq_init (IQUEUE *q, IQUEUE *share, int flags); |
/* Queue insert functions: |
- inserts a p into the q. p must not be already inserted into q. |
- four versions of the function; |
- iq_priority_insert -> ordered insertion using the priority field |
- iq_timespec_insert -> ordered insertion using the timespec field |
- iq_insertfirst -> insert at the first position of the queue |
- iq_insertlast -> insert at the last position of the queue |
*/ |
void iq_priority_insert (PID p, IQUEUE *q); |
void iq_timespec_insert (PID p, IQUEUE *q); |
void iq_insertfirst (PID p, IQUEUE *q); |
void iq_insertlast (PID p, IQUEUE *q); |
/* Queue extract functions: |
- extracts a task p from the queue q. |
- three versions of the function; |
- iq_extract -> extracts given a task p |
(that must be inserted in the queue) |
- iq_getfirst -> extracts the first task in the queue, |
NIL if the queue is empty |
- iq_getlast -> extracts the last task in the queue, |
NIL if the queue is empty |
*/ |
void iq_extract (PID p, IQUEUE *q); |
PID iq_getfirst ( IQUEUE *q); |
PID iq_getlast ( IQUEUE *q); |
/* Queue query functions: |
The first two functions return the first and the last task in the queue, |
NIL if the queue is empty. |
The second two functions can be used to get/set the priority or the |
timespec field used when queuing. |
*/ |
static __inline__ PID iq_queryfirst(IQUEUE *q) |
{ |
return q->first; |
} |
static __inline__ PID iq_querylast(IQUEUE *q) |
{ |
return q->last; |
} |
static __inline__ struct timespec *iq_query_timespec(PID p, IQUEUE *q) |
{ |
return &q->s->timespec_priority[p]; |
} |
static __inline__ DWORD *iq_query_priority (PID p, IQUEUE *q) |
{ |
return &q->s->priority[p]; |
} |
/unsupported/trunk/first/test3.c |
---|
0,0 → 1,213 |
/* |
* 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: test3.c,v 1.1 2004-06-01 11:42:45 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:45 $ |
------------ |
The purpose of this test is to show that two budgets with different |
period and budgets schedules correctly. |
2 never ending tasks are involved |
*/ |
/* |
* Copyright (C) 2002 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "cbsstar.h" |
#include "edfstar.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "drivers/keyb.h" |
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
int cbsstar_level, edfstar_level, edfstar_level2, mybudget, mybudget2; |
clear(); |
EDF_register_level(EDF_ENABLE_ALL); |
cbsstar_level = CBSSTAR_register_level(3, 0); |
mybudget = CBSSTAR_setbudget(cbsstar_level, 2000, 50000); |
edfstar_level = EDFSTAR_register_level(mybudget, cbsstar_level); |
mybudget2 = CBSSTAR_setbudget(cbsstar_level, 10000, 25000); |
edfstar_level2 = EDFSTAR_register_level(mybudget2, cbsstar_level); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
cprintf("edfstar_level=%d, edfstar_level2=%d\n", |
edfstar_level,edfstar_level2); |
// for the keyboard... |
CBS_register_level(CBS_ENABLE_ALL, 0); |
SEM_register_module(); |
CABS_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
KEYB_PARMS kparms = BASE_KEYB; |
HARTPORT_init(); |
KEYB_init(&kparms); |
__call_main__(mb); |
return (void *)0; |
} |
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
#include <kernel/kern.h> |
#include <drivers/keyb.h> |
#include <semaphore.h> |
sem_t s; |
void *star(void *arg) |
{ |
int j,z; |
for (;;) { |
for (z=0; z<5; z++) { |
for (j=0; j<60000; j++); |
sem_wait(&s); |
cputs((char *)arg); |
sem_post(&s); |
} |
} |
return NULL; |
} |
void create1() |
{ |
HARD_TASK_MODEL m1; |
PID p1a, p1c; |
hard_task_default_model(m1); |
hard_task_def_wcet(m1, 5000); |
hard_task_def_group(m1,1); |
hard_task_def_periodic(m1); |
hard_task_def_level(m1,2); |
hard_task_def_arg(m1,(void *)"O"); |
hard_task_def_mit(m1,5000); |
p1a = task_create("a", star, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_def_level(m1,3); |
hard_task_def_arg(m1,(void *)"."); |
hard_task_def_mit(m1,5000); |
p1c = task_create("c", star, &m1, NULL); |
if (p1c == -1) { |
perror("Could not create task c ..."); |
sys_end(); |
} |
group_activate(1); |
} |
void endfun(KEY_EVT *k) |
{ |
cprintf("ESC pressed!"); |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
KEY_EVT k; |
sem_init(&s,0,1); |
k.flag = 0; |
k.scan = KEY_ESC; |
k.ascii = 27; |
keyb_hook(k,endfun); |
create1(); |
return 0; |
} |
/unsupported/trunk/first/test4.c |
---|
0,0 → 1,231 |
/* |
* 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: test4.c,v 1.1 2004-06-01 11:42:45 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:45 $ |
------------ |
The purpose of this test is to show that two budgets with different |
period and budgets schedules correctly. |
2 never ending tasks are involved |
*/ |
/* |
* Copyright (C) 2002 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "cbsstar.h" |
#include "edfstar.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "drivers/keyb.h" |
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
int cbsstar_level; |
int edfstar_level, edfstar_level2, edfstar_level3; |
int mybudget, mybudget2; |
clear(); |
EDF_register_level(EDF_ENABLE_ALL); |
cbsstar_level = CBSSTAR_register_level(3, 0); |
mybudget = CBSSTAR_setbudget(cbsstar_level, 2000, 50000); |
edfstar_level = EDFSTAR_register_level(mybudget, cbsstar_level); |
mybudget2 = CBSSTAR_setbudget(cbsstar_level, 10000, 25000); |
edfstar_level2 = EDFSTAR_register_level(mybudget2, cbsstar_level); |
edfstar_level3 = EDFSTAR_register_level(mybudget2, cbsstar_level); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
cprintf("edfstar_level=%d, edfstar_level2=%d\n", |
edfstar_level,edfstar_level2); |
// for the keyboard... |
CBS_register_level(CBS_ENABLE_ALL, 0); |
SEM_register_module(); |
CABS_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
KEYB_PARMS kparms = BASE_KEYB; |
HARTPORT_init(); |
//keyb_def_ctrlC(kparms, NULL); |
//keyb_def_map(kparms,itaMap); |
KEYB_init(&kparms); |
__call_main__(mb); |
return (void *)0; |
} |
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
#include <kernel/kern.h> |
#include <drivers/keyb.h> |
#include <semaphore.h> |
sem_t s; |
void *star(void *arg) |
{ |
int j,z; |
for (;;) { |
for (z=0; z<50; z++) { |
for (j=0; j<60000; j++); |
// sem_wait(&s); |
cputs((char *)arg); |
// sem_post(&s); |
} |
task_endcycle(); |
} |
return NULL; |
} |
void create1() |
{ |
HARD_TASK_MODEL m1; |
PID p1a, p1b, p1c; |
hard_task_default_model(m1); |
hard_task_def_wcet(m1, 5000); |
hard_task_def_group(m1,1); |
hard_task_def_periodic(m1); |
hard_task_def_level(m1,2); |
hard_task_def_arg(m1,(void *)"O"); |
hard_task_def_mit(m1,5000); |
p1a = task_create("a", star, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_def_level(m1,3); |
hard_task_def_arg(m1,(void *)"."); |
hard_task_def_mit(m1,5000); |
p1b = task_create("b", star, &m1, NULL); |
if (p1b == -1) { |
perror("Could not create task c ..."); |
sys_end(); |
} |
hard_task_def_level(m1,4); |
hard_task_def_arg(m1,(void *)","); |
hard_task_def_mit(m1,5000); |
p1c = task_create("c", star, &m1, NULL); |
if (p1c == -1) { |
perror("Could not create task c ..."); |
sys_end(); |
} |
group_activate(1); |
} |
void endfun(KEY_EVT *k) |
{ |
cprintf("ESC pressed!"); |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
KEY_EVT k; |
sem_init(&s,0,1); |
k.flag = 0; |
k.scan = KEY_ESC; |
k.ascii = 27; |
keyb_hook(k,endfun); |
create1(); |
return 0; |
} |
/unsupported/trunk/first/test5.c |
---|
0,0 → 1,248 |
/* |
* 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: test5.c,v 1.1 2004-06-01 11:42:45 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:45 $ |
------------ |
The purpose of this test is to show that two budgets with different |
period and budgets schedules correctly. |
2 never ending tasks are involved |
*/ |
/* |
* Copyright (C) 2002 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "cbsstar.h" |
#include "edfstar.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "drivers/keyb.h" |
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
int cbsstar_level; |
int edfstar_level, edfstar_level2, edfstar_level3; |
int mybudget, mybudget2; |
clear(); |
EDF_register_level(EDF_ENABLE_ALL); |
cbsstar_level = CBSSTAR_register_level(3, 0); |
mybudget = CBSSTAR_setbudget(cbsstar_level, 2000, 50000); |
edfstar_level = EDFSTAR_register_level(mybudget, cbsstar_level); |
mybudget2 = CBSSTAR_setbudget(cbsstar_level, 10000, 25000); |
edfstar_level2 = EDFSTAR_register_level(mybudget2, cbsstar_level); |
edfstar_level3 = EDFSTAR_register_level(mybudget2, cbsstar_level); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
cprintf("edfstar_level=%d, edfstar_level2=%d\n", |
edfstar_level,edfstar_level2); |
// for the keyboard... |
CBS_register_level(CBS_ENABLE_ALL, 0); |
CBS_register_level(CBS_ENABLE_ALL, edfstar_level3); |
SEM_register_module(); |
CABS_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
KEYB_PARMS kparms = BASE_KEYB; |
HARTPORT_init(); |
//keyb_def_ctrlC(kparms, NULL); |
//keyb_def_map(kparms,itaMap); |
KEYB_init(&kparms); |
__call_main__(mb); |
return (void *)0; |
} |
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
#include <kernel/kern.h> |
#include <drivers/keyb.h> |
#include <semaphore.h> |
sem_t s; |
void *star(void *arg) |
{ |
int j,z; |
for (;;) { |
for (z=0; z<50; z++) { |
for (j=0; j<60000; j++); |
// sem_wait(&s); |
cputs((char *)arg); |
// sem_post(&s); |
} |
task_endcycle(); |
} |
return NULL; |
} |
void create1() |
{ |
HARD_TASK_MODEL m1; |
SOFT_TASK_MODEL ms; |
PID p1a, p1b, p1c, p2; |
hard_task_default_model(m1); |
hard_task_def_wcet(m1, 5000); |
hard_task_def_group(m1,1); |
hard_task_def_periodic(m1); |
hard_task_def_level(m1,2); |
hard_task_def_arg(m1,(void *)"O"); |
hard_task_def_mit(m1,5000); |
p1a = task_create("a", star, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_def_level(m1,3); |
hard_task_def_arg(m1,(void *)"."); |
hard_task_def_mit(m1,50000); |
p1b = task_create("b", star, &m1, NULL); |
if (p1b == -1) { |
perror("Could not create task c ..."); |
sys_end(); |
} |
hard_task_def_level(m1,4); |
hard_task_def_arg(m1,(void *)","); |
hard_task_def_mit(m1,50000); |
p1c = task_create("c", star, &m1, NULL); |
if (p1c == -1) { |
perror("Could not create task c ..."); |
sys_end(); |
} |
soft_task_default_model(ms); |
soft_task_def_met(ms, 5000); |
soft_task_def_period(ms, 30000); |
soft_task_def_group(ms,1); |
soft_task_def_periodic(ms); |
soft_task_def_level(ms,8); |
soft_task_def_arg(ms,(void *)"X"); |
p2 = task_create("S", star, &ms, NULL); |
if (p2 == -1) { |
perror("Could not create task S ..."); |
sys_end(); |
} |
group_activate(1); |
} |
void endfun(KEY_EVT *k) |
{ |
cprintf("ESC pressed!"); |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
KEY_EVT k; |
sem_init(&s,0,1); |
k.flag = 0; |
k.scan = KEY_ESC; |
k.ascii = 27; |
keyb_hook(k,endfun); |
create1(); |
return 0; |
} |
/unsupported/trunk/first/test6.c |
---|
0,0 → 1,248 |
/* |
* 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: test6.c,v 1.1 2004-06-01 11:42:45 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:45 $ |
------------ |
this test shows a set of 5 tasks (+main+dummy+keyboard driver). |
The first 4 tasks are scheduled by a RMSTAR Module, whereas the |
fifth one is a standard traditional EDF task. The 4 tasks uses a |
budget of 10000/100000. |
if edfstar.c is compiled with edfstar_printf3 active, a couple |
(dline, curtime) is showed (in ms). |
if cbsstar.c is compiled with cbsstar_printf3 active, the budget |
replenishments are showed. |
*/ |
/* |
* Copyright (C) 2002 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "cbsstar.h" |
#include "rmstar.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "drivers/keyb.h" |
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
int cbsstar_level, rmstar_level, mybudget; |
EDF_register_level(EDF_ENABLE_ALL); |
cbsstar_level = CBSSTAR_register_level(3, 0); |
mybudget = CBSSTAR_setbudget(cbsstar_level, 10000, 100000); |
rmstar_level = RMSTAR_register_level(mybudget, cbsstar_level); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
// for the keyboard... |
CBS_register_level(CBS_ENABLE_ALL, 0); |
SEM_register_module(); |
CABS_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
KEYB_PARMS kparms = BASE_KEYB; |
HARTPORT_init(); |
//keyb_def_ctrlC(kparms, NULL); |
//keyb_def_map(kparms,itaMap); |
KEYB_init(&kparms); |
__call_main__(mb); |
return (void *)0; |
} |
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
#include <kernel/kern.h> |
#include <drivers/keyb.h> |
void *star(void *arg) |
{ |
int i,j; |
for (i=0; i<5; i++) { |
for (j=0; j<100000; j++); |
cputc('°'); |
cputs((char *)arg); |
task_endcycle(); |
} |
return NULL; |
} |
void *edftask(void *arg) |
{ |
int i,j; |
for (i=0; i<5; i++) { |
for (j=0; j<100000; j++); |
cputc('°'); |
cputs((char *)arg); |
task_endcycle(); |
} |
return NULL; |
} |
void create1() |
{ |
HARD_TASK_MODEL m1, m2; |
PID p1a, p1b, p1c, p1d, p2; |
hard_task_default_model(m1); |
hard_task_def_wcet(m1, 5000); |
hard_task_def_level(m1,2); |
hard_task_def_group(m1,1); |
hard_task_def_periodic(m1); |
hard_task_def_arg(m1,(void *)"a"); |
hard_task_def_mit(m1,10000); |
p1a = task_create("a", star, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_def_arg(m1,(void *)"b"); |
hard_task_def_mit(m1,15000); |
p1b = task_create("b", star, &m1, NULL); |
if (p1b == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
hard_task_def_arg(m1,(void *)"c"); |
hard_task_def_mit(m1,20000); |
p1c = task_create("c", star, &m1, NULL); |
if (p1c == -1) { |
perror("Could not create task c ..."); |
sys_end(); |
} |
hard_task_def_arg(m1,(void *)"d"); |
hard_task_def_mit(m1,30000); |
p1d = task_create("d", star, &m1, NULL); |
if (p1d == -1) { |
perror("Could not create task d ..."); |
sys_end(); |
} |
hard_task_default_model(m2); |
hard_task_def_mit(m2,50000); // the budget has dline 100,000! |
hard_task_def_wcet(m2, 5000); |
hard_task_def_arg(m2,(void *)"Û"); |
hard_task_def_group(m2,1); |
hard_task_def_periodic(m2); |
p2 = task_create("2", edftask, &m2, NULL); |
if (p2 == -1) { |
perror("Could not create task edf ..."); |
sys_end(); |
} |
cprintf("stars=%d %d %d %d, star2=%d\n", p1a, p1b, p1c, p1d, p2); |
group_activate(1); |
} |
int main(int argc, char **argv) |
{ |
char c; |
clear(); |
cprintf("Hello, world!"); |
create1(); |
do { |
c =keyb_getch(BLOCK); |
} while (c != ESC); |
cprintf("ESC pressed!"); |
sys_end(); |
return 0; |
} |
/unsupported/trunk/first/test7.c |
---|
0,0 → 1,338 |
/* |
* 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: test7.c,v 1.1 2004-06-01 11:42:46 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:46 $ |
------------ |
this test shows a set of 5 tasks (+main+dummy+keyboard driver). |
The first 4 tasks are scheduled by a EDFSTAR Module, whereas the |
fifth one is a standard traditional EDF task. The 4 tasks uses a |
budget of 10000/100000. |
if edfstar.c is compiled with edfstar_printf3 active, a couple |
(dline, curtime) is showed (in ms). |
if cbsstar.c is compiled with cbsstar_printf3 active, the budget |
replenishments are showed. |
*/ |
/* |
* Copyright (C) 2002 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "cbsstar.h" |
#include "posixstar.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "modules/pi.h" |
#include "modules/nop.h" |
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
int cbsstar_level, posixstar_level, mybudget, mybudget1, posixstar_level1; |
EDF_register_level(EDF_ENABLE_ALL); |
cbsstar_level = CBSSTAR_register_level(3, 0); |
mybudget = CBSSTAR_setbudget(cbsstar_level, 15000, 30000); |
mybudget1 = CBSSTAR_setbudget(cbsstar_level, 14000, 56000); |
posixstar_level = POSIXSTAR_register_level(mybudget, cbsstar_level, 3000,1); |
posixstar_level1 = POSIXSTAR_register_level(mybudget1, cbsstar_level, 5000,1); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
// for the keyboard... |
//CBS_register_level(CBS_ENABLE_ALL, 0); |
//SEM_register_module(); |
PI_register_module(); |
NOP_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
//CABS_register_module(); |
//keyb_def_map(kparms,itaMap); |
//KEYB_init(&kparms); |
__call_main__(mb); |
return (void *)0; |
} |
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
#include <kernel/kern.h> |
#include <drivers/keyb.h> |
#include <semaphore.h> |
mutex_t s; |
void *star(void *arg) |
{ |
int j; |
for (;;) { |
for (j=0; j<5000; j++); |
//sem_wait(&s); |
mutex_lock(&s); |
cputc('°'); |
cputs((char *)arg); |
mutex_unlock(&s); |
//kern_printf("ril"); |
//sem_post(&s); |
//task_endcycle(); |
} |
return NULL; |
} |
void *edftask(void *arg) |
{ |
int i,j; |
while(1) { |
for (i=0;i<5; i++) { |
for (j=0; j<10; j++); |
//sem_wait(&s); |
//mutex_lock(&s); |
cputc('°'); |
cputs((char *)arg); |
//mutex_unlock(&s); |
//sem_post(&s); |
} |
task_endcycle(); |
} |
return NULL; |
} |
void create1() |
{ |
int i; |
NRT_TASK_MODEL m1; |
HARD_TASK_MODEL m2; |
PID p1a, p1b, p1c[20],p2,p3; |
struct timespec fineprg; |
nrt_task_default_model(m1); |
nrt_task_def_group(m1, 1); |
nrt_task_def_level(m1,2); |
nrt_task_def_arg(m1,(void *)"A"); |
nrt_task_def_weight(m1,0); |
p1a = task_create("a",star,&m1,NULL); |
if (p1a == -1) { |
perror("Could not create task <Write>"); |
sys_abort(-1); |
} |
nrt_task_def_arg(m1,(void *)"B"); |
nrt_task_def_group(m1, 1); |
nrt_task_def_level(m1,2); |
p1b = task_create("b", star, &m1, NULL); |
if (p1b == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
nrt_task_def_arg(m1,(void *)"1"); |
nrt_task_def_group(m1, 1); |
nrt_task_def_level(m1,2); |
p1c[5] = task_create("1", star, &m1, NULL); |
if (p1c[5] == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
nrt_task_def_arg(m1,(void *)"C"); |
nrt_task_def_group(m1, 1); |
nrt_task_def_level(m1,2); |
p1c[4] = task_create("c", star, &m1, NULL); |
if (p1c[4] == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
nrt_task_def_arg(m1,(void *)"D"); |
nrt_task_def_group(m1, 1); |
nrt_task_def_level(m1,2); |
p1c[5] = task_create("d", star, &m1, NULL); |
if (p1c[5] == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
nrt_task_def_arg(m1,(void *)"E"); |
nrt_task_def_group(m1, 1); |
nrt_task_def_level(m1,2); |
p1c[0] = task_create("e", star, &m1, NULL); |
if (p1c[0] == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
nrt_task_def_arg(m1,(void *)"F"); |
p1c[1] = task_create("f", star, &m1, NULL); |
if (p1c[1] == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
nrt_task_def_arg(m1,(void *)"G"); |
nrt_task_def_group(m1, 1); |
nrt_task_def_level(m1,2); |
p1c[2] = task_create("g", star, &m1, NULL); |
if (p1c[2] == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
nrt_task_def_arg(m1,(void *)"H"); |
p1c[3] = task_create("h", star, &m1, NULL); |
if (p1c[3] == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
nrt_task_def_arg(m1,(void *)"I"); |
p1c[4] = task_create("h", star, &m1, NULL); |
if (p1c[4] == -1) { |
perror("Could not create task b ..."); |
sys_end(); |
} |
hard_task_default_model(m2); |
hard_task_def_ctrl_jet(m2); |
hard_task_def_mit(m2,32000); // the budget has dline 100,000! |
hard_task_def_wcet(m2, 3000); |
hard_task_def_arg(m2,(void *)"X"); |
hard_task_def_group(m2,1); |
hard_task_def_periodic(m2); |
p2 = task_create("2", edftask, &m2, NULL); |
if (p2 == -1) { |
perror("Could not create task edf ..."); |
sys_end(); |
} |
hard_task_def_mit(m2,32000); // the budget has dline 100,000! |
hard_task_def_wcet(m2, 3000); |
hard_task_def_arg(m2,(void *)"K"); |
p3 = task_create("3", edftask, &m2, NULL); |
if (p3 == -1) { |
perror("Could not create task edf ..."); |
sys_end(); |
} |
cprintf("stars=%d", p2); |
fineprg.tv_sec=140; |
fineprg.tv_nsec=0; |
kern_event_post(&fineprg,(void(*)(void *))sys_end, NULL); |
group_activate(1); |
} |
int main(int argc, char **argv) |
{ |
char c='t'; |
PI_mutexattr_t a; |
PI_mutexattr_default(a); |
//NOP_mutexattr_t a; |
//NOP_mutexattr_default(a); |
mutex_init(&s,&a); |
clear(); |
cprintf("Hello, world!\nPress ESC to end the demo...\n"); |
create1(); |
do { |
//c =keyb_getch(BLOCK); |
// cprintf("[]"); |
} while (c != ESC); |
cprintf("ESC pressed!"); |
sys_end(); |
return 0; |
} |
/unsupported/trunk/first/cbsstar.h |
---|
0,0 → 1,157 |
/* |
* 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: cbsstar.h,v 1.1 2004-06-01 11:42:43 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:43 $ |
------------ |
This file contains the budget support for the multiapplication |
scheduling algorithm proposed in the framework of the FIRST Project |
Title: |
CBSSTAR |
Task Models Accepted: |
None! |
Guest Models Accepted: |
BUDGET_TASK_MODEL - A task that is attached to a budget |
int b; --> the number of the budget which the task is attached to |
Description: |
This module schedule its tasks following the CBS scheme. |
Every task is inserted using the guest calls. |
The module defines a limited set of budgets that the application |
can use. Every guest task will use a particular budget; FIFO |
scheduling is used inside a budget to schedule more than one ready |
task attached to the same budget. |
The tasks are inserted in an EDF level (or similar) with a JOB_TASK_MODEL, |
and the CBS level expects that the task is scheduled with the absolute |
deadline passed in the model. |
This module tries to implement a simplified version of the guest |
task interface: |
- To insert a guest task, use guest_create |
- When a task is dispatched, use guest_dispatch |
- When a task have to be suspended, you have to use: |
-> preemption: use guest_epilogue |
-> synchronization, end: use guest_end |
Remember: no check is done on the budget number passed with the model!!! |
Exceptions raised: |
XUNVALID_TASK |
This level doesn't support normal tasks, but just guest tasks. |
When a task operation is called, an exception is raised. |
Restrictions & special features: |
- This level doesn't manage the main task. |
- At init time we have to specify: |
. guarantee check |
(when all task are created the system will check that the task_set |
will not use more than the available bandwidth) |
- A function to return the used bandwidth of the level is provided. |
- A function is provided to allocate a buffer. |
*/ |
/* |
* Copyright (C) 2002 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 __CBSSTAR_H__ |
#define __CBSSTAR_H__ |
#include <kernel/kern.h> |
//#include <ll/ll.h> |
//#include <kernel/config.h> |
//#include <sys/types.h> |
//#include <kernel/types.h> |
//#include <modules/codes.h> |
/* ----------------------------------------------------------------------- |
BUDGET_TASK_MODEL: a model for guest tasks |
----------------------------------------------------------------------- */ |
#define BUDGET_PCLASS 0x0600 |
typedef struct { |
TASK_MODEL t; |
int b; |
} BUDGET_TASK_MODEL; |
#define budget_task_default_model(m,buf) \ |
task_default_model((m).t, BUDGET_PCLASS), \ |
(m).b = (buf); |
/* some constants for registering the Module in the right place */ |
#define CBSSTAR_LEVELNAME "CBSSTAR" |
#define CBSSTAR_LEVEL_CODE 106 |
#define CBSSTAR_LEVEL_VERSION 1 |
/* Registration function: |
int N Maximum number of budgets allocated for the applications |
LEVEL master the level that must be used as master level for the |
CBS tasks |
*/ |
LEVEL CBSSTAR_register_level(int n, LEVEL master); |
/* Allocates a budget to be used for an application. |
Input parameters: |
Q The budget |
T The period of the budget |
Return value: |
0..N The ID of the budget |
-1 no more free budgets |
-2 The budgets allocated locally to this module have bandwidth > 1 |
-3 wrong LEVEL id |
*/ |
int CBSSTAR_setbudget(LEVEL l, TIME Q, TIME T); |
#endif |
/unsupported/trunk/first/rmstar.c |
---|
0,0 → 1,640 |
/* |
* 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 2004-06-01 11:42:44 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:44 $ |
------------ |
**/ |
/* |
* 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> |
/* for iqueues */ |
/* #include "iqueue.h" Now iqueues are the only queue type into the kernel */ |
/* for BUDGET_TASK_MODEL */ |
#include "cbsstar.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; |
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); |
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 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 |
/* 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; |
#ifdef RMSTAR_DEBUG |
rmstar_printf("(E:ecy "); |
#endif |
/* 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... */ |
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 budget, 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; |
} |
iq_init(&lev->ready, NULL, 0); |
lev->activated = NIL; |
lev->budget = budget; |
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; |
} |
/unsupported/trunk/first/testiq.c |
---|
0,0 → 1,260 |
/* |
* 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: testiq.c,v 1.1 2004-06-01 11:42:46 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:46 $ |
------------ |
The purpose of this test is to show that two budgets with different |
period and budgets schedules correctly. |
2 never ending tasks are involved |
This test cannot compile because of the fact that QUEUE and QQUEUE |
types does not exist anymore! |
*/ |
/* |
* Copyright (C) 2002 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/cbs.h" |
#include "cbsstar.h" |
#include "edfstar.h" |
#include "modules/rr.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "modules/cabs.h" |
#include "drivers/keyb.h" |
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
/*+ sysyem tick in us +*/ |
#define TICK 0 |
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
clear(); |
EDF_register_level(EDF_ENABLE_ALL); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
dummy_register_level(); |
// for the keyboard... |
CBS_register_level(CBS_ENABLE_ALL, 0); |
SEM_register_module(); |
CABS_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
KEYB_PARMS kparms = BASE_KEYB; |
HARTPORT_init(); |
//keyb_def_ctrlC(kparms, NULL); |
//keyb_def_map(kparms,itaMap); |
KEYB_init(&kparms); |
__call_main__(mb); |
return (void *)0; |
} |
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
#include <kernel/kern.h> |
#include <drivers/keyb.h> |
#include "iqueue.h" |
sem_t s; |
PID p2,p3,p4; |
void *star(void *arg) |
{ |
int j; |
TIME last[5]; |
QUEUE i = NIL; |
IQUEUE ii; |
q_timespec_insert(p2,&i); |
q_timespec_insert(p3,&i); |
iq_init(&ii,NULL,0); |
*iq_query_timespec(p2,&ii) = proc_table[p2].timespec_priority; |
*iq_query_timespec(p3,&ii) = proc_table[p3].timespec_priority; |
*iq_query_timespec(p4,&ii) = proc_table[p4].timespec_priority; |
iq_timespec_insert(p2,&ii); |
iq_timespec_insert(p3,&ii); |
cprintf("p2=%ld.%ld\n",proc_table[p2].timespec_priority.tv_sec,proc_table[p2].timespec_priority.tv_nsec/1000); |
cprintf("p3=%ld.%ld\n",proc_table[p3].timespec_priority.tv_sec,proc_table[p3].timespec_priority.tv_nsec/1000); |
cprintf("p4=%ld.%ld\n",proc_table[p4].timespec_priority.tv_sec,proc_table[p4].timespec_priority.tv_nsec/1000); |
task_endcycle(); |
for (j=0; j<200000; j++) { |
q_timespec_insert(p4,&i); |
q_extract(p4,&i); |
} |
task_endcycle(); |
for (j=0; j<200000; j++) { |
iq_timespec_insert(p4,&ii); |
iq_extract(p4,&ii); |
} |
task_endcycle(); |
jet_gettable(exec_shadow, &last[0], 3); |
cprintf("\ninit=%d queue=%d iqueue=%d\n", |
(int)last[0], (int)last[1], (int)last[2]); |
sys_end(); |
return NULL; |
} |
void *fake(void *arg) |
{ |
cputs("#"); |
task_endcycle(); |
return NULL; |
} |
void create1() |
{ |
HARD_TASK_MODEL m1; |
PID p1a; |
hard_task_default_model(m1); |
hard_task_def_wcet(m1, 500000); |
hard_task_def_group(m1,1); |
hard_task_def_periodic(m1); |
hard_task_def_mit(m1,1000000); |
hard_task_def_ctrl_jet(m1); |
p1a = task_create("a", star, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_default_model(m1); |
hard_task_def_wcet(m1, 5000); |
hard_task_def_aperiodic(m1); |
hard_task_def_group(m1,1); |
hard_task_def_mit(m1,100000); |
p2 = task_create("a", fake, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_def_mit(m1,100001); |
p3 = task_create("a", fake, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
hard_task_def_mit(m1,100002); |
p4 = task_create("a", fake, &m1, NULL); |
if (p1a == -1) { |
perror("Could not create task a ..."); |
sys_end(); |
} |
group_activate(1); |
} |
void endfun(KEY_EVT *k) |
{ |
cprintf("ESC pressed!"); |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
KEY_EVT k; |
sem_init(&s,0,1); |
k.flag = 0; |
k.scan = KEY_ESC; |
k.ascii = 27; |
keyb_hook(k,endfun); |
create1(); |
return 0; |
} |
/unsupported/trunk/first/rmstar.h |
---|
0,0 → 1,128 |
/* |
* 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 2004-06-01 11:42:44 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:44 $ |
------------ |
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 budget, 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); |
#endif |
/unsupported/trunk/first/edfstar.c |
---|
0,0 → 1,657 |
/* |
* 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: edfstar.c,v 1.1 2004-06-01 11:42:43 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:43 $ |
------------ |
**/ |
/* |
* 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 "edfstar.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> |
/* for iqueues */ |
/* #include "iqueue.h" Now iqueues are the only queue type available |
into the kernel */ |
#include <kernel/iqueue.h> |
/* for BUDGET_TASK_MODEL */ |
#include "cbsstar.h" |
/* |
* DEBUG stuffs begin |
*/ |
//#define EDFSTAR_DEBUG |
#ifdef EDFSTAR_DEBUF |
static __inline__ fake_printf(char *fmt, ...) {} |
#define edfstar_printf fake_printf |
#define edfstar_printf2 fake_printf |
#define edfstar_printf3 fake_printf |
//#define edfstar_printf kern_printf |
//#define edfstar_printf2 kern_printf |
//#define edfstar_printf3 kern_printf |
#endif |
/* |
* DEBUG stuffs end |
*/ |
/* Status used in the level */ |
#define EDFSTAR_READY MODULE_STATUS_BASE /* - Ready status */ |
#define EDFSTAR_IDLE MODULE_STATUS_BASE+4 /* to wait the deadline */ |
/* flags */ |
#define EDFSTAR_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; |
int scheduling_level; |
} EDFSTAR_level_des; |
static void EDFSTAR_check_preemption(EDFSTAR_level_des *lev) |
{ |
PID first; |
#ifdef EDFSTAR_DEBUG |
edfstar_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); |
level_table[ lev->scheduling_level ]-> |
private_insert(lev->scheduling_level, first, (TASK_MODEL *)&b); |
} |
} |
} |
static void EDFSTAR_timer_deadline(void *par); |
static void EDFSTAR_internal_activate(EDFSTAR_level_des *lev, PID p, |
struct timespec *t) |
{ |
#ifdef EDFSTAR_DEBUG |
edfstar_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 = EDFSTAR_READY; |
iq_timespec_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 */ |
EDFSTAR_check_preemption(lev); |
} |
static void EDFSTAR_timer_deadline(void *par) |
{ |
PID p = (PID) par; |
EDFSTAR_level_des *lev; |
#ifdef EDFSTAR_DEBUG |
// edfstar_printf("(E:tdl "); |
#endif |
lev = (EDFSTAR_level_des *)level_table[proc_table[p].task_level]; |
switch (proc_table[p].status) { |
case EDFSTAR_IDLE: |
#ifdef EDFSTAR_DEBUG |
// edfstar_printf2("I%d",p); |
#endif |
/* set the request time */ |
EDFSTAR_internal_activate(lev,p,iq_query_timespec(p, &lev->ready)); |
event_need_reschedule(); |
break; |
default: |
#ifdef EDFSTAR_DEBUG |
// edfstar_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], |
EDFSTAR_timer_deadline, |
(void *)p); |
#ifdef EDFSTAR_DEBUG |
// edfstar_printf(")"); |
#endif |
} |
static void EDFSTAR_timer_guest_deadline(void *par) |
{ |
PID p = (PID) par; |
#ifdef EDFSTAR_DEBUG |
edfstar_printf("(E:gdl)"); |
#endif |
kern_raise(XDEADLINE_MISS,p); |
} |
static int EDFSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
/* if the EDFSTAR_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 EDFSTAR_DEBUG |
edfstar_printf("(E:tcr)"); |
#endif |
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; |
/* 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 int EDFSTAR_public_eligible(LEVEL l, PID p) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
#ifdef EDFSTAR_DEBUG |
edfstar_printf2("(E:eli)"); |
#endif |
return level_table[ lev->scheduling_level ]-> |
private_eligible(lev->scheduling_level,p); |
} |
static void EDFSTAR_public_dispatch(LEVEL l, PID p, int nostop) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
#ifdef EDFSTAR_DEBUG |
edfstar_printf("(E:dis)"); |
edfstar_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 EDFSTAR_public_epilogue(LEVEL l, PID p) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
#ifdef EDFSTAR_DEBUG |
edfstar_printf("(E:epi "); |
#endif |
/* 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 EDFSTAR_DEBUG |
edfstar_printf2("W%d",p); |
#endif |
proc_table[p].control &= ~CONTROL_CAP; |
lev->wcet_miss[p]++; |
} |
#ifdef EDFSTAR_DEBUG |
edfstar_printf(")"); |
#endif |
level_table[ lev->scheduling_level ]-> |
private_epilogue(lev->scheduling_level,p); |
proc_table[p].status = EDFSTAR_READY; |
} |
static void EDFSTAR_public_activate(LEVEL l, PID p) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
struct timespec t; |
#ifdef EDFSTAR_DEBUG |
edfstar_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); |
EDFSTAR_internal_activate(lev,p, &t); |
/* Set the deadline timer */ |
lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p], |
EDFSTAR_timer_deadline, |
(void *)p); |
} |
static void EDFSTAR_public_unblock(LEVEL l, PID p) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
#ifdef EDFSTAR_DEBUG |
edfstar_printf("(E:ins)"); |
#endif |
/* Insert task in the correct position */ |
proc_table[p].status = EDFSTAR_READY; |
iq_timespec_insert(p,&lev->ready); |
/* and check for preemption! */ |
EDFSTAR_check_preemption(lev); |
} |
static void EDFSTAR_public_block(LEVEL l, PID p) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
#ifdef EDFSTAR_DEBUG |
edfstar_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) */ |
EDFSTAR_check_preemption(lev); |
} |
static int EDFSTAR_public_message(LEVEL l, PID p, void *m) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
struct timespec temp; |
#ifdef EDFSTAR_DEBUG |
edfstar_printf("(E:ecy "); |
#endif |
/* 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 EDFSTAR_DEBUG |
edfstar_printf2("E%d",p); |
#endif |
/* Pending activation: reactivate the thread!!! */ |
lev->nact[p]--; |
/* see also EDFSTAR_timer_deadline */ |
kern_gettime(&temp); |
EDFSTAR_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 EDFSTAR_DEBUG |
edfstar_printf("e%d",p); |
#endif |
/* the task has terminated his job before it consume the wcet. All OK! */ |
proc_table[p].status = EDFSTAR_IDLE; |
/* and finally, a preemption check! */ |
EDFSTAR_check_preemption(lev); |
/* when the deadline timer fire, it recognize the situation and set |
correctly all the stuffs (like reactivation, etc... ) */ |
} |
#ifdef EDFSTAR_DEBUG |
edfstar_printf(")"); |
#endif |
jet_update_endcycle(); /* Update the Jet data... */ |
return 0; |
} |
static void EDFSTAR_public_end(LEVEL l, PID p) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
#ifdef EDFSTAR_DEBUG |
edfstar_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) */ |
EDFSTAR_check_preemption(lev); |
} |
/* Guest Functions |
These functions manages a JOB_TASK_MODEL, that is used to put |
a guest task in the EDFSTAR ready queue. */ |
static void EDFSTAR_private_insert(LEVEL l, PID p, TASK_MODEL *m) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_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; |
/* if the EDFSTAR_guest_create is called, then the pclass must be a |
valid pclass. */ |
*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] = EDFSTAR_FLAG_NORAISEEXC; |
else { |
lev->flag[p] = 0; |
lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready), |
EDFSTAR_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 = EDFSTAR_READY; |
/* check for preemption */ |
EDFSTAR_check_preemption(lev); |
/* there is no bandwidth guarantee at this level, it is performed |
by the level that inserts guest tasks... */ |
} |
static void EDFSTAR_private_dispatch(LEVEL l, PID p, int nostop) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
level_table[ lev->scheduling_level ]-> |
private_dispatch(lev->scheduling_level,p,nostop); |
} |
static void EDFSTAR_private_epilogue(LEVEL l, PID p) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_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 = EDFSTAR_READY; |
} |
static void EDFSTAR_private_extract(LEVEL l, PID p) |
{ |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
#ifdef EDFSTAR_DEBUG |
//kern_printf("EDFSTAR_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 EDFSTAR_DEBUG |
// kern_printf("EDFSTAR_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() */ |
EDFSTAR_check_preemption(lev); |
} |
/* Registration functions */ |
/* Registration function: |
int flags the init flags ... see EDFSTAR.h */ |
LEVEL EDFSTAR_register_level(int budget, int master) |
{ |
LEVEL l; /* the level that we register */ |
EDFSTAR_level_des *lev; /* for readableness only */ |
PID i; /* a counter */ |
#ifdef EDFSTAR_DEBUG |
printk("EDFSTAR_register_level\n"); |
#endif |
/* request an entry in the level_table */ |
l = level_alloc_descriptor(sizeof(EDFSTAR_level_des)); |
lev = (EDFSTAR_level_des *)level_table[l]; |
printk(" lev=%d\n",(int)lev); |
/* fill the standard descriptor */ |
lev->l.private_insert = EDFSTAR_private_insert; |
lev->l.private_extract = EDFSTAR_private_extract; |
lev->l.private_dispatch = EDFSTAR_private_dispatch; |
lev->l.private_epilogue = EDFSTAR_private_epilogue; |
lev->l.public_guarantee = NULL; |
lev->l.public_eligible = EDFSTAR_public_eligible; |
lev->l.public_create = EDFSTAR_public_create; |
lev->l.public_end = EDFSTAR_public_end; |
lev->l.public_dispatch = EDFSTAR_public_dispatch; |
lev->l.public_epilogue = EDFSTAR_public_epilogue; |
lev->l.public_activate = EDFSTAR_public_activate; |
lev->l.public_unblock = EDFSTAR_public_unblock; |
lev->l.public_block = EDFSTAR_public_block; |
lev->l.public_message = EDFSTAR_public_message; |
/* fill the EDFSTAR 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; |
} |
iq_init(&lev->ready, NULL, IQUEUE_NO_PRIORITY); |
lev->activated = NIL; |
lev->budget = budget; |
lev->scheduling_level = master; |
return l; |
} |
int EDFSTAR_get_dline_miss(PID p) |
{ |
LEVEL l = proc_table[p].task_level; |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
return lev->dline_miss[p]; |
} |
int EDFSTAR_get_wcet_miss(PID p) |
{ |
LEVEL l = proc_table[p].task_level; |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
return lev->wcet_miss[p]; |
} |
int EDFSTAR_get_nact(PID p) |
{ |
LEVEL l = proc_table[p].task_level; |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
return lev->nact[p]; |
} |
int EDFSTAR_reset_dline_miss(PID p) |
{ |
LEVEL l = proc_table[p].task_level; |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
lev->dline_miss[p] = 0; |
return 0; |
} |
int EDFSTAR_reset_wcet_miss(PID p) |
{ |
LEVEL l = proc_table[p].task_level; |
EDFSTAR_level_des *lev = (EDFSTAR_level_des *)(level_table[l]); |
lev->wcet_miss[p] = 0; |
return 0; |
} |
/unsupported/trunk/first/posixstar.c |
---|
0,0 → 1,541 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Trimarchi Michael <trimarchi@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: posixstar.c,v 1.1 2004-06-01 11:42:44 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:44 $ |
------------ |
This file contains the scheduling module compatible with POSIX |
specifications |
Read posixstar.h for further details. |
RR tasks have the CONTROL_CAP bit set |
**/ |
/* |
* Copyright (C) 2000 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 WARR2ANTY; without even the implied waRR2anty 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 <ll/stdio.h> |
#include <ll/string.h> |
#include <kernel/model.h> |
#include <kernel/descr.h> |
#include <kernel/var.h> |
#include <kernel/func.h> |
#include "posixstar.h" |
#include "cbsstar.h" |
//#define POSIXSTAR_DEBUG |
/*+ Status used in the level +*/ |
#define POSIXSTAR_READY MODULE_STATUS_BASE |
/*+ the level redefinition for the Round Robin level +*/ |
typedef struct { |
level_des l; /*+ the standard level descriptor +*/ |
int nact[MAX_PROC]; /*+ number of pending activations +*/ |
int priority[MAX_PROC]; /*+ priority of each task +*/ |
IQUEUE *ready; /*+ the ready queue array +*/ |
int slice; /*+ the level's time slice +*/ |
// the multiboot is not usefull for this module |
// struct multiboot_info *multiboot; /*+ used if the level have to insert |
// the main task +*/ |
int maxpriority; /*+ the priority are from 0 to maxpriority |
(i.e 0 to 31) +*/ |
int yielding; /*+ equal to 1 when a sched_yield is called +*/ |
int budget; |
PID activated; |
int scheduling_level; |
} POSIXSTAR_level_des; |
/* the private scheduler choice a task and insert in cbsstar module */ |
/* This is not efficient but very fair :-) |
The need of all this stuff is because if a task execute a long time |
due to (shadow!) priority inheritance, then the task shall go to the |
tail of the queue many times... */ |
static void POSIXSTAR_private_scheduler(POSIXSTAR_level_des * lev) |
{ |
/* the old posix scheduler select the private job for CBS */ |
PID p=NIL; |
int prio; |
prio = lev->maxpriority; |
for (;;) { |
p = iq_query_first(&lev->ready[prio]); |
if (p == NIL) { |
if (prio) { |
prio--; |
continue; |
} |
else { |
p=NIL; |
break; |
} |
} |
//if (p != NIL && (proc_table[p].control & CONTROL_CAP)) |
// kern_printf("CC SET %d",p); |
//kern_printf("task %d", p); |
if ((proc_table[p].control & CONTROL_CAP) && |
(proc_table[p].avail_time <= 0)) { |
if (proc_table[p].avail_time<=0) |
proc_table[p].avail_time += proc_table[p].wcet; |
//kern_printf("RR policy"); |
iq_extract(p,&lev->ready[prio]); |
iq_insertlast(p,&lev->ready[prio]); |
} |
else { |
break; |
} |
} |
if (p!=lev->activated) { |
if (lev->activated != NIL ) { |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level, lev->activated); |
//kern_printf("CBS ext %d",p); |
} |
lev->activated = p; |
if (p != NIL) { |
BUDGET_TASK_MODEL b; |
budget_task_default_model(b, lev->budget); |
//kern_printf("(Act %d",p); |
level_table[ lev->scheduling_level ]-> |
private_insert(lev->scheduling_level, p, (TASK_MODEL *)&b); |
} |
} |
} |
static int POSIXSTAR_public_eligible(LEVEL l, PID p) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
if (p==lev->activated) { |
//kern_printf("eli %d", p); |
return level_table[ lev->scheduling_level ]-> |
private_eligible(lev->scheduling_level,p); |
} |
return 0; |
} |
static int POSIXSTAR_public_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
NRT_TASK_MODEL *nrt; |
if (m->pclass != NRT_PCLASS) return -1; |
if (m->level != 0 && m->level != l) return -1; |
nrt = (NRT_TASK_MODEL *)m; |
/* the task state is set at SLEEP by the general task_create */ |
/* I used the wcet field because using wcet can account if a task |
consume more than the timeslice... */ |
if (nrt->inherit == NRT_INHERIT_SCHED && |
proc_table[exec_shadow].task_level == l) { |
/* We inherit the scheduling properties if the scheduling level |
*is* the same */ |
lev->priority[p] = lev->priority[exec_shadow]; |
proc_table[p].avail_time = proc_table[exec_shadow].avail_time; |
proc_table[p].wcet = proc_table[exec_shadow].wcet; |
proc_table[p].control = (proc_table[p].control & ~CONTROL_CAP) | |
(proc_table[exec_shadow].control & CONTROL_CAP); |
lev->nact[p] = (lev->nact[exec_shadow] == -1) ? -1 : 0; |
} |
else { |
if (nrt->weight<=lev->maxpriority) |
lev->priority[p] = nrt->weight; |
else lev->priority[p]=lev->maxpriority; |
if (nrt->slice) { |
proc_table[p].avail_time = nrt->slice; |
proc_table[p].wcet = nrt->slice; |
} |
else { |
proc_table[p].avail_time = lev->slice; |
proc_table[p].wcet = lev->slice; |
} |
if (nrt->policy == NRT_RR_POLICY) { |
proc_table[p].control |= CONTROL_CAP; |
//kern_printf("CCAP set:%d",p); |
} |
if (nrt->arrivals == SAVE_ARRIVALS) |
lev->nact[p] = 0; |
else |
lev->nact[p] = -1; |
} |
return 0; /* OK */ |
} |
static void POSIXSTAR_public_dispatch(LEVEL l, PID p, int nostop) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
//#ifdef POSIXSTAR_DEBUG |
//#endif |
/* the task state is set EXE by the scheduler() |
we extract the task from the ready queue |
NB: we can't assume that p is the first task in the queue!!! */ |
//iq_extract(p, &lev->ready[lev->priority[p]]); |
//if (!nostop) { |
//kern_printf("PDisp:%d(%d)",p, lev->activated); |
if (p==lev->activated) |
level_table[lev->scheduling_level]->private_dispatch(lev->scheduling_level, p, nostop); |
//} else |
// kern_printf("PDisp:%d(%d)",p, lev->activated); |
} |
static void POSIXSTAR_public_epilogue(LEVEL l, PID p) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
//#ifdef POSIXSTAR_DEBUG |
//kern_printf("PEpic:%d",p); |
//#endif |
if (p==lev->activated) { |
if (lev->yielding) { |
lev->yielding = 0; |
iq_extract(p,&lev->ready[lev->priority[p]]); |
iq_insertlast(p,&lev->ready[lev->priority[p]]); |
} |
/* check if the slice is finished and insert the task in the coPOSIXect |
qqueue position */ |
else if (proc_table[p].control & CONTROL_CAP && |
proc_table[p].avail_time <= 0) { |
//proc_table[p].avail_time += proc_table[p].wcet; |
//kern_printf("avail_time %d", proc_table[p].avail_time); |
iq_extract(p,&lev->ready[lev->priority[p]]); |
iq_insertlast(p,&lev->ready[lev->priority[p]]); |
//level_table[lev->scheduling_level]->private_extract(lev->scheduling_level,p); |
//lev->activated=NIL; |
POSIXSTAR_private_scheduler(lev); |
if (p==lev->activated) |
level_table[lev->scheduling_level]->private_epilogue(lev->scheduling_level,p); |
} |
else { |
//iq_insertfirst(p,&lev->ready[lev->priority[p]]); |
level_table[lev->scheduling_level]->private_epilogue(lev->scheduling_level,p); |
} |
proc_table[p].status = POSIXSTAR_READY; |
} |
} |
static void POSIXSTAR_internal_activate(POSIXSTAR_level_des *lev, PID p) |
{ |
/* Insert task in the correct position */ |
proc_table[p].status = POSIXSTAR_READY; |
iq_insertlast(p,&lev->ready[lev->priority[p]]); |
} |
static void POSIXSTAR_public_activate(LEVEL l, PID p) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
/* Test if we are trying to activate a non sleeping task */ |
/* save activation (only if needed...) */ |
if (proc_table[p].status != SLEEP) { |
if (lev->nact[p] != -1) |
lev->nact[p]++; |
return; |
} |
#ifdef POSIXSTAR_DEBUG |
kern_printf("PA:%d",p); |
#endif |
POSIXSTAR_internal_activate(lev, p); |
POSIXSTAR_private_scheduler(lev); |
} |
static void POSIXSTAR_public_unblock(LEVEL l, PID p) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
/* Similar to POSIX_task_activate, but we don't check in what state |
the task is */ |
/* Insert task in the coPOSIXect position */ |
//kern_printf("PU:%d", p); |
proc_table[p].status = POSIXSTAR_READY; |
iq_insertlast(p,&lev->ready[lev->priority[p]]); |
POSIXSTAR_private_scheduler(lev); |
} |
static void POSIXSTAR_public_block(LEVEL l, PID p) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
/* Extract the running task from the level |
. we have already extract it from the ready queue at the dispatch time. |
. the capacity event have to be removed by the generic kernel |
. the wcet don't need modification... |
. the state of the task is set by the calling function |
So, we do nothing!!! |
*/ |
//#ifdef POSIXSTAR_DEBUG |
//kern_printf("PB:%d", p); |
//#endif |
iq_extract(p,&lev->ready[lev->priority[p]]); |
POSIXSTAR_private_scheduler(lev); |
} |
static int POSIXSTAR_public_message(LEVEL l, PID p, void *m) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
if (lev->nact[p] > 0) { |
/* continue!!!! */ |
lev->nact[p]--; |
iq_extract(p,&lev->ready[lev->priority[p]]); |
iq_insertfirst(p,&lev->ready[lev->priority[p]]); |
proc_table[p].status = POSIXSTAR_READY; |
} |
else { |
proc_table[p].status = SLEEP; |
} |
//#ifdef POSIXSTAR_DEBUG |
kern_printf("PM:%d",p); |
//#endif |
POSIXSTAR_private_scheduler(lev); |
return 0; |
} |
static void POSIXSTAR_public_end(LEVEL l, PID p) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
#ifdef POSIXSTAR_DEBUG |
kern_printf("PEnd:%d", p); |
#endif |
lev->nact[p] = -1; |
/* then, we insert the task in the free queue */ |
proc_table[p].status = FREE; |
iq_priority_insert(p,NULL); |
POSIXSTAR_private_scheduler(lev); |
} |
/* Registration functions */ |
/*+ Registration function: |
TIME slice the slice for the Round Robin queue |
struct multiboot_info *mb used if createmain specified +*/ |
LEVEL POSIXSTAR_register_level(int budget, int master, TIME slice, |
int prioritylevels) |
{ |
LEVEL l; /* the level that we register */ |
POSIXSTAR_level_des *lev; /* for readableness only */ |
PID i; /* a counter */ |
int x; /* a counter */ |
printk("POSIXSTAR_register_level\n"); |
l = level_alloc_descriptor(sizeof(POSIXSTAR_level_des)); |
lev = (POSIXSTAR_level_des *)level_table[l]; |
printk(" lev=%d\n",(int)lev); |
/* fill the standard descriptor */ |
/* |
lev->l.private_insert = NULL; |
lev->l.private_extract = NULL; |
lev->l.private_dispatch = NULL; |
lev->l.private_epilogue = NULL; |
*/ |
//lev->l.public_scheduler = NULL; |
lev->l.public_create = POSIXSTAR_public_create; |
lev->l.public_end = POSIXSTAR_public_end; |
lev->l.public_dispatch = POSIXSTAR_public_dispatch; |
lev->l.public_epilogue = POSIXSTAR_public_epilogue; |
lev->l.public_activate = POSIXSTAR_public_activate; |
lev->l.public_unblock = POSIXSTAR_public_unblock; |
lev->l.public_block = POSIXSTAR_public_block; |
lev->l.public_message = POSIXSTAR_public_message; |
lev->l.public_eligible = POSIXSTAR_public_eligible; |
/* fill the POSIX descriptor part */ |
for (i = 0; i < MAX_PROC; i++) |
lev->nact[i] = -1; |
lev->maxpriority = prioritylevels -1; |
lev->ready = (IQUEUE *)kern_alloc(sizeof(IQUEUE) * prioritylevels); |
for (x = 0; x < prioritylevels; x++) |
iq_init(&lev->ready[x], NULL, 0); |
if (slice < POSIXSTAR_MINIMUM_SLICE) slice = POSIXSTAR_MINIMUM_SLICE; |
if (slice > POSIXSTAR_MAXIMUM_SLICE) slice = POSIXSTAR_MAXIMUM_SLICE; |
lev->slice = slice; |
lev->activated=NIL; |
lev->budget = budget; |
lev->scheduling_level = master; |
//lev->multiboot = mb; |
//if (createmain) |
// sys_atrunlevel(POSIXSTAR_call_main,(void *) l, RUNLEVEL_INIT); |
return l; |
} |
/*+ this function forces the running task to go to his queue tail; |
(it works only on the POSIX level) +*/ |
int POSIXSTAR_sched_yield(LEVEL l) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
if (proc_table[exec_shadow].task_level != l) |
return -1; |
proc_table[exec_shadow].context = kern_context_save(); |
lev->yielding = 1; |
scheduler(); |
kern_context_load(proc_table[exec_shadow].context); |
return 0; |
} |
/*+ this function returns the maximum level allowed for the POSIX level +*/ |
int POSIXSTAR_get_priority_max(LEVEL l) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
return lev->maxpriority; |
} |
/*+ this function returns the default timeslice for the POSIX level +*/ |
int POSIXSTAR_rr_get_interval(LEVEL l) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
return lev->slice; |
} |
/*+ this functions returns some paramaters of a task; |
policy must be NRT_RR_POLICY or NRT_FIFO_POLICY; |
priority must be in the range [0..prioritylevels] |
returns ENOSYS or ESRCH if there are problems +*/ |
int POSIXSTAR_getschedparam(LEVEL l, PID p, int *policy, int *priority) |
{ |
if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE) |
return ESRCH; |
if (proc_table[p].task_level != l) |
return ENOSYS; |
if (proc_table[p].control & CONTROL_CAP) |
*policy = NRT_RR_POLICY; |
else |
*policy = NRT_FIFO_POLICY; |
*priority = ((POSIXSTAR_level_des *)(level_table[l]))->priority[p]; |
return 0; |
} |
/*+ this functions sets paramaters of a task +*/ |
int POSIXSTAR_setschedparam(LEVEL l, PID p, int policy, int priority) |
{ |
POSIXSTAR_level_des *lev = (POSIXSTAR_level_des *)(level_table[l]); |
if (p<0 || p>= MAX_PROC || proc_table[p].status == FREE) |
return ESRCH; |
if (proc_table[p].task_level != l) |
return ENOSYS; |
if (policy == SCHED_RR) |
proc_table[p].control |= CONTROL_CAP; |
else if (policy == SCHED_FIFO) |
proc_table[p].control &= ~CONTROL_CAP; |
else |
return EINVAL; |
if (lev->priority[p] != priority) { |
if (proc_table[p].status == POSIXSTAR_READY) { |
iq_extract(p,&lev->ready[lev->priority[p]]); |
lev->priority[p] = priority; |
iq_insertlast(p,&lev->ready[priority]); |
} |
else |
lev->priority[p] = priority; |
} |
return 0; |
} |
/unsupported/trunk/first/makefile |
---|
0,0 → 1,35 |
# |
# |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
PROGS= test1 test2 test3 test4 test5 test6 test7 testiq |
include $(BASE)/config/example.mk |
test1: |
make -f $(SUBMAKE) APP=test1 INIT= OTHEROBJS="edfstar.o cbsstar.o" OTHERINCL= SHARKOPT=__OLDCHAR__ |
test2: |
make -f $(SUBMAKE) APP=test2 INIT= OTHEROBJS="edfstar.o cbsstar.o" OTHERINCL= SHARKOPT=__OLDCHAR__ |
test3: |
make -f $(SUBMAKE) APP=test3 INIT= OTHEROBJS="edfstar.o cbsstar.o" OTHERINCL= SHARKOPT=__OLDCHAR__ |
test4: |
make -f $(SUBMAKE) APP=test4 INIT= OTHEROBJS="edfstar.o cbsstar.o" OTHERINCL= SHARKOPT=__OLDCHAR__ |
test5: |
make -f $(SUBMAKE) APP=test5 INIT= OTHEROBJS="edfstar.o cbsstar.o" OTHERINCL= SHARKOPT=__OLDCHAR__ |
test6: |
make -f $(SUBMAKE) APP=test6 INIT= OTHEROBJS="rmstar.o cbsstar.o" OTHERINCL= SHARKOPT=__OLDCHAR__ |
test7: |
make -f $(SUBMAKE) APP=test7 INIT= OTHEROBJS="posixstar.o cbsstar.o" OTHERINCL= SHARKOPT=__OLDCHAR__ |
#testiq: |
# make -f $(SUBMAKE) APP=testiq INIT= OTHEROBJS="iqueue.o " OTHERINCL= |
/unsupported/trunk/first/edfstar.h |
---|
0,0 → 1,138 |
/* |
* 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: edfstar.h,v 1.1 2004-06-01 11:42:43 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:43 $ |
------------ |
Title: |
EDFSTAR |
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 EDF |
scheme. This module is derived from the EDFACT Scheduling Module. |
This module can not stay alone: when it have to schedule a task, it |
simply inserts it into another master module using a |
BUDGET_TASK_MODEL. |
No Task guarantee is performed at all. |
The tasks scheduled are only periodic. |
All the task are put in a queue and the scheduling is based on the |
deadline value. |
If a task miss a deadline a counter is incremented. |
If a task exausts the wcet a counter is incremented |
No ZOMBIE support!!!!!! |
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: |
- This level doesn't manage the main task. |
- Functions to return and reset the nact, wcet and dline miss |
counters are provided |
**/ |
/* |
* 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 __EDFSTAR_H__ |
#define __EDFSTAR_H__ |
#include <ll/ll.h> |
#include <kernel/config.h> |
#include <sys/types.h> |
#include <kernel/types.h> |
/* flags... */ |
#define EDFSTAR_ENABLE_GUARANTEE 1 /* Task Guarantee enabled */ |
#define EDFSTAR_ENABLE_ALL 1 |
#define EDFSTAR_FAILED_GUARANTEE 8 /* used in the module, unsettabl |
in EDF_register_level... */ |
#define EDFSTAR_LEVELNAME "EDFSTAR base" |
#define EDFSTAR_LEVEL_CODE 166 |
#define EDFSTAR_LEVEL_VERSION 1 |
/* Registration function: |
int budget The budget used by this module (see CBSSTAR.h) |
int master The master module used by EDFSTAR |
*/ |
LEVEL EDFSTAR_register_level(int budget, int master); |
/* returns respectively the number of dline, wcet or nact; -1 if error */ |
int EDFSTAR_get_dline_miss(PID p); |
int EDFSTAR_get_wcet_miss(PID p); |
int EDFSTAR_get_nact(PID p); |
/* resets respectively the number of dline, wcet miss; -1 if error */ |
int EDFSTAR_reset_dline_miss(PID p); |
int EDFSTAR_reset_wcet_miss(PID p); |
#endif |
/unsupported/trunk/first/iqueue.c |
---|
0,0 → 1,221 |
/* |
* 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: iqueue.c,v 1.1 2004-06-01 11:42:43 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:43 $ |
------------ |
*/ |
/* |
* Copyright (C) 2002 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 "iqueue.h" |
#include <kernel/mem.h> |
void iq_init (IQUEUE *q, IQUEUE *share, int flags) |
{ |
q->first = NIL; |
q->last = NIL; |
if (share) |
q->s = share->s; |
else { |
q->s = (struct IQUEUE_shared *)kern_alloc(sizeof(struct IQUEUE_shared)); |
if (!(flags & IQUEUE_NO_PRIORITY)) |
q->s->priority = (DWORD *)kern_alloc(sizeof(DWORD) * MAX_PROC); |
if (!(flags & IQUEUE_NO_TIMESPEC)) |
q->s->timespec_priority = (struct timespec *) |
kern_alloc(sizeof(struct timespec) * MAX_PROC); |
} |
} |
/*+ |
This function insert the task with PID i in the queue que. |
The insertion is made respecting the priority field. |
(the first item in the queue have the less priority) |
+*/ |
void iq_priority_insert (PID i, IQUEUE *que) |
{ |
DWORD prio; |
PID p,q; |
p = NIL; |
q = que->first; |
prio = que->s->priority[i]; |
while ((q != NIL) && (prio >= que->s->priority[q])) { |
p = q; |
q = que->s->next[q]; |
} |
if (p != NIL) |
que->s->next[p] = i; |
else |
que->first = i; |
if (q != NIL) |
que->s->prev[q] = i; |
else |
que->last = i; |
que->s->next[i] = q; |
que->s->prev[i] = p; |
} |
/* |
This function insert the task with PID i in the queue que. |
The insertion is made respecting the timespec priority field. |
(the first item in the queue have the less priority) |
*/ |
void iq_timespec_insert(PID i, IQUEUE *que) |
{ |
struct timespec prio; |
PID p,q; |
p = NIL; |
q = que->first; |
TIMESPEC_ASSIGN(&prio, &que->s->timespec_priority[i]); |
while ((q != NIL) && |
!TIMESPEC_A_LT_B(&prio, &que->s->timespec_priority[q])) { |
p = q; |
q = que->s->next[q]; |
} |
if (p != NIL) |
que->s->next[p] = i; |
else |
que->first = i; |
if (q != NIL) |
que->s->prev[q] = i; |
else |
que->last = i; |
que->s->next[i] = q; |
que->s->prev[i] = p; |
} |
void iq_insertfirst(PID p, IQUEUE *q) |
{ |
if (q->first != NIL) { |
q->s->next[p] = q->first; |
q->s->prev[q->first] = p; |
} |
else { |
q->last = p; |
q->s->next[p] = NIL; |
} |
q->s->prev[p] = NIL; |
q->first = p; |
} |
void iq_insertlast(PID p, IQUEUE *q) |
{ |
if (q->last != NIL) { |
q->s->prev[p] = q->last; |
q->s->next[q->last] = p; |
} |
else { |
q->first = p; |
q->s->prev[p] = NIL; |
} |
q->s->next[p] = NIL; |
q->last = p; |
} |
void iq_extract(PID i, IQUEUE *que) |
{ |
PID p,q; |
p = que->s->prev[i]; |
q = que->s->next[i]; |
if (p != NIL) |
que->s->next[p] = que->s->next[i]; |
else |
que->first = q; |
if (q != NIL) |
que->s->prev[q] = que->s->prev[i]; |
else |
que->last = p; |
} |
PID iq_getfirst(IQUEUE *q) |
{ |
PID p = q->first; |
if (p == NIL) |
return NIL; |
q->first = q->s->next[q->first]; |
if (q->first != NIL) |
q->s->prev[q->first] = NIL; |
else |
q->last = NIL; |
return p; |
} |
PID iq_getlast(IQUEUE *q) |
{ |
PID p = q->last; |
if (p == NIL) |
return NIL; |
q->last = q->s->prev[q->last]; |
if (q->last != NIL) |
q->s->next[q->last] = NIL; |
else |
q->first = NIL; |
return p; |
} |
/unsupported/trunk/cbs_ft/cbs_ft.c |
---|
0,0 → 1,811 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@hartik.sssup.it> |
* |
* Authors : Marco Caccamo and Paolo Gai |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: cbs_ft.c,v 1.1 2004-06-01 11:42:41 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:41 $ |
------------ |
This file contains the server CBS_FT |
Read CBS_FT.h for further details. |
**/ |
/* |
* Copyright (C) 2000 Marco Caccamo and 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 "cbs_ft.h" |
/*+ 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 +*/ |
/* structure of an element of the capacity queue */ |
struct cap_queue { |
int cap; |
struct timespec dead; |
struct cap_queue *next; |
}; |
/*+ the level redefinition for the CBS_FT level +*/ |
typedef struct { |
level_des l; /*+ the standard level descriptor +*/ |
/* The wcet are stored in the task descriptor, but we need |
an array for the deadlines. We can't use the timespec_priority |
field because it is used by the master level!!!... |
Notice that however the use of the timespec_priority field |
does not cause any problem... */ |
struct timespec cbs_ft_dline[MAX_PROC]; /*+ CBS_FT deadlines +*/ |
TIME period[MAX_PROC]; /*+ CBS_FT activation period +*/ |
int maxcap[MAX_PROC]; /* amount of capacity reserved to a primary+backup |
couple */ |
PID backup[MAX_PROC]; /* Backup task pointers, defined for primary tasks */ |
char CP[MAX_PROC]; /* checkpoint flag */ |
char P_or_B[MAX_PROC]; /* Type of task: PRIMARY or BACKUP */ |
struct timespec reactivation_time[MAX_PROC]; |
/*+ the time at witch the reactivation timer is post +*/ |
int reactivation_timer[MAX_PROC]; /*+ the recativation timer +*/ |
struct cap_queue *queue; /* pointer to the spare capacity queue */ |
int flags; /*+ the init flags... +*/ |
bandwidth_t U; /*+ the used bandwidth by the server +*/ |
int idle; /* the idle flag... */ |
struct timespec start_idle; /*gives the start time of the last idle period */ |
LEVEL scheduling_level; |
} CBS_FT_level_des; |
/* insert a capacity in the queue capacity ordering by deadline */ |
static int c_insert(struct timespec dead, int cap, struct cap_queue **que, |
PID p) |
{ |
struct cap_queue *prev, *n, *new; |
prev = NULL; |
n = *que; |
while ((n != NULL) && |
!TIMESPEC_A_LT_B(&dead, &n->dead)) { |
prev = n; |
n = n->next; |
} |
new = (struct cap_queue *)kern_alloc(sizeof(struct cap_queue)); |
if (new == NULL) { |
kern_printf("\nNew cash_queue element failed\n"); |
kern_raise(XINVALID_TASK, p); |
return -1; |
} |
new->next = NULL; |
new->cap = cap; |
new->dead = dead; |
if (prev != NULL) |
prev->next = new; |
else |
*que = new; |
if (n != NULL) |
new->next = n; |
return 0; |
} |
/* extract the first element from the capacity queue */ |
int c_extractfirst(struct cap_queue **que) |
{ |
struct cap_queue *p = *que; |
if (*que == NULL) return(-1); |
*que = (*que)->next; |
kern_free(p, sizeof(struct cap_queue)); |
return(1); |
} |
/* read data of the first element from the capacity queue */ |
static void c_readfirst(struct timespec *d, int *c, struct cap_queue *que) |
{ |
*d = que->dead; |
*c = que->cap; |
} |
/* write data of the first element from the capacity queue */ |
static void c_writefirst(struct timespec dead, int cap, struct cap_queue *que) |
{ |
que->dead = dead; |
que->cap = cap; |
} |
static void CBS_FT_activation(CBS_FT_level_des *lev, |
PID p, |
struct timespec *acttime) |
{ |
JOB_TASK_MODEL job; |
int capacity; |
/* This rule is used when we recharge the budget at initial task activation |
and each time a new task instance must be activated */ |
if (TIMESPEC_A_GT_B(acttime, &lev->cbs_ft_dline[p])) { |
/* we modify the deadline ... */ |
TIMESPEC_ASSIGN(&lev->cbs_ft_dline[p], acttime); |
} |
if (proc_table[p].avail_time > 0) |
proc_table[p].avail_time = 0; |
/* A spare capacity is inserted in the capacity queue!! */ |
ADDUSEC2TIMESPEC(lev->period[p], &lev->cbs_ft_dline[p]); |
capacity = lev->maxcap[p] - proc_table[ lev->backup[p] ].wcet; |
c_insert(lev->cbs_ft_dline[p], capacity, &lev->queue, p); |
/* it exploits available capacities from the capacity queue */ |
while (proc_table[p].avail_time < proc_table[p].wcet && |
lev->queue != NULL) { |
struct timespec dead; |
int cap, delta; |
delta = proc_table[p].wcet - proc_table[p].avail_time; |
c_readfirst(&dead, &cap, lev->queue); |
if (!TIMESPEC_A_GT_B(&dead, &lev->cbs_ft_dline[p])) { |
if (cap > delta) { |
proc_table[p].avail_time += delta; |
c_writefirst(dead, cap - delta, lev->queue); |
} |
else { |
proc_table[p].avail_time += cap; |
c_extractfirst(&lev->queue); |
} |
} |
else |
break; |
} |
/* 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(XINVALID_TASK, p); |
return; |
} |
/*if (p==6) |
kern_printf("(act_time:%d dead:%d av_time:%d)\n", |
acttime->tv_sec*1000000+ |
acttime->tv_nsec/1000, |
lev->cbs_ft_dline[p].tv_sec*1000000+ |
lev->cbs_ft_dline[p].tv_nsec/1000, |
proc_table[p].avail_time); */ |
#ifdef TESTG |
if (starttime && p == 3) { |
oldx = x; |
x = ((lev->cbs_ft_dline[p].tv_sec*1000000+lev->cbs_ft_dline[p].tv_nsec/1000)/5000 - starttime) + 20; |
// kern_printf("(a%d)",lev->cbs_ft_dline[p].tv_sec*1000000+lev->cbs_ft_dline[p].tv_nsec/1000); |
if (oldx > x) sys_end(); |
if (x<640) |
grx_plot(x, 15, 8); |
} |
#endif |
/* and, finally, we reinsert the task in the master level */ |
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); |
} |
/* 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]; |
if (proc_table[p].status == CBS_FT_IDLE) { |
/* the task has finished the current activation and must be |
reactivated */ |
/* request_time represents the time of the last instance release!! */ |
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 */ |
if (lev->idle == 1) { |
TIME interval; |
struct timespec delta; |
lev->idle = 0; |
SUBTIMESPEC(&t, &lev->start_idle, &delta); |
/* length of the idle interval expressed in usec! */ |
interval = TIMESPEC2NANOSEC(&delta) / 1000; |
/* it discharges the available capacities from the capacity queue */ |
while (interval > 0 && lev->queue != NULL) { |
struct timespec dead; |
int cap; |
c_readfirst(&dead, &cap, lev->queue); |
if (cap > interval) { |
c_writefirst(dead, cap - interval, lev->queue); |
interval = 0; |
} |
else { |
interval -= cap; |
c_extractfirst(&lev->queue); |
} |
} |
} |
CBS_FT_activation(lev,p,&lev->reactivation_time[p]); |
/* Set the reactivation timer */ |
TIMESPEC_ASSIGN(&lev->reactivation_time[p], &lev->cbs_ft_dline[p]); |
lev->reactivation_timer[p] = kern_event_post(&lev->reactivation_time[p], |
CBS_FT_timer_reactivate, |
(void *)p); |
event_need_reschedule(); |
} |
else { |
/* this situation cannot occur */ |
kern_printf("\nTrying to reactivate a primary task which is not IDLE!\n"); |
kern_raise(XINVALID_TASK,p); |
} |
} |
static void CBS_FT_avail_time_check(CBS_FT_level_des *lev, PID p) |
{ |
/*+ if the capacity became negative the remaining computation time |
is diminuished.... +*/ |
/* if (p==4) |
kern_printf("(old dead:%d av_time:%d)\n", |
lev->cbs_ft_dline[p].tv_sec*1000000+ |
lev->cbs_ft_dline[p].tv_nsec/1000, |
proc_table[p].avail_time); */ |
int newcap = proc_table[p].wcet / 100 * 30; |
if (newcap <= 0) |
newcap = proc_table[p].wcet; |
/* it exploits available capacities from the capacity queue */ |
while (proc_table[p].avail_time < newcap |
&& lev->queue != NULL) { |
struct timespec dead; |
int cap, delta; |
delta = newcap - proc_table[p].avail_time; |
c_readfirst(&dead, &cap, lev->queue); |
if (!TIMESPEC_A_GT_B(&dead, &lev->cbs_ft_dline[p])) { |
if (cap > delta) { |
proc_table[p].avail_time += delta; |
c_writefirst(dead, cap - delta, lev->queue); |
} |
else { |
proc_table[p].avail_time += cap; |
c_extractfirst(&lev->queue); |
} |
} |
else |
break; |
} |
/*if (p==6) |
kern_printf("(ATC dead:%d av_time:%d)\n", |
lev->cbs_ft_dline[p].tv_sec*1000000+ |
lev->cbs_ft_dline[p].tv_nsec/1000, |
proc_table[p].avail_time); */ |
/* if the budget is still empty, the backup task must be woken up. |
Remind that a short chunk of primary will go ahead executing |
before the task switch occurs */ |
if (proc_table[p].avail_time <= 0) { |
lev->CP[p] = 1; |
proc_table[p].avail_time += proc_table[ lev->backup[p] ].wcet; |
} |
/*if (p==6) |
kern_printf("(ATC1 dead:%d av_time:%d)\n", |
lev->cbs_ft_dline[p].tv_sec*1000000+ |
lev->cbs_ft_dline[p].tv_nsec/1000, |
proc_table[p].avail_time); */ |
} |
/*+ this function is called when a killed or ended task reach the |
period end +*/ |
static void CBS_FT_timer_zombie(void *par) |
{ |
PID p = (PID) par; |
CBS_FT_level_des *lev; |
lev = (CBS_FT_level_des *)level_table[proc_table[p].task_level]; |
/* we finally put the task in the FREE status */ |
proc_table[p].status = FREE; |
iq_insertfirst(p,&freedesc); |
/* and free the allocated bandwidth */ |
lev->U -= (MAX_BANDWIDTH / lev->period[p]) * (TIME)lev->maxcap[p]; |
} |
static PID CBS_FT_public_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); |
/* the CBS_FT don't schedule anything... |
it's an EDF level or similar that do it! */ |
return NIL; |
} |
/* The on-line guarantee is enabled only if the appropriate flag is set... */ |
static int CBS_FT_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
if (lev->flags & CBS_FT_FAILED_GUARANTEE) { |
*freebandwidth = 0; |
kern_printf("guarantee :garanzia fallita!!!!!!\n"); |
return 0; |
} |
else if (*freebandwidth >= lev->U) { |
*freebandwidth -= lev->U; |
return 1; |
} |
else { |
kern_printf("guarantee :garanzia fallita per mancanza di banda!!!!!!\n"); |
kern_printf("freeband: %d request band: %d", *freebandwidth, lev->U); |
return 0; |
} |
} |
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 (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; |
proc_table[p].avail_time = 0; |
NULL_TIMESPEC(&lev->cbs_ft_dline[p]); |
if (s->type == PRIMARY) { |
proc_table[p].wcet = (int)s->execP; |
lev->period[p] = s->period; |
lev->maxcap[p] = s->budget; |
lev->backup[p] = s->backup; |
lev->CP[p] = 0; |
lev->P_or_B[p] = PRIMARY; |
/* update the bandwidth... */ |
if (lev->flags & CBS_FT_ENABLE_GUARANTEE) { |
bandwidth_t b; |
b = (MAX_BANDWIDTH / lev->period[p]) * (TIME)lev->maxcap[p]; |
/* really update lev->U, checking an overflow... */ |
if (MAX_BANDWIDTH - lev->U > b) |
lev->U += b; |
else |
/* The task can NOT be guaranteed (U>MAX_BANDWIDTH)... |
(see EDF.c) */ |
lev->flags |= CBS_FT_FAILED_GUARANTEE; |
} |
} |
else { |
proc_table[p].wcet = (int)s->wcetB; |
lev->P_or_B[p] = BACKUP; |
/* Backup tasks are unkillable tasks! */ |
proc_table[p].control |= NO_KILL; |
} |
return 0; /* OK, also if the task cannot be guaranteed... */ |
} |
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 |
bandwidth */ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
if (lev->flags & CBS_FT_FAILED_GUARANTEE) |
lev->flags &= ~CBS_FT_FAILED_GUARANTEE; |
else |
lev->U -= (MAX_BANDWIDTH / lev->period[p]) * (TIME)lev->maxcap[p]; |
} |
static void CBS_FT_public_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); |
} |
static void CBS_FT_public_epilogue(LEVEL l, PID p) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
/* check if the budget is finished... */ |
if (proc_table[p].avail_time <= 0) { |
/* A backup task cannot ever exhaust its budget! */ |
if (lev->P_or_B[p] == BACKUP) { |
kern_printf("\nBACKUP wcet violation!\n"); |
kern_raise(XWCET_VIOLATION,p); |
/* we kill the current activation */ |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level, p); |
return; |
} |
/* we try to recharge the budget */ |
CBS_FT_avail_time_check(lev, p); |
/* 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(XINVALID_TASK, p); |
lev->CP[p] = 0; |
/* we kill the current activation */ |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level, p); |
return; |
} |
} |
/* the task returns into the ready queue by |
calling the guest_epilogue... */ |
level_table[ lev->scheduling_level ]-> |
private_epilogue(lev->scheduling_level,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; |
kern_gettime(&t); |
if (lev->P_or_B[p] == BACKUP) { |
kern_printf("\nTrying to activate a BACKUP task!\n"); |
kern_raise(XINVALID_TASK, p); |
} |
else { |
/* If idle=1, then we have to discharge the capacities stored in |
the capacity queue up to the length of the idle interval */ |
if (lev->idle == 1) { |
TIME interval; |
struct timespec delta; |
lev->idle = 0; |
SUBTIMESPEC(&t, &lev->start_idle, &delta); |
/* length of the idle interval expressed in usec! */ |
interval = TIMESPEC2NANOSEC(&delta) / 1000; |
/* it discharge the available capacities from the capacity queue */ |
while (interval > 0 && lev->queue != NULL) { |
struct timespec dead; |
int cap; |
c_readfirst(&dead, &cap, lev->queue); |
if (cap > interval) { |
c_writefirst(dead, cap - interval, lev->queue); |
interval = 0; |
} |
else { |
interval -= cap; |
c_extractfirst(&lev->queue); |
} |
} |
} |
CBS_FT_activation(lev, p, &t); |
/* Set the reactivation timer */ |
TIMESPEC_ASSIGN(&lev->reactivation_time[p], &lev->cbs_ft_dline[p]); |
lev->reactivation_timer[p] = kern_event_post(&lev->reactivation_time[p], |
CBS_FT_timer_reactivate, |
(void *)p); |
// kern_printf("act : %d %d |",lev->cbs_ft_dline[p].tv_nsec/1000,p); |
} |
} |
static int CBS_FT_public_message(LEVEL l, PID p, void *m) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level,p); |
proc_table[p].status = CBS_FT_IDLE; |
if (lev->P_or_B[p] == PRIMARY) { |
if (lev->CP[p]) { |
JOB_TASK_MODEL job; |
/* We have to start the backup task */ |
TIMESPEC_ASSIGN(&lev->cbs_ft_dline[ lev->backup[p] ], |
&lev->cbs_ft_dline[p]); |
proc_table[ lev->backup[p] ].avail_time = proc_table[p].avail_time; |
lev->CP[p] = 0; |
/* and, finally, we insert the backup task in the master level */ |
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], |
(TASK_MODEL *)&job); |
} |
else { |
/* A spare capacity is inserted in the capacity queue!! */ |
proc_table[p].avail_time += proc_table[ lev->backup[p] ].wcet; |
if (proc_table[p].avail_time > 0) { |
c_insert(lev->cbs_ft_dline[p], proc_table[p].avail_time, |
&lev->queue, p); |
proc_table[p].avail_time = 0; |
} |
} |
} |
else { |
/* this branch is for backup tasks: |
A spare capacity is inserted in the capacity queue!! */ |
if (proc_table[p].avail_time > 0) { |
c_insert(lev->cbs_ft_dline[p], proc_table[p].avail_time, |
&lev->queue, p); |
proc_table[p].avail_time = 0; |
} |
} |
jet_update_endcycle(); /* Update the Jet data... */ |
return 0; |
} |
static void CBS_FT_public_end(LEVEL l, PID p) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
/* A backup task cannot be killed, this behaviour can be modified |
in a new release */ |
if (lev->P_or_B[p] == BACKUP) { |
kern_printf("\nKilling a BACKUP task!\n"); |
kern_raise(XINVALID_TASK, p); |
return; |
} |
/* check if the capacity becomes negative... */ |
/* there is a while because if the wcet is << than the system tick |
we need to postpone the deadline many times */ |
while (proc_table[p].avail_time < 0) { |
/* the CBS_FT rule for recharging the capacity */ |
proc_table[p].avail_time += lev->maxcap[p]; |
ADDUSEC2TIMESPEC(lev->period[p], &lev->cbs_ft_dline[p]); |
} |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level,p); |
/* we delete the reactivation timer */ |
kern_event_delete(lev->reactivation_timer[p]); |
lev->reactivation_timer[p] = -1; |
/* Finally, we post the zombie event. when the end period is reached, |
the task descriptor and banwidth are freed */ |
proc_table[p].status = CBS_FT_ZOMBIE; |
lev->reactivation_timer[p] = kern_event_post(&lev->cbs_ft_dline[p], |
CBS_FT_timer_zombie, |
(void *)p); |
} |
/* Registration functions */ |
/*+ Registration function: |
int flags the init flags ... see CBS.h +*/ |
LEVEL CBS_FT_register_level(int flags, LEVEL master) |
{ |
LEVEL l; /* the level that we register */ |
CBS_FT_level_des *lev; /* for readableness only */ |
PID i; /* a counter */ |
printk("CBS_FT_register_level\n"); |
/* request an entry in the level_table */ |
l = level_alloc_descriptor(sizeof(CBS_FT_level_des)); |
lev = (CBS_FT_level_des *)level_table[l]; |
printk(" lev=%d\n",(int)lev); |
/* fill the standard descriptor */ |
lev->l.public_scheduler = CBS_FT_public_scheduler; |
if (flags & CBS_FT_ENABLE_GUARANTEE) |
lev->l.public_guarantee = CBS_FT_public_guarantee; |
else |
lev->l.public_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; |
/* fill the CBS_FT descriptor part */ |
for (i=0; i<MAX_PROC; i++) { |
NULL_TIMESPEC(&lev->cbs_ft_dline[i]); |
lev->period[i] = 0; |
NULL_TIMESPEC(&lev->reactivation_time[i]); |
lev->reactivation_timer[i] = -1; |
lev->maxcap[i] = 0; |
lev->backup[i] = NIL; |
lev->CP[i] = 0; |
lev->P_or_B[i] = PRIMARY; |
} |
lev->U = 0; |
lev->idle = 0; |
lev->queue = NULL; |
lev->scheduling_level = master; |
lev->flags = flags & 0x07; |
return l; |
} |
bandwidth_t CBS_FT_usedbandwidth(LEVEL l) |
{ |
CBS_FT_level_des *lev = (CBS_FT_level_des *)(level_table[l]); |
return lev->U; |
} |
void CBS_FT_Primary_Abort() |
{ |
PID p; |
CBS_FT_level_des *lev; |
kern_cli(); |
p = exec_shadow; |
lev = (CBS_FT_level_des *)level_table[proc_table[p].task_level]; |
lev->CP[p] = 1; |
kern_sti(); |
} |
char CBS_FT_Checkpoint() |
{ |
char f; |
PID p; |
CBS_FT_level_des *lev; |
kern_cli(); |
p = exec_shadow; |
lev = (CBS_FT_level_des *)level_table[proc_table[p].task_level]; |
f = lev->CP[p]; |
kern_sti(); |
return f; |
} |
/unsupported/trunk/cbs_ft/initfile.c |
---|
0,0 → 1,112 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@hartik.sssup.it> |
* |
* Authors : Marco caccamo and Paolo Gai |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: initfile.c,v 1.1 2004-06-01 11:42:42 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:42 $ |
------------ |
This file contains the server CBS_FT |
Read CBS_FT.h for further details. |
**/ |
/* |
* Copyright (C) 2000 Marco Caccamo and 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 "kernel/kern.h" |
#include <modules/edf.h> |
#include <modules/rr.h> |
#include "cbs_ft.h" |
#include <modules/cbs.h> |
#include <modules/dummy.h> |
#include <drivers/keyb.h> |
#include <modules/hartport.h> |
#include <modules/sem.h> |
#include <modules/cabs.h> |
/*+ system tick in us +*/ |
#define TICK 300 |
#define RRTICK 5000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
EDF_register_level(EDF_ENABLE_ALL); |
CBS_FT_register_level(CBS_FT_ENABLE_ALL, 0); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
CBS_register_level(CBS_ENABLE_ALL, 0); |
dummy_register_level(); |
SEM_register_module(); |
CABS_register_module(); |
// periodic timer |
return TICK; |
// one-shot timer |
// return 0 |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
HARTPORT_init(); |
KEYB_init(NULL); |
__call_main__(mb); |
return (void *)0; |
} |
/unsupported/trunk/cbs_ft/cbs_ft.h |
---|
0,0 → 1,166 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@hartik.sssup.it> |
* |
* Authors : Marco Caccamo and Paolo Gai |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: cbs_ft.h,v 1.1 2004-06-01 11:42:42 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:42 $ |
------------ |
This file contains the server CBS_FT |
Read CBS_FT.h for further details. |
**/ |
/* |
* Copyright (C) 2000 Marco Caccamo and 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 __CBS_FT__ |
#define __CBS_FT__ |
#include <ll/string.h> |
#include <kernel/model.h> |
#include <kernel/descr.h> |
#include <kernel/var.h> |
#include <kernel/func.h> |
/*+ flags... +*/ |
#define CBS_FT_ENABLE_GUARANTEE 1 /*+ Task Guarantee enabled +*/ |
#define CBS_FT_ENABLE_ALL 1 |
#define CBS_FT_FAILED_GUARANTEE 8 /*+ used in the module, unsettable |
in EDF_register_level... +*/ |
#define PRIMARY 1 |
#define BACKUP 2 |
#define FT_PCLASS 0x0700 // Nuova classe di task, quelli fault_tolerant |
#define CBS_FT_LEVELNAME "CBSFT base" |
#define CBS_FT_LEVEL_CODE 110 |
#define CBS_FT_LEVEL_VERSION 1 |
/* The Fault-Tolerant Task model extends the base task model |
This model cannot be APERIODIC, only PERIODIC tasks are allowed. |
A faut-tolerant application is composed by two different tasks (primary and |
backup). The backup task is characterized by its WCET and its type (BACKUP). |
The primary task must define the task period, its average execution time |
(used as sort of prediction in order to recharge the budget using the |
capacity cash queue!), the budget (budget / period = U that is, the |
bandwidth assigned to the fault-tolerant application), its type (PRIMARY) |
and finally the PID of the corresponding backup task. */ |
typedef struct { |
TASK_MODEL t; |
TIME wcetB; // WCET of the backup job (BACKUP TASK ONLY) |
TIME execP; // average exec. time of the primary job (PRIMARY TASK ONLY) |
TIME period; // period of the fault-tolerant task (PRIMARY TASK ONLY) |
int budget; // amount of guaranteed capacity (PRIMARY TASK ONLY) |
char type; // PRIMARY or BACKUP |
PID backup; // (PRIMARY TASK ONLY) |
} FT_TASK_MODEL; |
#define ft_task_default_model(m) \ |
task_default_model((m).t,FT_PCLASS), \ |
(m).period = 0, \ |
(m).wcetB = 0, \ |
(m).execP = 0, \ |
(m).budget = 0, \ |
(m).type = BACKUP, \ |
(m).backup = NIL |
#define ft_task_def_level(m,l) task_def_level((m).t,l) |
#define ft_task_def_arg(m,a) task_def_arg((m).t,a) |
#define ft_task_def_stack(m,s) task_def_stack((m).t,s) |
#define ft_task_def_stackaddr(m,s) task_def_stackaddr((m).t,s) |
#define ft_task_def_usemath(m) task_def_usemath((m).t) |
#define ft_task_def_ctrl_jet(m) task_def_ctrl_jet((m).t) |
#define ft_task_def_group(m,g) task_def_group((m).t,g) |
#define ft_task_def_period(m,o) (m).period = (o) |
#define ft_task_def_budget(m,o) (m).budget = (o) |
#define ft_task_def_backup(m) (m).type = BACKUP |
#define ft_task_def_primary(m) (m).type = PRIMARY |
#define ft_task_def_backup_task(m,b) (m).backup = b |
#define ft_task_def_backup_wcet(m,b) (m).wcetB = b |
#define ft_task_def_primary_exec(m,b) (m).execP = b |
/************************************************************************/ |
LEVEL CBS_FT_register_level(int flags, LEVEL master); |
bandwidth_t CBS_FT_usedbandwidth(LEVEL l); |
/* This function notifies to a primary task that the task itself has to |
suspend its execution (the task has to suspend itself with a |
task_endcycle() */ |
char CBS_FT_Checkpoint(void); |
/* This function sets the checkpoint flag! hence, at the next checkpoint, |
that is: |
if (CBS_FT_Checkpoint()) { |
task_endcycle(); |
continue; |
} |
the primary task will suspend itself switching to the backup task */ |
void CBS_FT_Primary_Abort(void); |
/***************************************************************************/ |
#endif |
/unsupported/trunk/cbs_ft/prova.c |
---|
0,0 → 1,429 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@hartik.sssup.it> |
* |
* Authors : Marco Caccamo and Paolo Gai |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://shark.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: prova.c,v 1.1 2004-06-01 11:42:42 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:42 $ |
------------ |
testcash.c |
test for the CASH Module, directly derived from Test Number 13 (D) |
**/ |
/* |
* Copyright (C) 2000 Marco Caccamo and 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 <modules/edf.h> |
#include "cbs_ft.h" |
#include <math.h> |
#include <stdlib.h> |
#define ASTER_LIM 60 |
#define DISPLAY_MAX 15 |
#define STAT_Y 9 |
#define INPUT 0.5 |
#define MAX_STAT 10000 |
#define RVAL 1 |
#define XVAL 2 |
#define DVAL 3 |
struct statistic { |
TIME r_time; |
TIME ex_time; |
long dead_post; |
}; |
struct statistic stat[MAX_STAT]; |
TIME val[MAX_STAT]; |
int n_stat = 0; |
TASK hard_aster1p(void) |
{ |
int i; |
int y = 1; |
int load1,j; |
char s[2]; |
s[0] = 'P'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 20000; //+ rand() % 25000; |
for (j=0; j<load1; j++) { |
if (CBS_FT_Checkpoint()) |
break; |
puts_xy(i,y,rand()%15+1,s); |
} |
//kern_cli(); |
//stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow); |
//jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
//kern_sti(); |
//n_stat++; |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK hard_aster1b(void) |
{ |
int i; |
int y = 1; |
int load1,j; |
char s[2]; |
s[0] = 'B'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 20000;// + rand()%4000; |
for (j=0; j<load1; j++) { |
puts_xy(i,y,rand()%15+1,s); |
} |
//kern_cli(); |
//stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow); |
//jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
//kern_sti(); |
//n_stat++; |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK hard_aster2p(void) |
{ |
int i; |
int y = 3; |
int load1,j; |
char s[2]; |
s[0] = 'P'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 20000 + rand() % 20000; |
for (j=0; j<load1; j++) { |
if (CBS_FT_Checkpoint()) |
break; |
puts_xy(i,y,rand()%15+1,s); |
} |
//kern_cli(); |
//stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow); |
//jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
//kern_sti(); |
//n_stat++; |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK hard_aster2b(void) |
{ |
int i; |
int y = 3; |
int load1,j; |
char s[2]; |
s[0] = 'T'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 20000; |
for (j=0; j<load1; j++) { |
puts_xy(i,y,rand()%15+1,s); |
} |
//kern_cli(); |
//stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow); |
//jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
//kern_sti(); |
//n_stat++; |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK clock() |
{ |
int s = 0, m = 0; |
while(1) { |
printf_xy(62,1,WHITE,"%2d:%2d",m,s); |
printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH); |
printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_FT_usedbandwidth(1)); |
task_endcycle(); |
if (++s > 59) { |
s = 0; |
m++; |
} |
printf_xy(62,1,WHITE,"%2d:%2d",m,s); |
printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH); |
printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
printf_xy(62,4,WHITE,"Ucbs=%12u",CBS_FT_usedbandwidth(1)); |
task_endcycle(); |
} |
} |
/* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
and plot on the screen the elapsed times... */ |
TASK jetcontrol() |
{ |
int i; /* a counter */ |
TIME sum, max, curr, last[5]; |
int nact; |
int j; /* the elements set by jet_gettable */ |
PID p; |
kern_cli(); |
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
kern_sti(); |
for (;;) { |
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue; |
for (j=0; j<5; j++) last[j] = 0; |
jet_gettable(p, &last[0], 5); |
kern_cli(); |
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6ld ³ %-6ld ³ %-4d ³ %-7ld ³ %-5ld ³ %-5ld ³ %-5ld ³ %-5ld ³ %-5ld", p, sum/(nact==0 ? 1 : nact), max, |
nact, curr, last[0], last[1], last[2], last[3], last[4]); |
kern_sti(); |
i++; |
} |
task_endcycle(); |
} |
} |
void save_stat(struct statistic p[], int n, char *name, int type) |
{ |
DOS_FILE *f; |
int i; |
char outstring[500]; |
for(i = 0; i < 500; i++) |
outstring[i] = '0'; |
f = DOS_fopen(name, "w"); |
if (!f) { |
cprintf("Cannot open %s!!!", name); |
goto end1; |
} |
for(i = 0; i < n; i++) { |
if (type == RVAL) |
val[i] = p[i].r_time; |
if (type == XVAL) |
val[i] = p[i].ex_time; |
if (type == DVAL) |
val[i] = p[i].dead_post; |
} |
memset(outstring, 0, 300); |
sprintf(outstring, "%ld \n", (long int)n); |
cprintf("%s", outstring); |
DOS_fwrite(outstring, 1, strlen(outstring), f); |
for(i = 0; i < n; i++) { |
memset(outstring, 0, 300); |
sprintf(outstring, "%ld %lu\n", (long int)i, val[i]); |
//cprintf("%s", outstring); |
DOS_fwrite(outstring, 1, strlen(outstring), f); |
} |
DOS_fclose(f); |
end1:cprintf("OK?"); |
} |
void result_save(void *p) |
{ |
save_stat(stat, n_stat, "stat1.tim", RVAL); |
} |
void fine() |
{ |
ll_abort(666); |
} |
int main(int argc, char **argv) |
{ |
PID p1,p2,p3, p4, p5, p6; |
HARD_TASK_MODEL m; |
FT_TASK_MODEL ftb; |
FT_TASK_MODEL ftp; |
// int i; |
struct timespec fineprg; |
//sys_atrunlevel(result_save, NULL, RUNLEVEL_AFTER_EXIT); |
srand(7); |
hard_task_default_model(m); |
hard_task_def_wcet(m,500); |
hard_task_def_mit(m,500000); |
hard_task_def_periodic(m); |
hard_task_def_group(m,1); |
hard_task_def_ctrl_jet(m); |
p1 = task_create("Clock",clock,&m,NULL); |
if (p1 == -1) { |
perror("testhd.c(main): Could not create task <Clock> ..."); |
sys_end(); |
} |
hard_task_def_wcet(m,500); |
hard_task_def_periodic(m); |
hard_task_def_mit(m,100000); |
p2 = task_create("JetControl",jetcontrol,&m,NULL); |
if (p2 == -1) { |
perror("testhd.c(main): Could not create task <JetControl> ..."); |
sys_end(); |
} |
ft_task_default_model(ftb); |
ft_task_def_usemath(ftb); |
ft_task_def_backup(ftb); |
ft_task_def_ctrl_jet(ftb); |
ft_task_def_backup_wcet(ftb, 7000); |
p3 = task_create("Hard_aster1b", hard_aster1b, &ftb,NULL); |
if (p3 == -1) { |
perror("testhd.c(main): Could not create task <aster1b> ..."); |
sys_end(); |
} |
ft_task_default_model(ftp); |
ft_task_def_usemath(ftp); |
ft_task_def_ctrl_jet(ftp); |
ft_task_def_group(ftp, 1); |
ft_task_def_period(ftp, 50000); |
ft_task_def_budget(ftp, 15000); |
ft_task_def_primary_exec(ftp, 7300); |
ft_task_def_primary(ftp); |
ft_task_def_backup_task(ftp, p3); |
p4 = task_create("Hard_aster1p", hard_aster1p, &ftp, NULL); |
if (p4 == -1) { |
perror("testhd.c(main): Could not create task <aster1p> ..."); |
sys_end(); |
} |
ft_task_def_backup_wcet(ftb, 6700); |
p5 = task_create("Hard_aster2b", hard_aster2b, &ftb, NULL); |
if (p5 == -1) { |
perror("testhd.c(main): Could not create task <aster2b> ..."); |
sys_end(); |
} |
ft_task_def_period(ftp, 100000); |
ft_task_def_budget(ftp, 8000); |
ft_task_def_primary_exec(ftp, 11000); |
ft_task_def_backup_task(ftp, p5); |
p6 = task_create("Hard_aster2p", hard_aster2p, &ftp, NULL); |
if (p6 == -1) { |
perror("testhd.c(main): Could not create task <aster2p> ..."); |
sys_end(); |
} |
printf_xy(0,STAT_Y + 15,WHITE,"Hard asteroide PID= %-3d ",p3); |
printf_xy(0,STAT_Y + 17,WHITE,"Clock PID= %-3d ",p1); |
printf_xy(0,STAT_Y + 18,WHITE,"JetControl PID= %-3d ",p2); |
task_nopreempt(); |
fineprg.tv_sec = 10; |
fineprg.tv_nsec = 0; |
kern_event_post(&fineprg,fine,NULL); |
group_activate(1); |
return 0; |
} |
/unsupported/trunk/cbs_ft/readme.txt |
---|
0,0 → 1,6 |
This Example has been made by Marco Caccamo. |
There is not a lot of documentation available, so if you have problems please |
send an e-mail to Marco ( http://gandalf.sssup.it/~caccamo/ ) |
Paolo |
/unsupported/trunk/cbs_ft/makefile |
---|
0,0 → 1,17 |
# |
# |
# |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
PROGS= prova |
include $(BASE)/config/example.mk |
prova: |
make -f $(SUBMAKE) APP=prova INIT= OTHEROBJS="initfile.o cbs_ft.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __GRX__" |
/unsupported/trunk/slsh/slsh.h |
---|
0,0 → 1,204 |
/* |
* 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: slsh.h,v 1.1 2004-06-01 11:42:47 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:47 $ |
------------ |
Author: Tomas Lennvall, Date: Feb 2000. |
This file contains the scheduling module for Slot shifting. |
Title: |
Slot Shifting |
Task Models Accepted: |
STATIC_TASK_MODEL - Periodic Hard tasks that are scheduled by |
an off-line scheduler, so that all guarantees regarding precedence, mutex |
deadline violation is taken care of. The tasks are in an executione schedule, |
that is the order in when they become ready. They have the following fields: |
est (earliest start time), wcet and absolute deadline. |
HARD_TASK_MODEL - Hard Tasks (Hard aperiodic requests) |
wcet field and drel field must be != 0. They are used to set the wcet |
and deadline of the tasks. |
periodicity field must be APERIODIC |
mit field is ignored. |
SOFT_TASK_MODEL - Soft Tasks (Unspecified tasks) |
wcet field must be != 0. periodicity filed must be APERIODIC |
period and met filed is ignored. |
Guest Models Accepted: |
NONE - Slot shifting handles all tasks by itself (at this moment). |
Description: |
This module schedules the offline scheduled tasks according to the slot- |
shifting paradigm, dividing time into slots of a fixed length and assigning |
tasks to execute in those slots. Slot-shifting also keeps track of the free |
bandwidth in the schedule by using disjoint intervals and sc (spare capacity). |
Each interval has a sc nr that represents the free bandwidth in that interval, |
the sc can be used by hard aperiodic tasks, static tasks from later interval or |
soft aperiodic tasks. Hard aperiodic tasks are guaranteed an incorporated in |
the schedule by reduction of sc before they execute. No guarantee is |
performed on the soft aperiodic tasks, they are run when no other task wants |
to execute and sc is available. |
Description: |
This module implements the Slot shifting algorithm, by Gerhard Fohler. Slot shifting |
schedules off-line scheduled tasks and also handles hard aperiodic requests by the |
guarantee alorithm. Slot shifting can also handle soft aperiodic tasks, |
called unspecified. That is tasks without a deadline. |
Exceptions raised: |
These exceptions are pclass-dependent... |
XDEADLINE_MISS |
If a task miss his deadline, the exception is raised. |
XWCET_VIOLATION |
If a task doesn't end the current cycle before if consume the wcet, |
an exception is raised, and the task is put in the EDF_WCET_VIOLATED |
state. To reactivate it, use EDF_task_activate via task_activate or |
manage directly the EDF data structure. Note that the exception is not |
handled properly, an XDEADLINE_MISS exeeption will also be raised at |
the period end... |
Restrictions & special features: |
- This level doesn't manage the main task. |
- At init time we can choose if the level have to activate |
. the wcet check |
(If a task require more time than declared, it is stopped and put in |
the state EDF_WCET_VIOLATED; a XWCET_VIOLATION exception is raised) |
. the task guarantee algorithm |
(when all task are created the system will check that the task_set |
will not use more than the available bandwidth) |
- The level use the priority and timespec_priority fields. |
- A function to return the used bandwidth of a level is provided. |
- The guest tasks don't provide the guest_endcycle function |
**/ |
/* |
* Copyright (C) 2000 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 __SLSH_H__ |
#define __SLSH_H__ |
#include <ll/ll.h> |
#include <kernel/config.h> |
#include <sys/types.h> |
#include <kernel/types.h> |
#define STATIC_PCLASS 0x0500 |
#define SLSH_LEVELNAME "Slot Shifting" |
#define SLSH_LEVEL_CODE 5 |
#define SLSH_LEVEL_VERSION 1 |
/* ----------------------------------------------------------------------- |
STATIC_TASK_MODEL: offline scheduled Tasks |
----------------------------------------------------------------------- */ |
/* Offline-scheduled tasks are hard periodic tasks that have been |
scheduled before runtime. All guarantees are made by the off- |
line scheduler so the tasks are already guaranteed. |
*/ |
typedef struct { |
TASK_MODEL t; |
TIME est; |
TIME wcet; |
TIME dabs; |
int interval; /* used in slot shifting */ |
} STATIC_TASK_MODEL; |
#define static_task_default_model(m) \ |
task_default_model((m).t,STATIC_PCLASS), \ |
(m).est = -1, \ |
(m).dabs = 0, \ |
(m).wcet = 0, \ |
(m).interval = -1; |
#define static_task_def_level(m,l) task_def_level((m).t,l) |
#define static_task_def_arg(m,a) task_def_arg((m).t,a) |
#define static_task_def_stack(m,s) task_def_stack((m).t,s) |
#define static_task_def_group(m,g) task_def_group((m).t,g) |
#define static_task_def_usemath(m) task_def_usemath((m).t) |
#define static_task_def_system(m) task_def_system((m).t) |
#define static_task_def_nokill(m) task_def_nokill((m).t) |
#define static_task_def_ctrl_jet(m) task_def_ctrl_jet((m).t) |
#define static_task_def_est(m,p) (m).est = (p) |
#define static_task_def_dabs(m,d) (m).dabs = (d) |
#define static_task_def_wcet(m,w) (m).wcet = (w) |
#define static_task_def_interval(m,i) (m).interval = (i) |
#define static_task_def_trace(m) task_def_trace((m).t) |
#define static_task_def_notrace(m) task_def_notrace((m).t) |
/*#define min(a, b) ((a) < (b) ? (a) : (b))*/ |
#define TIME2TIMESPEC(T, TS) \ |
( \ |
((TS).tv_sec = ((T)/1000000)), \ |
((TS).tv_nsec = (((T)%1000000) * 1000)), \ |
(TS) \ |
) |
/* define the interval struct */ |
typedef struct { |
int start; /* start of interval */ |
int end; /* end of interval */ |
int length; /* Length of interval */ |
int maxt; /* maximum execution time in interval */ |
int sc; /* spare capacity in interval */ |
} SLSH_interval; |
/*+ Registration function: */ |
LEVEL SLSH_register_level(); |
void SLSH_set_interval(LEVEL l, int start, int end, int maxt); |
void SLSH_set_variables(LEVEL l, TIME length); |
#endif |
/unsupported/trunk/slsh/slsh.c |
---|
0,0 → 1,750 |
/* |
* 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: slsh.c,v 1.1 2004-06-01 11:42:46 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:46 $ |
------------ |
This file contains the scheduling module for Slot-Shifting. |
Read slsh.h for further details. |
**/ |
/* |
* Copyright (C) 2000 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 "slsh.h" |
#include <ll/stdio.h> |
#include <ll/stdlib.h> |
#include <ll/string.h> |
#include <ll/math.h> /* for ceil(...) */ |
#include <ll/ll.h> /* for memcpy(...) */ |
#include <kernel/model.h> |
#include <kernel/descr.h> |
#include <kernel/var.h> |
#include <kernel/func.h> |
//#define eslsh_printf kern_printf |
#define slsh_printf printk |
/* Keeps information about static and guaranteed tasks */ |
typedef struct { |
int est; |
int dabs; |
int interval; |
} SLSH_task; |
/*+ Status used in the level +*/ |
#define SLSH_READY MODULE_STATUS_BASE |
#define SLSH_WAIT MODULE_STATUS_BASE + 1 |
#define SLSH_IDLE MODULE_STATUS_BASE + 2 |
#define SLSH_WCET_VIOLATED MODULE_STATUS_BASE + 3 |
/*+ defines +*/ |
#define MAX_INTERVALS 1000 /* 1000 intervals is max, for now */ |
/******+ the level redefinition for the SLOT SHIFT level +*******/ |
typedef struct { |
level_des l; /*+ the standard level descriptor+*/ |
/* task lists */ |
SLSH_task tasks[MAX_PROC]; /* est and dl's for static and guaranteed task */ |
IQUEUE idle_statics; /* finished static tasks */ |
IQUEUE unspecified; /* tasks with only a wcet */ |
/* the Intervals list */ |
SLSH_interval intervals[MAX_INTERVALS]; |
int current; /* current interval */ |
int last; /* last interval */ |
int slot; /* slot shifting time */ |
TIME slot_length; /* slothlength in real system time*/ |
int LCM; /* length (in slots) of ofline schedule */ |
int slot_event; /* save the event */ |
} SLSH_level_des; |
/* check if some tasks are ready, return 0 if ready, -1 otherwise */ |
static int SLSH_R(SLSH_task* tasks) |
{ |
int s; |
/* for all static tasks */ |
for(s = 0; tasks[s].est != -1; ++s) |
{ |
if(proc_table[s].status == SLSH_READY) |
return 0; |
} |
return -1; |
} |
/* check if unspecified exists, return 0 if it exists, -1 otherwise */ |
static int SLSH_T(IQUEUE *unspecified) |
{ |
if(!iq_isempty(unspecified)) |
return 0; |
else |
return -1; |
} |
/* return the sc in an interval */ |
static int SLSH_sc(SLSH_interval* intervals, int i) |
{ |
return intervals[i].sc; |
} |
/* return a static task from current interval or a guaranted task */ |
static PID SLSH_staticOrGuaranteed(SLSH_level_des* lev) |
{ |
int lowest_dl = 0; /* lowest dl found */ |
PID pid = 0; /* static or guaranteed task */ |
int t; |
/* Decide according to EDF, go through all static & guaranteed tasks */ |
for(t = 0; t < MAX_PROC; ++t) |
{ |
/* static tasks */ |
if(proc_table[t].pclass == STATIC_PCLASS) |
{ |
/* static task must belong to current interval */ |
if(lev->tasks[t].interval == lev->current) |
{ |
/* only ready tasks */ |
if(proc_table[t].status == SLSH_READY) |
{ |
/* a new lower dl was found */ |
if(lev->tasks[t].dabs < lowest_dl) |
{ |
lowest_dl = lev->tasks[t].dabs; |
pid = t; |
} |
} |
} |
} /* guaranteed tasks */ |
else if(proc_table[t].pclass == HARD_PCLASS) |
{ |
/* only ready tasks */ |
if(proc_table[t].status == SLSH_READY) |
{ |
/* a new lower dl was found */ |
if(lev->tasks[t].dabs < lowest_dl) |
{ |
lowest_dl = lev->tasks[t].dabs; |
pid = t; |
} |
} |
} |
}/* for all tasks */ |
return pid; |
} |
/* return a static task among the candidates, all ready statics */ |
static PID SLSH_candidates(SLSH_task* tasks) |
{ |
int lowest_dl = 0; |
PID pid = -1; |
int t; |
/* Use the EDL algorithm again to decide which task to run */ |
for(t = 0; t < MAX_PROC; ++t) |
{ |
/* only static tasks */ |
if(proc_table[t].pclass == STATIC_PCLASS) |
{ |
/* only ready tasks */ |
if(proc_table[t].status == SLSH_READY) |
{ |
/* a new lower dl was found */ |
if(tasks[t].dabs < lowest_dl) |
{ |
lowest_dl = tasks[t].dabs; |
pid = t; |
} |
}/* all ready tasks */ |
}/* all static tasks */ |
}/* for all tasks */ |
return pid; |
} |
/* decrease the sc in a interval by amount */ |
void SLSH_decSc(SLSH_interval* intervals, int i, int amount) |
{ |
intervals[i].sc -= amount; |
} |
void SLSH_incSc(SLSH_interval* intervals, int i, int amount) |
{ |
intervals[i].sc += amount; |
} |
/* swap the sc between intervals, also consider intervals with negative sc */ |
void SLSH_swapSc(SLSH_interval* intervals, int current, int task_interval) |
{ |
/* decrease the sc in the current interval */ |
SLSH_decSc(intervals, current, 1); |
/* update the other interval(s) */ |
if(intervals[task_interval].sc < 0) /* negative sc */ |
{ |
/* special case, increase next interval sc by 1 and also current interval (borrowing) */ |
if(task_interval == current + 1) |
{ |
SLSH_incSc(intervals, task_interval, 1); |
SLSH_incSc(intervals, current, 1); |
} |
else /* increase every interval sc that is negative between current and task_interval */ |
{ |
while(task_interval > current && intervals[task_interval].sc < 0) |
{ |
SLSH_incSc(intervals, task_interval, 1); |
task_interval--; |
} |
} |
} |
else /* ordinary swapping */ |
SLSH_incSc(intervals, task_interval, 1); |
} |
/* The scheduler, decides which task to run. */ |
static PID SLSH_public_scheduler(LEVEL l) |
{ |
SLSH_level_des* lev = (SLSH_level_des *)(level_table[l]); |
PID pid; |
/* The scheduler choses among static, guaranteed (hard aperiodic) and |
unspecified (soft aperiodic) tasks */ |
/* no ready tasks and no sc, execute idle task */ |
if(SLSH_R(lev->tasks) == 0 && SLSH_sc(lev->intervals, lev->current) == 0) |
return NIL; |
/* must execute a static from current intervall or a guaranteed task */ |
else if(SLSH_R(lev->tasks) > 0 && SLSH_sc(lev->intervals, lev->current) == 0) |
return SLSH_staticOrGuaranteed(lev); |
/* sc available... */ |
else if(SLSH_R(lev->tasks) > 0 && SLSH_sc(lev->intervals, lev->current) > 0) |
{ |
/* If unspecified exist, execute it according to FIFO order */ |
if(SLSH_T(&lev->unspecified) == 0) |
{ |
SLSH_decSc(lev->intervals, lev->current, 1); /* decrease sc by 1 */ |
return iq_getfirst(&lev->unspecified); |
} |
else /* No unspecified, execute task from candidates (statics) */ |
{ |
pid = SLSH_candidates(lev->tasks); |
/* sc needs to be swapped */ |
if(lev->tasks[pid].interval != lev->current) |
SLSH_swapSc(lev->intervals, lev->tasks[pid].interval, lev->current); |
return pid; |
} |
} |
kern_printf("(SLSH s)"); |
return NIL; |
} |
/* not used, slot-shifting handles all guarantees itself, it handles all bandwidth */ |
static int SLSH_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
{ |
*freebandwidth = 0; |
return 1; |
} |
/* get the interval that x is in */ |
static int SLSH_getInterval(SLSH_interval* intervals, int x, int last) |
{ |
int i; |
/* search through the intervals */ |
for(i = 0; i <= last; ++i) |
{ |
/* I is in the interval where start is smaller or equal and end is bigger */ |
if(intervals[i].start <= x && x < intervals[i].end) |
return i; |
} |
return -1; |
} |
/* get the start of the interval I */ |
static int SLSH_intervalStart(SLSH_interval* intervals, int I) |
{ |
return intervals[I].start; |
} |
/* split interval I into two parts, slow because of copying. OBS!!! no check if there is |
enough space in the intervals array */ |
static void SLSH_splitInterval(SLSH_level_des* lev, int I, int dabs) |
{ |
SLSH_interval left_interval; |
int i; |
lev->last++; |
/* move every interval above and including I */ |
for(i = lev->last; i > I; --i) |
memcpy(&lev->intervals[i], &lev->intervals[i - 1], sizeof(SLSH_interval)); |
/* Left interval start, end and length */ |
left_interval.start = lev->intervals[I].start; |
left_interval.end = dabs; |
left_interval.length = left_interval.end - left_interval.start; |
/* Right interval (uses old interval struct) start and length end remains as the old value */ |
lev->intervals[I + 1].start = dabs; |
lev->intervals[I + 1].length = lev->intervals[I + 1].end - lev->intervals[I + 1].start; |
/* check if sc still exists in the right interval */ |
if(lev->intervals[I + 1].length - lev->intervals[I + 1].maxt > 0) |
{ |
lev->intervals[I + 1].sc = lev->intervals[I + 1].length - lev->intervals[I + 1].maxt; |
left_interval.sc = left_interval.length; /* the whole interval is free, for now... */ |
} |
else /* no sc in the right interval */ |
{ |
lev->intervals[I + 1].maxt = lev->intervals[I + 1].length; |
left_interval.sc = lev->intervals[I + 1].sc; /* all sc in left interval */ |
lev->intervals[I + 1].sc = 0; |
} |
/* insert the new interval */ |
memcpy(&lev->intervals[I], &left_interval, sizeof(SLSH_interval)); |
} |
/* Reduce the sc from back to front by the wcet amount, interval splitting may be neccesary */ |
static void SLSH_updateSc(SLSH_level_des* lev, HARD_TASK_MODEL* h) |
{ |
int dabs = ceil((lev->slot + h->drel)/lev->slot_length); /* absolute deadline of request */ |
int dabs_interval = SLSH_getInterval(lev->intervals, dabs, lev->last); /* interval where dabs is */ |
int C = ceil(h->wcet/lev->slot_length); /* amount of sc to reduce */ |
int sc = 0; |
int i; |
/* check if interval splitting is neccesary */ |
if(lev->intervals[dabs_interval].end != dabs) |
SLSH_splitInterval(lev, dabs_interval, dabs); |
/* decrease sc in all intervals that are neccesary from dabs_interval o current */ |
for(i = dabs_interval; i >= lev->current && C > 0; --i) |
{ |
if((sc = SLSH_sc(lev->intervals, i)) >= 0) /* only decrease where sc exists */ |
{ |
if(sc > C) /* the last sc dec */ |
{ |
SLSH_decSc(lev->intervals, i, C); |
C = 0; |
} |
else /* to little sc in this interval, decrease it to 0 */ |
{ |
C -= SLSH_sc(lev->intervals, i); |
SLSH_decSc(lev->intervals, i, SLSH_sc(lev->intervals, i)); |
} |
} |
}/* for all intervals */ |
} |
/* the guarantee algorithm for hard aperiodic requests */ |
static int SLSH_guarantee(SLSH_level_des* lev, HARD_TASK_MODEL* h) |
{ |
int total_sc = 0; |
int temp, i; |
int dabs = ceil((lev->slot + h->drel)/lev->slot_length); /* absolute deadline of request */ |
int dabs_interval = SLSH_getInterval(lev->intervals, dabs, lev->last); /* interval where dabs is */ |
/* check if the sc up until request deadline is >= request wcet */ |
/* 1. the sc of the current interal */ |
total_sc = SLSH_sc(lev->intervals, lev->current); |
/* 2. the sc for all whole intervals between current and the interval |
with the request deadline */ |
for(i = (lev->current) + 1; i < dabs_interval; ++i) |
{ |
if((temp = SLSH_sc(lev->intervals, i)) > 0) |
total_sc += temp; |
} |
/* 3. the min of sc or the execution need in the last interval */ |
total_sc += min(SLSH_sc(lev->intervals, dabs_interval), |
dabs - SLSH_intervalStart(lev->intervals, |
dabs_interval)); |
if(total_sc >= h->wcet) |
{ /* update the sc in the intervals from back to front */ |
SLSH_updateSc(lev, h); |
return 0; |
} |
else |
return -1; |
} |
/* check if task model is accepted and store nessecary parameters */ |
static int SLSH_public_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
SLSH_level_des *lev = (SLSH_level_des *)(level_table[l]); |
STATIC_TASK_MODEL* s; |
HARD_TASK_MODEL* h; |
SOFT_TASK_MODEL* u; |
/* Check the models */ |
switch(m->pclass) |
{ |
case STATIC_PCLASS: /* offline scheduled tasks */ |
break; |
case HARD_PCLASS: /* hard aperiodic tasks */ |
h = (HARD_TASK_MODEL *) m; |
if (h->drel == 0 || h->wcet == 0) /* must be set */ |
return -1; |
break; |
case SOFT_PCLASS: /* soft aperiodic tasks */ |
u = (SOFT_TASK_MODEL *) m; |
if(u->wcet == 0) /* must be set */ |
return -1; |
break; |
default: |
return -1; |
} |
/* if the SLSH_task_create is called, then the pclass must be a |
valid pclass. Slot-shifting accepts STATIC_TASK, HARD_TASK |
and SOFT_TASK models with some restrictions */ |
/* est, dl and wcet is saved in slotlengths */ |
switch(m->pclass) |
{ |
case STATIC_PCLASS: /* offline scheduled tasks */ |
s = (STATIC_TASK_MODEL *) m; |
lev->tasks[p].est = ceil(s->est/lev->slot_length); |
lev->tasks[p].dabs = ceil(s->dabs/lev->slot_length); |
lev->tasks[p].interval = s->interval; |
proc_table[p].avail_time = s->wcet; |
proc_table[p].wcet = s->wcet; |
break; |
case HARD_PCLASS: /* hard aperiodic tasks */ |
h = (HARD_TASK_MODEL *) m; |
if(SLSH_guarantee(lev, h) == 0) |
{ |
/* convert drel to dabs */ |
lev->tasks[p].dabs = ceil((lev->slot + h->drel)/lev->slot_length); |
proc_table[p].avail_time = h->wcet; |
proc_table[p].wcet = h->wcet; |
} |
else /* task not guaranteed */ |
return -1; |
break; |
case SOFT_PCLASS: |
u = (SOFT_TASK_MODEL *) m; |
proc_table[p].avail_time = u->wcet; |
proc_table[p].wcet = u->wcet; |
iq_insertlast(p, &lev->unspecified); /* respect FIFO order */ |
break; |
default: /* a task model not supported */ |
return -1; |
} |
/* enable wcet check in the kernel */ |
proc_table[p].control |= CONTROL_CAP; |
return 0; |
} |
/************* The slot end event handler *************/ |
static void SLSH_slot_end(void* p) |
{ |
SLSH_level_des* lev = (SLSH_level_des *) p; |
PID pid; |
int i; |
/* increase slot "time" by 1 */ |
if(lev->slot < lev->LCM) |
{ |
lev->slot++; |
/* check if new statics are ready */ |
for(i = 0; lev->tasks[i].interval != -1; ++i) |
{ |
if(lev->tasks[i].est <= lev->slot && proc_table[i].status == SLSH_WAIT) |
proc_table[i].status = SLSH_READY; |
} |
/* check if current (interval) needs updating */ |
if(lev->current < SLSH_getInterval(lev->intervals, lev->slot, lev->last)) |
lev->current++; |
} |
else /* restart from the beginning of the offline schedule */ |
{ |
lev->slot = 0; |
while((pid = iq_getfirst(&lev->idle_statics)) != NIL) |
{ |
if(lev->tasks[pid].est <= lev->slot) |
proc_table[pid].status = SLSH_READY; |
else |
proc_table[pid].status = SLSH_WAIT; |
} |
} |
/* call for a rescheduling, reset event flag and increase slot by 1 */ |
lev->slot_event = -1; |
kern_printf("*"); |
event_need_reschedule(); |
} |
/* when a task becomes executing (EXE status) */ |
static void SLSH_public_dispatch(LEVEL l, PID pid, int nostop) |
{ |
SLSH_level_des *lev = (SLSH_level_des *)(level_table[l]); |
struct timespec t; |
/* the task state is set EXE by the scheduler() |
we extract the task from the unspecified queue. |
NB: we can't assume that p is the first task in the queue!!! */ |
if(proc_table[pid].pclass == SOFT_PCLASS) |
iq_extract(pid, &lev->unspecified); |
/* also start the timer for one slot length */ |
lev->slot_event = kern_event_post(&TIME2TIMESPEC(lev->slot_length, t), |
SLSH_slot_end, (void*) lev); |
} |
/* called when task is moved from EXE status */ |
static void SLSH_public_epilogue(LEVEL l, PID pid) |
{ |
SLSH_level_des *lev = (SLSH_level_des *)(level_table[l]); |
/* check if the wcet is finished... */ |
if (proc_table[pid].avail_time <= 0) |
{ |
/* if it is, raise a XWCET_VIOLATION exception */ |
kern_raise(XWCET_VIOLATION, pid); |
proc_table[pid].status = SLSH_WCET_VIOLATED; |
} |
else /* the end of a slot. the task returns into the ready queue... */ |
{ |
if(proc_table[pid].pclass == SOFT_PCLASS) |
iq_insertfirst(pid,&lev->unspecified); |
proc_table[pid].status = SLSH_READY; |
} |
} |
/* when task go from SLEEP to SLSH_READY or SLSH_WAIT */ |
static void SLSH_public_activate(LEVEL l, PID pid) |
{ |
SLSH_level_des *lev = (SLSH_level_des *)(level_table[l]); |
WORD type = proc_table[pid].pclass; |
/* Test if we are trying to activate a non sleeping task */ |
/* Ignore this; the task is already active */ |
if (proc_table[pid].status != SLEEP && proc_table[pid].status != SLSH_WCET_VIOLATED) |
return; |
/* make task ready or waiting, dependong on slot (the time) for static tasks only*/ |
if(type == STATIC_PCLASS && lev->tasks[pid].est <= lev->slot) |
proc_table[pid].status = SLSH_READY; |
else |
proc_table[pid].status = SLSH_WAIT; |
if(type == HARD_PCLASS) |
proc_table[pid].status = SLSH_READY; |
/* insert unspecified tasks in QQUEUE and make it ready */ |
if(type == SOFT_PCLASS) |
{ |
iq_insertlast(pid ,&lev->unspecified); |
proc_table[pid].status = SLSH_READY; |
} |
} |
/* when a task i returned to module from a semaphore, mutex ... */ |
static void SLSH_public_unblock(LEVEL l, PID pid) |
{ |
SLSH_level_des *lev = (SLSH_level_des *)(level_table[l]); |
/* change staus of task */ |
proc_table[pid].status = SLSH_READY; |
if(proc_table[pid].pclass == SOFT_PCLASS) |
iq_insertfirst(pid ,&lev->unspecified); |
} |
/* when a semaphore, mutex ... taskes a task from module */ |
static void SLSH_public_block(LEVEL l, PID pid) |
{ |
/* Extract the running task from the level |
. we have already extract it from the ready queue at the dispatch time. |
. the capacity event have to be removed by the generic kernel |
. the wcet don't need modification... |
. the state of the task is set by the calling function |
. the deadline must remain... |
So, we do nothing!!! |
*/ |
} |
/* the task has finihed its wcet, kill task (dont kill static tasks) */ |
static void SLSH_public_end(LEVEL l, PID pid) |
{ |
SLSH_level_des *lev = (SLSH_level_des *)(level_table[l]); |
if(proc_table[pid].pclass == SOFT_PCLASS) |
{ |
if (proc_table[pid].status == SLSH_READY) |
iq_extract(pid, &lev->unspecified); |
} |
else if(proc_table[pid].pclass == HARD_PCLASS) |
{ |
if (proc_table[pid].status == SLSH_READY) |
lev->tasks[pid].dabs = 0; |
} |
/* static tasks: put them in idle QUEUE, reset status and avail_time */ |
else if(proc_table[pid].pclass == STATIC_PCLASS) |
{ |
proc_table[pid].avail_time = proc_table[pid].wcet; |
proc_table[pid].status = SLSH_IDLE; |
iq_priority_insert(pid, &lev->idle_statics); |
} |
proc_table[pid].status = FREE; |
} |
/* called when a task should sleep but not execute for awhile, mabe a mode change */ |
//static void SLSH_task_sleep(LEVEL l, PID pid) |
//{ |
// |
// /* the task has terminated his job before it consume the wcet. All OK! */ |
// proc_table[pid].status = SLEEP; |
// |
// /* we reset the capacity counters... only for static tasks */ |
// if (proc_table[pid].pclass == STATIC_PCLASS) |
// proc_table[pid].avail_time = proc_table[pid].wcet; |
// |
//} |
/** Guest Functions, slot shifing accepts no guests, so all generates exceptions **/ |
/******* Registration functions *******/ |
/*+ Registration function: */ |
LEVEL SLSH_register_level() |
{ |
LEVEL l; /* the level that we register */ |
SLSH_level_des *lev; /* for readableness only */ |
PID i; /* a counter */ |
kern_printf("SLSH_register_level\n"); |
/* request an entry in the level_table */ |
l = level_alloc_descriptor(sizeof(SLSH_level_des)); |
lev = (SLSH_level_des *)level_table[l]; |
printk(" lev=%d\n",(int)lev); |
/* fill the standard descriptor */ |
lev->l.public_scheduler = SLSH_public_scheduler; |
lev->l.public_guarantee = SLSH_public_guarantee; |
lev->l.public_create = SLSH_public_create; |
lev->l.public_end = SLSH_public_end; |
lev->l.public_dispatch = SLSH_public_dispatch; |
lev->l.public_epilogue = SLSH_public_epilogue; |
lev->l.public_activate = SLSH_public_activate; |
lev->l.public_unblock = SLSH_public_unblock; |
lev->l.public_block = SLSH_public_block; |
/* fill the SLSH descriptor part */ |
for(i = 0; i < MAX_PROC; i++) |
{ |
lev->tasks[i].est = -1; |
lev->tasks[i].dabs = 0; |
lev->tasks[i].interval = -1; |
} |
for(i = 0; i < MAX_INTERVALS; i++) |
{ |
lev->intervals[i].start = -1; |
lev->intervals[i].end = -1; |
lev->intervals[i].length = 0; |
lev->intervals[i].maxt = 0; |
lev->intervals[i].sc = 0; |
} |
lev->current = 0; |
lev->last = NIL; |
lev->slot = 0; |
lev->slot_length = 0; |
lev->slot_event = -1; |
return l; |
} |
void SLSH_set_interval(LEVEL l, int start, int end, int maxt) |
{ |
SLSH_level_des* lev = (SLSH_level_des *)(level_table[l]); |
static int i = -1; |
i++; |
lev->intervals[i].start = start; |
lev->intervals[i].end = end; |
lev->intervals[i].length = end - start; |
lev->intervals[i].maxt = maxt; |
lev->intervals[i].sc = lev->intervals[i].length - maxt; |
lev->last = i; |
} |
void SLSH_set_variables(LEVEL l, TIME length) |
{ |
SLSH_level_des* lev = (SLSH_level_des *)(level_table[l]); |
lev->slot_length = length; |
} |
/unsupported/trunk/slsh/slshtest.c |
---|
0,0 → 1,173 |
/* |
* 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: slshtest.c,v 1.1 2004-06-01 11:42:47 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:47 $ |
------------ |
Slot shifting test |
**/ |
/* |
* Copyright (C) 2000 Paolo Gai and Tomas Lennvall |
* |
* 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 <kernel/config.h> |
#include "kernel/kern.h" |
#include "slsh.h" |
#include "drivers/keyb.h" |
/* a slot length of 100 ms */ |
#define SLOT_LENGTH 100000 |
TASK static1(void) |
{ |
int i = 0; |
kern_printf("Static1\n"); |
while(sys_gettime(NULL) < 10000) i++; |
return 0; |
} |
TASK static2(void) |
{ |
int i = 0; |
kern_printf("Static2\n"); |
while(sys_gettime(NULL) < 10000) i++; |
return 0; |
} |
TASK static3(void) |
{ |
kern_printf("Static3\n"); |
return 0; |
} |
void my_end(KEY_EVT *e) |
{ |
sys_end(); |
} |
int main(int argc, char** argv) |
{ |
STATIC_TASK_MODEL s; |
// HARD_TASK_MODEL h_aper; |
// SOFT_TASK_MODEL u; |
PID p1,p2,p3; |
struct timespec x; |
KEY_EVT emerg; |
kern_cli(); |
x.tv_sec=5; |
kern_event_post(&x,(void (*)(void *))sys_end,NULL); |
kern_sti(); |
//keyb_set_map(itaMap); |
emerg.ascii = 'x'; |
emerg.scan = KEY_X; |
emerg.flag = ALTL_BIT; |
keyb_hook(emerg,my_end); |
/* set som variables in the scheduling level */ |
SLSH_set_interval(0, 0, 8, 5); |
SLSH_set_interval(0, 8, 17, 7); |
SLSH_set_interval(0, 17, 20, 1); |
SLSH_set_variables(0, SLOT_LENGTH); |
static_task_default_model(s); |
static_task_def_group(s, 1); |
/* define time i ms */ |
/* static1 task */ |
static_task_def_est(s, 0); |
static_task_def_dabs(s, 800000); |
static_task_def_wcet(s, 500000); |
static_task_def_interval(s, 0); |
kern_printf("In main, before task creation\n"); |
p1 = task_create("Static 1", static1, &s, NULL); |
if(p1 == NIL) |
kern_printf("Cannot create: Static1!\n"); |
/* Static2 task */ |
static_task_def_est(s, 800000); |
static_task_def_dabs(s, 1700000); |
static_task_def_wcet(s, 700000); |
static_task_def_interval(s, 1); |
p2 = task_create("Static 2", static2, &s, NULL); |
if(p2 == NIL) |
kern_printf("Cannot create: Static2!\n"); |
/* Static3 task */ |
static_task_def_est(s, 1700000); |
static_task_def_dabs(s, 2000000); |
static_task_def_wcet(s, 100000); |
static_task_def_interval(s, 2); |
p3 = task_create("Static3", static3, &s, NULL); |
if(p3 == NIL) |
kern_printf("Cannot create: Static3!\n"); |
/* End task */ |
/*hard_task_default_model(h_aper); |
hard_task_def_wcet(h_aper, 100000); |
*/ |
kern_printf("After task creation\n"); |
group_activate(1); |
return 0; |
} |
/unsupported/trunk/slsh/readme.txt |
---|
0,0 → 1,6 |
This Example has been made by Tomas Lenvall. |
There is not a lot of documentation available, so if you have problems please |
send an e-mail to Tomas ( mailto:tlv@mdh.se ) |
Paolo |
/unsupported/trunk/slsh/makefile |
---|
0,0 → 1,16 |
# |
# |
# |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
PROGS=slshtest |
include $(BASE)/config/example.mk |
slshtest: |
make -f $(SUBMAKE) APP=slshtest INIT= OTHEROBJS="slshinit.o slsh.o" OTHERINCL= SHARKOPT=__OLDCHAR__ |
/unsupported/trunk/slsh/slshinit.c |
---|
0,0 → 1,117 |
/* |
* 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: slshinit.c,v 1.1 2004-06-01 11:42:47 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:47 $ |
------------ |
System initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
a Slot Shifting level |
a Dummy level |
It can accept these task models: |
STATIC_TASK_MODEL |
HARD_TASK_MODEL(aperiodic) |
SOFT_TASK_MODEL |
**/ |
/* |
* Copyright (C) 2000 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 "kernel/kern.h" |
#include "slsh.h" |
#include "modules/rr2.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "drivers/keyb.h" |
#include "modules/dummy.h" |
/*+ sysyem tick in us +*/ |
#define TICK 300 |
/* define RR tick in us*/ |
#define RRTICK 10000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
SLSH_register_level(); |
RR2_register_level(RRTICK, RR2_MAIN_YES, mb); |
dummy_register_level(); |
SEM_register_module(); |
return TICK; |
} |
NRT_TASK_MODEL nrt; |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
KEYB_PARMS k = BASE_KEYB; |
nrt_task_default_model(nrt); |
keyb_def_task(k,&nrt); |
HARTPORT_init(); |
KEYB_init(NULL); |
__call_main__(mb); |
return 0; |
} |
/unsupported/trunk/cash/testcash.c |
---|
0,0 → 1,455 |
/* |
* Project: HARTIK (HA-rd R-eal TI-me K-ernel) |
* |
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
* Gerardo Lamastra <gerardo@sssup.it> |
* |
* Authors : Paolo Gai <pj@hartik.sssup.it> |
* (see authors.txt for full list of hartik's authors) |
* |
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
* |
* http://www.sssup.it |
* http://retis.sssup.it |
* http://hartik.sssup.it |
*/ |
/** |
------------ |
CVS : $Id: testcash.c,v 1.1 2004-06-01 11:42:41 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:41 $ |
------------ |
testcash.c |
test for the CASH Module, directly derived from Test Number 13 (D) |
**/ |
/* |
* Copyright (C) 2000 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "cash.h" |
#include <math.h> |
#include <string.h> |
#define ASTER_LIM 60 |
#define DISPLAY_MAX 15 |
#define STAT_Y 9 |
#define INPUT 0.5 |
#define MAX_STAT 10000 |
#define RVAL 1 |
#define XVAL 2 |
#define DVAL 3 |
struct statistic { |
TIME r_time; |
TIME ex_time; |
long dead_post; |
}; |
struct statistic stat[MAX_STAT]; |
TIME val[MAX_STAT]; |
int n_stat = 0; |
TASK hard_asteroide(void) |
{ |
int i; |
int y = rand() % 7 + 1; |
double avg, l, fix, u; |
double wcet = 40200; |
int load1,j; |
char s[2]; |
s[0] = 'H'; s[1] = 0; |
/* exponential distribution parameters */ |
fix = wcet - 10.0/9.0 * wcet * (1 - INPUT); |
avg = 1.0/9.0 * wcet * (1 - INPUT); |
l = 10.0 / 9.0 * wcet * (1 - INPUT); |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
/* exponential distribution */ |
u = (double)rand(); |
u = u / (double)RAND_MAX; |
u = -avg * log(u); |
if (u > l) |
u = avg; |
load1 = fix + u; |
for (j=0; j<load1; j++) { |
puts_xy(i,y,rand()%15+1,s); |
} |
//kern_cli(); |
//stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow); |
//jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
//kern_sti(); |
//n_stat++; |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK hard_asteroide1(void) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
char s[2]; |
s[0] = 'H'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 40000 + rand()%20000; |
for (j=0; j<load1; j++) { |
puts_xy(i,y,rand()%15+1,s); |
} |
//kern_cli(); |
//stat[n_stat].r_time = CBSGHD_get_response_time(1, exec_shadow); |
//jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
//kern_sti(); |
//n_stat++; |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK hard_asteroide2(void) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
char s[2]; |
s[0] = 'H'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 80500; // + rand()%6000; |
for (j=0; j<load1; j++) { |
puts_xy(i,y,rand()%15+1,s); |
} |
//kern_cli(); |
//stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow); |
//jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
//kern_sti(); |
//n_stat++; |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK hard_asteroide3(void) |
{ |
int i; |
int y = rand() % 7 + 1; |
int load1,j; |
char s[2]; |
s[0] = 'T'; s[1] = 0; |
for (;;) { |
i = 1; |
while (i < ASTER_LIM) { |
load1 = 27000; |
for (j=0; j<load1; j++) { |
puts_xy(i,y,rand()%15+1,s); |
} |
//kern_cli(); |
//stat[n_stat].r_time = CBSGHD_get_response_time(5, exec_shadow); |
//jet_gettable(exec_shadow, &stat[n_stat].ex_time, 1); |
//kern_sti(); |
//n_stat++; |
task_endcycle(); |
puts_xy(i,y,WHITE," "); |
i++; |
} |
} |
} |
TASK clock() |
{ |
int s = 0, m = 0; |
while(1) { |
printf_xy(62,1,WHITE,"%2d:%2d",m,s); |
printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH); |
printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
printf_xy(62,4,WHITE,"Ucbs=%12u",CBSGHD_usedbandwidth(1)); |
task_endcycle(); |
if (++s > 59) { |
s = 0; |
m++; |
} |
printf_xy(62,1,WHITE,"%2d:%2d",m,s); |
printf_xy(62,2,WHITE,"Utot=%12u",MAX_BANDWIDTH); |
printf_xy(62,3,WHITE,"Uedf=%12u",EDF_usedbandwidth(0)); |
printf_xy(62,4,WHITE,"Ucbs=%12u",CBSGHD_usedbandwidth(1)); |
task_endcycle(); |
} |
} |
/* we consider the first ASTER_MAX + 2 tasks from the PID 2 |
and plot on the screen the elapsed times... */ |
TASK jetcontrol() |
{ |
int i; /* a counter */ |
TIME sum, max, curr, last[5]; |
int nact; |
int j; /* the elements set by jet_gettable */ |
PID p; |
kern_cli(); |
printf_xy(0,STAT_Y,WHITE,"PID ³ Mean T.³ Max T. ³ N.A. ³ Curr. ³ Last1 ³ Last2 ³ Last3 ³ Last4 ³ Last5"); |
kern_sti(); |
for (;;) { |
for (i=0,p=0; i<DISPLAY_MAX+5 && p<MAX_PROC; p++) { |
if (jet_getstat(p, &sum, &max, &nact, &curr) == -1) continue; |
for (j=0; j<5; j++) last[j] = 0; |
jet_gettable(p, &last[0], 5); |
kern_cli(); |
printf_xy(0,STAT_Y+i+1,WHITE,"%-3d ³ %-6ld ³ %-6ld ³ %-4d ³ %-7ld ³ %-5ld ³ %-5ld ³ %-5ld ³ %-5ld ³ %-5ld", p, sum/(nact==0 ? 1 : nact), max, |
nact, curr, last[0], last[1], last[2], last[3], last[4]); |
kern_sti(); |
i++; |
} |
task_endcycle(); |
} |
} |
void save_stat(struct statistic p[], int n, char *name, int type) |
{ |
DOS_FILE *f; |
int i; |
char outstring[500]; |
for(i = 0; i < 500; i++) |
outstring[i] = '0'; |
f = DOS_fopen(name, "w"); |
if (!f) { |
cprintf("Cannot open %s!!!", name); |
goto end1; |
} |
for(i = 0; i < n; i++) { |
if (type == RVAL) |
val[i] = p[i].r_time; |
if (type == XVAL) |
val[i] = p[i].ex_time; |
if (type == DVAL) |
val[i] = p[i].dead_post; |
} |
memset(outstring, 0, 300); |
sprintf(outstring, "%ld \n", (long int)n); |
cprintf("%s", outstring); |
DOS_fwrite(outstring, 1, strlen(outstring), f); |
for(i = 0; i < n; i++) { |
memset(outstring, 0, 300); |
sprintf(outstring, "%ld %lu\n", (long int)i, val[i]); |
//cprintf("%s", outstring); |
DOS_fwrite(outstring, 1, strlen(outstring), f); |
} |
DOS_fclose(f); |
end1:cprintf("OK?"); |
} |
void result_save(void *p) |
{ |
save_stat(stat, n_stat, "stat1.tim", RVAL); |
} |
void fine() |
{ |
sys_end(); |
} |
int main(int argc, char **argv) |
{ |
PID p1,p2,p3, p4, p5, p6, p7; |
ELASTIC_HARD_TASK_MODEL m; |
// int i; |
struct timespec fineprg; |
//sys_atrunlevel(result_save, NULL, RUNLEVEL_AFTER_EXIT); |
srand(7); |
elastic_hard_task_default_model(m); |
elastic_hard_task_def_wcet(m,500); |
elastic_hard_task_def_maxperiod(m,500000); |
elastic_hard_task_def_cnormal(m,500); |
elastic_hard_task_def_period(m,500000); |
elastic_hard_task_def_group(m,1); |
elastic_hard_task_def_ctrl_jet(m); |
p1 = task_create("Clock",clock,&m,NULL); |
if (p1 == -1) { |
perror("testhd.c(main): Could not create task <Clock> ..."); |
sys_end(); |
} |
elastic_hard_task_def_wcet(m,1000); |
elastic_hard_task_def_maxperiod(m,100000); |
elastic_hard_task_def_cnormal(m,1000); |
elastic_hard_task_def_period(m,100000); |
p2 = task_create("JetControl",jetcontrol,&m,NULL); |
if (p2 == -1) { |
perror("testhd.c(main): Could not create task <JetControl> ..."); |
sys_end(); |
} |
elastic_hard_task_def_wcet(m,21000); |
elastic_hard_task_def_maxperiod(m,155000); |
elastic_hard_task_def_cnormal(m,21000); |
elastic_hard_task_def_period(m,155000); |
p3 = task_create("Hard_asteroide1",hard_asteroide1,&m,NULL); |
if (p3 == -1) { |
perror("testhd.c(main): Could not create task <Hard asteroide> ..."); |
sys_end(); |
} |
elastic_hard_task_def_wcet(m,12000); |
elastic_hard_task_def_maxperiod(m,61000); |
elastic_hard_task_def_cnormal(m,12000); |
elastic_hard_task_def_period(m,61000); |
p4 = task_create("Hard_asteroide2",hard_asteroide,&m,NULL); |
if (p4 == -1) { |
perror("testhd.c(main): Could not create task <Hard asteroide> ..."); |
sys_end(); |
} |
elastic_hard_task_def_wcet(m,30000); |
elastic_hard_task_def_maxperiod(m,200000); |
elastic_hard_task_def_cnormal(m,30000); |
elastic_hard_task_def_period(m,200000); |
p5 = task_create("Hard_asteroide3",hard_asteroide2,&m,NULL); |
if (p5 == -1) { |
perror("testhd.c(main): Could not create task <Hard asteroide> ..."); |
sys_end(); |
} |
elastic_hard_task_def_wcet(m,30000); |
elastic_hard_task_def_maxperiod(m,100000); |
elastic_hard_task_def_cnormal(m,30000); |
elastic_hard_task_def_period(m,100000); |
p6 = task_create("Hard_asteroide3",hard_asteroide2,&m,NULL); |
if (p6 == -1) { |
perror("testhd.c(main): Could not create task <Hard asteroide> ..."); |
sys_end(); |
} |
elastic_hard_task_def_wcet(m,10000); |
elastic_hard_task_def_maxperiod(m,200000); |
elastic_hard_task_def_cnormal(m,2500); |
elastic_hard_task_def_period(m,49000); |
p7 = task_create("Hard_asteroide3",hard_asteroide3,&m,NULL); |
if (p7 == -1) { |
perror("testhd.c(main): Could not create task <Hard asteroide> ..."); |
sys_end(); |
} |
printf_xy(0,STAT_Y + 15,WHITE,"Hard asteroide PID= %-3d ",p3); |
printf_xy(0,STAT_Y + 17,WHITE,"Clock PID= %-3d ",p1); |
printf_xy(0,STAT_Y + 18,WHITE,"JetControl PID= %-3d ",p2); |
task_nopreempt(); |
fineprg.tv_sec = 30; |
fineprg.tv_nsec = 0; |
kern_event_post(&fineprg,fine,NULL); |
group_activate(1); |
return 0; |
} |
/unsupported/trunk/cash/cash.c |
---|
0,0 → 1,814 |
/* |
* 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: cash.c,v 1.1 2004-06-01 11:42:40 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:40 $ |
------------ |
This file contains the aperiodic server CBS (Total Bandwidth Server) |
Read CBS.h for further details. |
**/ |
/* |
* Copyright (C) 2000 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 "cash.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> |
/*+ Status used in the level +*/ |
#define CBSGHD_IDLE APER_STATUS_BASE /*+ waiting the activation +*/ |
#define CBSGHD_ZOMBIE APER_STATUS_BASE+1 /*+ waiting the period end +*/ |
/* structure of an element of the capacity queue */ |
struct cap_queue { |
int cap; |
struct timespec dead; |
struct cap_queue *next; |
}; |
/*+ the level redefinition for the CBS_HD level +*/ |
typedef struct { |
level_des l; /*+ the standard level descriptor +*/ |
/* The wcet are stored in the task descriptor, but we need |
an array for the deadlines. We can't use the timespec_priority |
field because it is used by the master level!!!... |
Notice that however the use of the timespec_priority field |
does not cause any problem... */ |
struct timespec cbsghd_dline[MAX_PROC]; /*+ CBSGHD deadlines +*/ |
TIME period[MAX_PROC]; /*+ CBSGHD activation period +*/ |
TIME maxperiod[MAX_PROC]; /*+ maximum period of each elastic task +*/ |
int cremaining[MAX_PROC]; /*+ instance remaining computation time +*/ |
TIME act_period[MAX_PROC]; /*+ actual period of each elastic task: it |
must be less than maxperiod!!! +*/ |
struct timespec request_time[MAX_PROC]; /* used for the response time */ |
TIME last_response_time[MAX_PROC]; /* response time of the last instance */ |
TIME cnormal[MAX_PROC]; /*+ CBSGHD normal computation time +*/ |
struct timespec reactivation_time[MAX_PROC]; |
/*+ the time at witch the reactivation timer is post +*/ |
int reactivation_timer[MAX_PROC]; |
/*+ the recativation timer +*/ |
struct cap_queue *queue; /* pointer to the spare capacity queue */ |
int flags; /*+ the init flags... +*/ |
bandwidth_t U; /*+ the used bandwidth by the server +*/ |
int idle; /* the idle flag... */ |
struct timespec start_idle; /*gives the start time of the last idle period */ |
LEVEL scheduling_level; |
} CBSGHD_level_des; |
/* insert a capacity in the queue capacity ordering by deadline */ |
static int c_insert(struct timespec dead, int cap, struct cap_queue **que, |
PID p) |
{ |
struct cap_queue *prev, *n, *new; |
prev = NULL; |
n = *que; |
while ((n != NULL) && |
!TIMESPEC_A_LT_B(&dead, &n->dead)) { |
prev = n; |
n = n->next; |
} |
new = (struct cap_queue *)kern_alloc(sizeof(struct cap_queue)); |
if (new == NULL) { |
kern_printf("\nNew cash_queue element failed\n"); |
kern_raise(XINVALID_TASK, p); |
return -1; |
} |
new->next = NULL; |
new->cap = cap; |
new->dead = dead; |
if (prev != NULL) |
prev->next = new; |
else |
*que = new; |
if (n != NULL) |
new->next = n; |
return 0; |
} |
/* extract the first element from the capacity queue */ |
static int c_extractfirst(struct cap_queue **que) |
{ |
struct cap_queue *p = *que; |
if (*que == NULL) return(-1); |
*que = (*que)->next; |
kern_free(p, sizeof(struct cap_queue)); |
return(1); |
} |
/* read data of the first element from the capacity queue */ |
static void c_readfirst(struct timespec *d, int *c, struct cap_queue *que) |
{ |
*d = que->dead; |
*c = que->cap; |
} |
/* write data of the first element from the capacity queue */ |
static void c_writefirst(struct timespec dead, int cap, struct cap_queue *que) |
{ |
que->dead = dead; |
que->cap = cap; |
} |
static void CBSGHD_activation(CBSGHD_level_des *lev, |
PID p, |
struct timespec *acttime) |
{ |
JOB_TASK_MODEL job; |
/* This rule is used when we recharge the budget at initial task activation |
and each time a new task instance must be activated */ |
if (TIMESPEC_A_GT_B(acttime, &lev->cbsghd_dline[p])) { |
/* we modify the deadline ... */ |
TIMESPEC_ASSIGN(&lev->cbsghd_dline[p], acttime); |
} |
lev->act_period[p] = 0; |
if (proc_table[p].avail_time > 0) |
proc_table[p].avail_time = 0; |
/* there is a while because if the wcet is << than the system tick |
we need to postpone the deadline many times */ |
while (proc_table[p].avail_time <= 0) { |
/* A spare capacity is inserted in the capacity queue!! */ |
ADDUSEC2TIMESPEC(lev->period[p], &lev->cbsghd_dline[p]); |
lev->act_period[p] += lev->period[p]; |
c_insert(lev->cbsghd_dline[p], lev->cnormal[p], &lev->queue, p); |
/* it exploits available capacities from the capacity queue */ |
while (proc_table[p].avail_time < (int)lev->cnormal[p] && |
lev->queue != NULL) { |
struct timespec dead; |
int cap, delta; |
delta = lev->cnormal[p] - proc_table[p].avail_time; |
c_readfirst(&dead, &cap, lev->queue); |
if (!TIMESPEC_A_GT_B(&dead, &lev->cbsghd_dline[p])) { |
if (cap > delta) { |
proc_table[p].avail_time += delta; |
c_writefirst(dead, cap - delta, lev->queue); |
} |
else { |
proc_table[p].avail_time += cap; |
c_extractfirst(&lev->queue); |
} |
} |
else |
break; |
} |
} |
lev->cremaining[p] = proc_table[p].wcet - proc_table[p].avail_time; |
#ifdef TESTG |
if (starttime && p == 3) { |
oldx = x; |
x = ((lev->cbsghd_dline[p].tv_sec*1000000+lev->cbsghd_dline[p].tv_nsec/1000)/5000 - starttime) + 20; |
// kern_printf("(a%d)",lev->cbsghd_dline[p].tv_sec*1000000+lev->cbsghd_dline[p].tv_nsec/1000); |
if (oldx > x) sys_end(); |
if (x<640) |
grx_plot(x, 15, 8); |
} |
#endif |
/* and, finally, we reinsert the task in the master level */ |
job_task_default_model(job, lev->cbsghd_dline[p]); |
job_task_def_yesexc(job); |
level_table[ lev->scheduling_level ]-> |
private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
} |
/* this is the periodic reactivation of the task... */ |
static void CBSGHD_timer_reactivate(void *par) |
{ |
PID p = (PID) par; |
CBSGHD_level_des *lev; |
lev = (CBSGHD_level_des *)level_table[proc_table[p].task_level]; |
if (proc_table[p].status == CBSGHD_IDLE) { |
/* the task has finished the current activation and must be |
reactivated */ |
/* request_time represents the time of the last instance release!! */ |
TIMESPEC_ASSIGN(&lev->request_time[p], &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 */ |
if (lev->idle == 1) { |
TIME interval; |
struct timespec delta; |
lev->idle = 0; |
SUBTIMESPEC(&lev->request_time[p], &lev->start_idle, &delta); |
/* length of the idle interval expressed in usec! */ |
interval = TIMESPEC2NANOSEC(&delta) / 1000; |
/* it discharge the available capacities from the capacity queue */ |
while (interval > 0 && lev->queue != NULL) { |
struct timespec dead; |
int cap; |
c_readfirst(&dead, &cap, lev->queue); |
if (cap > interval) { |
c_writefirst(dead, cap - interval, lev->queue); |
interval = 0; |
} |
else { |
interval -= cap; |
c_extractfirst(&lev->queue); |
} |
} |
} |
CBSGHD_activation(lev,p,&lev->reactivation_time[p]); |
/* check the constraint on the maximum period permitted... */ |
if (lev->act_period[p] > lev->maxperiod[p]) { |
kern_printf("Deadline miss(timer_react.! process:%d act_period:%lu maxperiod:%lu\n", |
p, lev->act_period[p], lev->maxperiod[p]); |
kern_raise(XDEADLINE_MISS,p); |
} |
/* Set the reactivation timer */ |
TIMESPEC_ASSIGN(&lev->reactivation_time[p], &lev->cbsghd_dline[p]); |
lev->reactivation_timer[p] = kern_event_post(&lev->reactivation_time[p], |
CBSGHD_timer_reactivate, |
(void *)p); |
event_need_reschedule(); |
} |
else { |
/* this situation cannot occur */ |
kern_printf("Trying to reactivate a task which is not IDLE!!!/n"); |
kern_raise(XINVALID_TASK,p); |
} |
} |
static void CBSGHD_avail_time_check(CBSGHD_level_des *lev, PID p) |
{ |
/*+ if the capacity became negative the remaining computation time |
is diminuished.... +*/ |
/* if (p==4) |
kern_printf("(old dead:%d av_time:%d crem:%d)\n", |
lev->cbsghd_dline[p].tv_sec*1000000+ |
lev->cbsghd_dline[p].tv_nsec/1000, proc_table[p].avail_time, |
lev->cremaining[p]); */ |
if (proc_table[p].avail_time < 0) |
lev->cremaining[p] += proc_table[p].avail_time; |
if (lev->cremaining[p] <= 0) { |
kern_printf("Task:%d WCET violation \n", p); |
kern_raise(XWCET_VIOLATION, p); |
ll_abort(666); |
} |
/* there is a while because if the wcet is << than the system tick |
we need to postpone the deadline many times */ |
while (proc_table[p].avail_time <= 0) { |
/* it exploits available capacities from the capacity queue */ |
while (proc_table[p].avail_time < lev->cremaining[p] |
&& lev->queue != NULL) { |
struct timespec dead; |
int cap, delta; |
delta = lev->cremaining[p] - proc_table[p].avail_time; |
c_readfirst(&dead, &cap, lev->queue); |
if (!TIMESPEC_A_GT_B(&dead, &lev->cbsghd_dline[p])) { |
if (cap > delta) { |
proc_table[p].avail_time += delta; |
c_writefirst(dead, cap - delta, lev->queue); |
} |
else { |
proc_table[p].avail_time += cap; |
c_extractfirst(&lev->queue); |
} |
} |
else |
break; |
} |
/* if (p==5 && proc_table[p].avail_time <= 0 && |
lev->cremaining[p] > lev->cnormal[p]) |
kern_printf("(inter dead:%d av_time:%d crem:%d)\n", |
lev->cbsghd_dline[p].tv_sec*1000000+ |
lev->cbsghd_dline[p].tv_nsec/1000, proc_table[p].avail_time, |
lev->cremaining[p]); */ |
/* The remaining computation time is modified according |
to the new budget! */ |
if (proc_table[p].avail_time > 0) |
lev->cremaining[p] -= proc_table[p].avail_time; |
else { |
/* the CBSGHD rule for recharging the capacity: */ |
if (lev->cremaining[p] > lev->cnormal[p]) { |
ADDUSEC2TIMESPEC(lev->period[p], &lev->cbsghd_dline[p]); |
lev->act_period[p] += lev->period[p]; |
/* A spare capacity is inserted in the capacity queue!! */ |
c_insert(lev->cbsghd_dline[p], lev->cnormal[p], &lev->queue, p); |
} |
else { |
TIME t; |
t = (lev->cremaining[p] * lev->period[p]) / lev->cnormal[p]; |
ADDUSEC2TIMESPEC(t, &lev->cbsghd_dline[p]); |
lev->act_period[p] += t; |
/* A spare capacity is inserted in the capacity queue!! */ |
c_insert(lev->cbsghd_dline[p], lev->cremaining[p], &lev->queue, p); |
} |
} |
} |
/* if (p==4) |
kern_printf("n dead:%d av_time:%d crem:%d)\n", |
lev->cbsghd_dline[p].tv_sec*1000000+ |
lev->cbsghd_dline[p].tv_nsec/1000, proc_table[p].avail_time, |
lev->cremaining[p]); */ |
/* check the constraint on the maximum period permitted... */ |
if (lev->act_period[p] > lev->maxperiod[p]) { |
/*kern_printf("n dead:%d av_time:%d crem:%d)\n", |
lev->cbsghd_dline[p].tv_sec*1000000+ |
lev->cbsghd_dline[p].tv_nsec/1000, proc_table[p].avail_time, |
lev->cremaining[p]); */ |
kern_printf("Deadline miss(av.time_check! process:%d act_period:%lu maxperiod:%lu\n", |
p, lev->act_period[p], lev->maxperiod[p]); |
kern_raise(XDEADLINE_MISS,p); |
} |
if (TIMESPEC_A_LT_B(&lev->reactivation_time[p], &lev->cbsghd_dline[p])) { |
/* we delete the reactivation timer */ |
kern_event_delete(lev->reactivation_timer[p]); |
/* repost the event at the next instance deadline... */ |
lev->reactivation_time[p] = lev->cbsghd_dline[p]; |
lev->reactivation_timer[p] = kern_event_post(&lev->reactivation_time[p], |
CBSGHD_timer_reactivate, |
(void *)p); |
} |
#ifdef TESTG |
if (starttime && p == 3) { |
oldx = x; |
x = ((lev->cbsghd_dline[p].tv_sec*1000000+ |
lev->cbsghd_dline[p].tv_nsec/1000)/5000 - starttime) + 20; |
// kern_printf("(e%d avail%d)",lev->cbsghd_dline[p].tv_sec*1000000+ |
lev->cbsghd_dline[p].tv_nsec/1000,proc_table[p].avail_time); |
if (oldx > x) sys_end(); |
if (x<640) |
grx_plot(x, 15, 2); |
} |
#endif |
} |
/*+ this function is called when a killed or ended task reach the |
period end +*/ |
static void CBSGHD_timer_zombie(void *par) |
{ |
PID p = (PID) par; |
CBSGHD_level_des *lev; |
lev = (CBSGHD_level_des *)level_table[proc_table[p].task_level]; |
/* we finally put the task in the FREE status */ |
proc_table[p].status = FREE; |
iq_insertfirst(p,&freedesc); |
/* and free the allocated bandwidth */ |
lev->U -= (MAX_BANDWIDTH/lev->period[p]) * lev->cnormal[p]; |
} |
static PID CBSGHD_public_scheduler(LEVEL l) |
{ |
CBSGHD_level_des *lev = (CBSGHD_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); |
/* the CBSGHD don't schedule anything... |
it's an EDF level or similar that do it! */ |
return NIL; |
} |
/* The on-line guarantee is enabled only if the appropriate flag is set... */ |
static int CBSGHD_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
if (lev->flags & CBSGHD_FAILED_GUARANTEE) { |
*freebandwidth = 0; |
//kern_printf("guarantee :garanzia fallita!!!!!!\n"); |
return 0; |
} |
else if (*freebandwidth >= lev->U) { |
*freebandwidth -= lev->U; |
return 1; |
} |
else { |
//kern_printf("guarantee :garanzia fallita per mancanza di banda!!!!!!\n"); |
//kern_printf("freeband: %d request band: %d", *freebandwidth, lev->U); |
return 0; |
} |
} |
static int CBSGHD_public_create(LEVEL l, PID p, TASK_MODEL *m) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
ELASTIC_HARD_TASK_MODEL *s; |
bandwidth_t b1, b2; |
if (m->pclass != ELASTIC_HARD_PCLASS) return -1; |
if (m->level != 0 && m->level != l) return -1; |
s = (ELASTIC_HARD_TASK_MODEL *)m; |
/* kern_printf("accept :ELASTIC TASK found!!!!!!\n"); */ |
b1 = (MAX_BANDWIDTH / s->period) * s->cnormal; |
b2 = (MAX_BANDWIDTH / s->maxperiod) * s->wcet; |
if (!(s->wcet && s->cnormal && s->period && s->maxperiod && |
s->wcet >= s->cnormal && b1 >= b2) ) |
return -1; |
/* kern_printf("period: %d maxperiod: %d cnormal: %d wcet: %d, b1: %d b2: |
%d\n", s->period, s->maxperiod, s->cnormal, s->wcet, b1, b2); */ |
/* now we know that m is a valid model */ |
/* Enable wcet check */ |
proc_table[p].avail_time = 0; |
proc_table[p].wcet = s->wcet; |
proc_table[p].control |= CONTROL_CAP; |
lev->period[p] = s->period; |
lev->maxperiod[p] = s->maxperiod; |
lev->cnormal[p] = s->cnormal; |
NULL_TIMESPEC(&lev->cbsghd_dline[p]); |
NULL_TIMESPEC(&lev->request_time[p]); |
/* update the bandwidth... */ |
if (lev->flags & CBSGHD_ENABLE_GUARANTEE) { |
bandwidth_t b; |
b = (MAX_BANDWIDTH / s->period) * s->cnormal; |
/* really update lev->U, checking an overflow... */ |
if (MAX_BANDWIDTH - lev->U > b) |
lev->U += b; |
else |
/* The task can NOT be guaranteed (U>MAX_BANDWIDTH)... |
(see EDF.c) */ |
lev->flags |= CBSGHD_FAILED_GUARANTEE; |
} |
return 0; /* OK, also if the task cannot be guaranteed... */ |
} |
static void CBSGHD_public_detach(LEVEL l, PID p) |
{ |
/* the CBSGHD level doesn't introduce any dinamic allocated new field. |
we have only to reset the NO_GUARANTEE FIELD and decrement the allocated |
bandwidth */ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
if (lev->flags & CBSGHD_FAILED_GUARANTEE) |
lev->flags &= ~CBSGHD_FAILED_GUARANTEE; |
else |
lev->U -= (MAX_BANDWIDTH / lev->period[p]) * lev->cnormal[p]; |
} |
static void CBSGHD_public_dispatch(LEVEL l, PID p, int nostop) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
level_table[ lev->scheduling_level ]-> |
private_dispatch(lev->scheduling_level,p,nostop); |
} |
static void CBSGHD_public_epilogue(LEVEL l, PID p) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
JOB_TASK_MODEL job; |
/* check if the budget is finished... */ |
if ( proc_table[p].avail_time <= 0) { |
/* we kill the current activation */ |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level, p); |
/* we modify the deadline */ |
CBSGHD_avail_time_check(lev, p); |
/* and, finally, we reinsert the task in the master level */ |
job_task_default_model(job, lev->cbsghd_dline[p]); |
job_task_def_yesexc(job); |
level_table[ lev->scheduling_level ]-> |
private_insert(lev->scheduling_level, p, (TASK_MODEL *)&job); |
// kern_printf("epil : dl %d per %d p %d |\n", |
// lev->cbsghd_dline[p].tv_nsec/1000,lev->period[p],p); |
} |
else |
/* the task has been preempted. it returns into the ready queue by |
calling the guest_epilogue... */ |
level_table[ lev->scheduling_level ]-> |
private_epilogue(lev->scheduling_level,p); |
} |
static void CBSGHD_public_activate(LEVEL l, PID p) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
kern_gettime(&lev->request_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 */ |
if (lev->idle == 1) { |
TIME interval; |
struct timespec delta; |
lev->idle = 0; |
SUBTIMESPEC(&lev->request_time[p], &lev->start_idle, &delta); |
/* length of the idle interval expressed in usec! */ |
interval = TIMESPEC2NANOSEC(&delta) / 1000; |
/* it discharge the available capacities from the capacity queue */ |
while (interval > 0 && lev->queue != NULL) { |
struct timespec dead; |
int cap; |
c_readfirst(&dead, &cap, lev->queue); |
if (cap > interval) { |
c_writefirst(dead, cap - interval, lev->queue); |
interval = 0; |
} |
else { |
interval -= cap; |
c_extractfirst(&lev->queue); |
} |
} |
} |
CBSGHD_activation(lev, p, &lev->request_time[p]); |
/* check the constraint on the maximum period permitted... */ |
if (lev->act_period[p] > lev->maxperiod[p]) { |
kern_printf("Deadline miss(task_activ.! process:%d act_period:%lu maxperiod:%lu\n", |
p, lev->act_period[p], lev->maxperiod[p]); |
kern_raise(XDEADLINE_MISS,p); |
} |
/* Set the reactivation timer */ |
TIMESPEC_ASSIGN(&lev->reactivation_time[p], &lev->cbsghd_dline[p]); |
lev->reactivation_timer[p] = kern_event_post(&lev->reactivation_time[p], |
CBSGHD_timer_reactivate, |
(void *)p); |
// kern_printf("act : %d %d |",lev->cbsghd_dline[p].tv_nsec/1000,p); |
} |
static void CBSGHD_public_unblock(LEVEL l, PID p) |
{ |
printk("CBSGHD_task_insert\n"); |
kern_raise(XINVALID_TASK,p); |
} |
static void CBSGHD_public_block(LEVEL l, PID p) |
{ |
printk("CBSGHD_task_extract\n"); |
kern_raise(XINVALID_TASK,p); |
} |
static int CBSGHD_public_message(LEVEL l, PID p, void *m) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
struct timespec act_time, res; |
/* It computes the response time of the current instance... */ |
kern_gettime(&act_time); |
SUBTIMESPEC(&act_time, &lev->request_time[p], &res); |
/* response time expressed in usec! */ |
lev->last_response_time[p] = TIMESPEC2NANOSEC(&res) / 1000; |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level,p); |
/* A spare capacity is inserted in the capacity queue!! */ |
if (proc_table[p].avail_time > 0) { |
c_insert(lev->cbsghd_dline[p], proc_table[p].avail_time, &lev->queue, p); |
proc_table[p].avail_time = 0; |
} |
proc_table[p].status = CBSGHD_IDLE; |
jet_update_endcycle(); /* Update the Jet data... */ |
return 0; |
} |
static void CBSGHD_public_end(LEVEL l, PID p) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
/* check if the capacity became negative... */ |
/* there is a while because if the wcet is << than the system tick |
we need to postpone the deadline many times */ |
while (proc_table[p].avail_time < 0) { |
/* the CBSGHD rule for recharging the capacity */ |
proc_table[p].avail_time += lev->cnormal[p]; |
ADDUSEC2TIMESPEC(lev->period[p], &lev->cbsghd_dline[p]); |
} |
level_table[ lev->scheduling_level ]-> |
private_extract(lev->scheduling_level,p); |
/* we delete the reactivation timer */ |
kern_event_delete(lev->reactivation_timer[p]); |
lev->reactivation_timer[p] = -1; |
/* Finally, we post the zombie event. when the end period is reached, |
the task descriptor and banwidth are freed */ |
proc_table[p].status = CBSGHD_ZOMBIE; |
lev->reactivation_timer[p] = kern_event_post(&lev->cbsghd_dline[p], |
CBSGHD_timer_zombie, |
(void *)p); |
} |
/* Registration functions */ |
/*+ Registration function: |
int flags the init flags ... see CBS.h +*/ |
LEVEL CBSGHD_register_level(int flags, LEVEL master) |
{ |
LEVEL l; /* the level that we register */ |
CBSGHD_level_des *lev; /* for readableness only */ |
PID i; /* a counter */ |
printk("CBSGHD_register_level\n"); |
/* request an entry in the level_table */ |
l = level_alloc_descriptor(sizeof(CBSGHD_level_des)); |
lev = (CBSGHD_level_des *)level_table[l]; |
printk(" lev=%d\n",(int)lev); |
/* fill the standard descriptor */ |
lev->l.public_scheduler = CBSGHD_public_scheduler; |
if (flags & CBSGHD_ENABLE_GUARANTEE) |
lev->l.public_guarantee = CBSGHD_public_guarantee; |
else |
lev->l.public_guarantee = NULL; |
lev->l.public_create = CBSGHD_public_create; |
lev->l.public_detach = CBSGHD_public_detach; |
lev->l.public_end = CBSGHD_public_end; |
lev->l.public_dispatch = CBSGHD_public_dispatch; |
lev->l.public_epilogue = CBSGHD_public_epilogue; |
lev->l.public_activate = CBSGHD_public_activate; |
lev->l.public_unblock = CBSGHD_public_unblock; |
lev->l.public_block = CBSGHD_public_block; |
lev->l.public_message = CBSGHD_public_message; |
/* fill the CBSGHD descriptor part */ |
for (i=0; i<MAX_PROC; i++) { |
NULL_TIMESPEC(&lev->cbsghd_dline[i]); |
lev->period[i] = 0; |
NULL_TIMESPEC(&lev->request_time[i]); |
lev->last_response_time[i] = 0; |
NULL_TIMESPEC(&lev->reactivation_time[i]); |
lev->reactivation_timer[i] = -1; |
} |
lev->U = 0; |
lev->idle = 0; |
lev->queue = NULL; |
lev->scheduling_level = master; |
lev->flags = flags & 0x07; |
return l; |
} |
int CBSGHD_get_response_time(LEVEL l, PID p) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
return lev->last_response_time[p]; |
} |
bandwidth_t CBSGHD_usedbandwidth(LEVEL l) |
{ |
CBSGHD_level_des *lev = (CBSGHD_level_des *)(level_table[l]); |
return lev->U; |
} |
/unsupported/trunk/cash/initcash.c |
---|
0,0 → 1,128 |
/* |
* 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: initcash.c,v 1.1 2004-06-01 11:42:41 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:41 $ |
------------ |
System initialization file |
The tick is set to TICK ms. |
This file contains the 2 functions needed to initialize the system. |
These functions register the following levels: |
an EDF (Earliest Deadline First) level |
a RR (Round Robin) level |
a CBSHD (Constant Bandwidth Server with Hard Deadlines) level |
a Dummy level |
It can accept these task models (into () the mandatory fields): |
HARD_TASK_MODEL (wcet+mit) at level 0 |
NRT_TASK_MODEL at level 1 |
ELASTIC_HARD_TASK_MODEL (cnormal,period,wcet,maxperiod) at level 5 |
**/ |
/* |
* Copyright (C) 2000 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 "kernel/kern.h" |
#include "modules/edf.h" |
#include "modules/rr.h" |
#include "modules/tbs.h" |
#include "modules/cbs.h" |
#include "cash.h" |
#include "modules/dummy.h" |
#include "modules/sem.h" |
#include "modules/hartport.h" |
#include "drivers/keyb.h" |
/*+ sysyem tick in us +*/ |
#define TICK 300 |
#define RRTICK 5000 |
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
EDF_register_level(EDF_ENABLE_ALL); |
CBSGHD_register_level(CBSGHD_ENABLE_ALL, 0); |
RR_register_level(RRTICK, RR_MAIN_YES, mb); |
/* CBS_register_level(CBS_ENABLE_ALL, 0); */ |
//CBSHD_register_level(CBSHD_ENABLE_ALL, 0); |
dummy_register_level(); |
SEM_register_module(); |
return TICK; |
} |
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
HARTPORT_init(); |
KEYB_init(NULL); |
__call_main__(mb); |
return (void *)0; |
} |
/unsupported/trunk/cash/cash.h |
---|
0,0 → 1,177 |
/* |
* 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: cash.h,v 1.1 2004-06-01 11:42:41 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-06-01 11:42:41 $ |
------------ |
This file contains the server CBSHD (CASH Algorithm) |
Title: |
CBSHD (Constant Bandwidth Server with hard deadlines) |
Task Models Accepted: |
ELASTIC_HARD_TASK_MODEL - Elastic Hard Tasks |
wcet field must be != 0 |
cnormal field must be != 0 |
period field must be != 0 |
Description: |
This module schedule his tasks following the CBSHD scheme. |
(see Marco Caccamo, Giorgio Buttazzo and Lui Sha |
"Elastic Feedback Control" |
Proceedings of the EUROMICRO 2000) |
The tasks are inserted in an EDF level (or similar) with a JOB_TASK_MODEL, |
and the CBSHD level expects that the task is scheduled with the absolute |
deadline passed in the model. |
The task guarantee is based on the factor utilization approach. |
Exceptions raised: |
XUNVALID_GUEST |
This level doesn't support guests. When a guest operation |
is called, the exception is raised. |
These exceptions are pclass-dependent... |
XDEADLINE_MISS |
If a task miss his deadline, the exception is raised. |
Restrictions & special features: |
- This level doesn't manage the main task. |
- At init time we have to specify: |
. guarantee check |
(when all task are created the system will check that the task_set |
will not use more than the available bandwidth) |
- A function to return the used bandwidth of the level is provided. |
- A function to return the pending activations of the task. |
**/ |
/* |
* Copyright (C) 2000 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 __CBSGHD_H__ |
#define __CBSGHD_H__ |
#include <ll/ll.h> |
#include <kernel/config.h> |
#include <sys/types.h> |
#include <kernel/types.h> |
/*+ flags... +*/ |
#define CBSGHD_ENABLE_GUARANTEE 1 /*+ Task Guarantee enabled +*/ |
#define CBSGHD_ENABLE_ALL 1 |
#define CBSGHD_FAILED_GUARANTEE 8 /*+ used in the module, unsettabl |
in EDF_register_level... +*/ |
#define ELASTIC_HARD_PCLASS 0x0600 |
#define CBSGHD_LEVELNAME "CBSGHD base" |
#define CBSGHD_LEVEL_CODE 106 |
#define CBSGHD_LEVEL_VERSION 1 |
/* ----------------------------------------------------------------------- |
ELASTIC_HARD_TASK_MODEL: elastic hard Tasks |
----------------------------------------------------------------------- */ |
typedef struct { |
TASK_MODEL t; |
TIME cnormal; |
TIME period; |
TIME wcet; |
TIME maxperiod; |
} ELASTIC_HARD_TASK_MODEL; |
#define elastic_hard_task_default_model(m) \ |
task_default_model((m).t,ELASTIC_HARD_PCLASS), \ |
(m).cnormal = 0, \ |
(m).period = 0, \ |
(m).wcet = 0, \ |
(m).maxperiod = 0 |
#define elastic_hard_task_def_level(m,l) task_def_level((m).t,l) |
#define elastic_hard_task_def_arg(m,a) task_def_arg((m).t,a) |
#define elastic_hard_task_def_stack(m,s) task_def_stack((m).t,s) |
#define elastic_hard_task_def_stackaddr(m,s) task_def_stackaddr((m).t,s) |
#define elastic_hard_task_def_group(m,g) task_def_group((m).t,g) |
#define elastic_hard_task_def_usemath(m) task_def_usemath((m).t) |
#define elastic_hard_task_def_system(m) task_def_system((m).t) |
#define elastic_hard_task_def_nokill(m) task_def_nokill((m).t) |
#define elastic_hard_task_def_ctrl_jet(m) task_def_ctrl_jet((m).t) |
#define elastic_hard_task_def_cnormal(m,c) (m).cnormal = (c) |
#define elastic_hard_task_def_period(m,p) (m).period = (p) |
#define elastic_hard_task_def_wcet(m,w) (m).wcet = (w) |
#define elastic_hard_task_def_maxperiod(m,p) (m).maxperiod = (p) |
#define elastic_hard_task_def_joinable(m) task_def_joinable((m).t) |
#define elastic_hard_task_def_unjoinable(m) task_def_unjoinable((m).t) |
/*+ Registration function: |
int flags Options to be used in this level instance... |
LEVEL master the level that must be used as master level for the |
CBSGHD tasks |
returns the level number at which the module has been registered. |
+*/ |
LEVEL CBSGHD_register_level(int flags, LEVEL master); |
/*+ Returns the used bandwidth of a level +*/ |
bandwidth_t CBSGHD_usedbandwidth(LEVEL l); |
#endif |
/unsupported/trunk/cash/readme.txt |
---|
0,0 → 1,6 |
This Example has been made by Marco Caccamo. |
There is not a lot of documentation available, so if you have problems please |
send an e-mail to Marco ( http://gandalf.sssup.it/~caccamo/ ) |
Paolo |
/unsupported/trunk/cash/makefile |
---|
0,0 → 1,17 |
# |
# |
# |
ifndef BASE |
BASE=../.. |
endif |
include $(BASE)/config/config.mk |
PROGS=testcash |
include $(BASE)/config/example.mk |
testcash: |
make -f $(SUBMAKE) APP=testcash INIT= OTHEROBJS="initcash.o cash.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __GRX__" |