Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1209 → Rev 1208

/demos/trunk/loader/loader.c
2,9 → 2,6
#include "parser.h"
#include "dosread.h"
 
#include "fsf_contract.h"
#include "fsf_server.h"
 
/* Memory pointers on loaded file */
extern void *start_file;
extern void *end_file;
20,6 → 17,10
 
struct timespec zero_time;
int cal_cycles = 0;
int cal_rit_start = 0;
int cal_rit_calc_const = 0;
int cal_rit_calc_mean = 0;
int cal_rit_calc_gauss = 0;
 
mutex_t mux_table[MAX_MUTEX];
 
33,9 → 34,11
int crit_start,crit_len;
long long crit_start_cycles = 0, crit_len_cycles = 0;
struct timespec next_time;
static int act= 0;
struct loader_task *l = (struct loader_task *)(arg);
char tmp[20];
act++;
act_1 = TIMESPEC2USEC(&l->act_par_2);
act_2 = TIMESPEC2USEC(&l->act_par_3);
act_3 = TIMESPEC2USEC(&l->act_par_4);
71,15 → 74,16
}
#ifdef TASK_OUTPUT
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, "R[000000]");
printf_xy(exec_shadow % 20 + 60, exec_shadow / 20, GREEN, "R");
#endif
if (l->exec_type == PAR_EXEC_CONST)
exec_cycles = (long long)(exec_1) * CALIBRATION_DELTA / cal_cycles;
exec_cycles = (long long)(exec_1 - cal_rit_start - cal_rit_calc_const)
* CALIBRATION_DELTA / cal_cycles;
if (l->exec_type == PAR_EXEC_MEAN)
exec_cycles = (long long)(exec_1 + rand() % exec_2 - exec_2/2)
* CALIBRATION_DELTA / cal_cycles;
exec_cycles = (long long)(exec_1 - cal_rit_start - cal_rit_calc_mean
+ rand() % exec_2 - exec_2/2) * CALIBRATION_DELTA / cal_cycles;
if (l->exec_type == PAR_EXEC_GAUSS)
exec_cycles = 0;
104,20 → 108,19
else {
for (i=0;i<crit_start_cycles;i++) kern_gettime(NULL);
#ifdef TASK_OUTPUT
sprintf(tmp,"B[%02d][%02d]",exec_shadow,l->resource);
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, RED,tmp);
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, RED,"B");
#endif
mutex_lock(&mux_table[l->resource]);
for (i=0;i<crit_len_cycles;i++) kern_gettime(NULL);
mutex_unlock(&mux_table[l->resource]);
#ifdef TASK_OUTPUT
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN,"R[000000]");
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, GREEN,"R");
#endif
for (i=0;i<exec_cycles;i++) kern_gettime(NULL);
}
 
#ifdef TASK_OUTPUT
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, BLUE, "E[000000]");
printf_xy(exec_shadow % 20 + 60, exec_shadow / 20, WHITE, "E");
#endif
return NULL;
134,10 → 137,12
int crit_start,crit_len;
long long crit_start_cycles = 0, crit_len_cycles = 0;
struct timespec next_time;
int act = 0;
static int act=0;
int extra_rit, k;
struct loader_task *l = (struct loader_task *)(arg);
char tmp[20];
act++;
act_1 = TIMESPEC2USEC(&l->act_par_2);
act_2 = TIMESPEC2USEC(&l->act_par_3);
act_3 = TIMESPEC2USEC(&l->act_par_4);
146,6 → 151,8
exec_2 = TIMESPEC2USEC(&l->exec_par_2);
exec_3 = TIMESPEC2USEC(&l->exec_par_3);
 
extra_rit = cal_rit_start;
 
if (l->crit_type == PAR_CRIT) {
crit_1 = TIMESPEC2USEC(&l->crit_par_1);
crit_2 = TIMESPEC2USEC(&l->crit_par_2);
153,15 → 160,16
crit_4 = TIMESPEC2USEC(&l->crit_par_4);
}
 
k = 0;
while(1) {
 
task_testcancel();
 
act++;
 
#ifdef TASK_OUTPUT
sprintf(tmp,"X[%06d]",act);
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, tmp);
k++;
if (k > 15) k = 1;
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X");
#endif
 
if (l->act_type == PAR_ACT_MEAN) {
178,11 → 186,12
}
 
if (l->exec_type == PAR_EXEC_CONST)
exec_cycles = (long long)(exec_1) * CALIBRATION_DELTA / cal_cycles;
exec_cycles = (long long)(exec_1 - extra_rit - cal_rit_calc_const)
* CALIBRATION_DELTA / cal_cycles;
if (l->exec_type == PAR_EXEC_MEAN)
exec_cycles = (long long)(exec_1 + rand() % exec_2 - exec_2/2)
* CALIBRATION_DELTA / cal_cycles;
exec_cycles = (long long)(exec_1 - extra_rit - cal_rit_calc_mean
+ rand() % exec_2 - exec_2/2) * CALIBRATION_DELTA / cal_cycles;
if (l->exec_type == PAR_EXEC_GAUSS)
exec_cycles = 0;
202,20 → 211,20
}
}
extra_rit = 0;
 
if (l->crit_type == PAR_NO_CRIT)
for (i=0;i<exec_cycles;i++) kern_gettime(NULL);
else {
for (i=0;i<crit_start_cycles;i++) kern_gettime(NULL);
#ifdef TASK_OUTPUT
sprintf(tmp,"B[%02d][%02d]",exec_shadow,l->resource);
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, RED, tmp);
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"B");
#endif
mutex_lock(&mux_table[l->resource]);
for (i=0;i<crit_len_cycles;i++) kern_gettime(NULL);
mutex_unlock(&mux_table[l->resource]);
#ifdef TASK_OUTPUT
sprintf(tmp,"X[%06d]",act);
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, tmp);
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X");
#endif
for (i=0;i<exec_cycles;i++) kern_gettime(NULL);
}
238,10 → 247,12
int crit_start,crit_len;
long long crit_start_cycles = 0, crit_len_cycles = 0;
struct timespec next_time;
int act = 0;
static int act=0;
int extra_rit, k;
struct loader_task *l = (struct loader_task *)(arg);
char tmp[20];
act++;
act_1 = TIMESPEC2USEC(&l->act_par_2);
act_2 = TIMESPEC2USEC(&l->act_par_3);
act_3 = TIMESPEC2USEC(&l->act_par_4);
250,6 → 261,8
exec_2 = TIMESPEC2USEC(&l->exec_par_2);
exec_3 = TIMESPEC2USEC(&l->exec_par_3);
 
extra_rit = cal_rit_start;
 
if (l->crit_type == PAR_CRIT) {
crit_1 = TIMESPEC2USEC(&l->crit_par_1);
crit_2 = TIMESPEC2USEC(&l->crit_par_2);
257,15 → 270,16
crit_4 = TIMESPEC2USEC(&l->crit_par_4);
}
 
k = 0;
while(1) {
 
task_testcancel();
 
act++;
 
#ifdef TASK_OUTPUT
sprintf(tmp,"X[%06d]",act);
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, tmp);
k++;
if (k > 15) k = 1;
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X");
#endif
 
if (l->act_type == PAR_ACT_MEAN) {
282,11 → 296,12
}
 
if (l->exec_type == PAR_EXEC_CONST)
exec_cycles = (long long)(exec_1) * CALIBRATION_DELTA / cal_cycles;
exec_cycles = (long long)(exec_1 - extra_rit - cal_rit_calc_const)
* CALIBRATION_DELTA / cal_cycles;
if (l->exec_type == PAR_EXEC_MEAN)
exec_cycles = (long long)(exec_1 + rand() % exec_2 - exec_2/2)
* CALIBRATION_DELTA / cal_cycles;
exec_cycles = (long long)(exec_1 - extra_rit - cal_rit_calc_mean
+ rand() % exec_2 - exec_2/2) * CALIBRATION_DELTA / cal_cycles;
if (l->exec_type == PAR_EXEC_GAUSS)
exec_cycles = 0;
306,20 → 321,20
}
}
extra_rit = 0;
 
if (l->crit_type == PAR_NO_CRIT)
for (i=0;i<exec_cycles;i++) kern_gettime(NULL);
else {
for (i=0;i<crit_start_cycles;i++) kern_gettime(NULL);
#ifdef TASK_OUTPUT
sprintf(tmp,"B[%02d][%02d]",exec_shadow,l->resource);
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, RED, tmp);
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"B");
#endif
mutex_lock(&mux_table[l->resource]);
for (i=0;i<crit_len_cycles;i++) kern_gettime(NULL);
mutex_unlock(&mux_table[l->resource]);
#ifdef TASK_OUTPUT
sprintf(tmp,"X[%06d]",act);
printf_xy((exec_shadow % 5) * 9 + 34, exec_shadow / 5 + 5, GREEN, tmp);
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X");
#endif
for (i=0;i<exec_cycles;i++) kern_gettime(NULL);
}
335,6 → 350,9
{
long long i;
struct timespec start,end,diff;
int temp = 1234567;
int temp_1 = 1234567;
int temp_2 = 1234567;
 
kern_cli();
kern_gettime(&start);
347,6 → 365,36
 
cprintf("Calibration usec/[%d cycles] = %d\n",CALIBRATION_DELTA,cal_cycles);
 
kern_cli();
kern_gettime(&start);
temp = (long long)(temp_1) * CALIBRATION_DELTA / cal_cycles;
kern_gettime(&end);
kern_sti();
SUBTIMESPEC(&end,&start,&diff);
cal_rit_calc_const = TIMESPEC2USEC(&diff);
 
kern_cli();
kern_gettime(&start);
temp = (long long)(temp_1 + rand() % temp_2 - temp_2/2) * CALIBRATION_DELTA / cal_cycles;
kern_gettime(&end);
kern_sti();
SUBTIMESPEC(&end,&start,&diff);
cal_rit_calc_mean = TIMESPEC2USEC(&diff);
 
kern_cli();
kern_gettime(&start);
temp = TIMESPEC2USEC(&start);
kern_gettime(&end);
kern_sti();
SUBTIMESPEC(&end,&start,&diff);
cal_rit_start = TIMESPEC2USEC(&diff) * 6 + cal_rit_calc_const;
cprintf("Calibration delay start = %d const = %d mean = %d gauss = %d\n",
cal_rit_start,cal_rit_calc_const,cal_rit_calc_mean,cal_rit_calc_gauss);
 
return 0;
 
}
507,54 → 555,6
}
 
if (current->task_type == PAR_TASK_FSF) {
 
if (current->local_scheduler == PAR_POSIX) {
pthread_t j;
int err;
err = fsf_create_thread(current->server,&j,NULL,back_task,(void *)current,NULL);
if (err) {
cprintf("Error fsf task creating\n");
sys_end();
}
}
 
if (current->local_scheduler == PAR_EDF) {
HARD_TASK_MODEL ht;
pthread_t j;
int err;
 
hard_task_default_model(ht);
hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
err = fsf_create_thread(current->server,&j,NULL,test_task,(void *)current,&ht);
if (err) {
cprintf("Error fsf task creating\n");
sys_end();
}
 
}
 
if (current->local_scheduler == PAR_RM) {
HARD_TASK_MODEL ht;
pthread_t j;
int err;
hard_task_default_model(ht);
hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
err = fsf_create_thread(current->server,&j,NULL,test_task,(void *)current,&ht);
if (err) {
cprintf("Error fsf task creating\n");
sys_end();
}
}
 
total_task++;
 
}
 
}
 
cprintf("Task group %d created. Worst case BW = %d.%d \n",
577,15 → 577,11
struct timespec start_time;
 
while (current != NULL) {
ADDTIMESPEC(&zero_time,&current->act_par_1,&start_time);
 
if (current->task_type != PAR_TASK_FSF) {
ADDTIMESPEC(&zero_time,&current->act_par_1,&start_time);
kern_event_post(&start_time, (void *)((void *)group_activate), (void *)(current->group));
 
kern_event_post(&start_time, (void *)((void *)group_activate), (void *)(current->group));
 
}
 
current = current->next;
 
}
592,8 → 588,6
 
}
 
void fsfinit(void);
 
int main()
{
 
607,8 → 601,6
 
calibrate_cycle();
 
fsfinit();
 
loader_mutex_create(start_loader_task);
loader_task_create(start_loader_task);