Blame |
Last modification |
View Log
| RSS feed
/* 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 <kernel/kern.h> //Shark dependent header, it's used only for TASK_OUTPUT debug
#include "fsf_contract.h" //Framework main header
#include "func.h" //Generic function definitions
/* Activate task output debug */
#define TASK_OUTPUT
int cal_cycles
= 0; //Calibration const, it converts usec in 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
);
char tmp
[20];
#ifdef TASK_OUTPUT
sprintf(tmp
,"[ONESHOT]");
printf_xy
((get_current_exec_task
() % 5) * 9 + 34,get_current_exec_task
() / 5 + 5, GREEN
, tmp
);
#endif
exec_cycles
= (long long)(TIMESPEC2USEC
(&l
->exec
[l
->act_current
-1])) * CALIBRATION_DELTA
/ cal_cycles
;
for (i
=0;i
<exec_cycles
;i
++)
__asm__ __volatile__
("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
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;
int act
= 0;
struct loader_task
*l
= (struct loader_task
*)(arg
);
char tmp
[20];
while(1) {
#ifdef TASK_OUTPUT
sprintf(tmp
,"C[%06d]",act
);
printf_xy
((get_current_exec_task
() % 5) * 9 + 34,get_current_exec_task
() / 5 + 5, GREEN
, tmp
);
#endif
exec_cycles
= (long long)(TIMESPEC2USEC
(&l
->exec
[l
->act_current
-1])) * CALIBRATION_DELTA
/ cal_cycles
;
for (i
=0;i
<exec_cycles
;i
++)
__asm__ __volatile__
("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
generic_task_endcycle
();
act
++;
}
return NULL
;
}
/* BT: Background Task:
begin
while (1) {
- execution
}
end (never end)
*/
void *back_task
(void *arg
)
{
long long i
,exec_cycles
= 0;
int act
= 0;
struct loader_task
*l
= (struct loader_task
*)(arg
);
char tmp
[20];
while(1) {
#ifdef TASK_OUTPUT
sprintf(tmp
,"B[%06d]",act
);
printf_xy
((get_current_exec_task
() % 5) * 9 + 34,get_current_exec_task
() / 5 + 5, GREEN
, tmp
);
#endif
exec_cycles
= (long long)(TIMESPEC2USEC
(&l
->exec
[l
->act_current
-1])) * CALIBRATION_DELTA
/ cal_cycles
;
for (i
=0;i
<exec_cycles
;i
++)
__asm__ __volatile__
("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
act
++;
}
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;
switch(current
->task_type
) {
case PAR_TASK_OS
:
err
= generic_create_thread
(generic_get_server_from_contract
(current
->contract
),&j
,NULL
,
oneshot_task
,(void *)current
,generic_get_task_model
(current
));
break;
case PAR_TASK_BT
:
err
= generic_create_thread
(generic_get_server_from_contract
(current
->contract
),&j
,NULL
,
back_task
,(void *)current
,generic_get_task_model
(current
));
break;
case PAR_TASK_CT
:
err
= generic_create_thread
(generic_get_server_from_contract
(current
->contract
),&j
,NULL
,
periodic_task
,(void *)current
,generic_get_task_model
(current
));
break;
}
if (err
) {
printf("Error fsf task creating\n");
generic_end_simulation
();
}
}
current
= &loader_task_list
[k
];
}
printf("Created %d loader tasks\n",k
);
}
/* Main Function */
int start_environment
()
{
struct timespec total
= {20,0};
generic_calibrate_cycle
();
generic_fsfinit
();
loader_task_create
();
generic_start_simulation
();
generic_set_simulation_time
(&total
);
return 0;
}