Rev 1370 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include "func.h"
#include "calibrate.h"
#include <tracer.h>
#include "FTrace_udp.h"
#include "FTrace_chunk.h"
extern int cal_cycles;
extern struct timespec zero_time;
extern struct loader_task loader_task_list[];
extern struct loader_contract loader_contract_list[];
extern int total_loader_task;
extern int total_loader_contract;
mutex_t mutex_table[MAX_MUTEX];
int main_chunk;
/* Runtime Calibration */
int calibrate_cycle()
{
long long i;
struct timespec start,end,diff;
if (cal_cycles != 0) return 0;
kern_cli();
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
kern_gettime(&start);
for (i=0;i<CALIBRATION_DELTA;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
kern_gettime(&end);
kern_sti();
SUBTIMESPEC(&end,&start,&diff);
cal_cycles = TIMESPEC2USEC(&diff);
cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles);
return 0;
}
int get_server_from_contract(int contract)
{
int i;
for(i=0;i<total_loader_contract;i++)
if (loader_contract_list[i].number == contract)
return loader_contract_list[i].server;
return -1;
}
void *get_task_model(struct loader_task *current) {
if (current->local_scheduler == PAR_POSIX) {
static NRT_TASK_MODEL nrt;
nrt_task_default_model(nrt);
nrt_task_def_save_arrivals(nrt);
nrt_task_def_ctrl_jet(nrt);
nrt_task_def_group(nrt,current->group);
nrt_task_def_usemath(nrt);
return &nrt;
}
if (current->local_scheduler == PAR_EDF) {
static HARD_TASK_MODEL ht;
hard_task_default_model(ht);
hard_task_def_ctrl_jet(ht);
hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline));
hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet));
hard_task_def_group(ht,current->group);
hard_task_def_aperiodic(ht);
hard_task_def_usemath(ht);
return &ht;
}
if (current->local_scheduler == PAR_RM) {
static HARD_TASK_MODEL ht;
hard_task_default_model(ht);
hard_task_def_mit(ht,TIMESPEC2USEC(¤t->deadline));
hard_task_def_wcet(ht,TIMESPEC2USEC(¤t->wcet));
hard_task_def_ctrl_jet(ht);
hard_task_def_group(ht,current->group);
hard_task_def_usemath(ht);
return &ht;
}
return NULL;
}
TASK finish_task() {
#ifdef __NEW_TRACER__
FTrace_OSD_init_udp(1,"192.168.82.43","192.168.82.20");
FTrace_send_chunk(main_chunk, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
sys_end();
#else
sys_end();
#endif
return NULL;
}
void end_simulation() {
#ifdef __NEW_TRACER__
int i;
struct loader_task *l = loader_task_list;
NRT_TASK_MODEL nrt;
TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
FTrace_disable();
i = 0;
while (i < total_loader_task) {
group_kill(l->group);
i++;
l=&loader_task_list[i];
}
nrt_task_default_model(nrt);
task_activate(task_create("Finish",finish_task,&nrt,NULL));
#else
sys_end();
#endif
}
void set_simulation_time (struct timespec *total) {
struct timespec end_time;
ADDTIMESPEC(&zero_time,total,&end_time);
kern_event_post(&end_time,(void *)((void *)(end_simulation)),NULL);
}
/* Set the zero_time and post the first activation event */
void start_simulation() {
int i;
struct loader_task *l = loader_task_list;
struct timespec end_time;
PI_mutexattr_t a;
PI_mutexattr_default(a);
i = 0;
#ifdef __NEW_TRACER__
main_chunk = FTrace_chunk_create(10000000, 1000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
FTrace_actual_chunk_select(main_chunk);
FTrace_enable();
#endif
TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0);
kern_gettime(&zero_time);
while (i < total_loader_task) {
if (l->muxstatus == 1) {
mutex_init(&mutex_table[l->resource],&a);
l->muxstatus = 2;
}
if (l->act_number > 0) {
ADDTIMESPEC(&zero_time, &l->act[0], &end_time);
l->act_current++;
kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
}
i++;
l=&loader_task_list[i];
}
}
/* Activate task and post the new activation event */
void loader_task_activate(struct loader_task *l) {
struct timespec actual_time,end_time;
kern_gettime(&actual_time);
group_activate(l->group);
if (l->act_number > l->act_current) {
ADDTIMESPEC(&actual_time, &l->act[l->act_current], &end_time);
l->act_current++;
kern_event_post(&end_time,(void *)((void *)(loader_task_activate)),l);
}
}