0,0 → 1,331 |
/* |
* Project: S.Ha.R.K. |
* |
* Coordinators: |
* Giorgio Buttazzo <giorgio@sssup.it> |
* Paolo Gai <pj@gandalf.sssup.it> |
* |
* Authors : |
* Giacomo Guidi <giacomo@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 |
*/ |
|
/* |
* 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 "pthread.h" |
#include "modules/posix.h" |
|
#include "fsf_contract.h" |
#include "fsf_server.h" |
|
#include "modules/dummy.h" |
|
#include "modules/sem.h" |
#include "modules/pi.h" |
#include "modules/pc.h" |
|
#include "modules/hartport.h" |
#include "modules/cabs.h" |
|
#include "drivers/keyb.h" |
#include <stdlib.h> |
|
// -------------------------------------------------- |
// -------------------------------------------------- |
// Init Part |
// -------------------------------------------------- |
// -------------------------------------------------- |
|
/*+ sysyem tick in us +*/ |
#define TICK 0 |
|
/*+ RR tick in us +*/ |
#define RRTICK 10000 |
|
int grubstar_level; |
|
TIME __kernel_register_levels__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
|
EDF_register_level(EDF_ENABLE_ALL); |
POSIX_register_level(RRTICK, 1, mb, 32); |
grubstar_level = GRUBSTAR_register_level(5, 0); |
FSF_register_module(grubstar_level); |
dummy_register_level(); |
|
// for the keyboard... |
CBS_register_level(CBS_ENABLE_ALL, 0); |
|
PI_register_module(); |
PC_register_module(); |
|
SEM_register_module(); |
|
PTHREAD_register_module(1, 0, 1); |
|
return TICK; |
} |
|
|
TASK __init__(void *arg) |
{ |
struct multiboot_info *mb = (struct multiboot_info *)arg; |
|
HARTPORT_init(); |
|
KEYB_init(NULL); |
|
__call_main__(mb); |
|
return (void *)0; |
|
} |
|
// -------------------------------------------------- |
// -------------------------------------------------- |
// The Test |
// -------------------------------------------------- |
// -------------------------------------------------- |
|
pthread_t j1 = -1; |
pthread_t j2 = -1; |
pthread_t j3 = -1; |
pthread_t j4 = -1; |
fsf_server_id_t server1 = -1; |
fsf_server_id_t server2 = -1; |
fsf_server_id_t server3 = -1; |
fsf_server_id_t server4 = -1; |
fsf_contract_parameters_t contract; |
|
pthread_mutex_t mux; |
|
void *star(void *arg) |
{ |
struct timespec actual,end; |
int actpersecond,act; |
int cycle,rec; |
|
act = 0; |
actpersecond = 0; |
cycle = 0; |
rec = 0; |
for (;;) { |
|
cycle++; |
kern_gettime(&actual); |
rec = GRUBSTAR_get_last_reclaiming(grubstar_level); |
|
if (act == 0) { |
TIMESPEC_ASSIGN(&end,&actual); |
end.tv_sec++; |
} |
|
if (TIMESPEC_A_LT_B(&actual,&end)) { |
act++; |
} else { |
actpersecond = act; |
act = 0; |
} |
|
//pthread_mutex_lock(&mux); |
printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d", |
exec_shadow,actpersecond,cycle,rec); |
//pthread_mutex_unlock(&mux); |
|
} |
|
return NULL; |
|
} |
|
void *periodic_star(void *arg) |
{ |
struct timespec actual,end; |
int actpersecond,act; |
int cycle,rec; |
|
act = 0; |
actpersecond = 0; |
cycle = 0; |
rec = 0; |
for (;;) { |
|
cycle++; |
kern_gettime(&actual); |
rec = GRUBSTAR_get_last_reclaiming(grubstar_level); |
|
if (act == 0) { |
TIMESPEC_ASSIGN(&end,&actual); |
end.tv_sec++; |
} |
|
if (TIMESPEC_A_LT_B(&actual,&end)) { |
act++; |
} else { |
actpersecond = act; |
act = 0; |
} |
|
//pthread_mutex_lock(&mux); |
printf_xy(0,exec_shadow,RED,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d", |
exec_shadow,actpersecond,cycle,rec); |
//pthread_mutex_unlock(&mux); |
|
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++); |
//cputc('#'); |
//cputs((char *)(arg)); |
} |
|
task_endcycle(); |
} |
|
return NULL; |
} |
|
|
void create() |
{ |
HARD_TASK_MODEL mhard; |
|
struct timespec period1 = {0,100000000}; //30% |
struct timespec period2 = {0,200000000}; //15% |
struct timespec period3 = {0,300000000}; //10% |
struct timespec budget1 = {0,30000000}; |
struct timespec budget2 = {0,30000000}; |
struct timespec budget3 = {0,30000000}; |
|
PID t1, t2; |
|
kern_printf("(Start Create)"); |
|
hard_task_default_model(mhard); |
hard_task_def_ctrl_jet(mhard); |
hard_task_def_mit(mhard,30000); |
hard_task_def_wcet(mhard,3000); |
hard_task_def_arg(mhard,(void *)"X"); |
hard_task_def_group(mhard,1); |
hard_task_def_periodic(mhard); |
hard_task_def_level(mhard,0); |
|
t1 = task_create("X", edftask, &mhard, NULL); |
if (t1 == NIL) { |
perror("Could not create task X ..."); |
sys_end(); |
} |
|
hard_task_def_mit(mhard,30000); |
hard_task_def_wcet(mhard,3000); |
hard_task_def_arg(mhard,(void *)"Y"); |
t2 = task_create("Y", edftask, &mhard, NULL); |
if (t2 == NIL) { |
perror("Could not create task Y ..."); |
sys_end(); |
} |
|
//group_activate(1); |
|
fsf_initialize_contract(&contract); |
|
fsf_set_contract_basic_parameters(&contract,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
fsf_negotiate_contract(&contract,&server1); |
|
fsf_set_contract_basic_parameters(&contract,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
fsf_negotiate_contract(&contract,&server2); |
|
fsf_set_contract_basic_parameters(&contract,&budget3,&period3,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
fsf_negotiate_contract(&contract,&server3); |
|
fsf_set_contract_basic_parameters(&contract,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
fsf_set_local_scheduler_parameter(&contract, FSF_SCHEDULER_EDF); |
fsf_negotiate_contract(&contract,&server4); |
|
kern_printf("(End Create)"); |
|
} |
|
int main(int argc, char **argv) |
{ |
|
char ch = 0; |
int err; |
HARD_TASK_MODEL ht; |
|
pthread_mutex_init(&mux,NULL); |
|
create(); |
|
do { |
ch = keyb_getch(BLOCK); |
|
switch(ch) { |
case '1': |
err = fsf_create_thread(server1,&j1,NULL,star,NULL,NULL); |
kern_printf("(%d)",err); |
break; |
case '2': |
err = fsf_create_thread(server2,&j2,NULL,star,NULL,NULL); |
kern_printf("(%d)",err); |
break; |
case '3': |
err = fsf_create_thread(server3,&j3,NULL,star,NULL,NULL); |
kern_printf("(%d)",err); |
break; |
case '4': |
hard_task_default_model(ht); |
hard_task_def_mit(ht,200000); |
hard_task_def_wcet(ht,100000); |
err = fsf_create_thread(server4,&j4,NULL,periodic_star,NULL,&ht); |
kern_printf("(%d)",err); |
break; |
} |
|
} while(ch != ESC); |
|
sys_end(); |
|
return 0; |
|
} |
|