Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1209 → Rev 1208

/demos/trunk/loader/fsfinit.c
File deleted
/demos/trunk/loader/initfile.c
6,7 → 6,7
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
38,52 → 38,46
#include "kernel/kern.h"
#include "modules/edf.h"
#include "modules/cbs.h"
#include "modules/posix.h"
#include "pthread.h"
#include "drivers/keyb.h"
#include "modules/rr.h"
#include "modules/dummy.h"
 
#include "modules/sem.h"
#include "modules/dummy.h"
#include "modules/hartport.h"
#include "modules/cabs.h"
 
#include "fsf_contract.h"
#include "fsf_server.h"
#include "drivers/keyb.h"
 
#include "modules/pi.h"
#include "modules/pc.h"
 
#include "dosread.h"
 
/*+ sysyem tick in us +*/
#define TICK 0
 
/*+ RR tick in us +*/
#define RRTICK 10000
 
void *start_file;
void *end_file;
void *start_file = NULL;
void *end_file = NULL;
 
TIME __kernel_register_levels__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
int grubstar_level;
 
EDF_register_level(EDF_ENABLE_ALL);
POSIX_register_level(RRTICK, 1, mb, 32);
grubstar_level = GRUBSTAR_register_level(FSF_MAX_N_SERVERS, 0);
FSF_register_module(grubstar_level);
CBS_register_level(CBS_ENABLE_ALL, 0);
RR_register_level(RRTICK, RR_MAIN_YES, mb);
dummy_register_level();
CBS_register_level(CBS_ENABLE_ALL,0);
 
SEM_register_module();
 
PI_register_module();
PC_register_module();
CABS_register_module();
 
PTHREAD_register_module(1, 0, 1);
 
dos_preload("loadfile.txt",100000,&start_file,&end_file);
 
cprintf("Start file ptr = %08lx\n",(long)(start_file));
cprintf("End file ptr = %08lx\n",(long)(end_file));
cprintf("Size = %8ld\n",(long)(end_file - start_file));
 
return TICK;
 
}
 
TASK __init__(void *arg)
96,3 → 90,4
 
return (void *)0;
}
 
/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);
/demos/trunk/loader/loadfile.txt
30,26 → 30,12
#
 
TOTAL_EXEC_TIME:[20][0];
 
BACK:[1]:[1]:ACT_SINGLE([4][0]):[0][0]:[0][0]
:EXEC_CONST([0][5000]):NO_CRIT;
 
HARD:[0]:[10]:ACT_PERIODIC([5][0],[0][10000]):[0][10000]:[0][100]
:EXEC_CONST([0][50]):CRIT([0],[0][5],[0][10],[0][20],[0][1]);
 
FSF:[S0]:POSIX:[1]:ACT_SINGLE([0][0]):[0][0]:[0][0]
:EXEC_CONST([0][5000]):CRIT([1],[0][500],[0][1000],[0][2000],[0][1]);
 
FSF:[S1]:POSIX:[1]:ACT_SINGLE([0][0]):[0][0]:[0][0]
:EXEC_CONST([0][5000]):CRIT([1],[0][500],[0][1000],[0][2000],[0][1]);
 
FSF:[S2]:POSIX:[20]:ACT_SINGLE([0][0]):[0][0]:[0][0]
:EXEC_CONST([0][16000]):CRIT([2],[0][500],[0][1000],[0][5000],[0][10000]);
 
FSF:[S3]:EDF:[5]:ACT_PERIODIC([0][0],[0][200000]):[0][200000]:[0][20000]
:EXEC_CONST([0][15000]):CRIT([2],[0][5000],[0][10000],[0][5000],[0][1]);
 
FSF:[S3]:EDF:[5]:ACT_PERIODIC([0][0],[0][111111]):[0][111111]:[0][11111]
:EXEC_MEAN([0][10000],[0][5000]):NO_CRIT;
 
HARD:[0]:[10]:ACT_MEAN([3][0],[1][0],[0][100000]):[0][900000]:[0][10000]
:EXEC_MEAN([0][5000],[0][1000]):NO_CRIT;
HARD:[0]:[10]:ACT_PERIODIC([1][0],[0][300000]):[0][100000]:[0][5000]
:EXEC_CONST([0][1000]):NO_CRIT;
SOFT:[1]:[10]:ACT_PERIODIC([2][0],[0][200000]):[0][200000]:[0][5000]
:EXEC_CONST([0][4000]):CRIT([0],[0][0],[0][1000],[0][2000],[0][1]);
BACK:[2]:[1]:ACT_SINGLE([3][0]):[0][0]:[0][0]
:EXEC_CONST([0][1000]):NO_CRIT;
END
/demos/trunk/loader/parser.c
93,11 → 93,6
*buf += 5;
return PAR_FOUND;
}
if (!strncmp(*buf, "FSF:",4)) {
*val = PAR_TASK_FSF;
*buf += 4;
return PAR_FOUND;
}
break;
 
case PAR_TASK_NUMBER:
115,24 → 110,6
*buf += i;
return PAR_FOUND;
break;
 
case PAR_LOCAL_SCHEDULER:
if (!strncmp(*buf,"POSIX",5)) {
*buf += 5;
*val = PAR_POSIX;
return PAR_FOUND;
}
if (!strncmp(*buf,"EDF",3)) {
*buf += 3;
*val = PAR_EDF;
return PAR_FOUND;
}
if (!strncmp(*buf,"RM",2)) {
*buf += 2;
*val = PAR_RM;
return PAR_FOUND;
}
break;
case PAR_ACT_TYPE:
if (!strncmp(*buf,"ACT_SINGLE(",11)) {
201,23 → 178,6
return PAR_ERROR;
break;
 
case PAR_FSF_SERVER:
if (!strncmp(*buf,"[S",2)) {
*buf += 2;
i = 0;
while (((char *)(*buf))[i] >= '0' && ((char *)(*buf))[i] <= '9') {
str[i] = ((char *)(*buf))[i];
i++;
}
if (((char *)(*buf))[i] != ']') return PAR_ERROR;
str[i] = 0;
*val = atoi(str);
i += 2;
*buf += i;
return PAR_FOUND;
} else return PAR_ERROR;
break;
 
}
 
return PAR_ERROR;
277,37 → 237,16
 
} else par_error(line_num);
 
if (ld->task_type == PAR_TASK_FSF) {
res = find_break(pbuf,PAR_FSF_SERVER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("TASK SERVER = %d\n",val);
#endif
ld->server = val;
} else par_error(line_num);
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("TASK LEVEL = %d\n",val);
#endif
 
res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("TASK LOCAL SCHEDULER = %d\n",val);
#endif
ld->local_scheduler = val;
} else par_error(line_num);
} else {
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("TASK LEVEL = %d\n",val);
#endif
ld->task_level = val;
 
ld->task_level = val;
} else par_error(line_num);
 
} else par_error(line_num);
}
 
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
/demos/trunk/loader/parser.h
31,18 → 31,10
#define PAR_TASK_HARD 22
#define PAR_TASK_SOFT 23
#define PAR_TASK_BACK 24
#define PAR_TASK_FSF 25
 
#define PAR_NO_CRIT 26
#define PAR_CRIT 27
#define PAR_NO_CRIT 25
#define PAR_CRIT 26
 
#define PAR_FSF_SERVER 28
 
#define PAR_LOCAL_SCHEDULER 29
#define PAR_POSIX 30
#define PAR_EDF 31
#define PAR_RM 32
 
struct loader_task {
int number;
int group;
66,8 → 58,6
struct timespec crit_par_2;
struct timespec crit_par_3;
struct timespec crit_par_4;
int server;
int local_scheduler;
struct loader_task *next;
};
 
/demos/trunk/loader/makefile
12,5 → 12,5
include $(BASE)/config/example.mk
 
loader:
make -f $(SUBMAKE) APP=loader INIT= OTHEROBJS="fsfinit.o initfile.o parser.o dosread.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __FIRST__"
make -f $(SUBMAKE) APP=loader INIT= OTHEROBJS="initfile.o parser.o dosread.o" OTHERINCL= SHARKOPT="__OLDCHAR__"