Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1236 → Rev 1237

/demos/trunk/loader/time.h
0,0 → 1,67
#ifndef __TIME_H__
#define __TIME_H__
 
#include <stdio.h>
 
#define TIMESPEC2NANOSEC(t) ((t)->tv_sec * 1000000000 + (t)->tv_nsec)
#define TIMESPEC2USEC(t) ((t)->tv_sec * 1000000 + (t)->tv_nsec / 1000)
#define NULL_TIMESPEC(t) ((t)->tv_sec = (t)->tv_nsec = 0)
#define ADDNANO2TIMESPEC(n, t) ((t)->tv_nsec += (n), \
(t)->tv_sec += (t)->tv_nsec / 1000000000, \
(t)->tv_nsec %= 1000000000)
 
#define SUBTIMESPEC(s1, s2, d) \
((d)->tv_nsec = ((s1)->tv_nsec >= (s2)->tv_nsec) ? \
(((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec), \
(s1)->tv_nsec - (s2)->tv_nsec) \
: \
(((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec - 1), \
(1000000000 + (s1)->tv_nsec - (s2)->tv_nsec)))
 
/*
* ...and these not!
*/
 
extern __inline__ void ADDTIMESPEC(const struct timespec *s1,
const struct timespec *s2,
struct timespec *d)
{
d->tv_sec = s1->tv_sec + s2->tv_sec;
d->tv_nsec = s1->tv_nsec + s2->tv_nsec;
 
if (d->tv_nsec < 0) {
d->tv_sec--;
d->tv_nsec += 1000000000;
} else if (d->tv_nsec >= 1000000000) {
d->tv_sec++;
d->tv_nsec -= 1000000000;
}
}
 
 
#define ADDUSEC2TIMESPEC(m, t) ((t)->tv_nsec += (m%1000000)*1000, \
(t)->tv_sec += ((t)->tv_nsec / 1000000000) + (m/1000000), \
(t)->tv_nsec %= 1000000000)
 
#define TIMESPEC_A_LT_B(a,b) \
( \
((a)->tv_sec < (b)->tv_sec) || \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec < (b)->tv_nsec) \
)
 
#define TIMESPEC_A_GT_B(a,b) \
( \
((a)->tv_sec > (b)->tv_sec) || \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec > (b)->tv_nsec) \
)
 
#define TIMESPEC_A_EQ_B(a,b) \
((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec == (b)->tv_nsec)
 
#define TIMESPEC_A_NEQ_B(a,b) \
((a)->tv_sec != (b)->tv_sec || (a)->tv_nsec != (b)->tv_nsec)
 
#define TIMESPEC_ASSIGN(t1,t2) \
((t1)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec)
 
#endif
/demos/trunk/loader/lparser.c
0,0 → 1,394
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "parser.h"
#include "time.h"
 
#define PARSER_DEBUG
 
static int find_break(char **buf, int find_type, struct timespec *time, int *val)
{
 
int i;
char str[20];
 
i = 0;
while (((char *)(*buf))[i] == ' ' || ((char *)(*buf))[i] == ':' ||
((char *)(*buf))[i] == '\n' || ((char *)(*buf))[i] == '\r') i++;
*buf += i;
 
if (!strncmp(*buf,"END",3) && find_type == PAR_NOTHING) {
*buf += 5;
return PAR_END;
}
i = 0;
if (((char *)(*buf))[0] == '#' && find_type == PAR_NOTHING) {
while (((char *)(*buf))[i] != '\n' && ((char *)(*buf))[i] != '\r') i++;
*buf += i;
return PAR_FOUND;
}
 
switch (find_type) {
case PAR_NOTHING:
if (((char *)(*buf))[0] == ';' ||
((char *)(*buf))[0] < 32) {
*buf += 1;
return PAR_FOUND;
}
break;
 
case PAR_TOTAL_EXEC_TIME:
if (!strncmp(*buf, "TOTAL_EXEC_TIME:",16)) {
*buf += 16;
return PAR_FOUND;
}
break;
case PAR_TIME:
if (((char *)(*buf))[0] != '[') return PAR_ERROR;
*buf += 1;
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;
time->tv_sec = atoi(str);
i += 2;
*buf += i;
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;
time->tv_nsec = atoi(str) * 1000;
i += 2;
*buf += i;
return PAR_FOUND;
break;
 
case PAR_TASK_TYPE:
if (!strncmp(*buf, "OS:",3)) {
*val = PAR_TASK_OS;
*buf += 3;
return PAR_FOUND;
}
if (!strncmp(*buf, "CT:",3)) {
*val = PAR_TASK_CT;
*buf += 3;
return PAR_FOUND;
}
if (!strncmp(*buf, "BT:",3)) {
*val = PAR_TASK_BT;
*buf += 3;
return PAR_FOUND;
}
break;
 
case PAR_TASK_NUMBER:
if (((char *)(*buf))[0] != '[') return PAR_ERROR;
*buf += 1;
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;
break;
 
case PAR_ACT_TYPE:
if (!strncmp(*buf,"ACT_SINGLE(",11)) {
*buf += 11;
*val = PAR_ACT_SINGLE;
return PAR_FOUND;
}
if (!strncmp(*buf,"ACT_PERIODIC(",13)) {
*buf += 13;
*val = PAR_ACT_PERIODIC;
return PAR_FOUND;
}
if (!strncmp(*buf,"ACT_MEAN(",9)) {
*buf += 9;
*val = PAR_ACT_MEAN;
return PAR_FOUND;
}
return PAR_ERROR;
break;
 
case PAR_LOCAL_SCHEDULER:
if (!strncmp(*buf,"POSIX",5)) {
*buf += 5;
*val = PAR_POSIX;
return PAR_FOUND;
}
if (!strncmp(*buf,"EDF",5)) {
*buf += 5;
*val = PAR_ACT_PERIODIC;
return PAR_FOUND;
}
if (!strncmp(*buf,"RM",2)) {
*buf += 2;
*val = PAR_ACT_MEAN;
return PAR_FOUND;
}
return PAR_ERROR;
break;
 
case PAR_EXEC_TYPE:
if (!strncmp(*buf,"EXEC_CONST(",11)) {
*buf += 11;
*val = PAR_EXEC_CONST;
return PAR_FOUND;
}
if (!strncmp(*buf,"EXEC_MEAN(",10)) {
*buf += 10;
*val = PAR_EXEC_MEAN;
return PAR_FOUND;
}
return PAR_ERROR;
break;
 
case PAR_CRIT_SESSION:
if (!strncmp(*buf,"NO_CRIT",7)) {
*buf += 7;
*val = PAR_NO_CRIT;
return PAR_FOUND;
}
if (!strncmp(*buf,"CRIT(",5)) {
*buf += 5;
*val = PAR_CRIT;
return PAR_FOUND;
}
return PAR_ERROR;
break;
 
}
 
return PAR_ERROR;
 
}
 
void par_error(int line_num)
{
 
printf("\nParser error: line [%d]\n",line_num);
exit(1);
 
}
 
/* result:
* 0 -> nothing
* 1 -> total
* 2 -> new task-loader
* 3 -> end file
*/
int line_parser(char **pbuf, int line_num, struct timespec *total, struct loader_task **last)
{
struct timespec time;
struct loader_task *ld = NULL;
int val, res;
 
res = find_break(pbuf, PAR_NOTHING, &time, &val);
if (res == PAR_FOUND) return 0;
if (res == PAR_END) return 3;
 
res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val);
if (res == PAR_FOUND) {
NULL_TIMESPEC(total);
res = find_break(pbuf, PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
TIMESPEC_ASSIGN(total,&time);
#ifdef PARSER_DEBUG
printf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total->tv_sec,total->tv_nsec);
#endif
return 1;
} else par_error(line_num);
}
 
res = find_break(pbuf,PAR_TASK_TYPE, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("TASK TYPE = %d\n",val);
#endif
 
ld = malloc(sizeof(struct loader_task));
if (ld == NULL) par_error(line_num);
ld->next = NULL;
*last = ld;
ld->task_type = val;
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("TASK SERVER = %d\n",val);
#endif
ld->server = val;
} else par_error(line_num);
 
res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("TASK LOCAL SCHEDULER = %d\n",val);
#endif
ld->local_scheduler = val;
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("TASK NUMBER = %d\n",val);
#endif
 
ld->number = val;
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("DEADLINE: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->deadline,&time);
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->wcet,&time);
} else par_error(line_num);
 
res = find_break(pbuf,PAR_ACT_TYPE, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("ACTIVATION TYPE: %d (",val);
#endif
 
ld->act_type = val;
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->act_par_1,&time);
} else par_error(line_num);
 
if (ld->act_type != PAR_ACT_SINGLE) {
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->act_par_2,&time);
} else par_error(line_num);
}
 
#ifdef PARSER_DEBUG
printf(")\n");
#endif
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_EXEC_TYPE, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("EXEC TYPE: %d (",val);
#endif
ld->exec_type = val;
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->exec_par_1,&time);
} else par_error(line_num);
if (ld->exec_type != PAR_EXEC_CONST) {
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->exec_par_2,&time);
} else par_error(line_num);
}
#ifdef PARSER_DEBUG
printf(")\n");
#endif
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_CRIT_SESSION, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("CRITITCAL SESSION: %d (",val);
#endif
ld->crit_type = val;
if (ld->crit_type == PAR_CRIT) {
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("[%d]",val);
#endif
ld->resource = val;
} else par_error(line_num);
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->crit_par_1,&time);
} else par_error(line_num);
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->crit_par_2,&time);
} else par_error(line_num);
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->crit_par_3,&time);
} else par_error(line_num);
res = find_break(pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
#endif
TIMESPEC_ASSIGN(&ld->crit_par_4,&time);
} else par_error(line_num);
 
}
#ifdef PARSER_DEBUG
printf(")\n");
#endif
} else par_error(line_num);
 
return 2;
 
}
 
/demos/trunk/loader/event_gen.c
6,18 → 6,14
#include <stdio.h>
#include <stdlib.h>
 
#define EVENT_HEADER "event_header.h"
#include "parser.h"
#include "time.h"
 
#define EVENT_HEADER "eventh.h"
#define EVENT_DEFINE "eventc.c"
#define ACT_LIST "act_list.h"
 
#define ACT_SINGLE 0
#define ACT_PERIODIC 1
#define ACT_MEAN 2
#define ACT_INVALID 3
 
#define EXEC_CONST 0
#define EXEC_MEAN 1
#define EXEC_INVALID 2
 
int act_number;
 
int write_struct(void)
25,10 → 21,11
 
FILE *file_event_header;
 
file_event_header = fopen(EVENT_HEADER,"w");
file_event_header = fopen(EVENT_DEFINE,"w");
if (file_event_header == NULL) return 1;
 
fprintf(file_event_header, "\n#include \"%s\"\n\n",ACT_LIST);
fprintf(file_event_header, "\n#include \"event_gen.h\"\n");
fprintf(file_event_header, "#include \"%s\"\n",ACT_LIST);
 
fprintf(file_event_header, "struct loader_task loader_task_list[] = {\n");
 
38,43 → 35,18
 
}
 
int select_basic_par(char *task_name)
int write_basic_par(struct loader_task *c)
{
 
int number,group,server,deadline,wcet,local_scheduler;
FILE *file_event_header;
 
printf("\nInsert the number of tasks\n");
printf("> ");
scanf("%d",&number);
printf("Insert the group number\n");
printf("> ");
scanf("%d",&group);
printf("Insert the server number\n");
printf("> ");
scanf("%d",&server);
 
printf("Insert the local scheduler type\n");
printf(" 0 - POSIX\n");
printf(" 1 - EDF\n");
printf(" 2 - RM\n");
printf(" 3 - MPEGSTAR\n");
printf("> ");
scanf("%d",&local_scheduler);
 
printf("Insert the deadline [us]\n");
printf("> ");
scanf("%d",&deadline);
printf("Insert the wcet [us]\n");
printf("> ");
scanf("%d",&wcet);
 
file_event_header = fopen(EVENT_HEADER,"a+");
file_event_header = fopen(EVENT_DEFINE,"a+");
if (file_event_header == NULL) return 1;
fprintf(file_event_header, " {\"%s\",%d,%d,%d,%d,{%d,%d},{%d,%d},ACT_NUMBER_%s,act_%s,exec_%s},\n",
task_name,number,group,server,local_scheduler,deadline / 1000000, deadline % 1000000 * 1000,
wcet / 1000000, wcet % 1000000 * 1000, task_name, task_name, task_name);
fprintf(file_event_header, " {\"%s\",%d,%d,%d,%d,%d,{%d,%d},{%d,%d},%d,0,act_%s,exec_%s},\n",
c->name,c->task_type,c->server,c->local_scheduler,c->number,c->group,
c->deadline.tv_sec, c->deadline.tv_nsec,c->act_number,
c->wcet.tv_sec, c->wcet.tv_nsec, c->name, c->name, c->name);
 
fclose(file_event_header);
 
87,7 → 59,7
 
FILE *file_event_header;
 
file_event_header = fopen(EVENT_HEADER,"a+");
file_event_header = fopen(EVENT_DEFINE,"a+");
if (file_event_header == NULL) return 1;
 
fprintf(file_event_header,"};\n\n");
98,100 → 70,23
 
}
 
int select_act_type(void)
int write_single_act(struct timespec *t, struct loader_task *c)
{
char act_type[10];
 
printf("\nInsert the activation type\n");
printf(" S - Single\n");
printf(" P - Periodic\n");
printf(" M - Sporadic with constant distribution (Mean,Delta)\n");
printf("> ");
scanf("%s",act_type);
 
switch (act_type[0]) {
 
case 's':
case 'S':
 
return ACT_SINGLE;
break;
 
case 'p':
case 'P':
return ACT_PERIODIC;
break;
case 'm':
case 'M':
return ACT_MEAN;
break;
 
default:
 
return ACT_INVALID;
}
 
return ACT_INVALID;
 
}
 
int select_exec_type(void)
{
char exec_type[10];
printf("\nInsert the execution time\n");
printf(" C - Const Exec Time\n");
printf(" M - Variable with constant distribution (Mean,Delta)\n");
printf("> ");
scanf("%s",exec_type);
switch (exec_type[0]) {
case 'c':
case 'C':
return EXEC_CONST;
break;
case 'm':
case 'M':
return EXEC_MEAN;
break;
default:
 
return EXEC_INVALID;
 
}
 
return EXEC_INVALID;
 
}
 
int write_single_act(char *task_name)
{
 
FILE *file_act_header;
int time_usec;
 
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
 
act_number = 1;
fprintf(file_act_header,"\n#define ACT_NUMBER_%s %d\n\n",task_name,act_number);
if (TIMESPEC_A_GT_B(t,&c->act_par_1)) {
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d}};\n\n",c->name,
c->act_par_1.tv_sec,c->act_par_1.tv_nsec);
c->act_number = 1;
} else {
fprintf(file_act_header,"struct timespec act_%s[] = {{0,0}};\n\n",c->name);
c->act_number = 0;
}
 
printf("\nInsert single activation time [us]\n");
printf("> ");
scanf("%d",&time_usec);
 
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d}};\n\n",task_name,
time_usec/1000000,time_usec%1000000*1000);
 
fclose(file_act_header);
 
return 0;
198,36 → 93,28
 
}
 
int write_periodic_act(char *task_name)
int write_periodic_act(struct timespec *t, struct loader_task *c)
{
 
FILE *file_act_header;
int i,first_time_usec,per_time_usec;
long long tot_time_usec;
int i;
struct timespec tot_time;
int period;
 
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
printf("\nInsert the number of activations\n");
printf("> ");
scanf("%d",&act_number);
printf("Insert first activation time [us]\n");
printf("> ");
scanf("%d",&first_time_usec);
printf("Insert periodic activation time [us]\n");
printf("> ");
scanf("%d",&per_time_usec);
fprintf(file_act_header,"\n#define ACT_NUMBER_%s %d\n\n",task_name,act_number);
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",task_name,
first_time_usec/1000000,first_time_usec%1000000*1000);
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",c->name,
c->act_par_1.tv_sec,c->act_par_1.tv_nsec);
 
tot_time_usec = first_time_usec;
for (i=0;i<act_number-1;i++) {
tot_time_usec += per_time_usec;
c->act_number = 1;
TIMESPEC_ASSIGN(&tot_time,&c->act_par_1);
period = TIMESPEC2USEC(&c->act_par_2);
while (TIMESPEC_A_GT_B(t, &tot_time)) {
c->act_number++;
ADDUSEC2TIMESPEC(period,&tot_time);
fprintf(file_act_header," {%d,%d},\n",
(int)tot_time_usec/1000000,(int)tot_time_usec%1000000*1000);
c->act_par_2.tv_sec,c->act_par_2.tv_nsec);
}
 
fprintf(file_act_header," };\n\n");
238,39 → 125,28
 
}
 
int write_mean_act(char *task_name)
int write_mean_act(struct timespec *t,struct loader_task *c)
{
 
FILE *file_act_header;
int i,first_time_usec,mean_time_usec,delta_time_usec;
long long tot_time_usec;
struct timespec tot_time;
int next_act;
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
printf("\nInsert the number of activations\n");
printf("> ");
scanf("%d",&act_number);
printf("Insert first activation time [us]\n");
printf("> ");
scanf("%d",&first_time_usec);
printf("Insert mean peridic time [us]\n");
printf("> ");
scanf("%d",&mean_time_usec);
printf("Insert delta time [us]\n");
printf("> ");
scanf("%d",&delta_time_usec);
 
fprintf(file_act_header,"\n#define ACT_NUMBER_%s %d\n\n",task_name,act_number);
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",task_name,
first_time_usec/1000000,first_time_usec%1000000*1000);
tot_time_usec = first_time_usec;
for (i=0;i<act_number-1;i++) {
tot_time_usec += mean_time_usec + random() % delta_time_usec - delta_time_usec/2;
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",c->name,
c->act_par_1.tv_sec,c->act_par_1.tv_nsec);
c->act_number = 1;
TIMESPEC_ASSIGN(&tot_time,&c->act_par_1);
while (TIMESPEC_A_GT_B(t, &tot_time)) {
c->act_number++;
next_act = TIMESPEC2USEC(&c->act_par_2) + random() % TIMESPEC2USEC(&c->act_par_3) - TIMESPEC2USEC(&c->act_par_3) / 2;
ADDUSEC2TIMESPEC(next_act,&tot_time);
fprintf(file_act_header," {%d,%d},\n",
(int)tot_time_usec/1000000,(int)tot_time_usec%1000000*1000);
next_act / 1000000, next_act % 1000000 * 1000);
}
fprintf(file_act_header," };\n\n");
281,7 → 157,7
}
 
int write_exec_const(char *task_name)
int write_exec_const(struct loader_task *c)
{
 
FILE *file_exec_header;
290,16 → 166,12
file_exec_header = fopen(ACT_LIST,"a+");
if (file_exec_header == NULL) return 1;
printf("Insert execution time [us]\n");
printf("> ");
scanf("%d",&exec_time_usec);
fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",task_name,
exec_time_usec/1000000,exec_time_usec%1000000*1000);
fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",c->name,
c->exec_par_1.tv_sec,c->exec_par_1.tv_nsec);
 
for (i=0; i< act_number-1; i++)
fprintf(file_exec_header," {%d,%d},\n",
exec_time_usec/1000000,exec_time_usec%1000000*1000);
c->exec_par_1.tv_sec,c->exec_par_1.tv_nsec);
 
fprintf(file_exec_header," };\n\n");
309,31 → 181,25
 
}
 
int write_exec_mean(char *task_name)
int write_exec_mean(struct loader_task *c)
{
FILE *file_exec_header;
int exec_time_usec,mean_time_usec,delta_time_usec,i;
struct timespec exec_time;
int i;
file_exec_header = fopen(ACT_LIST,"a+");
if (file_exec_header == NULL) return 1;
printf("Insert mean execution time [us]\n");
printf("> ");
scanf("%d",&mean_time_usec);
printf("Insert delta execution time [us]\n");
printf("> ");
scanf("%d",&delta_time_usec);
 
exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
//exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",
exec_time_usec/1000000,exec_time_usec%1000000*1000);
for (i=0; i< act_number-1; i++) {
exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
c->exec_par_1.tv_sec,c->exec_par_1.tv_nsec);
TIMESPEC_ASSIGN(&exec_time,&c->exec_par_1); for (i=0; i< act_number-1; i++) {
//exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
fprintf(file_exec_header," {%d,%d},\n",
exec_time_usec/1000000,exec_time_usec%1000000*1000);
exec_time.tv_sec,exec_time.tv_nsec);
}
fprintf(file_exec_header," };\n\n");
344,53 → 210,58
}
 
void *start;
void *end;
 
int main(void) {
 
char task_name[100];
char act_type,exec_type;
int err;
struct timespec total_time;
struct loader_task *start_loader_task, *current;
int err,ldnum;
 
printf("\nEvent Generator\n\n");
printf("\nEvent Generator\n");
 
printf("Read loader file\n");
 
dos_preload("loadfile.txt",100000,&start,&end);
 
printf("Parsing file\n");
 
line_reader(start, end, &total_time, &start_loader_task);
 
srandom(12354132);
 
write_struct();
 
while(1) {
current = start_loader_task;
ldnum = 0;
 
printf("Insert the task name\n");
printf("Write \"q\" to quit program\n");
printf("> ");
scanf("%s",task_name);
while(current != NULL) {
 
if (strlen(task_name) == 1 && task_name[0] == 'q') {
close_loader();
exit(0);
}
sprintf(current->name,"ltask%d",ldnum);
current->group = ldnum;
 
select_basic_par(task_name);
write_basic_par(current);
 
while((act_type = select_act_type()) == ACT_INVALID) {
printf("Error: Invalid Act Type\n");
}
 
switch (act_type) {
case ACT_SINGLE:
err = write_single_act(task_name);
switch (current->act_type) {
case PAR_ACT_SINGLE:
err = write_single_act(&total_time,current);
if (err != 0) {
printf("Error writing activation header\n");
exit(1);
}
break;
case ACT_PERIODIC:
err = write_periodic_act(task_name);
case PAR_ACT_PERIODIC:
err = write_periodic_act(&total_time,current);
if (err != 0) {
printf("Error writing activation header\n");
exit(1);
}
break;
case ACT_MEAN:
err = write_mean_act(task_name);
case PAR_ACT_MEAN:
err = write_mean_act(&total_time,current);
if (err != 0) {
printf("Error writing activation header\n");
exit(1);
398,20 → 269,16
break;
}
 
while((exec_type = select_exec_type()) == EXEC_INVALID) {
printf("Error: Invalid Exec Type\n");
}
switch (exec_type) {
case EXEC_CONST:
err = write_exec_const(task_name);
switch (current->exec_type) {
case PAR_EXEC_CONST:
err = write_exec_const(current);
if (err != 0) {
printf("Error writing exec header\n");
exit(1);
}
break;
case EXEC_MEAN:
err = write_exec_mean(task_name);
case PAR_EXEC_MEAN:
err = write_exec_mean(current);
if (err != 0) {
printf("Error writing exec header\n");
exit(1);
419,8 → 286,12
break;
}
 
current = current->next;
 
}
 
close_loader();
 
return 0;
 
}
/demos/trunk/loader/load.txt
0,0 → 1,30
# TASK TYPE:SERVER NUMBER:LOCAL SCHEDULER:NUMBER OF TASK:DEADLINE:WCET:TASK ACT TYPE (PAR1,PAR2,...):
# :TASK EXEC TYPE (PAR1,PAR2,...):CRITICAL SESSION (PAR1,PAR2,PAR3,PAR4);
#
# TASK TYPE
# OS - ONE_SHOT
# CT - CYCLICAL_TASK
# BT - BACKGROUND_TASK
#
# TASK EXEC TYPE
# EXEC_CONST(TIME)
# - CONSTANT EXEC TIME
# EXEC_MEAN(MEAN, DELTA)
# - VARIABLE EXEC TIME WITH CONSTANT DISTRIBUTION
#
# TASK ACTIVATION TIME
# ACT_SINGLE(START_TIME)
# ACT_PERIODIC(START_TIME, PERIOD)
# ACT_MEAN(START_TIME, MEAN, DELTA)
#
# CRITICAL SESSION
# CRIT(RES NUMBER, MEAN_START, DELTA_START, MEAN_LEN, DELTA_LEN)
# NO_CRIT
#
 
TOTAL_EXEC_TIME:[20][0];
 
OS:[0]:POSIX:[1]:[0][0]:[0][0]:ACT_SINGLE([0][0]):
:EXEC_CONST([0][16000]):CRIT([2],[0][500],[0][1000],[0][5000],[0][10000]);
 
END
/demos/trunk/loader/lparser.h
0,0 → 1,77
#ifndef __LPARSER_H__
#define __LPARSER_H__
 
#define PAR_TOTAL_EXEC_TIME 0
#define PAR_TIME 1
#define PAR_ACT_TYPE 2
#define PAR_TASK_NUMBER 3
#define PAR_EXEC_TYPE 4
#define PAR_TASK_TYPE 5
#define PAR_NOTHING 6
#define PAR_DEADLINE 7
#define PAR_ERROR 8
#define PAR_FOUND 9
#define PAR_CRIT_SESSION 10
#define PAR_END 11
 
#define PAR_EXEC_CONST 12
#define PAR_EXEC_MEAN 13
 
#define PAR_ACT_SINGLE 16
#define PAR_ACT_PERIODIC 17
#define PAR_ACT_MEAN 18
 
#define PAR_TASK_OS 21
#define PAR_TASK_CT 22
#define PAR_TASK_BT 23
 
#define PAR_NO_CRIT 26
#define PAR_CRIT 27
 
#define PAR_LOCAL_SCHEDULER 29
#define PAR_POSIX 30
#define PAR_EDF 31
#define PAR_RM 32
 
#define PAR_FSF_SERVER 33
 
struct loader_task {
char name[20];
int number;
int group;
int server;
int local_scheduler;
int task_type;
 
int act_type;
struct timespec act_par_1;
struct timespec act_par_2;
struct timespec act_par_3;
int exec_type;
struct timespec exec_par_1;
struct timespec exec_par_2;
struct timespec exec_par_3;
struct timespec deadline;
struct timespec wcet;
int act_number;
struct timespec *act;
struct timespec *exec;
 
int crit_type;
int resource;
struct timespec crit_par_1;
struct timespec crit_par_2;
struct timespec crit_par_3;
struct timespec crit_par_4;
struct loader_task *next;
 
};
 
int line_parser(char **buf, int line_num, struct timespec *total, struct loader_task **last);
 
#endif
 
/demos/trunk/loader/event_gen.h
3,15 → 3,17
struct loader_task {
 
char name[20];
int number;
int group;
int task_type;
int server;
int local_scheduler;
int number;
int group;
struct timespec deadline;
struct timespec wcet;
int act_number;
int act_current;
 
struct timespec *act;
struct timespec *exec;
/demos/trunk/loader/lread.c
0,0 → 1,69
#include <stdio.h>
#include <stdlib.h>
#include "parser.h"
#include "time.h"
 
int dos_preload(char *file_name, long max_size, void **start_file, void **end_file)
{
FILE *file;
void *buf;
long rd;
file = fopen(file_name,"r");
if (file == NULL) return -1;
buf = malloc(max_size);
*start_file = buf;
while(((rd = fread(buf, 1, 2048, file)) == 2048) &&
((buf - *start_file + rd) < (max_size-2048))) {
buf += rd;
}
*end_file = buf + rd;
fclose(file);
return(0);
}
 
int line_reader(void *start_file, void *end_file, struct timespec *total, struct loader_task **start_loader_task)
{
char *pbuf = start_file;
int res,line_num,total_loader_task;
struct loader_task *current = NULL;
 
NULL_TIMESPEC(total);
 
line_num = 0;
total_loader_task = 0;
while ((void *)(pbuf) < end_file) {
line_num++;
 
if (*start_loader_task == NULL)
res = line_parser(&pbuf, line_num, total, &current);
else
res = line_parser(&pbuf, line_num, total, &current->next);
 
if (res == 2) {
total_loader_task++;
if (*start_loader_task == NULL)
*start_loader_task = current;
else
current = current->next;
}
 
if (res == 3) break;
 
}
 
printf("Total decoded lines %d\n",line_num);
printf("Total loader task %d\n",total_loader_task);
printf("Simulation time sec = %ld usec = %ld\n",total->tv_sec,total->tv_nsec/1000);
 
return 0;
 
}
/demos/trunk/loader/makefile
12,5 → 12,8
include $(BASE)/config/example.mk
 
newloader:
make -f $(SUBMAKE) APP=newloader INIT= OTHEROBJS="fsfinit.o initfile.o shark.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __FIRST__"
#make -f $(SUBMAKE) APP=newloader INIT= OTHEROBJS="fsfinit.o initfile.o shark.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __FIRST__"
gcc -o lread.o -c lread.c
gcc -o lparser.o -c lparser.c
gcc -o event_gen event_gen.c lparser.o lread.o
 
/demos/trunk/loader/lread.h
0,0 → 1,10
#ifndef __LREAD_H__
#define __LREAD_H__
 
#include "lparser.h"
 
int dos_preload(char *file_name, long max_size, void **start, void **end);
 
int line_reader(void *start, void *end, struct timespec *total, struct loader_task **start_loader_task);
 
#endif