Subversion Repositories shark

Rev

Rev 1229 | Rev 1232 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1225 giacomo 1
/* Event Generator
2
 *
3
 * Giacomo Guidi
4
 */
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
 
1228 giacomo 9
#define EVENT_HEADER "event_header.h"
10
#define ACT_LIST "act_list.h"
1225 giacomo 11
 
12
#define ACT_SINGLE 0
13
#define ACT_PERIODIC 1
14
#define ACT_MEAN 2
15
#define ACT_INVALID 3
16
 
1226 giacomo 17
#define EXEC_CONST 0
18
#define EXEC_MEAN 1
19
#define EXEC_INVALID 2
20
 
1227 giacomo 21
int act_number;
22
 
1228 giacomo 23
int write_struct(void)
24
{
25
 
26
  FILE *file_event_header;
27
 
28
  file_event_header = fopen(EVENT_HEADER,"w");
29
  if (file_event_header == NULL) return 1;
30
 
31
  fprintf(file_event_header, "\nstruct loader_task {\n");
32
 
33
  fprintf(file_event_header, "char name[20];\n");
34
 
35
  fprintf(file_event_header, "int number;\n");
36
  fprintf(file_event_header, "int group;\n");
37
  fprintf(file_event_header, "int server;\n");
38
 
1229 giacomo 39
  fprintf(file_event_header, "int local_scheduler;\n");
40
 
1228 giacomo 41
  fprintf(file_event_header, "struct timespec deadline;\n");
42
  fprintf(file_event_header, "struct timespec wcet;\n");
43
 
44
  fprintf(file_event_header, "int act_number;\n");
45
  fprintf(file_event_header, "struct timespec *act;\n");
46
  fprintf(file_event_header, "struct timespec *exec;\n");
47
 
48
  fprintf(file_event_header, "};\n\n");
49
 
1229 giacomo 50
  fprintf(file_event_header, "#define LOADER_POSIX_SCHEDULER 0\n");
51
  fprintf(file_event_header, "#define LOADER_EDF_SCHEDULER 1\n");
52
  fprintf(file_event_header, "#define LOADER_RM_SCHEDULER 2\n");
53
  fprintf(file_event_header, "#define LOADER_MPEGSTAR_SCHEDULER 3\n\n");
54
 
1228 giacomo 55
  fprintf(file_event_header, "#include \"%s\"\n\n",ACT_LIST);
56
 
57
  fprintf(file_event_header, "struct loader_task loader_task_list[] = {\n");
58
 
59
  fclose(file_event_header);
60
 
61
  return 0;
62
 
63
}
64
 
65
int select_basic_par(char *task_name)
66
{
67
 
1229 giacomo 68
  int number,group,server,deadline,wcet,local_scheduler;
1228 giacomo 69
  FILE *file_event_header;
70
 
71
  printf("\nInsert the number of tasks\n");
72
  printf("> ");
73
  scanf("%d",&number);
74
  printf("Insert the group number\n");
75
  printf("> ");
76
  scanf("%d",&group);
77
  printf("Insert the server number\n");
78
  printf("> ");
79
  scanf("%d",&server);
1229 giacomo 80
 
81
  printf("Insert the local scheduler type\n");
82
  printf(" 0 - POSIX\n");
83
  printf(" 1 - EDF\n");
84
  printf(" 2 - RM\n");
85
  printf(" 3 - MPEGSTAR\n");
86
  printf("> ");
87
  scanf("%d",&local_scheduler);
88
 
1228 giacomo 89
  printf("Insert the deadline [us]\n");
90
  printf("> ");
91
  scanf("%d",&deadline);
92
  printf("Insert the wcet [us]\n");
93
  printf("> ");
94
  scanf("%d",&wcet);
95
 
96
  file_event_header = fopen(EVENT_HEADER,"a+");
97
  if (file_event_header == NULL) return 1;
98
 
1230 giacomo 99
  fprintf(file_event_header, "  {\"%s\",%d,%d,%d,%d,{%d,%d},{%d,%d},ACT_NUMBER_%s,act_%s,exec_%s},\n",
1229 giacomo 100
                             task_name,number,group,server,local_scheduler,deadline / 1000000, deadline % 1000000 * 1000,
1230 giacomo 101
                             wcet / 1000000, wcet % 1000000 * 1000, task_name, task_name, task_name);
1228 giacomo 102
 
103
  fclose(file_event_header);
104
 
105
  return 0;  
106
 
107
}
108
 
109
int close_loader()
110
{
111
 
112
  FILE *file_event_header;
113
 
114
  file_event_header = fopen(EVENT_HEADER,"a+");
115
  if (file_event_header == NULL) return 1;
116
 
117
  fprintf(file_event_header,"};\n\n");
118
 
119
  fclose(file_event_header);
120
 
121
  return 0;
122
 
123
}
124
 
1225 giacomo 125
int select_act_type(void)
126
{
127
  char act_type[10];
128
 
129
  printf("\nInsert the activation type\n");
130
  printf(" S - Single\n");
131
  printf(" P - Periodic\n");
132
  printf(" M - Sporadic with constant distribution (Mean,Delta)\n");
133
  printf("> ");
134
  scanf("%s",act_type);
135
 
136
  switch (act_type[0]) {
137
 
138
    case 's':
139
    case 'S':
140
 
141
      return ACT_SINGLE;
142
      break;
143
 
144
    case 'p':
145
    case 'P':
146
 
147
      return ACT_PERIODIC;
148
      break;
149
 
150
    case 'm':
151
    case 'M':
152
 
153
      return ACT_MEAN;
154
      break;
155
 
156
    default:
157
 
158
      return ACT_INVALID;
159
 
160
  }
161
 
162
  return ACT_INVALID;
163
 
164
}
165
 
1226 giacomo 166
int select_exec_type(void)
167
{
168
  char exec_type[10];
169
 
170
  printf("\nInsert the execution time\n");
171
  printf(" C - Const Exec Time\n");
1228 giacomo 172
  printf(" M - Variable with constant distribution (Mean,Delta)\n");
1226 giacomo 173
  printf("> ");
174
  scanf("%s",exec_type);
175
 
176
  switch (exec_type[0]) {
177
 
178
    case 'c':
179
    case 'C':
180
 
181
      return EXEC_CONST;
182
      break;
183
 
184
    case 'm':
185
    case 'M':
186
 
187
      return EXEC_MEAN;
188
      break;
189
 
190
    default:
191
 
192
      return EXEC_INVALID;
193
 
194
  }
195
 
196
  return EXEC_INVALID;
197
 
198
}
199
 
1225 giacomo 200
int write_single_act(char *task_name)
201
{
202
 
203
  FILE *file_act_header;
204
  int time_usec;
205
 
1228 giacomo 206
  file_act_header = fopen(ACT_LIST,"a+");
1225 giacomo 207
  if (file_act_header == NULL) return 1;
208
 
1227 giacomo 209
  act_number = 1;
1230 giacomo 210
  fprintf(file_act_header,"\n#define ACT_NUMBER_%s %d\n\n",task_name,act_number);
1227 giacomo 211
 
1225 giacomo 212
  printf("\nInsert single activation time [us]\n");
213
  printf("> ");
214
  scanf("%d",&time_usec);
215
 
1228 giacomo 216
  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d}};\n\n",task_name,
217
          time_usec/1000000,time_usec%1000000*1000);
1225 giacomo 218
 
219
  fclose(file_act_header);
220
 
221
  return 0;
222
 
223
}
224
 
225
int write_periodic_act(char *task_name)
226
{
227
 
228
  FILE *file_act_header;
1227 giacomo 229
  int i,first_time_usec,per_time_usec;
1225 giacomo 230
  long long tot_time_usec;
1228 giacomo 231
 
232
  file_act_header = fopen(ACT_LIST,"a+");
1225 giacomo 233
  if (file_act_header == NULL) return 1;
234
 
235
  printf("\nInsert the number of activations\n");
236
  printf("> ");
1227 giacomo 237
  scanf("%d",&act_number);                        
1225 giacomo 238
  printf("Insert first activation time [us]\n");
239
  printf("> ");
240
  scanf("%d",&first_time_usec);
241
  printf("Insert periodic activation time [us]\n");
242
  printf("> ");
243
  scanf("%d",&per_time_usec);
1230 giacomo 244
 
245
  fprintf(file_act_header,"\n#define ACT_NUMBER_%s %d\n\n",task_name,act_number);
246
 
1228 giacomo 247
  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",task_name,
248
          first_time_usec/1000000,first_time_usec%1000000*1000);
1225 giacomo 249
 
250
  tot_time_usec = first_time_usec;
1227 giacomo 251
  for (i=0;i<act_number-1;i++) {
1225 giacomo 252
    tot_time_usec += per_time_usec;
1228 giacomo 253
    fprintf(file_act_header,"  {%d,%d},\n",
1227 giacomo 254
            (int)tot_time_usec/1000000,(int)tot_time_usec%1000000*1000);
1225 giacomo 255
  }
256
 
1228 giacomo 257
  fprintf(file_act_header,"  };\n\n");
1225 giacomo 258
 
259
  fclose(file_act_header);
260
 
261
  return 0;
262
 
263
}
264
 
265
int write_mean_act(char *task_name)
266
{
267
 
268
  FILE *file_act_header;
1227 giacomo 269
  int i,first_time_usec,mean_time_usec,delta_time_usec;
1225 giacomo 270
  long long tot_time_usec;
271
 
1228 giacomo 272
  file_act_header = fopen(ACT_LIST,"a+");
1225 giacomo 273
  if (file_act_header == NULL) return 1;
274
 
275
  printf("\nInsert the number of activations\n");
276
  printf("> ");
1227 giacomo 277
  scanf("%d",&act_number);
1225 giacomo 278
  printf("Insert first activation time [us]\n");
279
  printf("> ");
280
  scanf("%d",&first_time_usec);
281
  printf("Insert mean peridic time [us]\n");
282
  printf("> ");
283
  scanf("%d",&mean_time_usec);
284
  printf("Insert delta time [us]\n");
285
  printf("> ");
286
  scanf("%d",&delta_time_usec);
1230 giacomo 287
 
288
  fprintf(file_act_header,"\n#define ACT_NUMBER_%s %d\n\n",task_name,act_number);
1225 giacomo 289
 
1228 giacomo 290
  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",task_name,
291
          first_time_usec/1000000,first_time_usec%1000000*1000);
1225 giacomo 292
 
293
  tot_time_usec = first_time_usec;
1227 giacomo 294
  for (i=0;i<act_number-1;i++) {
1225 giacomo 295
    tot_time_usec += mean_time_usec + random() % delta_time_usec - delta_time_usec/2;
296
    fprintf(file_act_header,"                                    {%d,%d},\n",
1227 giacomo 297
            (int)tot_time_usec/1000000,(int)tot_time_usec%1000000*1000);
1225 giacomo 298
  }
299
 
1228 giacomo 300
  fprintf(file_act_header,"  };\n\n");
1225 giacomo 301
 
302
  fclose(file_act_header);
303
 
304
  return 0;
305
 
306
}
307
 
1226 giacomo 308
int write_exec_const(char *task_name)
309
{
310
 
1227 giacomo 311
  FILE *file_exec_header;
312
  int exec_time_usec,i;
313
 
1228 giacomo 314
  file_exec_header = fopen(ACT_LIST,"a+");
1227 giacomo 315
  if (file_exec_header == NULL) return 1;
316
 
317
  printf("Insert execution time [us]\n");
318
  printf("> ");
319
  scanf("%d",&exec_time_usec);
320
 
1228 giacomo 321
  fprintf(file_exec_header,"struct timespec exec_%s[] =  {{%d,%d},\n",task_name,
322
          exec_time_usec/1000000,exec_time_usec%1000000*1000);
1227 giacomo 323
 
324
  for (i=0; i< act_number-1; i++)  
1228 giacomo 325
    fprintf(file_exec_header,"  {%d,%d},\n",
1227 giacomo 326
          exec_time_usec/1000000,exec_time_usec%1000000*1000);
327
 
1228 giacomo 328
  fprintf(file_exec_header,"  };\n\n");
1227 giacomo 329
 
330
  fclose(file_exec_header);
331
 
1226 giacomo 332
  return 0;
333
 
334
}
335
 
336
int write_exec_mean(char *task_name)
337
{
338
 
1227 giacomo 339
  FILE *file_exec_header;
340
  int exec_time_usec,mean_time_usec,delta_time_usec,i;
341
 
1228 giacomo 342
  file_exec_header = fopen(ACT_LIST,"a+");
1227 giacomo 343
  if (file_exec_header == NULL) return 1;
344
 
345
  printf("Insert mean execution time [us]\n");
346
  printf("> ");
347
  scanf("%d",&mean_time_usec);
348
  printf("Insert delta execution time [us]\n");
349
  printf("> ");
350
  scanf("%d",&delta_time_usec);
351
 
352
  exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
353
 
1228 giacomo 354
  fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",
355
          exec_time_usec/1000000,exec_time_usec%1000000*1000);
1227 giacomo 356
 
357
  for (i=0; i< act_number-1; i++) {
358
    exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
1228 giacomo 359
    fprintf(file_exec_header,"  {%d,%d},\n",
1227 giacomo 360
          exec_time_usec/1000000,exec_time_usec%1000000*1000);
361
  }
362
 
1228 giacomo 363
  fprintf(file_exec_header,"  };\n\n");
1227 giacomo 364
 
365
  fclose(file_exec_header);
366
 
1226 giacomo 367
  return 0;
368
 
369
}
370
 
1225 giacomo 371
int main(void) {
372
 
373
  char task_name[100];
1226 giacomo 374
  char act_type,exec_type;
1225 giacomo 375
  int err;
376
 
377
  printf("\nEvent Generator\n\n");
378
 
379
  srandom(12354132);
380
 
1228 giacomo 381
  write_struct();
382
 
1226 giacomo 383
  while(1) {
1225 giacomo 384
 
1226 giacomo 385
    printf("Insert the task name\n");
386
    printf("Write \"q\" to quit program\n");
387
    printf("> ");
388
    scanf("%s",task_name);
1225 giacomo 389
 
1229 giacomo 390
    if (strlen(task_name) == 1 && task_name[0] == 'q') {
391
      close_loader();
392
      exit(0);
393
    }
1226 giacomo 394
 
1228 giacomo 395
    select_basic_par(task_name);
396
 
1226 giacomo 397
    while((act_type = select_act_type()) == ACT_INVALID) {
398
      printf("Error: Invalid Act Type\n");
399
    }
400
 
401
    switch (act_type) {
402
     case ACT_SINGLE:
403
       err = write_single_act(task_name);
404
        if (err != 0) {
405
          printf("Error writing activation header\n");
406
          exit(1);
407
        }
408
        break;
409
      case ACT_PERIODIC:
410
        err = write_periodic_act(task_name);
411
        if (err != 0) {
412
          printf("Error writing activation header\n");
413
          exit(1);
414
        }
415
        break;
416
      case ACT_MEAN:
417
        err = write_mean_act(task_name);
418
        if (err != 0) {
419
          printf("Error writing activation header\n");
420
          exit(1);
421
        }
422
        break;
423
    }
424
 
425
    while((exec_type = select_exec_type()) == EXEC_INVALID) {
426
      printf("Error: Invalid Exec Type\n");
427
    }
428
 
429
    switch (exec_type) {
430
      case EXEC_CONST:
431
        err = write_exec_const(task_name);
432
        if (err != 0) {
433
          printf("Error writing exec header\n");
434
          exit(1);
435
        }
436
        break;
437
      case EXEC_MEAN:
438
        err = write_exec_mean(task_name);
439
        if (err != 0) {
440
          printf("Error writing exec header\n");
441
          exit(1);
442
        }
443
        break;
444
    }
445
 
1225 giacomo 446
  }
447
 
448
  return 0;
449
 
450
}