Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1609 → Rev 1608

/demos/trunk/loader/common/nload.c
0,0 → 1,315
/* FSF Loader
*
* Load and run a specific set of tasks/contracts
*
* This is the system indipendent part
*
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* Michael Timarchi <trimarchi@gandalf.sssup.it>
*
*/
 
#include "fsf.h"
 
#include "calibrate.h"
#include "func.h" //Generic function definitions
#include "lconst.h"
 
/* Activate task output debug */
//#define TASK_OUTPUT
 
int cal_cycles = CALIBRATION_RESULT; //Calibration const, it converts usec to cycles
struct timespec zero_time; //Zero time of the simulation
extern struct loader_task loader_task_list[]; //Loader task array
extern int total_loader_task; //Loader task number
 
/* OS: Oneshot Task:
begin
- execution
end
*/
void *oneshot_task(void *arg)
{
long long i,exec_cycles = 0;
struct loader_task *l = (struct loader_task *)(arg);
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
char tmp[20];
#endif
#endif
 
start_oneshot_task();
 
/* to avoid problem if the task start inside the create function */
if (l->act_current == 0) l->act_current = 1;
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"[ONESHOT]");
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
#endif
 
exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
/* Execution delay */
for (i=0;i<exec_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
end_oneshot_task();
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"[--END--]");
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
#endif
 
return NULL;
}
 
/* CT: Cyclical Task:
begin
while (1) {
- execution
- end_cycle
}
end (never end)
*/
void *periodic_task(void *arg)
{
long long i,exec_cycles = 0,block_cycles = 0;
int act = 0;
struct loader_task *l = (struct loader_task *)(arg);
 
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
char tmp[20];
#endif
#endif
 
start_periodic_task();
 
if (l->act_current == 0) l->act_current = 1;
 
while(1) {
 
start_job_periodic_task();
 
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"C[%06d]",act);
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
#endif
exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
block_cycles = (long long)(TIMESPEC2USEC(&l->block[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
 
/* Execution delay */
for (i=0;i<exec_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
if (l->muxstatus == 2) {
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"C[LOCK%02d]",l->resource);
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, RED, tmp);
#endif
#endif
 
generic_lock_mutex(l->resource);
for (i=0;i<block_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
generic_unlock_mutex(l->resource);
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"C[FREE%02d]",l->resource);
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
#endif
 
}
 
end_job_periodic_task();
 
generic_task_endcycle();
act++;
}
 
end_periodic_task();
 
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"[--END--]");
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
#endif
return NULL;
}
 
/* BT: Background Task:
begin
while (1) {
- execution
}
end (never end)
*/
void *back_task(void *arg)
{
long long i,exec_cycles = 0,block_cycles = 0;
int act = 0;
struct loader_task *l = (struct loader_task *)(arg);
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
char tmp[20];
#endif
#endif
 
start_back_task();
 
if (l->act_current == 0) l->act_current = 1;
 
while(1) {
 
start_job_back_task();
 
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"B[%06d]",act);
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
#endif
exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
block_cycles = (long long)(TIMESPEC2USEC(&l->block[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
/* Execution delay */
for (i=0;i<exec_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
if (l->muxstatus == 2) {
 
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"B[LOCK%02d]",l->resource);
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, RED, tmp);
#endif
#endif
 
generic_lock_mutex(l->resource);
for (i=0;i<block_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
generic_unlock_mutex(l->resource);
 
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"C[FREE%02d]",l->resource);
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
#endif
 
}
 
end_job_back_task();
 
act++;
}
 
end_back_task();
#ifdef TASK_OUTPUT
#ifdef OS_SHARK
sprintf(tmp,"[--END--]");
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
#endif
return NULL;
}
 
/* Task create */
/* this function create the task struct in memory */
void loader_task_create()
{
 
struct loader_task *current = loader_task_list;
int i=0, k=0;
 
while (k <total_loader_task) {
k++;
for (i=0; i < current->number; i++) {
pthread_t j;
int err = 0;
//cprintf("(%d, type %d)", i, current->task_type);
switch(current->task_type) {
case PAR_TASK_OS:
err = fsf_create_local_thread(generic_get_server_from_contract(current->contract),generic_get_task_model(current), &j,NULL,
oneshot_task,(void *)current);
break;
case PAR_TASK_BT:
err = fsf_create_local_thread(generic_get_server_from_contract(current->contract),generic_get_task_model(current), &j,NULL,
back_task,(void *)current);
break;
case PAR_TASK_CT:
err = fsf_create_local_thread(generic_get_server_from_contract(current->contract),generic_get_task_model(current), &j,NULL, periodic_task,(void *)current);
break;
}
if (err) {
printf("Error fsf task creating %d\n", err);
generic_end_simulation();
}
}
 
current = &loader_task_list[k];
 
}
printf("Created %d loader tasks\n",k);
 
}
 
/* Main Function */
int start_environment()
{
 
extern struct timespec total_time;
 
/* Calibrate the exec time */
generic_calibrate_cycle();
/* Create the servers usign defined contracts */
generic_fsfinit();
 
/* Create the tasks */
loader_task_create();
 
/* Start the simulation */
generic_start_simulation();
 
/* Set the simulation end time */
generic_set_simulation_time(&total_time);
 
return 0;
 
}
/demos/trunk/loader/common/lconst.h
0,0 → 1,37
#define PAR_TOTAL_EXEC_TIME 0
#define PAR_TIME 1
#define PAR_ACT_TYPE 2
#define PAR_TASK_NUMBER 3
#define PAR_EXEC_TYPE 4
#define PAR_TASK_TYPE 5
#define PAR_NOTHING 6
#define PAR_DEADLINE 7
#define PAR_ERROR 8
#define PAR_FOUND 9
#define PAR_CRIT_SESSION 10
#define PAR_END 11
 
#define PAR_EXEC_CONST 12
#define PAR_EXEC_MEAN 13
 
#define PAR_CONTRACT_SECTION 14
#define PAR_TASK_SECTION 15
 
#define PAR_ACT_SINGLE 16
#define PAR_ACT_PERIODIC 17
#define PAR_ACT_MEAN 18
 
#define PAR_TASK_OS 21
#define PAR_TASK_CT 22
#define PAR_TASK_BT 23
 
#define PAR_NO_CRIT 26
#define PAR_CRIT 27
 
#define PAR_LOCAL_SCHEDULER 29
#define PAR_POSIX 30
#define PAR_EDF 31
#define PAR_RM 32
#define PAR_NONE 33
 
#define PAR_FSF_SERVER 34
/demos/trunk/loader/common/nload.h
0,0 → 1,46
/* Generic Struct for loader task */
#ifndef __NLOAD_H__
#define __NLOAD_H__
 
#include "func.h" //Constant definition for loader and linux parser
 
struct loader_task {
 
char name[20]; //Task name
int task_type; //Tast type (OS,CT,BT)
int contract; //Contract number
int local_scheduler; //Local scheduler for the task
int number; //How many copies of this task
int group; //Group number
struct timespec deadline; //Task deadline
struct timespec wcet; //Task wcet
int act_number; //Number of activations precalcolated
int act_current; //Actual activation number
 
int resource;
int muxstatus;
 
struct timespec *act; //Activation list
struct timespec *exec; //Execution time list
struct timespec *block; //Blocking time
 
};
 
struct loader_contract {
 
int number; //Contract number
struct timespec cmin;
struct timespec tmax;
struct timespec cmax;
struct timespec tmin;
int workload;
struct timespec deadline;
int local_scheduler;
int server; //Server number linked to this contract
 
};
 
#endif
 
/demos/trunk/loader/common/time.h
0,0 → 1,65
#ifndef __TIME_H__
#define __TIME_H__
 
#define TIMESPEC2NANOSEC(t) ((t)->tv_sec * 1000000000 + (t)->tv_nsec)
#define TIMESPEC2USEC(t) ((t)->tv_sec * 1000000 + (t)->tv_nsec / 1000)
#define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0)
#define ADDNANO2TIMESPEC(n, t) ((t)->tv_nsec += (n), \
(t)->tv_sec += (t)->tv_nsec / 1000000000, \
(t)->tv_nsec %= 1000000000)
 
#define SUBTIMESPEC(s1, s2, d) \
((d)->tv_nsec = ((s1)->tv_nsec >= (s2)->tv_nsec) ? \
(((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec), \
(s1)->tv_nsec - (s2)->tv_nsec) \
: \
(((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec - 1), \
(1000000000 + (s1)->tv_nsec - (s2)->tv_nsec)))
 
/*
* ...and these not!
*/
 
extern __inline__ void ADDTIMESPEC(const struct timespec *s1,
const struct timespec *s2,
struct timespec *d)
{
d->tv_sec = s1->tv_sec + s2->tv_sec;
d->tv_nsec = s1->tv_nsec + s2->tv_nsec;
 
if (d->tv_nsec < 0) {
d->tv_sec--;
d->tv_nsec += 1000000000;
} else if (d->tv_nsec >= 1000000000) {
d->tv_sec++;
d->tv_nsec -= 1000000000;
}
}
 
 
#define ADDUSEC2TIMESPEC(m, t) ((t)->tv_nsec += (m%1000000)*1000, \
(t)->tv_sec += ((t)->tv_nsec / 1000000000) + (m/1000000), \
(t)->tv_nsec %= 1000000000)
 
#define TIMESPEC_A_LT_B(a,b) \
( \
((a)->tv_sec < (b)->tv_sec) || \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec < (b)->tv_nsec) \
)
 
#define TIMESPEC_A_GT_B(a,b) \
( \
((a)->tv_sec > (b)->tv_sec) || \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec > (b)->tv_nsec) \
)
 
#define TIMESPEC_A_EQ_B(a,b) \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec == (b)->tv_nsec)
 
#define TIMESPEC_A_NEQ_B(a,b) \
((a)->tv_sec != (b)->tv_sec || (a)->tv_nsec != (b)->tv_nsec)
 
#define TIMESPEC_ASSIGN(t1,t2) \
((t1)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec)
 
#endif
/demos/trunk/loader/common/calibrate.h
0,0 → 1,8
 
/* Nunber of calibration iterations */
#define CALIBRATION_DELTA 100000
 
/* Usec of exec time for CALIBRATING_DELTA iterations
Set to 0 if you calibrate during loader execution */
#define CALIBRATION_RESULT 0
 
/demos/trunk/loader/makefile
0,0 → 1,88
#
# help can be found in readme.txt
#
 
# -----------------------------------------------------
#
# OS dependent variables:
 
# all the OS dependent variables and dependencies are under $(OS)/makefile.in
 
# This makefile will execute the dependency os_specific_dep to "fill"
# the out directory with OS-specific stuffs; Then, the makefile
# generated in the out directory will be executed with $(TEST) as
# parameter.
 
ifndef $(BASE)
BASE=../..
endif
 
include $(BASE)/config/config.mk
 
ifeq ($(OS),MARTE)
OSINCLUDE=marte/makefile.in
endif
 
ifeq ($(OS),SHARK)
OSINCLUDE=shark/makefile.in
endif
 
# -----------------------------------------------------
 
.PHONY: all clean help
 
help:
ifeq ($(CAT),cat)
cat readme.txt
endif
 
all: out out/common.done out/$(TEST).done os_specific_dep
make -C out $(TEST)
 
clean:
make -C generators clean
make -C generators/java clean
rm -rf out
 
out/common.done:
cd out; cp -sf ../common/*.c .
cd out; cp -sf ../common/*.h .
touch out/common.done
 
# note: the out dependency is present only in the "all" dependency
# (there is some strange case with the updating of the out date that I
# do not know how to resolve...
out:
mkdir out
 
# -----------------------------------------------------
#
# Testcase generation
 
# .FSF Format
# -----------------------
 
generators/event_gen:
make -C generators event_gen
 
out/%.done: loadfile/%.fsf generators/event_gen
cd out; ../generators/event_gen ../loadfile/$(TEST).fsf
touch out/$*.done
 
# .FSF2 Format
# -----------------------
 
generators/java/Applicazione.class:
make -C generators/java all
 
out/%.done: loadfile/%.fsf2 generators/java/Applicazione.class
cd generators/java; ./java_gen ../../loadfile/$(TEST).fsf2; mv event.c ../../out/
touch out/$*.done
 
# other file formats
# -----------------------
out/%.done: loadfile/%.otherformat
echo Other file formats that are not specified yet...
touch out/$*.done
 
include $(OSINCLUDE)
/demos/trunk/loader/readme.txt
0,0 → 1,64
FIRST Framework Evaluation architecture
---------------------------------------
 
makefile usage:
 
$ make OS=<osname> TEST=<demo> all
 
where:
 
<osname> is the name of the target operating system and it can be:
 
- MARTE for MaRTE OS
- SHARK for Shark
 
<demo> is the name of the test case that have to be compiled. The
specification of the test case is contained inside the loadfile
directory.
 
Valid extensions for the test case specification files are:
.fsf - old script file
.fsf2 - XML version
(other extensions can be added easily)
 
For example:
 
make OS=SHARK TEST=load all
 
these makefile will:
- prepare the out directory with the common files
- add the shark initialization files
- parse a file loadfile/load.fsf (the file extension is guessed automatically
by the makefile) to produce source code inside out
- compile the resulting shark application
 
-------------------------------------------------------------------------
 
XML Parser & Java setup
 
To use the XML parser (file extension .fsf2) you need to properly setup
your system, and you need toinstall the following libraries:
 
- JDOM BETA 9 - http://www.jdom.org
- XERCES (Parser SAX with XSD support) - http://xml.apache.org
 
On my Linux system, after installing the Sun's j2re,
I did the following commands (as root):
 
# mkdir j
# cd j
# wget http://www.jdom.org/dist/binary/jdom-b9.tar.gz
# tar xvzf jdom-b9.tar.gz
# cp jdom-b9/build/jdom.jar /usr/java/j2re1.4.1_02/lib/
# wget http://www.apache.org/dist/xml/xerces-j/Xerces-J-bin.2.6.0.tar.gz
# tar xvzf Xerces-J-bin.2.6.0.tar.gz
# cp ./xerces-2_6_0/xercesImpl.jar /usr/java/j2re1.4.1_02/lib/
# cp ./xerces-2_6_0/xml-apis.jar /usr/java/j2re1.4.1_02/lib/
 
then, as user, I did
 
$ export CLASSPATH=/usr/java/j2re1.4.1_02/lib
 
Enjoy,
 
Michael, Giacomo, PJ