/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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 |
*/ |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
*/ |
/* |
* 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]; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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 |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
**/ |
/* |
* 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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:50 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:50 $ |
------------ |
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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:50 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:50 $ |
------------ |
Title: |
RMSTAR |
Task Models Accepted: |
HARD_TASK_MODEL - Hard Tasks (only Periodic) |
wcet field and mit field must be != 0. They are used to set the wcet |
and period of the tasks. |
periodicity field can be only PERIODIC |
drel field is ignored |
Guest Models Accepted: |
JOB_TASK_MODEL - a single guest task activation |
Identified by an absolute deadline and a period. |
period field is ignored |
Description: |
This module schedule his tasks following the classic RM |
scheme. |
Note: This module is derived from the EDFSTAR Scheduling Module. I |
have just changed RM in EDF and iq_timespec_insert with |
iq_priority_insert... |
Exceptions raised: |
XUNVALID_GUEST XUNVALID_TASK |
some primitives are not implemented: |
task_sleep, task_delay, guest_endcycle, guest_sleep, guest_delay |
XACTIVATION |
If a task is actiated through task_activate or guest_activate more than |
one time |
Restrictions & special features: |
see edfstar.h |
**/ |
/* |
* Copyright (C) 2001 Paolo Gai |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by |
* the Free Software Foundation; either version 2 of the License, or |
* (at your option) any later version. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
*/ |
#ifndef __RMSTAR_H__ |
#define __RMSTAR_H__ |
#include <ll/ll.h> |
#include <kernel/config.h> |
#include <sys/types.h> |
#include <kernel/types.h> |
/* flags... */ |
#define RMSTAR_ENABLE_GUARANTEE 1 /* Task Guarantee enabled */ |
#define RMSTAR_ENABLE_ALL 1 |
#define RMSTAR_FAILED_GUARANTEE 8 /* used in the module, unsettabl |
in RM_register_level... */ |
#define RMSTAR_LEVELNAME "RMSTAR base" |
#define RMSTAR_LEVEL_CODE 166 |
#define RMSTAR_LEVEL_VERSION 1 |
/* Registration function: |
int budget The budget used by this module (see CBSSTAR.h) |
int master The master module used by RMSTAR |
*/ |
LEVEL RMSTAR_register_level(int 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 |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
**/ |
/* |
* 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; |
} |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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; |
} |
/advdemos/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= |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
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 |
/advdemos/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.1.1 2004-05-24 17:54:51 giacomo Exp $ |
File: $File$ |
Revision: $Revision: 1.1.1.1 $ |
Last update: $Date: 2004-05-24 17:54:51 $ |
------------ |
*/ |
/* |
* 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; |
} |