Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1206 → Rev 1205

/demos/trunk/loader/loader.c
9,9 → 9,6
/* Calibration Loops */
#define CALIBRATION_DELTA 1000000
 
/* Mutex number */
#define MAX_MUTEX 10
 
/* Activate task output */
#define TASK_OUTPUT
 
22,8 → 19,6
int cal_rit_calc_mean = 0;
int cal_rit_calc_gauss = 0;
 
mutex_t mux_table[MAX_MUTEX];
 
/* Not Real-Time Task */
TASK nrt_test_task(void *arg)
{
30,9 → 25,6
long long i,exec_cycles = 0;
int exec_1,exec_2,exec_3;
int act_1,act_2,act_3,next_act;
int crit_1 = 0,crit_2 = 0,crit_3 = 0,crit_4 = 0;
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);
39,6 → 31,10
act++;
#ifdef TASK_OUTPUT
cprintf("(Act %d Pid %d Grp %d Lev %d)",act,exec_shadow,l->group,l->task_level);
#endif
 
act_1 = TIMESPEC2USEC(&l->act_par_2);
act_2 = TIMESPEC2USEC(&l->act_par_3);
act_3 = TIMESPEC2USEC(&l->act_par_4);
66,15 → 62,8
exec_2 = TIMESPEC2USEC(&l->exec_par_2);
exec_3 = TIMESPEC2USEC(&l->exec_par_3);
if (l->crit_type == PAR_CRIT) {
crit_1 = TIMESPEC2USEC(&l->crit_par_1);
crit_2 = TIMESPEC2USEC(&l->crit_par_2);
crit_3 = TIMESPEC2USEC(&l->crit_par_3);
crit_4 = TIMESPEC2USEC(&l->crit_par_4);
}
#ifdef TASK_OUTPUT
printf_xy(exec_shadow % 20 + 60, exec_shadow / 20, GREEN, "R");
printf_xy(exec_shadow % 20 + 60, exec_shadow / 20, GREEN, "S");
#endif
if (l->exec_type == PAR_EXEC_CONST)
91,34 → 80,8
if (l->exec_type == PAR_EXEC_GAUSS_MAX)
exec_cycles = 0;
 
if (l->crit_type == PAR_CRIT) {
crit_start = crit_1 + rand() % crit_2 - crit_2/2;
crit_len = crit_3 + rand() % crit_4 - crit_4/2;
crit_start_cycles = (long long)(crit_start) * CALIBRATION_DELTA / cal_cycles;
crit_len_cycles = (long long)(crit_len) * CALIBRATION_DELTA / cal_cycles;
exec_cycles -= crit_start_cycles + crit_len_cycles;
if (exec_cycles < 0) {
cprintf("Error: exec_cycles < 0\n");
sys_end();
}
}
for (i=0;i<exec_cycles;i++);
 
if (l->crit_type == PAR_NO_CRIT)
for (i=0;i<exec_cycles;i++);
else {
for (i=0;i<crit_start_cycles;i++);
#ifdef TASK_OUTPUT
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++);
mutex_unlock(&mux_table[l->resource]);
#ifdef TASK_OUTPUT
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, GREEN,"R");
#endif
for (i=0;i<exec_cycles;i++);
}
 
#ifdef TASK_OUTPUT
printf_xy(exec_shadow % 20 + 60, exec_shadow / 20, WHITE, "E");
#endif
133,9 → 96,6
long long i,exec_cycles = 0;
int exec_1,exec_2,exec_3;
int act_1,act_2,act_3,next_act;
int crit_1 = 0,crit_2 = 0,crit_3 = 0,crit_4 = 0;
int crit_start,crit_len;
long long crit_start_cycles = 0, crit_len_cycles = 0;
struct timespec next_time;
static int act=0;
int extra_rit, k;
143,6 → 103,10
act++;
#ifdef TASK_OUTPUT
cprintf("(Act %d Pid %d Grp %d Lev %d)",act,exec_shadow,l->group,l->task_level);
#endif
 
act_1 = TIMESPEC2USEC(&l->act_par_2);
act_2 = TIMESPEC2USEC(&l->act_par_3);
act_3 = TIMESPEC2USEC(&l->act_par_4);
153,13 → 117,6
 
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);
crit_3 = TIMESPEC2USEC(&l->crit_par_3);
crit_4 = TIMESPEC2USEC(&l->crit_par_4);
}
 
k = 0;
while(1) {
198,36 → 155,10
 
if (l->exec_type == PAR_EXEC_GAUSS_MAX)
exec_cycles = 0;
if (l->crit_type == PAR_CRIT) {
crit_start = crit_1 + rand() % crit_2 - crit_2/2;
crit_len = crit_3 + rand() % crit_4 - crit_4/2;
crit_start_cycles = (long long)(crit_start) * CALIBRATION_DELTA / cal_cycles;
crit_len_cycles = (long long)(crit_len) * CALIBRATION_DELTA / cal_cycles;
exec_cycles -= crit_start_cycles + crit_len_cycles;
if (exec_cycles < 0) {
cprintf("Error: exec_cycles < 0\n");
sys_end();
}
}
extra_rit = 0;
 
if (l->crit_type == PAR_NO_CRIT)
for (i=0;i<exec_cycles;i++);
else {
for (i=0;i<crit_start_cycles;i++);
#ifdef TASK_OUTPUT
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++);
mutex_unlock(&mux_table[l->resource]);
#ifdef TASK_OUTPUT
printf_xy(exec_shadow % 20 + 59, exec_shadow / 20, k,"X");
#endif
for (i=0;i<exec_cycles;i++);
}
for (i=0;i<exec_cycles;i++);
task_endcycle();
291,31 → 222,6
 
}
 
/* Mutex create */
void loader_mutex_create(struct loader_task *start_loader_task)
{
 
struct loader_task *current = start_loader_task;
int res = 0;
PI_mutexattr_t a;
 
PI_mutexattr_default(a);
 
while (current != NULL) {
if (current->crit_type == PAR_CRIT) {
mutex_init(&mux_table[current->resource],&a);
res++;
}
 
current = current->next;
 
}
 
cprintf("Created %d mutex\n",res);
 
}
 
/* Task create */
void loader_task_create(struct loader_task *start_loader_task)
{
472,8 → 378,6
 
calibrate_cycle();
 
loader_mutex_create(start_loader_task);
loader_task_create(start_loader_task);
kern_gettime(&zero_time);
/demos/trunk/loader/loadfile.txt
1,11 → 1,9
# TASK TYPE:TASK LEVEL:NUMBER OF:TASK ACT TYPE (PAR0,PAR1,...)
# :DEADLINE:WCET:TASK EXEC TYPE:CRIT_START (PAR0,PAR1,PAR2):CRIT_LEN (PAR0,PAR1,PAR2);
# TASK TYPE:TASK LEVEL:NUMBER OF:TASK ACT TYPE (PAR0,PAR1,...):DEADLINE:WCET:TASK EXEC TYPE;
#
# TASK TYPE
# NRT - NON REAL TIME
# HARD - HARD REAL TIME
# SOFT - SOFT REAL TIME
# BACK - BACKGROUND TASK
#
# TASK EXEC TYPE
# EXEC_CONST(TIME)
23,17 → 21,9
# ACT_MEAN(START_TIME, MEAN, DELTA)
# ACT_GAUSS(START_TIME, MEAN, SIGMA)
# ACT_GAUSS_MAX(START_TIME, MEAN, SIGMA, MAX)
#
# CRITICAL SESSION
# CRIT(RES NUMBER, MEAN_START, DELTA_START, MEAN_LEN, DELTA_LEN)
# NO_CRIT
#
 
TOTAL_EXEC_TIME:[200][0];
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][2000]):NO_CRIT;
HARD:[0]:[10]:ACT_MEAN([3][0],[1][0],[0][100000]):[0][900000]:[0][10000]:EXEC_MEAN([0][5000],[0][1000]);
HARD:[0]:[10]:ACT_PERIODIC([1][0],[0][300000]):[0][100000]:[0][5000]:EXEC_CONST([0][1000]);
SOFT:[1]:[10]:ACT_PERIODIC([2][0],[0][200000]):[0][200000]:[0][5000]:EXEC_CONST([0][2000]);
 
/demos/trunk/loader/dosread.c
30,8 → 30,9
int line_reader(void *start, void *end, struct timespec *total, struct loader_task **start_loader_task)
{
char line_buf[1000];
char *pbuf = start;
int res,line_num,total_loader_task;
int i,res,line_num,total_loader_task;
struct loader_task *current = NULL;
 
NULL_TIMESPEC(total);
39,13 → 40,19
line_num = 0;
total_loader_task = 0;
while ((void *)(pbuf) < end) {
i = 0;
line_num++;
while ((char)(pbuf[i]) != '\n') {
line_buf[i] = pbuf[i];
i++;
}
pbuf += i+1;
line_buf[i] = 0;
 
if (*start_loader_task == NULL)
res = line_parser(&pbuf, line_num, total, &current);
res = line_parser(line_buf, line_num, total, &current);
else
res = line_parser(&pbuf, line_num, total, &current->next);
res = line_parser(line_buf, line_num, total, &current->next);
 
if (res == 2) {
total_loader_task++;
54,9 → 61,6
else
current = current->next;
}
 
if (res == 3) break;
 
}
 
cprintf("Total decoded lines %d\n",line_num);
/demos/trunk/loader/parser.h
4,17 → 4,15
#include <kernel/kern.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_TIME 2
#define PAR_ACT_TYPE 3
#define PAR_TASK_NUMBER 4
#define PAR_EXEC_TYPE 5
#define PAR_TASK_TYPE 6
#define PAR_NOTHING 8
#define PAR_DEADLINE 9
#define PAR_ERROR 10
#define PAR_FOUND 11
 
#define PAR_EXEC_CONST 12
#define PAR_EXEC_MEAN 13
30,11 → 28,7
#define PAR_TASK_NRT 21
#define PAR_TASK_HARD 22
#define PAR_TASK_SOFT 23
#define PAR_TASK_BACK 24
 
#define PAR_NO_CRIT 25
#define PAR_CRIT 26
 
struct loader_task {
int number;
int group;
52,16 → 46,10
struct timespec act_par_2;
struct timespec act_par_3;
struct timespec act_par_4;
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);
int line_parser(char *buf, int line_num, struct timespec *total, struct loader_task **last);
 
#endif
 
/demos/trunk/loader/parser.c
4,7 → 4,7
#include <stdio.h>
#include "parser.h"
 
#define PARSER_DEBUG
//#define PARSER_DEBUG
 
static int find_break(char **buf, int find_type, struct timespec *time, int *val)
{
13,31 → 13,18
char str[20];
 
i = 0;
while (((char *)(*buf))[i] == ' ' || ((char *)(*buf))[i] == ':' ||
((char *)(*buf))[i] == '\n' || ((char *)(*buf))[i] == '\r') i++;
while (((char *)(*buf))[i] == ' ' || ((char *)(*buf))[i] == ':') 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;
if (((char *)(*buf))[0] == '#' ||
((char *)(*buf))[0] == ';' ||
((char *)(*buf))[0] == 0 ||
((char *)(*buf))[0] == '\n' ||
((char *)(*buf))[0] == '\r') return PAR_FOUND;
break;
 
case PAR_TOTAL_EXEC_TIME:
if (!strncmp(*buf, "TOTAL_EXEC_TIME:",16)) {
159,20 → 146,6
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;
191,22 → 164,21
* 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)
int line_parser(char *buf, int line_num, struct timespec *total, struct loader_task **last)
{
char *pbuf = buf;
struct timespec time;
struct loader_task *ld = NULL;
int val, res;
 
res = find_break(pbuf, PAR_NOTHING, &time, &val);
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);
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);
res = find_break(&pbuf, PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
TIMESPEC_ASSIGN(total,&time);
#ifdef PARSER_DEBUG
216,7 → 188,7
} else par_error(line_num);
}
 
res = find_break(pbuf,PAR_TASK_TYPE, &time, &val);
res = find_break(&pbuf,PAR_TASK_TYPE, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("TASK TYPE = %d\n",val);
232,7 → 204,7
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
res = find_break(&pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("TASK LEVEL = %d\n",val);
242,7 → 214,7
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
res = find_break(&pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("TASK NUMBER = %d\n",val);
252,7 → 224,7
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_ACT_TYPE, &time, &val);
res = find_break(&pbuf,PAR_ACT_TYPE, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("ACTIVATION TYPE: %d (",val);
260,7 → 232,7
 
ld->act_type = val;
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
269,7 → 241,7
} else par_error(line_num);
 
if (ld->act_type != PAR_ACT_SINGLE) {
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
279,7 → 251,7
}
 
if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC) {
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
290,7 → 262,7
 
if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC &&
ld->act_type != PAR_ACT_MEAN && ld->act_type != PAR_ACT_GAUSS) {
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
305,7 → 277,7
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("DEADLINE: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000);
313,7 → 285,7
TIMESPEC_ASSIGN(&ld->deadline,&time);
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000);
321,13 → 293,13
TIMESPEC_ASSIGN(&ld->wcet,&time);
} else par_error(line_num);
 
res = find_break(pbuf,PAR_EXEC_TYPE, &time, &val);
res = find_break(&pbuf,PAR_EXEC_TYPE, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("EXEC TYPE: %d (",val);
#endif
ld->exec_type = val;
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
336,7 → 308,7
} else par_error(line_num);
if (ld->exec_type != PAR_EXEC_CONST) {
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
347,7 → 319,7
if (ld->exec_type != PAR_EXEC_CONST && ld->exec_type != PAR_EXEC_MEAN &&
ld->exec_type != PAR_EXEC_GAUSS) {
res = find_break(pbuf,PAR_TIME, &time, &val);
res = find_break(&pbuf,PAR_TIME, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
362,57 → 334,6
 
} else par_error(line_num);
 
res = find_break(pbuf,PAR_CRIT_SESSION, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
cprintf("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
cprintf("[%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
cprintf(",[%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
cprintf(",[%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
cprintf(",[%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
cprintf(",[%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
cprintf(")\n");
#endif
} else par_error(line_num);
 
return 2;
 
}