Blame |
Last modification |
View Log
| RSS feed
/*
* 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
TIME __kernel_register_levels__
(void *arg
)
{
struct multiboot_info
*mb
= (struct multiboot_info
*)arg
;
int grubstar_level
;
EDF_register_level
(EDF_ENABLE_ALL
);
POSIX_register_level
(RRTICK
, 1, mb
, 32);
grubstar_level
= GRUBSTAR_register_level
(4, 0);
FSF_register_module
(grubstar_level
, (int)(MAX_BANDWIDTH
* 0.9));
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 contract1
, contract2
;
pthread_mutex_t mux
;
#define TASK_PERIOD 1000000
void *periodic_star
(void *arg
)
{
struct timespec actual
,end
,next_time
;
int actpersecond
,act
,cycle
;
int mean
,nmean
;
bool was_deadline_missed
, was_budget_overran
;
act
= 0;
actpersecond
= 0;
mean
= 0;
nmean
= 0;
cycle
= 0;
for (;;) {
kern_gettime
(&actual
);
cycle
++;
if (act
== 0) {
TIMESPEC_ASSIGN
(&end
,&actual
);
end.
tv_sec++;
}
if (TIMESPEC_A_LT_B
(&actual
,&end
)) {
act
++;
} else {
actpersecond
= act
;
act
= 0;
mean
= (mean
* nmean
+ actpersecond
) / (nmean
+1);
nmean
++;
}
//pthread_mutex_lock(&mux);
printf_xy
(0,exec_shadow
,WHITE
,"Thread %3d Act_per_Second = %8d Mean = %8d Cycle = %8d",
exec_shadow
,actpersecond
,mean
,cycle
);
//pthread_mutex_unlock(&mux);
kern_gettime
(&next_time
);
ADDUSEC2TIMESPEC
(TASK_PERIOD
, &next_time
);
fsf_schedule_next_timed_job
(NULL
, NULL
, NULL
, &was_deadline_missed
, &was_budget_overran
);
}
return NULL
;
}
void *star
(void *arg
)
{
struct timespec actual
,end
;
int actpersecond
,act
;
int mean
,nmean
,cycle
;
act
= 0;
actpersecond
= 0;
mean
= 0;
nmean
= 0;
cycle
= 0;
for (;;) {
cycle
++;
kern_gettime
(&actual
);
if (act
== 0) {
TIMESPEC_ASSIGN
(&end
,&actual
);
end.
tv_sec++;
}
if (TIMESPEC_A_LT_B
(&actual
,&end
)) {
act
++;
} else {
actpersecond
= act
;
act
= 0;
mean
= (mean
* nmean
+ actpersecond
) / (nmean
+1);
nmean
++;
}
//pthread_mutex_lock(&mux);
printf_xy
(0,exec_shadow
,WHITE
,"Thread %3d Act_per_Second = %8d Mean = %8d Cycle = %8d",
exec_shadow
,actpersecond
,mean
,cycle
);
//pthread_mutex_unlock(&mux);
}
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};
struct timespec period2
= {0,100000000};
struct timespec budget1
= {0,30000000};
struct timespec budget2
= {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
,32000);
hard_task_def_wcet
(mhard
,3000);
hard_task_def_arg
(mhard
,(void *)"X");
hard_task_def_group
(mhard
,1);
hard_task_def_periodic
(mhard
);
t1
= task_create
("X", edftask
, &mhard
, NULL
);
if (t1
== NIL
) {
perror("Could not create task X ...");
sys_end
();
}
hard_task_def_mit
(mhard
,32000);
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
(&contract1
);
fsf_set_contract_basic_parameters
(&contract1
,&budget1
,&period1
,NULL
,NULL
,FSF_DEFAULT_WORKLOAD
);
fsf_initialize_contract
(&contract2
);
fsf_set_contract_basic_parameters
(&contract2
,&budget2
,&period2
,NULL
,NULL
,FSF_DEFAULT_WORKLOAD
);
kern_printf
("(End Create)");
}
int main
(int argc
, char **argv
)
{
NRT_TASK_MODEL nrt
;
char ch
= 0;
int err
;
pthread_mutex_init
(&mux
,NULL
);
create
();
nrt_task_default_model
(nrt
);
nrt_task_def_save_arrivals
(nrt
);
nrt_task_def_ctrl_jet
(nrt
);
do {
ch
= keyb_getch
(BLOCK
);
switch(ch
) {
case '1':
err
= fsf_create_thread
(server1
,&j1
,NULL
,star
,NULL
,&nrt
);
kern_printf
("(%d)",err
);
break;
case '2':
err
= fsf_create_thread
(server2
,&j2
,NULL
,star
,NULL
,&nrt
);
kern_printf
("(%d)",err
);
break;
case '3':
err
= fsf_create_thread
(server1
,&j3
,NULL
,star
,NULL
,&nrt
);
kern_printf
("(%d)",err
);
break;
case '4':
err
= fsf_create_thread
(server2
,&j4
,NULL
,star
,NULL
,&nrt
);
kern_printf
("(%d)",err
);
break;
case 'q':
err
= fsf_negotiate_contract
(&contract1
,&server1
);
cprintf
("(%d)",err
);
break;
case 'w':
err
= fsf_negotiate_contract
(&contract2
,&server2
);
kern_printf
("(%d)",err
);
break;
case 'e':
err
= fsf_negotiate_contract
(&contract1
,&server3
);
kern_printf
("(%d)",err
);
break;
case 'r':
err
= fsf_cancel_contract
(&server1
);
kern_printf
("(%d)",err
);
break;
case 't':
err
= fsf_cancel_contract
(&server2
);
kern_printf
("(%d)",err
);
break;
case 'y':
err
= fsf_cancel_contract
(&server3
);
kern_printf
("(%d)",err
);
break;
}
} while(ch
!= ESC
);
sys_end
();
return 0;
}