Blame |
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
;
extern unsigned int clk_per_msec
;
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
;
static fsf_sched_params_t pr
;
pr.
policy=FSF_RR
;
pr.
params=&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 &pr
;
}
if (current
->local_scheduler
== PAR_EDF
) {
static HARD_TASK_MODEL ht
;
static fsf_sched_params_t pr
;
pr.
policy=FSF_EDF
;
pr.
params=&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 &pr
;
}
if (current
->local_scheduler
== PAR_NONE
) {
static DUMMY_TASK_MODEL d
;
static fsf_sched_params_t pr
;
pr.
policy=FSF_NONE
;
pr.
params=&d
;
dummy_task_default_model
(d
);
dummy_task_def_group
(d
,current
->group
);
return &pr
;
}
if (current
->local_scheduler
== PAR_RM
) {
static HARD_TASK_MODEL ht
;
static fsf_sched_params_t pr
;
pr.
policy=FSF_FP
;
pr.
params=&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 &pr
;
}
return NULL
;
}
TASK finish_task
() {
#ifdef __NEW_TRACER__
//FTrace_OSD_init_udp(1,"192.168.82.43","192.168.82.205");
FTrace_OSD_init_udp
(1, "192.168.82.205", "192.168.82.43");
FTrace_send_chunk
(main_chunk
, 0, FTRACE_CHUNK_FLAG_FREE
| FTRACE_CHUNK_FLAG_CYC
);
exit(0);
#else
exit(0);
#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
exit(0);
#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
;
PISTAR_mutexattr_t a
;
PISTAR_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);
TRACER_LOGEVENT
(FTrace_EVT_trace_start
,proc_table
[exec_shadow
].
context,clk_per_msec
);
for (i
=0;i
<10;i
++)
if (proc_table
[i
].
context != 0) TRACER_LOGEVENT
(FTrace_EVT_id
,
(unsigned short int)proc_table
[i
].
context,i
);
i
= 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
);
}
}