Rev 1510 | Rev 1517 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1494 | giacomo | 1 | #include <stdio.h> |
2 | #include <stdlib.h> |
||
1499 | giacomo | 3 | #include <math.h> |
4 | #include <unistd.h> |
||
1500 | giacomo | 5 | #include <string.h> |
1494 | giacomo | 6 | |
7 | #define MAXCONTEXT 100 |
||
8 | #define MAXJOB 100000 |
||
9 | |||
10 | #define INT_CTX 1 |
||
11 | #define INT_PID 9999 |
||
12 | #define PID_NO_DEF -1 |
||
13 | |||
1495 | giacomo | 14 | #define BACKGROUND 0 |
15 | #define PERIODICAL 1 |
||
16 | #define INTERRUPT 2 |
||
17 | |||
1499 | giacomo | 18 | #define DRAW_NUM 1000 |
19 | |||
1495 | giacomo | 20 | struct ctx_exec { |
1494 | giacomo | 21 | int ctx; |
22 | unsigned long long dtsc; |
||
23 | unsigned long long start; |
||
24 | }; |
||
25 | |||
1495 | giacomo | 26 | struct ctx_to_pid { |
1494 | giacomo | 27 | int ctx; |
28 | int pid; |
||
29 | }; |
||
30 | |||
1495 | giacomo | 31 | struct endcycle { |
1494 | giacomo | 32 | int ctx; |
33 | unsigned long long tsc; |
||
34 | }; |
||
35 | |||
1510 | giacomo | 36 | void Error(int num, int line) { |
37 | printf("Finite-State machine error %d at line %d\n",num,line); |
||
1494 | giacomo | 38 | exit(2); |
39 | } |
||
40 | |||
1495 | giacomo | 41 | int context_total = 0,endcycle_total = 0,job_total = 0,exec_total = 0; |
42 | struct ctx_exec *exec_list; |
||
43 | struct ctx_to_pid *context_list; |
||
44 | struct endcycle *endcycle_list; |
||
45 | struct ctx_exec *job_list; |
||
1494 | giacomo | 46 | |
1497 | giacomo | 47 | unsigned int clk_per_msec = 0; |
48 | |||
1495 | giacomo | 49 | unsigned long long log_start_tsc = 0; |
50 | unsigned long long log_end_tsc = 0; |
||
1499 | giacomo | 51 | unsigned long long total_dtsc = 0; |
1495 | giacomo | 52 | |
1501 | giacomo | 53 | /* Data for gnuplot external call */ |
1500 | giacomo | 54 | int draw_data[DRAW_NUM+1]; |
1499 | giacomo | 55 | |
56 | int gnuplot_clear() { |
||
57 | |||
58 | int i; |
||
59 | |||
60 | for (i=0;i<DRAW_NUM;i++) |
||
61 | draw_data[i] = 0; |
||
62 | |||
63 | return 0; |
||
64 | |||
65 | } |
||
66 | |||
1500 | giacomo | 67 | int gnuplot_draw(char *title,unsigned long long max_limit,int type) { |
1499 | giacomo | 68 | |
69 | FILE *gnuplot_data, *gnuplot_command; |
||
1500 | giacomo | 70 | char temp_name[30]; |
71 | int i,pid,*current_mem; |
||
1499 | giacomo | 72 | |
1500 | giacomo | 73 | current_mem = malloc(sizeof(int)*(DRAW_NUM+1)); |
74 | memcpy(current_mem,draw_data,sizeof(int)*(DRAW_NUM+1)); |
||
1499 | giacomo | 75 | |
1500 | giacomo | 76 | pid = fork(); |
77 | if (pid == 0) { |
||
1499 | giacomo | 78 | |
1500 | giacomo | 79 | srand(getpid()); |
1499 | giacomo | 80 | |
1500 | giacomo | 81 | sprintf(temp_name,"/tmp/pwcet%d",rand()%10000); |
82 | |||
83 | gnuplot_data = fopen(temp_name,"w"); |
||
1504 | giacomo | 84 | gnuplot_command = popen("gnuplot -persist","w"); |
1500 | giacomo | 85 | |
86 | for (i=0;i<DRAW_NUM;i++) |
||
87 | fprintf(gnuplot_data,"%f\t%f\n",(double)i * (double)max_limit / (double)DRAW_NUM,(float)(current_mem[i])); |
||
88 | |||
89 | fflush(gnuplot_data); |
||
90 | fclose(gnuplot_data); |
||
91 | |||
92 | fprintf(gnuplot_command,"set xlabel \"Time [us]\"\n"); |
||
93 | if (type == 0) { |
||
94 | fprintf(gnuplot_command,"set ylabel \"Frequency [#]\"\n"); |
||
95 | |||
96 | fprintf(gnuplot_command,"plot \"%s\" using 1:2 title \"%s\" with lines\n",temp_name,title); |
||
97 | fflush(gnuplot_command); |
||
98 | } else { |
||
99 | fprintf(gnuplot_command,"set ylabel \"Time [us]\"\n"); |
||
100 | |||
101 | fprintf(gnuplot_command,"plot \"%s\" using 1:2 title \"%s\" with lines\n",temp_name,title); |
||
102 | fflush(gnuplot_command); |
||
103 | } |
||
104 | |||
105 | pclose(gnuplot_command); |
||
106 | |||
107 | exit(0); |
||
108 | |||
109 | } |
||
110 | |||
1499 | giacomo | 111 | return 0; |
112 | |||
113 | } |
||
114 | |||
1501 | giacomo | 115 | int stats_from_execs(int ctx_num, unsigned long long *tot_tsc, |
116 | unsigned long long *min_tsc, |
||
117 | unsigned long long *mean_tsc, |
||
118 | unsigned long long *max_tsc, |
||
119 | unsigned long long *first_tsc, |
||
120 | int *number) { |
||
121 | |||
122 | unsigned long long temp_tsc; |
||
123 | int k,i; |
||
124 | |||
125 | temp_tsc = 0; |
||
126 | *max_tsc = 0; |
||
127 | *mean_tsc = 0; |
||
128 | *min_tsc = 0xFFFFFFFF; |
||
129 | *first_tsc = 0; |
||
130 | k = 0; |
||
131 | for (i=0;i<exec_total;i++) |
||
132 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
133 | if (*first_tsc == 0) *first_tsc = exec_list[i].start - log_start_tsc; |
||
134 | if (exec_list[i].dtsc > *max_tsc) *max_tsc = exec_list[i].dtsc; |
||
135 | if (exec_list[i].dtsc < *min_tsc) *min_tsc = exec_list[i].dtsc; |
||
136 | temp_tsc += exec_list[i].dtsc; |
||
137 | k++; |
||
138 | } |
||
139 | |||
140 | *number = k; |
||
141 | *tot_tsc = temp_tsc; |
||
1505 | giacomo | 142 | if (k != 0) *mean_tsc = temp_tsc / k; |
1501 | giacomo | 143 | |
144 | return 0; |
||
145 | |||
146 | } |
||
147 | |||
148 | int stats_from_jobs(int ctx_num, unsigned long long *tot_tsc, |
||
149 | unsigned long long *min_tsc, |
||
150 | unsigned long long *mean_tsc, |
||
151 | unsigned long long *max_tsc, |
||
152 | unsigned long long *first_tsc, |
||
153 | int *number) { |
||
154 | |||
155 | unsigned long long temp_tsc; |
||
156 | int k,i; |
||
157 | |||
158 | temp_tsc = 0; |
||
159 | *max_tsc = 0; |
||
160 | *mean_tsc = 0; |
||
161 | *min_tsc = 0xFFFFFFFF; |
||
162 | *first_tsc = 0; |
||
163 | k = 0; |
||
164 | for (i=0;i<job_total;i++) |
||
165 | if (job_list[i].ctx == context_list[ctx_num].ctx) { |
||
166 | if (*first_tsc == 0) *first_tsc = job_list[i].start - log_start_tsc; |
||
167 | if (job_list[i].dtsc > *max_tsc) *max_tsc = job_list[i].dtsc; |
||
168 | if (job_list[i].dtsc < *min_tsc) *min_tsc = job_list[i].dtsc; |
||
169 | temp_tsc += job_list[i].dtsc; |
||
170 | k++; |
||
171 | } |
||
172 | |||
173 | *number = k; |
||
174 | *tot_tsc = temp_tsc; |
||
1505 | giacomo | 175 | if (k != 0) *mean_tsc = temp_tsc / k; |
1501 | giacomo | 176 | |
177 | return 0; |
||
178 | |||
179 | } |
||
180 | |||
181 | int arr_stats_from_execs(int ctx_num, unsigned long long *min_tsc, |
||
182 | unsigned long long *mean_tsc, |
||
183 | unsigned long long *max_tsc) { |
||
184 | |||
185 | unsigned long long last_start,temp_tsc,delta_start; |
||
186 | int i,k; |
||
187 | |||
188 | last_start = 0; |
||
189 | temp_tsc = 0; |
||
190 | *max_tsc = 0; |
||
191 | *min_tsc = 0xFFFFFFFF; |
||
1505 | giacomo | 192 | *mean_tsc = 0; |
1501 | giacomo | 193 | k = 0; |
194 | for (i=0;i<exec_total;i++) |
||
195 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
196 | if (last_start == 0) { |
||
197 | last_start = exec_list[i].start; |
||
198 | } else { |
||
199 | delta_start = exec_list[i].start - last_start; |
||
200 | if (delta_start > *max_tsc) *max_tsc = delta_start; |
||
201 | if (delta_start < *min_tsc) *min_tsc = delta_start; |
||
202 | temp_tsc += delta_start; |
||
203 | k++; |
||
204 | last_start = exec_list[i].start; |
||
205 | } |
||
206 | } |
||
207 | |||
1505 | giacomo | 208 | if (k != 0) *mean_tsc = temp_tsc / k; |
1501 | giacomo | 209 | |
210 | return 0; |
||
211 | |||
212 | } |
||
213 | |||
214 | int arr_stats_from_jobs(int ctx_num, unsigned long long *min_tsc, |
||
215 | unsigned long long *mean_tsc, |
||
216 | unsigned long long *max_tsc) { |
||
217 | |||
218 | unsigned long long last_start,temp_tsc,delta_start; |
||
219 | int i,k; |
||
220 | |||
221 | last_start = 0; |
||
222 | temp_tsc = 0; |
||
223 | *max_tsc = 0; |
||
224 | *min_tsc = 0xFFFFFFFF; |
||
1505 | giacomo | 225 | *mean_tsc = 0; |
1501 | giacomo | 226 | k = 0; |
227 | for (i=0;i<job_total;i++) |
||
228 | if (job_list[i].ctx == context_list[ctx_num].ctx) { |
||
229 | if (last_start == 0) { |
||
230 | last_start = job_list[i].start; |
||
231 | } else { |
||
232 | delta_start = job_list[i].start - last_start; |
||
233 | if (delta_start > *max_tsc) *max_tsc = delta_start; |
||
234 | if (delta_start < *min_tsc) *min_tsc = delta_start; |
||
235 | temp_tsc += delta_start; |
||
236 | k++; |
||
237 | last_start = job_list[i].start; |
||
238 | } |
||
239 | } |
||
240 | |||
1505 | giacomo | 241 | if (k != 0) *mean_tsc = temp_tsc / k; |
1501 | giacomo | 242 | |
243 | return 0; |
||
244 | |||
245 | } |
||
246 | |||
247 | int plot_exec_demand_function(int ctx_num, char *pidstr) { |
||
248 | |||
249 | unsigned long long max_limit; |
||
250 | char tmpstr[50]; |
||
251 | int i; |
||
252 | |||
253 | gnuplot_clear(); |
||
254 | |||
255 | max_limit = total_dtsc*1000/clk_per_msec; |
||
256 | |||
257 | for (i=0;i<exec_total;i++) |
||
258 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
259 | int h1,h2,h3; |
||
260 | |||
261 | h1 = ((exec_list[i].start-log_start_tsc)*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
262 | h2 = ((exec_list[i].start+exec_list[i].dtsc-log_start_tsc)*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
263 | for (h3=h1;h3<h2;h3++) |
||
264 | if (h3 <= DRAW_NUM) draw_data[h3] += (exec_list[i].dtsc*1000/clk_per_msec)*(h3-h1)/(h2-h1); |
||
265 | for (h3=h2;h3<=DRAW_NUM;h3++) |
||
266 | if (h3 <= DRAW_NUM) draw_data[h3] += (exec_list[i].dtsc*1000/clk_per_msec); |
||
267 | |||
268 | } |
||
269 | |||
270 | sprintf(tmpstr,"Ctx [%d:%s] Demand-Function",context_list[ctx_num].ctx,pidstr); |
||
271 | gnuplot_draw(tmpstr,max_limit,1); |
||
272 | |||
273 | return 0; |
||
274 | |||
275 | } |
||
276 | |||
277 | int plot_exec_c_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) { |
||
278 | |||
279 | unsigned long long max_limit; |
||
280 | char tmpstr[50]; |
||
281 | int i,h; |
||
282 | |||
1505 | giacomo | 283 | if (max_tsc == 0) return 0; |
284 | |||
1501 | giacomo | 285 | gnuplot_clear(); |
286 | |||
287 | max_limit = max_tsc*1000/clk_per_msec; |
||
288 | |||
289 | for (i=0;i<exec_total;i++) |
||
290 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
291 | h = (exec_list[i].dtsc*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
292 | if (h <= DRAW_NUM) draw_data[h]++; |
||
293 | } |
||
294 | |||
295 | sprintf(tmpstr,"Ctx [%d:%s] Exec C-dist",context_list[ctx_num].ctx,pidstr); |
||
296 | gnuplot_draw(tmpstr,max_limit,0); |
||
297 | |||
298 | return 0; |
||
299 | |||
300 | } |
||
301 | |||
302 | int plot_job_c_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) { |
||
303 | |||
304 | unsigned long long max_limit; |
||
305 | char tmpstr[50]; |
||
306 | int i,h; |
||
307 | |||
1505 | giacomo | 308 | if (max_tsc == 0) return 0; |
309 | |||
1501 | giacomo | 310 | gnuplot_clear(); |
311 | |||
312 | max_limit = max_tsc*1000/clk_per_msec; |
||
313 | |||
314 | for (i=0;i<job_total;i++) |
||
315 | if (job_list[i].ctx == context_list[ctx_num].ctx) { |
||
316 | h = (job_list[i].dtsc*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
317 | if (h <= DRAW_NUM) draw_data[h]++; |
||
318 | } |
||
319 | |||
320 | sprintf(tmpstr,"Ctx [%d:%s] Job C-dist",context_list[ctx_num].ctx,pidstr); |
||
321 | gnuplot_draw(tmpstr,max_limit,0); |
||
322 | |||
323 | return 0; |
||
324 | |||
325 | } |
||
326 | |||
327 | int plot_exec_arr_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) { |
||
328 | |||
329 | unsigned long long max_limit,last_start,delta_start; |
||
330 | char tmpstr[50]; |
||
331 | int i,h; |
||
332 | |||
1505 | giacomo | 333 | if (max_tsc == 0) return 0; |
334 | |||
1501 | giacomo | 335 | gnuplot_clear(); |
336 | |||
337 | max_limit = max_tsc*1000/clk_per_msec; |
||
338 | |||
339 | last_start = 0; |
||
340 | for (i=0;i<exec_total;i++) |
||
341 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
342 | if (last_start == 0) { |
||
343 | last_start = exec_list[i].start; |
||
344 | } else { |
||
345 | delta_start = exec_list[i].start - last_start; |
||
346 | |||
347 | h = (delta_start*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
348 | if (h <= DRAW_NUM) draw_data[h]++; |
||
349 | |||
350 | last_start = exec_list[i].start; |
||
351 | } |
||
352 | } |
||
353 | |||
354 | sprintf(tmpstr,"Ctx [%d:%s] Exec Arr.Delta",context_list[ctx_num].ctx,pidstr); |
||
355 | gnuplot_draw(tmpstr,max_limit,0); |
||
356 | |||
357 | return 0; |
||
358 | |||
359 | } |
||
360 | |||
361 | int plot_job_arr_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) { |
||
362 | |||
363 | unsigned long long max_limit,last_start,delta_start; |
||
364 | char tmpstr[50]; |
||
365 | int i,h; |
||
366 | |||
1505 | giacomo | 367 | if (max_tsc == 0) return 0; |
368 | |||
1501 | giacomo | 369 | gnuplot_clear(); |
370 | |||
371 | max_limit = max_tsc*1000/clk_per_msec; |
||
372 | |||
373 | last_start = 0; |
||
374 | for (i=0;i<job_total;i++) |
||
375 | if (job_list[i].ctx == context_list[ctx_num].ctx) { |
||
376 | if (last_start == 0) { |
||
377 | last_start = job_list[i].start; |
||
378 | } else { |
||
379 | delta_start = job_list[i].start - last_start; |
||
380 | |||
381 | h = (delta_start*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
382 | if (h <= DRAW_NUM) draw_data[h]++; |
||
383 | |||
384 | last_start = job_list[i].start; |
||
385 | } |
||
386 | } |
||
387 | |||
388 | sprintf(tmpstr,"Ctx [%d:%s] Job Arr.Delta",context_list[ctx_num].ctx,pidstr); |
||
389 | gnuplot_draw(tmpstr,max_limit,0); |
||
390 | |||
391 | return 0; |
||
392 | |||
393 | } |
||
394 | |||
1495 | giacomo | 395 | int create_lists(char *filename) { |
396 | |||
1494 | giacomo | 397 | FILE *input_file; |
398 | |||
1495 | giacomo | 399 | int type,par1,par2,k,i,state; |
400 | |||
1494 | giacomo | 401 | int current_context = 0; |
1495 | giacomo | 402 | int current_exec = 0; |
1494 | giacomo | 403 | int current_endcycle = 0; |
404 | |||
1508 | giacomo | 405 | int kill_delta = 0; |
406 | |||
1495 | giacomo | 407 | unsigned long long last_tsc, tsc; |
1494 | giacomo | 408 | |
1495 | giacomo | 409 | input_file = fopen(filename,"r"); |
1494 | giacomo | 410 | |
1495 | giacomo | 411 | /* Memory alloc */ |
412 | exec_list = malloc(sizeof(struct ctx_exec) * MAXJOB); |
||
413 | context_list = malloc(sizeof(struct ctx_to_pid) * MAXCONTEXT); |
||
414 | endcycle_list = malloc(sizeof(struct endcycle) * MAXJOB); |
||
1494 | giacomo | 415 | |
1495 | giacomo | 416 | /* Finite-State machine |
417 | * |
||
418 | * FS-Machine states: |
||
1494 | giacomo | 419 | |
420 | |||
421 | 1 - Context running |
||
422 | 2 - Interrupt running |
||
423 | |||
424 | 10 - End |
||
425 | |||
1495 | giacomo | 426 | */ |
1494 | giacomo | 427 | |
428 | for(i=0;i<MAXCONTEXT;i++) { |
||
1495 | giacomo | 429 | context_list[i].ctx = 0; |
430 | context_list[i].pid = PID_NO_DEF; |
||
1494 | giacomo | 431 | } |
432 | |||
433 | /* The start context + interrupt context */ |
||
1495 | giacomo | 434 | context_total = 2; |
1494 | giacomo | 435 | current_context = 0; |
436 | last_tsc = 0; |
||
437 | context_list[0].ctx = 0; |
||
438 | context_list[0].pid = PID_NO_DEF; |
||
439 | context_list[1].ctx = INT_CTX; |
||
440 | context_list[1].pid = INT_PID; |
||
441 | |||
442 | state = 0; |
||
443 | |||
444 | k = 0; |
||
445 | while(!feof(input_file)) { |
||
446 | |||
447 | fscanf(input_file,"%d %llu",&type,&tsc); |
||
448 | k++; |
||
449 | |||
450 | switch (type) { |
||
451 | |||
452 | case 0: |
||
453 | case 1: |
||
454 | |||
455 | /* No par */ |
||
456 | break; |
||
457 | |||
458 | case 2: |
||
459 | case 3: |
||
460 | case 4: |
||
461 | case 6: |
||
462 | case 7: |
||
463 | case 8: |
||
464 | |||
465 | /* 1 par */ |
||
466 | fscanf(input_file,"%d",&par1); |
||
467 | break; |
||
468 | |||
469 | case 5: |
||
1508 | giacomo | 470 | case 9: |
1494 | giacomo | 471 | /* 2 par */ |
472 | fscanf(input_file,"%d %d",&par1,&par2); |
||
473 | break; |
||
474 | |||
475 | } |
||
476 | |||
477 | switch (type) { |
||
478 | |||
479 | case 0: |
||
1510 | giacomo | 480 | if (state != 0) Error(1,k); |
1494 | giacomo | 481 | printf("EVT:Log starts at [%12llu]\n",tsc); |
482 | last_tsc = tsc; |
||
483 | log_start_tsc = tsc; |
||
1495 | giacomo | 484 | exec_list[current_exec].start = tsc; |
1494 | giacomo | 485 | state = 1; |
486 | break; |
||
487 | |||
488 | case 1: |
||
489 | printf("EVT:Log ends at [%12llu]\n",tsc); |
||
1495 | giacomo | 490 | exec_list[current_exec].dtsc = tsc - last_tsc; |
491 | exec_list[current_exec].ctx = current_context; |
||
492 | current_exec++; |
||
1494 | giacomo | 493 | last_tsc = tsc; |
494 | log_end_tsc = tsc; |
||
495 | state = 10; |
||
496 | break; |
||
497 | |||
498 | /* Int start */ |
||
499 | case 2: |
||
1510 | giacomo | 500 | if (state == 0) Error(2,k); |
1495 | giacomo | 501 | exec_list[current_exec].dtsc = tsc - last_tsc; |
502 | exec_list[current_exec].ctx = current_context; |
||
503 | current_exec++; |
||
1494 | giacomo | 504 | last_tsc = tsc; |
505 | current_context = INT_CTX; |
||
1495 | giacomo | 506 | exec_list[current_exec].start = tsc; |
1494 | giacomo | 507 | state = 2; |
508 | break; |
||
509 | |||
510 | /* Int end */ |
||
511 | case 3: |
||
1510 | giacomo | 512 | if (state != 2) Error(3,k); |
1495 | giacomo | 513 | exec_list[current_exec].dtsc = tsc - last_tsc; |
514 | exec_list[current_exec].ctx = current_context; |
||
515 | current_exec++; |
||
1494 | giacomo | 516 | last_tsc = tsc; |
1511 | giacomo | 517 | if (par1 > 16) { |
518 | current_context = par1; |
||
1494 | giacomo | 519 | |
1511 | giacomo | 520 | for (i=0;i<context_total;i++) |
1494 | giacomo | 521 | if (par1 == context_list[i].ctx) break; |
1511 | giacomo | 522 | if (i == context_total) { |
1495 | giacomo | 523 | context_list[context_total].ctx = par1; |
524 | context_total++; |
||
1511 | giacomo | 525 | } |
1494 | giacomo | 526 | } |
527 | |||
1495 | giacomo | 528 | exec_list[current_exec].start = tsc; |
1494 | giacomo | 529 | state = 1; |
530 | break; |
||
531 | |||
532 | /* Change ctx */ |
||
533 | case 4: |
||
534 | |||
1495 | giacomo | 535 | exec_list[current_exec].dtsc = tsc - last_tsc; |
536 | exec_list[current_exec].ctx = current_context; |
||
537 | current_exec++; |
||
1494 | giacomo | 538 | last_tsc = tsc; |
539 | current_context = par1; |
||
540 | |||
1495 | giacomo | 541 | for (i=0;i<context_total;i++) |
1494 | giacomo | 542 | if (par1 == context_list[i].ctx) break; |
1495 | giacomo | 543 | if (i == context_total) { |
544 | context_list[context_total].ctx = par1; |
||
545 | context_total++; |
||
1494 | giacomo | 546 | } |
547 | |||
1495 | giacomo | 548 | exec_list[current_exec].start = tsc; |
1494 | giacomo | 549 | state = 1; |
550 | break; |
||
551 | |||
552 | /* Task create */ |
||
553 | case 5: |
||
554 | |||
1495 | giacomo | 555 | for (i=0;i<context_total;i++) |
1508 | giacomo | 556 | if (par1 == context_list[i].ctx) { |
557 | context_list[i].pid = par2; |
||
558 | break; |
||
559 | } |
||
1495 | giacomo | 560 | if (i == context_total) { |
561 | context_list[context_total].ctx = par1; |
||
562 | context_list[context_total].pid = par2; |
||
563 | context_total++; |
||
1494 | giacomo | 564 | } |
565 | |||
566 | break; |
||
1508 | giacomo | 567 | |
568 | /* Task kill */ |
||
569 | case 7: |
||
1494 | giacomo | 570 | |
1508 | giacomo | 571 | for (i=0;i<context_total;i++) |
572 | if (par1 == context_list[i].ctx) break; |
||
1510 | giacomo | 573 | if (i == context_total) Error(5,k); |
1508 | giacomo | 574 | else { |
575 | |||
576 | kill_delta += 1000; |
||
577 | |||
578 | for (k=0;k<current_endcycle;k++) |
||
579 | if (endcycle_list[k].ctx == par1) |
||
580 | endcycle_list[k].ctx += kill_delta; |
||
581 | for (k=0;k<current_exec;k++) |
||
582 | if (exec_list[k].ctx == par1) |
||
583 | exec_list[k].ctx += kill_delta; |
||
584 | context_list[context_total].ctx = context_list[i].ctx + kill_delta; |
||
585 | context_list[context_total].pid = context_list[i].pid; |
||
586 | context_total++; |
||
587 | |||
588 | if (current_context == par1) current_context += kill_delta; |
||
589 | |||
590 | } |
||
591 | |||
592 | break; |
||
593 | |||
1494 | giacomo | 594 | /* Task endcycle */ |
595 | case 8: |
||
596 | |||
1495 | giacomo | 597 | for (i=0;i<context_total;i++) |
1494 | giacomo | 598 | if (par1 == context_list[i].ctx) break; |
1510 | giacomo | 599 | if (i == context_total) Error(4,k); |
1494 | giacomo | 600 | |
601 | endcycle_list[current_endcycle].ctx = par1; |
||
602 | endcycle_list[current_endcycle].tsc = tsc; |
||
603 | current_endcycle++; |
||
604 | |||
605 | break; |
||
606 | |||
1508 | giacomo | 607 | /* Task id */ |
608 | case 9: |
||
609 | |||
610 | for (i=0;i<context_total;i++) |
||
611 | if (par1 == context_list[i].ctx) { |
||
612 | context_list[i].pid = par2; |
||
613 | break; |
||
614 | } |
||
615 | if (i == context_total) { |
||
616 | context_list[context_total].ctx = par1; |
||
617 | context_list[context_total].pid = par2; |
||
618 | context_total++; |
||
619 | } |
||
620 | |||
621 | break; |
||
622 | |||
1494 | giacomo | 623 | } |
624 | |||
1495 | giacomo | 625 | if (current_exec == MAXJOB-1) { |
626 | printf("Too many execs...\n"); |
||
1494 | giacomo | 627 | exit(3); |
628 | } |
||
629 | |||
630 | if (current_endcycle == MAXJOB-1) { |
||
631 | printf("Too many endcycle...\n"); |
||
632 | exit(4); |
||
633 | } |
||
634 | |||
635 | if (state == 10) break; |
||
636 | |||
637 | } |
||
638 | |||
1495 | giacomo | 639 | endcycle_total = current_endcycle; |
640 | exec_total = current_exec; |
||
1494 | giacomo | 641 | |
1495 | giacomo | 642 | return k; |
1494 | giacomo | 643 | |
1495 | giacomo | 644 | } |
1494 | giacomo | 645 | |
1495 | giacomo | 646 | int create_job_list() { |
1494 | giacomo | 647 | |
1495 | giacomo | 648 | int current_job = 0, h, i, k; |
649 | int temp_ctx; |
||
650 | unsigned long long temp_tsc, endcycle_start_tsc; |
||
651 | unsigned long long endcycle_end_tsc; |
||
1494 | giacomo | 652 | |
1495 | giacomo | 653 | job_list = malloc(sizeof(struct ctx_exec) * MAXJOB); |
1494 | giacomo | 654 | |
1495 | giacomo | 655 | for (k=0;k<context_total;k++) { |
1494 | giacomo | 656 | |
1495 | giacomo | 657 | temp_ctx = context_list[k].ctx; |
658 | endcycle_start_tsc = 0; |
||
1494 | giacomo | 659 | |
1495 | giacomo | 660 | for (h=0;h<endcycle_total;h++) { |
1494 | giacomo | 661 | |
1495 | giacomo | 662 | if (endcycle_list[h].ctx == temp_ctx) { |
1494 | giacomo | 663 | |
1495 | giacomo | 664 | if (endcycle_start_tsc == 0) |
665 | endcycle_start_tsc = log_start_tsc; |
||
1494 | giacomo | 666 | |
667 | endcycle_end_tsc = endcycle_list[h].tsc; |
||
668 | temp_tsc = 0; |
||
669 | |||
1495 | giacomo | 670 | job_list[current_job].start = 0; |
1494 | giacomo | 671 | |
1495 | giacomo | 672 | for(i=0;i<exec_total;i++) |
673 | if (exec_list[i].ctx == temp_ctx) { |
||
674 | if (exec_list[i].start < endcycle_end_tsc && |
||
675 | exec_list[i].start >= endcycle_start_tsc) { |
||
676 | if (job_list[current_job].start == 0) |
||
677 | job_list[current_job].start = exec_list[i].start; |
||
678 | temp_tsc += exec_list[i].dtsc; |
||
1494 | giacomo | 679 | } |
680 | } |
||
681 | |||
1495 | giacomo | 682 | job_list[current_job].dtsc = temp_tsc; |
683 | job_list[current_job].ctx = temp_ctx; |
||
684 | current_job++; |
||
1494 | giacomo | 685 | |
686 | endcycle_start_tsc = endcycle_end_tsc; |
||
687 | |||
1495 | giacomo | 688 | } |
1494 | giacomo | 689 | |
1495 | giacomo | 690 | } |
1494 | giacomo | 691 | |
1495 | giacomo | 692 | } |
693 | |||
694 | job_total = current_job; |
||
695 | |||
1494 | giacomo | 696 | return 0; |
697 | |||
698 | } |
||
699 | |||
1495 | giacomo | 700 | int elaborate_statistics(int num, int task_type) { |
701 | |||
1501 | giacomo | 702 | char pidstr[10]; |
703 | unsigned long long tot_tsc,mean_tsc,max_tsc,min_tsc,first_tsc; |
||
704 | int number; |
||
1495 | giacomo | 705 | |
706 | switch (context_list[num].pid) { |
||
707 | case PID_NO_DEF: |
||
708 | sprintf(pidstr,"NODEF"); |
||
709 | break; |
||
710 | case INT_PID: |
||
711 | sprintf(pidstr," INT"); |
||
712 | break; |
||
713 | default: |
||
714 | sprintf(pidstr,"%5d",context_list[num].pid); |
||
715 | break; |
||
716 | } |
||
717 | |||
718 | if (task_type == BACKGROUND) { |
||
719 | |||
720 | printf("Background Task CTX [%5d] PID [%s]\n",context_list[num].ctx,pidstr); |
||
721 | |||
1501 | giacomo | 722 | stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number); |
723 | |||
724 | printf(" Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec); |
||
725 | printf(" Mean CPU Bandwidth [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%'); |
||
726 | printf(" after first exec [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%'); |
||
727 | printf(" Execs Number [%12d]\n",number); |
||
1499 | giacomo | 728 | printf(" Min Exec dTSC [%12llu] us [%12llu]\n",min_tsc, min_tsc*1000/clk_per_msec); |
1501 | giacomo | 729 | printf(" Mean Exec dTSC [%12llu] us [%12llu]\n",mean_tsc, mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 730 | printf(" Max Exec dTSC [%12llu] us [%12llu]\n\n",max_tsc, max_tsc*1000/clk_per_msec); |
1495 | giacomo | 731 | |
1501 | giacomo | 732 | plot_exec_demand_function(num,pidstr); |
1500 | giacomo | 733 | |
1495 | giacomo | 734 | } |
735 | |||
736 | if (task_type == INTERRUPT) { |
||
737 | |||
738 | printf("Interrupts\n"); |
||
739 | |||
1501 | giacomo | 740 | stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number); |
1499 | giacomo | 741 | |
1501 | giacomo | 742 | printf(" Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec); |
743 | printf(" Mean CPU Bandwidth [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%'); |
||
744 | printf(" after first int [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%'); |
||
745 | printf(" Interrupts Number [%12d]\n",number); |
||
1499 | giacomo | 746 | printf(" Min Interrupt dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
1501 | giacomo | 747 | printf(" Mean Interrupt dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 748 | printf(" Max Interrupt dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
1495 | giacomo | 749 | |
1501 | giacomo | 750 | plot_exec_c_distrib(num,max_tsc,pidstr); |
1500 | giacomo | 751 | |
1501 | giacomo | 752 | arr_stats_from_execs(num,&min_tsc,&mean_tsc,&max_tsc); |
1499 | giacomo | 753 | |
1505 | giacomo | 754 | if (max_tsc > 0) { |
1496 | giacomo | 755 | |
1505 | giacomo | 756 | printf(" Min Arr. Delta dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
757 | printf(" Mean Arr. Delta dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
||
758 | printf(" Max Arr. Delta dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
||
1499 | giacomo | 759 | |
1505 | giacomo | 760 | plot_exec_arr_distrib(num,max_tsc,pidstr); |
761 | |||
762 | } |
||
763 | |||
1495 | giacomo | 764 | } |
765 | |||
766 | if (task_type == PERIODICAL) { |
||
767 | |||
768 | printf("Periodical Task CTX [%5d] PID [%s]\n",context_list[num].ctx,pidstr); |
||
769 | |||
1501 | giacomo | 770 | stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number); |
771 | |||
772 | printf(" Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec); |
||
773 | printf(" Mean CPU Bandwidth [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%'); |
||
774 | printf(" after first exec [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%'); |
||
775 | printf(" Execs Number [%12d]\n",number); |
||
1499 | giacomo | 776 | printf(" Min Exec dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
1501 | giacomo | 777 | printf(" Mean Exec dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 778 | printf(" Max Exec dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
1495 | giacomo | 779 | |
1501 | giacomo | 780 | plot_exec_demand_function(num,pidstr); |
1500 | giacomo | 781 | |
1501 | giacomo | 782 | stats_from_jobs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number); |
783 | |||
784 | printf(" Total Job Exec dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec); |
||
785 | printf(" Jobs Number [%12d]\n",number); |
||
1499 | giacomo | 786 | printf(" Min Job dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
1501 | giacomo | 787 | printf(" Mean Job dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 788 | printf(" Max Job dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
1496 | giacomo | 789 | |
1501 | giacomo | 790 | plot_job_c_distrib(num,max_tsc,pidstr); |
1499 | giacomo | 791 | |
1501 | giacomo | 792 | arr_stats_from_jobs(num,&min_tsc,&mean_tsc,&max_tsc); |
1499 | giacomo | 793 | |
1505 | giacomo | 794 | if (max_tsc > 0) { |
795 | |||
796 | printf(" Min Arr. Delta dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
||
797 | printf(" Mean Arr. Delta dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
||
798 | printf(" Max Arr. Delta dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
||
1495 | giacomo | 799 | |
1505 | giacomo | 800 | plot_job_arr_distrib(num,max_tsc,pidstr); |
1499 | giacomo | 801 | |
1505 | giacomo | 802 | } |
803 | |||
1495 | giacomo | 804 | } |
805 | |||
806 | return 0; |
||
807 | |||
808 | } |
||
809 | |||
810 | int main(int argc, char *argv[]) { |
||
811 | |||
812 | int events_total,k,i; |
||
813 | int task_type; |
||
814 | unsigned long long total_tsc; |
||
815 | |||
1500 | giacomo | 816 | srand(getpid()); |
817 | |||
1497 | giacomo | 818 | if (argc < 3) { |
819 | printf("%s: Enter the input file name and clk_per_msec [%s filename clk_per_msec]\n",argv[0],argv[0]); |
||
1495 | giacomo | 820 | exit(1); |
821 | } |
||
822 | |||
823 | printf("\n"); |
||
1497 | giacomo | 824 | |
825 | clk_per_msec = atoi(argv[2]); |
||
826 | |||
827 | printf("Clk/msec = %u\n\n",clk_per_msec); |
||
828 | |||
1495 | giacomo | 829 | events_total = create_lists(argv[1]); |
830 | |||
1499 | giacomo | 831 | total_dtsc = log_end_tsc - log_start_tsc; |
1495 | giacomo | 832 | |
1499 | giacomo | 833 | printf("\nTotal dTSC [%12llu] us [%12llu]\n", total_dtsc, total_dtsc*1000/clk_per_msec); |
834 | printf("Events [%12d]\n",events_total); |
||
835 | printf("Execs [%12d]\n",exec_total); |
||
836 | printf("EndCycles [%12d]\n",endcycle_total); |
||
837 | |||
1495 | giacomo | 838 | total_tsc = 0; |
839 | for (i=0;i<exec_total;i++) |
||
840 | total_tsc += exec_list[i].dtsc; |
||
841 | |||
842 | /* Exec total execution check */ |
||
843 | printf("\nExec TSC sum = %llu (%2.2f)\n",total_tsc,(float)total_tsc/((float)(log_end_tsc - log_start_tsc))*100.0); |
||
844 | |||
845 | printf("\nPreemption Removing.... \n"); |
||
846 | |||
847 | /* Remove preemption from the computation time */ |
||
848 | create_job_list(); |
||
1500 | giacomo | 849 | /* |
1495 | giacomo | 850 | for (k=0;k<job_total;k++) |
851 | printf("Job CTX [%5d] Start [%12llu] dTSC [%12llu]\n", |
||
852 | job_list[k].ctx,job_list[k].start,job_list[k].dtsc); |
||
1500 | giacomo | 853 | */ |
1495 | giacomo | 854 | printf("\nCompute Task Statistics.... \n\n"); |
855 | |||
856 | for (i=0;i<context_total;i++) { |
||
857 | |||
858 | task_type = BACKGROUND; |
||
859 | |||
860 | if (context_list[i].ctx == INT_CTX) task_type = INTERRUPT; |
||
861 | |||
862 | for (k=0;k<job_total;k++) |
||
863 | if (job_list[k].ctx == context_list[i].ctx) { |
||
864 | task_type = PERIODICAL; |
||
865 | break; |
||
866 | } |
||
867 | |||
868 | elaborate_statistics(i,task_type); |
||
869 | |||
870 | } |
||
1500 | giacomo | 871 | |
1495 | giacomo | 872 | return 0; |
873 | |||
874 | } |
||
875 |