Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1227 → Rev 1228

/demos/trunk/loader/event_gen.h
1,12 → 1,24
/* Event Generator Header
*
* Giacomo Guidi
*/
/* Generic Struct for loader task */
 
/* Posix TimeSpec */
struct new_timespec {
long tv_sec;
long tv_nsec;
struct loader_task {
 
int number;
int group;
int server;
int local_scheduler;
int task_level;
int task_type;
struct timespec deadline;
struct timespec wcet;
struct timespec act;
struct timespec exec;
 
};
 
#define MAX_LOADER_TASK 100
 
struct loader_task loader_task_list[MAX_LOADER_TASK];
 
/demos/trunk/loader/event_gen.c
6,11 → 6,9
#include <stdio.h>
#include <stdlib.h>
 
#include "event_gen.h"
#define EVENT_HEADER "event_header.h"
#define ACT_LIST "act_list.h"
 
#define ACT_HEADER "act_header.h"
#define EXEC_HEADER "exec_header.h"
 
#define ACT_SINGLE 0
#define ACT_PERIODIC 1
#define ACT_MEAN 2
22,6 → 20,92
 
int act_number;
 
int write_struct(void)
{
 
FILE *file_event_header;
 
file_event_header = fopen(EVENT_HEADER,"w");
if (file_event_header == NULL) return 1;
 
fprintf(file_event_header, "\nstruct loader_task {\n");
 
fprintf(file_event_header, "char name[20];\n");
 
fprintf(file_event_header, "int number;\n");
fprintf(file_event_header, "int group;\n");
fprintf(file_event_header, "int server;\n");
fprintf(file_event_header, "struct timespec deadline;\n");
fprintf(file_event_header, "struct timespec wcet;\n");
fprintf(file_event_header, "int act_number;\n");
fprintf(file_event_header, "struct timespec *act;\n");
fprintf(file_event_header, "struct timespec *exec;\n");
 
fprintf(file_event_header, "};\n\n");
 
fprintf(file_event_header, "#include \"%s\"\n\n",ACT_LIST);
 
fprintf(file_event_header, "struct loader_task loader_task_list[] = {\n");
 
fclose(file_event_header);
 
return 0;
 
}
 
int select_basic_par(char *task_name)
{
 
int number,group,server,deadline,wcet;
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 deadline [us]\n");
printf("> ");
scanf("%d",&deadline);
printf("Insert the wcet [us]\n");
printf("> ");
scanf("%d",&wcet);
 
file_event_header = fopen(EVENT_HEADER,"a+");
if (file_event_header == NULL) return 1;
fprintf(file_event_header, " {\"%s\",%d,%d,%d,{%d,%d},{%d,%d},%d,act_%s,exec_%s},\n",
task_name,number,group,server,deadline / 1000000, deadline % 1000000 * 1000,
wcet / 1000000, wcet % 1000000 * 1000, act_number, task_name, task_name);
 
fclose(file_event_header);
 
return 0;
 
}
 
int close_loader()
{
 
FILE *file_event_header;
 
file_event_header = fopen(EVENT_HEADER,"a+");
if (file_event_header == NULL) return 1;
 
fprintf(file_event_header,"};\n\n");
 
fclose(file_event_header);
 
return 0;
 
}
 
int select_act_type(void)
{
char act_type[10];
69,7 → 153,7
printf("\nInsert the execution time\n");
printf(" C - Const Exec Time\n");
printf(" M - Mean with constant distribution (Mean,Delta)\n");
printf(" M - Variable with constant distribution (Mean,Delta)\n");
printf("> ");
scanf("%s",exec_type);
103,7 → 187,7
FILE *file_act_header;
int time_usec;
 
file_act_header = fopen(ACT_HEADER,"a+");
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
 
act_number = 1;
112,8 → 196,8
printf("> ");
scanf("%d",&time_usec);
 
fprintf(file_act_header,"\nstruct timespec %s_act_event[1] = {%d,%d};\n",
task_name,time_usec/1000000,time_usec%1000000*1000);
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);
 
127,8 → 211,8
FILE *file_act_header;
int i,first_time_usec,per_time_usec;
long long tot_time_usec;
file_act_header = fopen(ACT_HEADER,"a+");
 
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
printf("\nInsert the number of activations\n");
141,17 → 225,17
printf("> ");
scanf("%d",&per_time_usec);
fprintf(file_act_header,"\nstruct timespec %s_act_event[%d] = {{%d,%d},\n",
task_name,act_number,first_time_usec/1000000,first_time_usec%1000000*1000);
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 += per_time_usec;
fprintf(file_act_header," {%d,%d},\n",
fprintf(file_act_header," {%d,%d},\n",
(int)tot_time_usec/1000000,(int)tot_time_usec%1000000*1000);
}
 
fprintf(file_act_header,"};\n");
fprintf(file_act_header," };\n\n");
fclose(file_act_header);
 
166,7 → 250,7
int i,first_time_usec,mean_time_usec,delta_time_usec;
long long tot_time_usec;
file_act_header = fopen(ACT_HEADER,"a+");
file_act_header = fopen(ACT_LIST,"a+");
if (file_act_header == NULL) return 1;
printf("\nInsert the number of activations\n");
182,8 → 266,8
printf("> ");
scanf("%d",&delta_time_usec);
fprintf(file_act_header,"\nstruct timespec %s_act_event[%d] = {{%d,%d},\n",
task_name,act_number,first_time_usec/1000000,first_time_usec%1000000*1000);
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++) {
192,7 → 276,7
(int)tot_time_usec/1000000,(int)tot_time_usec%1000000*1000);
}
fprintf(file_act_header,"};\n");
fprintf(file_act_header," };\n\n");
fclose(file_act_header);
 
206,7 → 290,7
FILE *file_exec_header;
int exec_time_usec,i;
file_exec_header = fopen(EXEC_HEADER,"a+");
file_exec_header = fopen(ACT_LIST,"a+");
if (file_exec_header == NULL) return 1;
printf("Insert execution time [us]\n");
213,14 → 297,14
printf("> ");
scanf("%d",&exec_time_usec);
fprintf(file_exec_header,"\nstruct timespec %s_exec_time[%d] = {{%d,%d},\n",
task_name,act_number,exec_time_usec/1000000,exec_time_usec%1000000*1000);
fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",task_name,
exec_time_usec/1000000,exec_time_usec%1000000*1000);
 
for (i=0; i< act_number-1; i++)
fprintf(file_exec_header," {%d,%d},\n",
fprintf(file_exec_header," {%d,%d},\n",
exec_time_usec/1000000,exec_time_usec%1000000*1000);
 
fprintf(file_exec_header,"};\n");
fprintf(file_exec_header," };\n\n");
fclose(file_exec_header);
 
234,7 → 318,7
FILE *file_exec_header;
int exec_time_usec,mean_time_usec,delta_time_usec,i;
file_exec_header = fopen(EXEC_HEADER,"a+");
file_exec_header = fopen(ACT_LIST,"a+");
if (file_exec_header == NULL) return 1;
printf("Insert mean execution time [us]\n");
246,16 → 330,16
 
exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
fprintf(file_exec_header,"\nstruct timespec %s_exec_time[%d] = {{%d,%d},\n",
task_name,act_number,exec_time_usec/1000000,exec_time_usec%1000000*1000);
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;
fprintf(file_exec_header," {%d,%d},\n",
fprintf(file_exec_header," {%d,%d},\n",
exec_time_usec/1000000,exec_time_usec%1000000*1000);
}
fprintf(file_exec_header,"};\n");
fprintf(file_exec_header," };\n\n");
fclose(file_exec_header);
273,6 → 357,8
 
srandom(12354132);
 
write_struct();
 
while(1) {
 
printf("Insert the task name\n");
282,6 → 368,8
 
if (strlen(task_name) == 1 && task_name[0] == 'q') exit(0);
 
select_basic_par(task_name);
 
while((act_type = select_act_type()) == ACT_INVALID) {
printf("Error: Invalid Act Type\n");
}
333,6 → 421,8
 
}
 
close_loader();
 
return 0;
 
}