/*
* 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 "edf/edf/edf.h"
#include "cbs/cbs/cbs.h"
#include "pthread.h"
#include "posix/posix/posix.h"
#include "fsf.h"
#include "fsf_server.h"
#include "dummy/dummy/dummy.h"
#include "sem/sem/sem.h"
#include "pi/pi/pi.h"
#include "pc/pc/pc.h"
#include "hartport/hartport/hartport.h"
#include "cabs/cabs/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
;
int posix_level
;
//fsf_shared_object_t obj;
//fsf_shared_operation_t op;
TIME __kernel_register_levels__
(void *arg
)
{
struct multiboot_info
*mb
= (struct multiboot_info
*)arg
;
EDF_register_level
(EDF_ENABLE_ALL
);
posix_level
=POSIX_register_level
(RRTICK
, 1, mb
, 32);
grubstar_level
= GRUBSTAR_register_level
(5, 0);
FSF_register_module
(posix_level
,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 jposix
= -1;
pthread_t j1
= -1;
pthread_t j2
= -1;
fsf_server_id_t server1
= -1;
fsf_server_id_t server2
= -1;
fsf_contract_parameters_t contract
;
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
= SERVER_get_last_reclaiming
(grubstar_level
,exec_shadow
);
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
= SERVER_get_last_reclaiming
(grubstar_level
,exec_shadow
);
if (act
== 0) {
TIMESPEC_ASSIGN
(&end
,&actual
);
end.
tv_sec++;
}
if (TIMESPEC_A_LT_B
(&actual
,&end
)) {
act
++;
} else {
actpersecond
= act
;
act
= 0;
}
//fsf_lock_object(&op);
printf_xy
(0,exec_shadow
,RED
,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
exec_shadow
,actpersecond
,cycle
,rec
);
//fsf_unlock_object(&op);
task_endcycle
();
}
return NULL
;
}
int keyinc
= 5;
void *edftask
(void *arg
)
{
long long j
;
while(1) {
for (j
=0; j
<10000*keyinc
; j
++);
task_endcycle
();
}
return NULL
;
}
void create
()
{
struct timespec period1
= {0,90000000}; //30%
struct timespec period2
= {0,75000000}; //80%
struct timespec budget1
= {0,30000000};
struct timespec budget2
= {0,60000000};
FSF_start_service_task
();
kern_printf
("(Start Create)");
fsf_initialize_contract
(&contract
);
fsf_set_contract_basic_parameters
(&contract
,&budget1
,&period1
,FSF_DEFAULT_WORKLOAD
);
fsf_set_contract_scheduling_policy
(&contract
, FSF_EDF
);
fsf_set_contract_reclamation_parameters
(&contract
,&budget2
, &period2
, FSF_DEFAULT_GRANULARITY
, NULL
, 1, 0);
fsf_negotiate_contract
(&contract
,&server1
);
fsf_set_contract_basic_parameters
(&contract
,&budget1
,&period1
,FSF_DEFAULT_WORKLOAD
);
fsf_set_contract_scheduling_policy
(&contract
, FSF_EDF
);
fsf_set_contract_reclamation_parameters
(&contract
,&budget2
, &period2
,FSF_DEFAULT_GRANULARITY
, NULL
, 1, 1);
fsf_negotiate_contract
(&contract
,&server2
);
kern_printf
("(End Create)");
}
void renegotiate
(void) {
struct timespec period2
= {0,75000000};
struct timespec budget2
= {0,60000000};
struct timespec budget1
= {0,60000000};
union sigval sval
;
for (;;) {
fsf_set_contract_basic_parameters
(&contract
,&budget2
,&period2
,FSF_DEFAULT_WORKLOAD
);
fsf_set_contract_reclamation_parameters
(&contract
,&budget1
, &period2
,FSF_DEFAULT_GRANULARITY
, NULL
, 20, 0);
//fsf_request_contract_renegotiation(&contract,server2, 0, sval);
fsf_renegotiate_contract
(&contract
, server2
);
budget2.
tv_nsec -=60000;
task_endcycle
();
}
}
int main
(int argc
, char **argv
)
{
int err
;
HARD_TASK_MODEL ht
;
struct timespec endtimer
;
//fsf_init_shared_object(&obj,1);
//op.op_id=1;
//op.wcet.tv_sec=0;
//op.wcet.tv_nsec=100000;
//fsf_declare_shared_object_operation(&obj, &op);
srand(kern_gettime
(NULL
));
create
();
kern_gettime
(&endtimer
);
endtimer.
tv_sec += 20;
kern_event_post
(&endtimer
, (void (*)(void *))(exit), NULL
);
hard_task_default_model
(ht
);
hard_task_def_mit
(ht
,200000);
hard_task_def_wcet
(ht
,5000);
err
= fsf_create_thread
(server1
,&j1
,NULL
,periodic_star
,NULL
,&ht
);
kern_printf
("(%d)",err
);
task_activate
(j1
);
hard_task_default_model
(ht
);
hard_task_def_mit
(ht
,1000000);
hard_task_def_wcet
(ht
,50000);
err
= fsf_create_thread
(server1
,&j1
,NULL
,renegotiate
,NULL
,&ht
);
kern_printf
("(%d)",err
);
task_activate
(j1
);
hard_task_default_model
(ht
);
hard_task_def_mit
(ht
,159000);
hard_task_def_wcet
(ht
,5000);
err
= fsf_create_thread
(server2
,&j2
,NULL
,periodic_star
,NULL
,&ht
);
kern_printf
("(%d)",err
);
task_activate
(j2
);
hard_task_default_model
(ht
);
hard_task_def_mit
(ht
,159000);
hard_task_def_wcet
(ht
,5000);
err
= fsf_create_thread
(server2
,&j2
,NULL
,periodic_star
,NULL
,&ht
);
kern_printf
("(%d)",err
);
task_activate
(j2
);
return 0;
}