Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1253 → Rev 1254

/demos/trunk/loader/loadfile/load.fsf
0,0 → 1,74
# CONTRACT SECTION
#
# CONTRACT NUMBER:CMIN:TMAX:CMAX:TMIN:WORKLOAD:LOCAL SCHEDULER
#
# YOU WILL HAVE A SERVER FOR EACH SPECIFIED CONTRACT,
# SO IN THE TASK SECTION YOU CAN SPECIFY THE "CONTRACT NUMBER"
# INSTEAD OF THE SERVER NUMBER, WHICH IS CALCULATED INSIDE THE
# LOADER
#
# ALL THE TIME PARAMETERS INSIDE THIS FILE ARE ALWAYS EXPRESSED AS
# "[SECONDS][MICROSECONDS]" TO AVOID FLOATING POINT CALCULATIONS
#
# WORKLOAD
# 0 BOUNDED
# 1 INDETERMINATED
#
# LOCAL SCHEDULER
# POSIX - DEFAULT FOR THE FRAMEWORK
# EDF
# RM
#
# TASK SECTION
#
# TASK TYPE:CONTRACT 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];
# SIMULATION TOTAL TIME
 
CONTRACT SECTION
 
[0]:[0][3000]:[0][10000]:[0][3000]:[0][10000]:[0]:POSIX;
[1]:[0][6000]:[0][30000]:[0][6000]:[0][30000]:[0]:POSIX;
[2]:[0][3000]:[0][30000]:[0][3000]:[0][30000]:[0]:POSIX;
[3]:[0][6000]:[0][30000]:[0][6000]:[0][30000]:[0]:POSIX;
 
END
 
TASK SECTION
 
BT:[0]:POSIX:[1]:[0][0]:[0][0]:ACT_SINGLE([3][0]):
:EXEC_CONST([0][16000]):NO_CRIT;
 
BT:[1]:POSIX:[1]:[0][0]:[0][0]:ACT_SINGLE([4][0]):
:EXEC_CONST([0][16000]):NO_CRIT;
 
BT:[2]:POSIX:[1]:[0][0]:[0][0]:ACT_SINGLE([5][0]):
:EXEC_CONST([0][16000]):NO_CRIT;
 
BT:[3]:POSIX:[1]:[0][0]:[0][0]:ACT_SINGLE([6][0]):
:EXEC_CONST([0][20000]):NO_CRIT;
 
END
/demos/trunk/loader/common/nload.h
0,0 → 1,37
/* Generic Struct for loader task */
 
#include "lconst.h" //Constant definition for loader and linux parser
 
struct loader_task {
 
char name[20]; //Task name
int task_type; //Tast type (OS,CT,BT)
int contract; //Contract number
int local_scheduler; //Local scheduler for the task
int number; //How many copies of this task
int group; //Group number
struct timespec deadline; //Task deadline
struct timespec wcet; //Task wcet
int act_number; //Number of activations precalcolated
int act_current; //Actual activation number
 
struct timespec *act; //Activation list
struct timespec *exec; //Execution time list
 
};
 
struct loader_contract {
 
int number; //Contract number
struct timespec cmin;
struct timespec tmax;
struct timespec cmax;
struct timespec tmin;
int workload;
int local_scheduler;
int server; //Server number linked to this contract
 
};
 
/demos/trunk/loader/common/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/common/lconst.h
0,0 → 1,36
#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_CONTRACT_SECTION 14
#define PAR_TASK_SECTION 15
 
#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
/demos/trunk/loader/common/calibrate.h
0,0 → 1,8
 
/* Nunber of calibration iterations */
#define CALIBRATING_DELTA 100000
 
/* Usec of exec time for CALIBRATING_DELTA iterations
Set to 0 if you calibrate during loader execution */
#define CALIBRATING_RESULT 0
 
/demos/trunk/loader/common/nload.c
0,0 → 1,212
/* FSF Loader
*
* Load and run a specific set of tasks/contracts
*
* This is the system indipendent part
*
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* Michael Timarchi <trimarchi@gandalf.sssup.it>
*
*/
 
#include "fsf_contract.h" //Framework main header
#include "calibrate.h"
#include "func.h" //Generic function definitions
 
/* Activate task output debug */
#define TASK_OUTPUT
 
int cal_cycles = CALIBRATING_RESULT; //Calibration const, it converts usec to cycles
struct timespec zero_time; //Zero time of the simulation
extern struct loader_task loader_task_list[]; //Loader task array
extern int total_loader_task; //Loader task number
 
/* OS: Oneshot Task:
begin
- execution
end
*/
void *oneshot_task(void *arg)
{
long long i,exec_cycles = 0;
struct loader_task *l = (struct loader_task *)(arg);
char tmp[20];
 
if (l->act_current == 0) l->act_current = 1;
#ifdef TASK_OUTPUT
sprintf(tmp,"[ONESHOT]");
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
 
exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
/* Execution delay */
for (i=0;i<exec_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
return NULL;
}
 
/* CT: Cyclical Task:
begin
while (1) {
- execution
- end_cycle
}
end (never end)
*/
void *periodic_task(void *arg)
{
long long i,exec_cycles = 0;
int act = 0;
struct loader_task *l = (struct loader_task *)(arg);
char tmp[20];
 
if (l->act_current == 0) l->act_current = 1;
 
while(1) {
 
#ifdef TASK_OUTPUT
sprintf(tmp,"C[%06d]",act);
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
/* Execution delay */
for (i=0;i<exec_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
generic_task_endcycle();
act++;
}
return NULL;
}
 
/* BT: Background Task:
begin
while (1) {
- execution
}
end (never end)
*/
void *back_task(void *arg)
{
long long i,exec_cycles = 0;
int act = 0;
struct loader_task *l = (struct loader_task *)(arg);
char tmp[20];
 
if (l->act_current == 0) l->act_current = 1;
 
while(1) {
 
#ifdef TASK_OUTPUT
sprintf(tmp,"B[%06d]",act);
printf_xy((get_current_exec_task() % 5) * 9 + 34,get_current_exec_task() / 5 + 5, GREEN, tmp);
#endif
exec_cycles = (long long)(TIMESPEC2USEC(&l->exec[l->act_current-1])) * CALIBRATION_DELTA / cal_cycles;
/* Execution delay */
for (i=0;i<exec_cycles;i++)
__asm__ __volatile__ ("xorl %%eax,%%eax\n\t"
"cpuid\n\t"
:::"eax","ebx","ecx","edx");
act++;
}
return NULL;
}
 
/* Task create */
/* this function create the task struct in memory */
void loader_task_create()
{
 
struct loader_task *current = loader_task_list;
int i=0, k=0;
 
while (k <total_loader_task) {
k++;
for (i=0; i < current->number; i++) {
pthread_t j;
int err = 0;
switch(current->task_type) {
case PAR_TASK_OS:
 
/* generic_task_create(
server number,
pthread_t of created task (-1 if failed),
pthread_attr_t,
task_body,
arg of the body (must be "(void *)current"),
arg for real-time task specification)
*/
 
err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL,
oneshot_task,(void *)current,generic_get_task_model(current));
break;
case PAR_TASK_BT:
err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL,
back_task,(void *)current,generic_get_task_model(current));
break;
case PAR_TASK_CT:
err = generic_create_thread(generic_get_server_from_contract(current->contract),&j,NULL,
periodic_task,(void *)current,generic_get_task_model(current));
break;
}
if (err) {
printf("Error fsf task creating\n");
generic_end_simulation();
}
}
 
current = &loader_task_list[k];
 
}
printf("Created %d loader tasks\n",k);
 
}
 
/* Main Function */
int start_environment()
{
 
extern struct timespec total_time;
 
/* Calibrate the exec time */
generic_calibrate_cycle();
/* Create the servers usign defined contracts */
generic_fsfinit();
 
/* Create the tasks */
loader_task_create();
 
/* Start the simulation */
generic_start_simulation();
 
/* Set the simulation end time */
generic_set_simulation_time(&total_time);
 
return 0;
 
}
/demos/trunk/loader/shark/func.h
0,0 → 1,22
#ifndef FUNC_H
#define FUNC_H
 
#include "shark.h"
 
#define get_current_exec_task() exec_shadow
#define generic_get_server_from_contract get_server_from_contract
#define generic_create_thread fsf_create_thread
#define generic_calibrate_cycle calibrate_cycle
#define generic_set_next_activation set_next_activation
#define generic_set_simulation_time set_simulation_time
#define generic_get_task_model get_task_model
#define generic_start_simulation start_simulation
#define generic_fsfinit() fsfinit()
#define generic_task_endcycle() task_endcycle()
#define generic_end_simulation() sys_end()
#define printf cprintf
#endif
 
#endif
 
 
/demos/trunk/loader/shark/fsfinit.c
0,0 → 1,48
#include "kernel/kern.h"
#include "fsf_server.h"
#include "fsf_contract.h"
#include "func.h"
 
extern struct loader_contract loader_contract_list[];
extern int total_loader_contract;
 
void fsfinit()
{
 
struct loader_contract *c;
fsf_contract_parameters_t contract;
fsf_server_id_t server;
int i;
long long bw;
 
for (i=0;i<total_loader_contract;i++) {
 
c = &loader_contract_list[i];
 
fsf_initialize_contract(&contract);
 
fsf_set_contract_basic_parameters(&contract,&c->cmin,&c->tmax,&c->cmax,&c->tmin,c->workload);
 
if (c->local_scheduler != PAR_POSIX) {
switch (c->local_scheduler) {
case PAR_EDF:
fsf_set_local_scheduler_parameter(&contract,FSF_SCHEDULER_EDF);
break;
case PAR_RM:
fsf_set_local_scheduler_parameter(&contract,FSF_SCHEDULER_RM);
break;
}
 
}
fsf_negotiate_contract(&contract,&server);
c->server = server;
bw = (long long)(MAX_BANDWIDTH) * TIMESPEC2USEC(&c->cmin) / TIMESPEC2USEC(&c->tmax);
cprintf("FSF CONTRACT %d SERVER %d MIN BW %d.%03d\n", c->number, c->server,
(int)(bw * 100 / MAX_BANDWIDTH),
(int)(bw * 100000 / MAX_BANDWIDTH % 1000));
}
 
}
/demos/trunk/loader/shark/initfile.c
0,0 → 1,98
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Giacomo Guidi <giacomo@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
 
#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/sem.h"
#include "modules/dummy.h"
#include "modules/hartport.h"
 
#include "fsf_contract.h"
#include "fsf_server.h"
 
#include "modules/pi.h"
#include "modules/pc.h"
 
#define TICK 0
 
#define RRTICK 10000
 
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);
dummy_register_level();
CBS_register_level(CBS_ENABLE_ALL,0);
 
SEM_register_module();
 
PI_register_module();
PC_register_module();
 
PTHREAD_register_module(1, 0, 1);
 
return TICK;
 
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
HARTPORT_init();
 
__call_main__(mb);
 
return (void *)0;
}
 
int main() {
 
return start_environment();
}
 
/demos/trunk/loader/shark/shark.c
0,0 → 1,146
#include "func.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;
 
/* Delay Calibration */
int calibrate_cycle()
{
long long i;
struct timespec start,end,diff;
 
if (cal_cycles != 0) return;
 
kern_cli();
kern_gettime(&start);
for (i=0;i<CALIBRATION_DELTA;i++)
__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;
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 &nrt;
 
}
 
if (current->local_scheduler == PAR_EDF) {
static HARD_TASK_MODEL ht;
 
hard_task_default_model(ht);
hard_task_def_ctrl_jet(ht);
hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
hard_task_def_group(ht,current->group);
hard_task_def_usemath(ht);
return &ht;
}
 
 
if (current->local_scheduler == PAR_RM) {
static HARD_TASK_MODEL ht;
hard_task_default_model(ht);
hard_task_def_mit(ht,TIMESPEC2USEC(&current->deadline));
hard_task_def_wcet(ht,TIMESPEC2USEC(&current->wcet));
hard_task_def_ctrl_jet(ht);
hard_task_def_group(ht,current->group);
hard_task_def_usemath(ht);
return &ht;
}
 
return NULL;
}
 
void set_simulation_time (struct timespec *total) {
struct timespec end_time;
ADDTIMESPEC(&zero_time,total,&end_time);
kern_event_post(&end_time,(void *)((void *)(sys_end)),NULL);
 
}
 
int calibration_func() {
return kern_gettime(NULL);
 
}
 
void start_simulation() {
int i;
struct loader_task *l = loader_task_list;
struct timespec end_time;
 
i = 0;
 
kern_gettime(&zero_time);
while (i < total_loader_task) {
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];
 
}
 
}
 
 
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);
 
}
 
}
/demos/trunk/loader/shark/shark.h
0,0 → 1,17
#ifndef SHARK_H
#define SHARK_H
 
#include "kernel/kern.h"
#include "common/nload.h"
 
int calibrate_cycle();
void start_simulation();
void *get_task_model(struct loader_task *current);
void set_simulation_time (struct timespec *total);
void set_next_activation(struct timespec *next);
void loader_task_activate(struct loader_task *l);
int get_server_from_contract(int contract);
 
int fsfinit();
 
#endif
/demos/trunk/loader/generators/lread.c
0,0 → 1,95
#include <stdio.h>
#include <stdlib.h>
#include "lparser.h"
#include "common/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, struct loader_contract **start_loader_contract)
{
char *pbuf = start_file;
int res,line_num,total_loader_task,total_loader_contract;
struct loader_task *current_t = NULL;
struct loader_contract *current_c = NULL;
 
NULL_TIMESPEC(total);
 
line_num = 0;
total_loader_task = 0;
total_loader_contract = 0;
 
while ((void *)(pbuf) < end_file) {
line_num++;
if (*start_loader_contract == NULL)
res = line_parser_contract(&pbuf, line_num, total, &current_c);
else
res = line_parser_contract(&pbuf, line_num, total, &current_c->next);
if (res == 2) {
total_loader_contract++;
if (*start_loader_contract == NULL)
*start_loader_contract = current_c;
else
current_c = current_c->next;
}
 
if (res == 3) break;
 
}
 
while ((void *)(pbuf) < end_file) {
line_num++;
 
if (*start_loader_task == NULL)
res = line_parser_task(&pbuf, line_num, &current_t);
else
res = line_parser_task(&pbuf, line_num, &current_t->next);
 
if (res == 2) {
total_loader_task++;
if (*start_loader_task == NULL)
*start_loader_task = current_t;
else
current_t = current_t->next;
}
 
if (res == 3) break;
 
}
 
printf("Total decoded lines %d\n",line_num);
printf("Total loader contract %d\n",total_loader_contract);
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/generators/lparser.c
0,0 → 1,503
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "lparser.h"
#include "common/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 += 3;
return PAR_END;
}
 
if (!strncmp(*buf,"CONTRACT SECTION",16) && find_type == PAR_NOTHING) {
*buf += 16;
return PAR_CONTRACT_SECTION;
}
 
if (!strncmp(*buf,"TASK SECTION",12) && find_type == PAR_NOTHING) {
*buf += 12;
return PAR_TASK_SECTION;
}
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",3)) {
*buf += 3;
*val = PAR_EDF;
return PAR_FOUND;
}
if (!strncmp(*buf,"RM",2)) {
*buf += 2;
*val = PAR_RM;
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_task(char **pbuf, int line_num, 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_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);
}
 
if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC) {
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_3,&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);
}
 
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_3,&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;
 
}
 
int line_parser_contract(char **pbuf, int line_num, struct timespec *total, struct loader_contract **last)
{
 
struct timespec time;
struct loader_contract *lc = 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_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("CONTRACT [%d]",val);
#endif
 
lc = malloc(sizeof(struct loader_contract));
if (lc == NULL) par_error(line_num);
lc->next = NULL;
*last = lc;
lc->number = 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(&lc->cmin,&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(&lc->tmax,&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(&lc->cmax,&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(&lc->tmin,&time);
} else par_error(line_num);
 
res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf(",[%d]\n",val);
#endif
lc->workload = val;
} else par_error(line_num);
res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val);
if (res == PAR_FOUND) {
#ifdef PARSER_DEBUG
printf("LOCAL SCHEDULER = %d\n",val);
#endif
lc->local_scheduler = val;
} else par_error(line_num);
return 2;
 
}
/demos/trunk/loader/generators/event_gen.c
0,0 → 1,426
/* Event Generator
*
* Giacomo Guidi
*/
 
#include <stdio.h>
#include <stdlib.h>
 
#include "lparser.h"
#include "lread.h"
#include "time.h"
#include "common/time.h"
 
#define LOADFILE_DIR "../loadfile/"
 
#define EVENT_DEFINE "event.c"
#define ACT_LIST "event.c"
 
int write_struct(void)
{
 
FILE *file_event_header;
 
file_event_header = fopen(EVENT_DEFINE,"w");
if (file_event_header == NULL) return 1;
 
fprintf(file_event_header, "\n#include \"func.h\"\n");
 
fclose(file_event_header);
 
return 0;
 
}
 
int write_basic_par_start(void)
{
 
FILE *file_event_header;
file_event_header = fopen(EVENT_DEFINE,"a+");
if (file_event_header == NULL) return 1;
fprintf(file_event_header, "struct loader_task loader_task_list[] = {\n");
 
fclose(file_event_header);
 
return 0;
 
}
 
int write_contract_start(void)
{
FILE *file_event_header;
file_event_header = fopen(EVENT_DEFINE,"a+");
if (file_event_header == NULL) return 1;
fprintf(file_event_header, "struct loader_contract loader_contract_list[] = {\n");
fclose(file_event_header);
return 0;
}
 
int write_basic_par(struct loader_task *c)
{
 
FILE *file_event_header;
 
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,%d},%d,0,act_%s,exec_%s},\n",
c->name,(int)c->task_type,(int)c->server,(int)c->local_scheduler,(int)c->number,(int)c->group,
(int)c->deadline.tv_sec, (int)c->deadline.tv_nsec,
(int)c->wcet.tv_sec, (int)c->wcet.tv_nsec,
(int)c->act_number, c->name, c->name);
 
fclose(file_event_header);
 
return 0;
 
}
 
int write_contract(struct loader_contract *c)
{
FILE *file_event_header;
file_event_header = fopen(EVENT_DEFINE,"a+");
if (file_event_header == NULL) return 1;
fprintf(file_event_header, " {%d,{%d,%d},{%d,%d},{%d,%d},{%d,%d},%d,%d,-1},\n",
(int)c->number,(int)c->cmin.tv_sec,(int)c->cmin.tv_nsec,
(int)c->tmax.tv_sec,(int)c->tmax.tv_nsec,
(int)c->cmax.tv_sec,(int)c->cmax.tv_nsec,
(int)c->tmin.tv_sec,(int)c->tmin.tv_nsec,
(int)c->workload,(int)c->local_scheduler);
 
fclose(file_event_header);
return 0;
}
 
int close_loader_task(int total_task_number)
{
 
FILE *file_event_header;
 
file_event_header = fopen(EVENT_DEFINE,"a+");
if (file_event_header == NULL) return 1;
 
fprintf(file_event_header,"};\n\n");
 
fprintf(file_event_header,"int total_loader_task = %d;\n\n",total_task_number);
 
fclose(file_event_header);
 
return 0;
 
}
 
int close_loader_contract(int total_contract_number)
{
FILE *file_event_header;
file_event_header = fopen(EVENT_DEFINE,"a+");
if (file_event_header == NULL) return 1;
fprintf(file_event_header,"};\n\n");
fprintf(file_event_header,"int total_loader_contract = %d;\n\n",total_contract_number);
fclose(file_event_header);
return 0;
}
 
int write_simulation_time(struct timespec *total)
{
 
FILE *file_event_header;
file_event_header = fopen(EVENT_DEFINE,"a+");
if (file_event_header == NULL) return 1;
fprintf(file_event_header,"struct timespec total_time = {%d,%d};\n\n",(int)total->tv_sec,(int)total->tv_nsec);
fclose(file_event_header);
return 0;
 
 
}
 
int write_single_act(struct timespec *t, struct loader_task *c)
{
 
FILE *file_act_header;
 
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
 
if (TIMESPEC_A_GT_B(t,&c->act_par_1)) {
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d}};\n\n",c->name,
(int)c->act_par_1.tv_sec,(int)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;
}
 
fclose(file_act_header);
 
return 0;
 
}
 
int write_periodic_act(struct timespec *t, struct loader_task *c)
{
 
FILE *file_act_header;
struct timespec tot_time;
int period;
 
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",c->name,
(int)c->act_par_1.tv_sec,(int)c->act_par_1.tv_nsec);
 
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)c->act_par_2.tv_sec,(int)c->act_par_2.tv_nsec);
}
 
fprintf(file_act_header," };\n\n");
fclose(file_act_header);
 
return 0;
 
}
 
int write_mean_act(struct timespec *t,struct loader_task *c)
{
 
FILE *file_act_header;
struct timespec tot_time;
int next_act;
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",c->name,
(int)c->act_par_1.tv_sec,(int)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",
next_act / 1000000, next_act % 1000000 * 1000);
}
fprintf(file_act_header," };\n\n");
fclose(file_act_header);
 
return 0;
}
 
int write_exec_const(struct loader_task *c)
{
 
FILE *file_exec_header;
int i;
file_exec_header = fopen(ACT_LIST,"a+");
if (file_exec_header == NULL) return 1;
fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",c->name,
(int)c->exec_par_1.tv_sec,(int)c->exec_par_1.tv_nsec);
 
for (i=0; i< c->act_number-1; i++)
fprintf(file_exec_header," {%d,%d},\n",
(int)c->exec_par_1.tv_sec,(int)c->exec_par_1.tv_nsec);
 
fprintf(file_exec_header," };\n\n");
fclose(file_exec_header);
 
return 0;
 
}
 
int write_exec_mean(struct loader_task *c)
{
FILE *file_exec_header;
int exec_time_usec;
int i;
file_exec_header = fopen(ACT_LIST,"a+");
if (file_exec_header == NULL) return 1;
exec_time_usec = TIMESPEC2USEC(&c->exec_par_2) + random() % TIMESPEC2USEC(&c->exec_par_3) - TIMESPEC2USEC(&c->exec_par_3) / 2;
fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",c->name,
exec_time_usec / 1000000, exec_time_usec % 1000000 * 1000);
for (i=0; i< c->act_number-1; i++) {
exec_time_usec = TIMESPEC2USEC(&c->exec_par_2) + random() % TIMESPEC2USEC(&c->exec_par_3) - TIMESPEC2USEC(&c->exec_par_3) / 2;
fprintf(file_exec_header," {%d,%d},\n",
exec_time_usec / 1000000, exec_time_usec % 1000000 * 1000);
}
fprintf(file_exec_header," };\n\n");
fclose(file_exec_header);
return 0;
}
 
void *start;
void *end;
 
int main(int argc, char **argv) {
 
char loadfile[100];
struct timespec total_time;
struct loader_task *start_loader_task = NULL, *current_t;
struct loader_contract *start_loader_contract = NULL, *current_c;
int err,ldnum;
int total_task_number;
int total_contract_number;
 
printf("\nEvent Generator\n");
 
if (argc < 2) {
printf("Error: event_gen loadfile.fsf\n");
exit(1);
}
 
printf("Read loader file %s\n",argv[1]);
 
sprintf(loadfile,"%s%s",LOADFILE_DIR,argv[1]);
err = dos_preload(loadfile,100000,&start,&end);
 
if (err != 0) {
printf("Error: File not found\n");
exit(1);
}
 
printf("Parsing file\n");
 
line_reader(start, end, &total_time, &start_loader_task, &start_loader_contract);
 
srandom(time(NULL));
 
write_struct();
 
current_t = start_loader_task;
ldnum = 1;
 
while(current_t != NULL) {
 
sprintf(current_t->name,"ltask%d",ldnum);
current_t->group = ldnum;
ldnum++;
 
switch (current_t->act_type) {
case PAR_ACT_SINGLE:
err = write_single_act(&total_time,current_t);
if (err != 0) {
printf("Error writing activation header\n");
exit(1);
}
break;
case PAR_ACT_PERIODIC:
err = write_periodic_act(&total_time,current_t);
if (err != 0) {
printf("Error writing activation header\n");
exit(1);
}
break;
case PAR_ACT_MEAN:
err = write_mean_act(&total_time,current_t);
if (err != 0) {
printf("Error writing activation header\n");
exit(1);
}
break;
}
 
switch (current_t->exec_type) {
case PAR_EXEC_CONST:
err = write_exec_const(current_t);
if (err != 0) {
printf("Error writing exec header\n");
exit(1);
}
break;
case PAR_EXEC_MEAN:
err = write_exec_mean(current_t);
if (err != 0) {
printf("Error writing exec header\n");
exit(1);
}
break;
}
 
current_t = current_t->next;
 
}
 
write_basic_par_start();
 
total_task_number = 0;
current_t = start_loader_task;
while(current_t != NULL) {
 
write_basic_par(current_t);
 
current_t = current_t->next;
 
total_task_number++;
 
}
 
close_loader_task(total_task_number);
 
write_contract_start();
 
total_contract_number = 0;
current_c = start_loader_contract;
while(current_c != NULL) {
 
write_contract(current_c);
 
current_c = current_c->next;
total_contract_number++;
 
}
 
close_loader_contract(total_contract_number);
 
write_simulation_time(&total_time);
 
return 0;
 
}
/demos/trunk/loader/generators/makefile
0,0 → 1,11
all:
 
gcc -o lparser.o -c -Wall lparser.c -I. -I..
gcc -o lread.o -c -Wall lread.c -I. -I..
gcc -o event_gen -Wall lparser.o lread.o -I. -I.. -lc event_gen.c
 
clean:
 
rm *.o
rm event_gen
 
/demos/trunk/loader/generators/lread.h
0,0 → 1,11
#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, struct loader_contract **start_loader_contract);
 
#endif
/demos/trunk/loader/generators/lparser.h
0,0 → 1,61
#ifndef __LPARSER_H__
#define __LPARSER_H__
 
#include "common/lconst.h"
 
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;
 
};
 
struct loader_contract {
 
int number;
struct timespec cmin;
struct timespec tmax;
struct timespec cmax;
struct timespec tmin;
int workload;
int local_scheduler;
 
struct loader_contract *next;
 
};
 
int line_parser_contract(char **buf, int line_num, struct timespec *total_time, struct loader_contract **last);
 
int line_parser_task(char **buf, int line_num, struct loader_task **last);
 
#endif
 
/demos/trunk/loader/makefile
12,8 → 12,5
include $(BASE)/config/example.mk
 
nload:
make -f $(SUBMAKE) APP=nload INIT= OTHEROBJS="fsfinit.o initfile.o shark.o event.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
make -f $(SUBMAKE) APP="./common/nload" INIT= OTHEROBJS="./shark/initfile.o ./shark/shark.o ./shark/fsfinit.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __FIRST__"