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