Subversion Repositories shark

Rev

Rev 1228 | 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
 
1229 giacomo 99
  fprintf(file_event_header, "  {\"%s\",%d,%d,%d,%d,{%d,%d},{%d,%d},%d,act_%s,exec_%s},\n",
100
                             task_name,number,group,server,local_scheduler,deadline / 1000000, deadline % 1000000 * 1000,
1228 giacomo 101
                             wcet / 1000000, wcet % 1000000 * 1000, act_number, task_name, task_name);
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;
210
 
1225 giacomo 211
  printf("\nInsert single activation time [us]\n");
212
  printf("> ");
213
  scanf("%d",&time_usec);
214
 
1228 giacomo 215
  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d}};\n\n",task_name,
216
          time_usec/1000000,time_usec%1000000*1000);
1225 giacomo 217
 
218
  fclose(file_act_header);
219
 
220
  return 0;
221
 
222
}
223
 
224
int write_periodic_act(char *task_name)
225
{
226
 
227
  FILE *file_act_header;
1227 giacomo 228
  int i,first_time_usec,per_time_usec;
1225 giacomo 229
  long long tot_time_usec;
1228 giacomo 230
 
231
  file_act_header = fopen(ACT_LIST,"a+");
1225 giacomo 232
  if (file_act_header == NULL) return 1;
233
 
234
  printf("\nInsert the number of activations\n");
235
  printf("> ");
1227 giacomo 236
  scanf("%d",&act_number);                        
1225 giacomo 237
  printf("Insert first activation time [us]\n");
238
  printf("> ");
239
  scanf("%d",&first_time_usec);
240
  printf("Insert periodic activation time [us]\n");
241
  printf("> ");
242
  scanf("%d",&per_time_usec);
243
 
1228 giacomo 244
  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",task_name,
245
          first_time_usec/1000000,first_time_usec%1000000*1000);
1225 giacomo 246
 
247
  tot_time_usec = first_time_usec;
1227 giacomo 248
  for (i=0;i<act_number-1;i++) {
1225 giacomo 249
    tot_time_usec += per_time_usec;
1228 giacomo 250
    fprintf(file_act_header,"  {%d,%d},\n",
1227 giacomo 251
            (int)tot_time_usec/1000000,(int)tot_time_usec%1000000*1000);
1225 giacomo 252
  }
253
 
1228 giacomo 254
  fprintf(file_act_header,"  };\n\n");
1225 giacomo 255
 
256
  fclose(file_act_header);
257
 
258
  return 0;
259
 
260
}
261
 
262
int write_mean_act(char *task_name)
263
{
264
 
265
  FILE *file_act_header;
1227 giacomo 266
  int i,first_time_usec,mean_time_usec,delta_time_usec;
1225 giacomo 267
  long long tot_time_usec;
268
 
1228 giacomo 269
  file_act_header = fopen(ACT_LIST,"a+");
1225 giacomo 270
  if (file_act_header == NULL) return 1;
271
 
272
  printf("\nInsert the number of activations\n");
273
  printf("> ");
1227 giacomo 274
  scanf("%d",&act_number);
1225 giacomo 275
  printf("Insert first activation time [us]\n");
276
  printf("> ");
277
  scanf("%d",&first_time_usec);
278
  printf("Insert mean peridic time [us]\n");
279
  printf("> ");
280
  scanf("%d",&mean_time_usec);
281
  printf("Insert delta time [us]\n");
282
  printf("> ");
283
  scanf("%d",&delta_time_usec);
284
 
1228 giacomo 285
  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",task_name,
286
          first_time_usec/1000000,first_time_usec%1000000*1000);
1225 giacomo 287
 
288
  tot_time_usec = first_time_usec;
1227 giacomo 289
  for (i=0;i<act_number-1;i++) {
1225 giacomo 290
    tot_time_usec += mean_time_usec + random() % delta_time_usec - delta_time_usec/2;
291
    fprintf(file_act_header,"                                    {%d,%d},\n",
1227 giacomo 292
            (int)tot_time_usec/1000000,(int)tot_time_usec%1000000*1000);
1225 giacomo 293
  }
294
 
1228 giacomo 295
  fprintf(file_act_header,"  };\n\n");
1225 giacomo 296
 
297
  fclose(file_act_header);
298
 
299
  return 0;
300
 
301
}
302
 
1226 giacomo 303
int write_exec_const(char *task_name)
304
{
305
 
1227 giacomo 306
  FILE *file_exec_header;
307
  int exec_time_usec,i;
308
 
1228 giacomo 309
  file_exec_header = fopen(ACT_LIST,"a+");
1227 giacomo 310
  if (file_exec_header == NULL) return 1;
311
 
312
  printf("Insert execution time [us]\n");
313
  printf("> ");
314
  scanf("%d",&exec_time_usec);
315
 
1228 giacomo 316
  fprintf(file_exec_header,"struct timespec exec_%s[] =  {{%d,%d},\n",task_name,
317
          exec_time_usec/1000000,exec_time_usec%1000000*1000);
1227 giacomo 318
 
319
  for (i=0; i< act_number-1; i++)  
1228 giacomo 320
    fprintf(file_exec_header,"  {%d,%d},\n",
1227 giacomo 321
          exec_time_usec/1000000,exec_time_usec%1000000*1000);
322
 
1228 giacomo 323
  fprintf(file_exec_header,"  };\n\n");
1227 giacomo 324
 
325
  fclose(file_exec_header);
326
 
1226 giacomo 327
  return 0;
328
 
329
}
330
 
331
int write_exec_mean(char *task_name)
332
{
333
 
1227 giacomo 334
  FILE *file_exec_header;
335
  int exec_time_usec,mean_time_usec,delta_time_usec,i;
336
 
1228 giacomo 337
  file_exec_header = fopen(ACT_LIST,"a+");
1227 giacomo 338
  if (file_exec_header == NULL) return 1;
339
 
340
  printf("Insert mean execution time [us]\n");
341
  printf("> ");
342
  scanf("%d",&mean_time_usec);
343
  printf("Insert delta execution time [us]\n");
344
  printf("> ");
345
  scanf("%d",&delta_time_usec);
346
 
347
  exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
348
 
1228 giacomo 349
  fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",
350
          exec_time_usec/1000000,exec_time_usec%1000000*1000);
1227 giacomo 351
 
352
  for (i=0; i< act_number-1; i++) {
353
    exec_time_usec = mean_time_usec + random() % delta_time_usec - delta_time_usec / 2;
1228 giacomo 354
    fprintf(file_exec_header,"  {%d,%d},\n",
1227 giacomo 355
          exec_time_usec/1000000,exec_time_usec%1000000*1000);
356
  }
357
 
1228 giacomo 358
  fprintf(file_exec_header,"  };\n\n");
1227 giacomo 359
 
360
  fclose(file_exec_header);
361
 
1226 giacomo 362
  return 0;
363
 
364
}
365
 
1225 giacomo 366
int main(void) {
367
 
368
  char task_name[100];
1226 giacomo 369
  char act_type,exec_type;
1225 giacomo 370
  int err;
371
 
372
  printf("\nEvent Generator\n\n");
373
 
374
  srandom(12354132);
375
 
1228 giacomo 376
  write_struct();
377
 
1226 giacomo 378
  while(1) {
1225 giacomo 379
 
1226 giacomo 380
    printf("Insert the task name\n");
381
    printf("Write \"q\" to quit program\n");
382
    printf("> ");
383
    scanf("%s",task_name);
1225 giacomo 384
 
1229 giacomo 385
    if (strlen(task_name) == 1 && task_name[0] == 'q') {
386
      close_loader();
387
      exit(0);
388
    }
1226 giacomo 389
 
1228 giacomo 390
    select_basic_par(task_name);
391
 
1226 giacomo 392
    while((act_type = select_act_type()) == ACT_INVALID) {
393
      printf("Error: Invalid Act Type\n");
394
    }
395
 
396
    switch (act_type) {
397
     case ACT_SINGLE:
398
       err = write_single_act(task_name);
399
        if (err != 0) {
400
          printf("Error writing activation header\n");
401
          exit(1);
402
        }
403
        break;
404
      case ACT_PERIODIC:
405
        err = write_periodic_act(task_name);
406
        if (err != 0) {
407
          printf("Error writing activation header\n");
408
          exit(1);
409
        }
410
        break;
411
      case ACT_MEAN:
412
        err = write_mean_act(task_name);
413
        if (err != 0) {
414
          printf("Error writing activation header\n");
415
          exit(1);
416
        }
417
        break;
418
    }
419
 
420
    while((exec_type = select_exec_type()) == EXEC_INVALID) {
421
      printf("Error: Invalid Exec Type\n");
422
    }
423
 
424
    switch (exec_type) {
425
      case EXEC_CONST:
426
        err = write_exec_const(task_name);
427
        if (err != 0) {
428
          printf("Error writing exec header\n");
429
          exit(1);
430
        }
431
        break;
432
      case EXEC_MEAN:
433
        err = write_exec_mean(task_name);
434
        if (err != 0) {
435
          printf("Error writing exec header\n");
436
          exit(1);
437
        }
438
        break;
439
    }
440
 
1225 giacomo 441
  }
442
 
443
  return 0;
444
 
445
}