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