Rev 1500 | Rev 1504 | 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 | |||
36 | void Error(int num) { |
||
1495 | giacomo | 37 | printf("Finite-State machine error: %d\n",num); |
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"); |
||
84 | gnuplot_command = popen("gnuplot","w"); |
||
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 | sleep(100); |
||
106 | |||
107 | pclose(gnuplot_command); |
||
108 | |||
109 | exit(0); |
||
110 | |||
111 | } |
||
112 | |||
1499 | giacomo | 113 | return 0; |
114 | |||
115 | } |
||
116 | |||
1501 | giacomo | 117 | int stats_from_execs(int ctx_num, unsigned long long *tot_tsc, |
118 | unsigned long long *min_tsc, |
||
119 | unsigned long long *mean_tsc, |
||
120 | unsigned long long *max_tsc, |
||
121 | unsigned long long *first_tsc, |
||
122 | int *number) { |
||
123 | |||
124 | unsigned long long temp_tsc; |
||
125 | int k,i; |
||
126 | |||
127 | temp_tsc = 0; |
||
128 | *max_tsc = 0; |
||
129 | *mean_tsc = 0; |
||
130 | *min_tsc = 0xFFFFFFFF; |
||
131 | *first_tsc = 0; |
||
132 | k = 0; |
||
133 | for (i=0;i<exec_total;i++) |
||
134 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
135 | if (*first_tsc == 0) *first_tsc = exec_list[i].start - log_start_tsc; |
||
136 | if (exec_list[i].dtsc > *max_tsc) *max_tsc = exec_list[i].dtsc; |
||
137 | if (exec_list[i].dtsc < *min_tsc) *min_tsc = exec_list[i].dtsc; |
||
138 | temp_tsc += exec_list[i].dtsc; |
||
139 | k++; |
||
140 | } |
||
141 | |||
142 | *number = k; |
||
143 | *tot_tsc = temp_tsc; |
||
144 | *mean_tsc = temp_tsc / k; |
||
145 | |||
146 | return 0; |
||
147 | |||
148 | } |
||
149 | |||
150 | int stats_from_jobs(int ctx_num, unsigned long long *tot_tsc, |
||
151 | unsigned long long *min_tsc, |
||
152 | unsigned long long *mean_tsc, |
||
153 | unsigned long long *max_tsc, |
||
154 | unsigned long long *first_tsc, |
||
155 | int *number) { |
||
156 | |||
157 | unsigned long long temp_tsc; |
||
158 | int k,i; |
||
159 | |||
160 | temp_tsc = 0; |
||
161 | *max_tsc = 0; |
||
162 | *mean_tsc = 0; |
||
163 | *min_tsc = 0xFFFFFFFF; |
||
164 | *first_tsc = 0; |
||
165 | k = 0; |
||
166 | for (i=0;i<job_total;i++) |
||
167 | if (job_list[i].ctx == context_list[ctx_num].ctx) { |
||
168 | if (*first_tsc == 0) *first_tsc = job_list[i].start - log_start_tsc; |
||
169 | if (job_list[i].dtsc > *max_tsc) *max_tsc = job_list[i].dtsc; |
||
170 | if (job_list[i].dtsc < *min_tsc) *min_tsc = job_list[i].dtsc; |
||
171 | temp_tsc += job_list[i].dtsc; |
||
172 | k++; |
||
173 | } |
||
174 | |||
175 | *number = k; |
||
176 | *tot_tsc = temp_tsc; |
||
177 | *mean_tsc = temp_tsc / k; |
||
178 | |||
179 | return 0; |
||
180 | |||
181 | } |
||
182 | |||
183 | int arr_stats_from_execs(int ctx_num, unsigned long long *min_tsc, |
||
184 | unsigned long long *mean_tsc, |
||
185 | unsigned long long *max_tsc) { |
||
186 | |||
187 | unsigned long long last_start,temp_tsc,delta_start; |
||
188 | int i,k; |
||
189 | |||
190 | last_start = 0; |
||
191 | temp_tsc = 0; |
||
192 | *max_tsc = 0; |
||
193 | *min_tsc = 0xFFFFFFFF; |
||
194 | k = 0; |
||
195 | for (i=0;i<exec_total;i++) |
||
196 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
197 | if (last_start == 0) { |
||
198 | last_start = exec_list[i].start; |
||
199 | } else { |
||
200 | delta_start = exec_list[i].start - last_start; |
||
201 | if (delta_start > *max_tsc) *max_tsc = delta_start; |
||
202 | if (delta_start < *min_tsc) *min_tsc = delta_start; |
||
203 | temp_tsc += delta_start; |
||
204 | k++; |
||
205 | last_start = exec_list[i].start; |
||
206 | } |
||
207 | } |
||
208 | |||
209 | *mean_tsc = temp_tsc / k; |
||
210 | |||
211 | return 0; |
||
212 | |||
213 | } |
||
214 | |||
215 | int arr_stats_from_jobs(int ctx_num, unsigned long long *min_tsc, |
||
216 | unsigned long long *mean_tsc, |
||
217 | unsigned long long *max_tsc) { |
||
218 | |||
219 | unsigned long long last_start,temp_tsc,delta_start; |
||
220 | int i,k; |
||
221 | |||
222 | last_start = 0; |
||
223 | temp_tsc = 0; |
||
224 | *max_tsc = 0; |
||
225 | *min_tsc = 0xFFFFFFFF; |
||
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 | |||
241 | *mean_tsc = temp_tsc / k; |
||
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 | |||
283 | gnuplot_clear(); |
||
284 | |||
285 | max_limit = max_tsc*1000/clk_per_msec; |
||
286 | |||
287 | for (i=0;i<exec_total;i++) |
||
288 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
289 | h = (exec_list[i].dtsc*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
290 | if (h <= DRAW_NUM) draw_data[h]++; |
||
291 | } |
||
292 | |||
293 | sprintf(tmpstr,"Ctx [%d:%s] Exec C-dist",context_list[ctx_num].ctx,pidstr); |
||
294 | gnuplot_draw(tmpstr,max_limit,0); |
||
295 | |||
296 | return 0; |
||
297 | |||
298 | } |
||
299 | |||
300 | int plot_job_c_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) { |
||
301 | |||
302 | unsigned long long max_limit; |
||
303 | char tmpstr[50]; |
||
304 | int i,h; |
||
305 | |||
306 | gnuplot_clear(); |
||
307 | |||
308 | max_limit = max_tsc*1000/clk_per_msec; |
||
309 | |||
310 | for (i=0;i<job_total;i++) |
||
311 | if (job_list[i].ctx == context_list[ctx_num].ctx) { |
||
312 | h = (job_list[i].dtsc*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
313 | if (h <= DRAW_NUM) draw_data[h]++; |
||
314 | } |
||
315 | |||
316 | sprintf(tmpstr,"Ctx [%d:%s] Job C-dist",context_list[ctx_num].ctx,pidstr); |
||
317 | gnuplot_draw(tmpstr,max_limit,0); |
||
318 | |||
319 | return 0; |
||
320 | |||
321 | } |
||
322 | |||
323 | int plot_exec_arr_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) { |
||
324 | |||
325 | unsigned long long max_limit,last_start,delta_start; |
||
326 | char tmpstr[50]; |
||
327 | int i,h; |
||
328 | |||
329 | gnuplot_clear(); |
||
330 | |||
331 | max_limit = max_tsc*1000/clk_per_msec; |
||
332 | |||
333 | last_start = 0; |
||
334 | for (i=0;i<exec_total;i++) |
||
335 | if (exec_list[i].ctx == context_list[ctx_num].ctx) { |
||
336 | if (last_start == 0) { |
||
337 | last_start = exec_list[i].start; |
||
338 | } else { |
||
339 | delta_start = exec_list[i].start - last_start; |
||
340 | |||
341 | h = (delta_start*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
342 | if (h <= DRAW_NUM) draw_data[h]++; |
||
343 | |||
344 | last_start = exec_list[i].start; |
||
345 | } |
||
346 | } |
||
347 | |||
348 | sprintf(tmpstr,"Ctx [%d:%s] Exec Arr.Delta",context_list[ctx_num].ctx,pidstr); |
||
349 | gnuplot_draw(tmpstr,max_limit,0); |
||
350 | |||
351 | return 0; |
||
352 | |||
353 | } |
||
354 | |||
355 | int plot_job_arr_distrib(int ctx_num, unsigned long long max_tsc, char *pidstr) { |
||
356 | |||
357 | unsigned long long max_limit,last_start,delta_start; |
||
358 | char tmpstr[50]; |
||
359 | int i,h; |
||
360 | |||
361 | gnuplot_clear(); |
||
362 | |||
363 | max_limit = max_tsc*1000/clk_per_msec; |
||
364 | |||
365 | last_start = 0; |
||
366 | for (i=0;i<job_total;i++) |
||
367 | if (job_list[i].ctx == context_list[ctx_num].ctx) { |
||
368 | if (last_start == 0) { |
||
369 | last_start = job_list[i].start; |
||
370 | } else { |
||
371 | delta_start = job_list[i].start - last_start; |
||
372 | |||
373 | h = (delta_start*1000/clk_per_msec) * DRAW_NUM / max_limit; |
||
374 | if (h <= DRAW_NUM) draw_data[h]++; |
||
375 | |||
376 | last_start = job_list[i].start; |
||
377 | } |
||
378 | } |
||
379 | |||
380 | sprintf(tmpstr,"Ctx [%d:%s] Job Arr.Delta",context_list[ctx_num].ctx,pidstr); |
||
381 | gnuplot_draw(tmpstr,max_limit,0); |
||
382 | |||
383 | return 0; |
||
384 | |||
385 | } |
||
386 | |||
1495 | giacomo | 387 | int create_lists(char *filename) { |
388 | |||
1494 | giacomo | 389 | FILE *input_file; |
390 | |||
1495 | giacomo | 391 | int type,par1,par2,k,i,state; |
392 | |||
1494 | giacomo | 393 | int current_context = 0; |
1495 | giacomo | 394 | int current_exec = 0; |
1494 | giacomo | 395 | int current_endcycle = 0; |
396 | |||
1495 | giacomo | 397 | unsigned long long last_tsc, tsc; |
1494 | giacomo | 398 | |
1495 | giacomo | 399 | input_file = fopen(filename,"r"); |
1494 | giacomo | 400 | |
1495 | giacomo | 401 | /* Memory alloc */ |
402 | exec_list = malloc(sizeof(struct ctx_exec) * MAXJOB); |
||
403 | context_list = malloc(sizeof(struct ctx_to_pid) * MAXCONTEXT); |
||
404 | endcycle_list = malloc(sizeof(struct endcycle) * MAXJOB); |
||
1494 | giacomo | 405 | |
1495 | giacomo | 406 | /* Finite-State machine |
407 | * |
||
408 | * FS-Machine states: |
||
1494 | giacomo | 409 | |
410 | |||
411 | 1 - Context running |
||
412 | 2 - Interrupt running |
||
413 | |||
414 | 10 - End |
||
415 | |||
1495 | giacomo | 416 | */ |
1494 | giacomo | 417 | |
418 | for(i=0;i<MAXCONTEXT;i++) { |
||
1495 | giacomo | 419 | context_list[i].ctx = 0; |
420 | context_list[i].pid = PID_NO_DEF; |
||
1494 | giacomo | 421 | } |
422 | |||
423 | /* The start context + interrupt context */ |
||
1495 | giacomo | 424 | context_total = 2; |
1494 | giacomo | 425 | current_context = 0; |
426 | last_tsc = 0; |
||
427 | context_list[0].ctx = 0; |
||
428 | context_list[0].pid = PID_NO_DEF; |
||
429 | context_list[1].ctx = INT_CTX; |
||
430 | context_list[1].pid = INT_PID; |
||
431 | |||
432 | state = 0; |
||
433 | |||
434 | k = 0; |
||
435 | while(!feof(input_file)) { |
||
436 | |||
437 | fscanf(input_file,"%d %llu",&type,&tsc); |
||
438 | k++; |
||
439 | |||
440 | switch (type) { |
||
441 | |||
442 | case 0: |
||
443 | case 1: |
||
444 | |||
445 | /* No par */ |
||
446 | break; |
||
447 | |||
448 | case 2: |
||
449 | case 3: |
||
450 | case 4: |
||
451 | case 6: |
||
452 | case 7: |
||
453 | case 8: |
||
454 | |||
455 | /* 1 par */ |
||
456 | fscanf(input_file,"%d",&par1); |
||
457 | break; |
||
458 | |||
459 | case 5: |
||
460 | /* 2 par */ |
||
461 | fscanf(input_file,"%d %d",&par1,&par2); |
||
462 | break; |
||
463 | |||
464 | } |
||
465 | |||
466 | switch (type) { |
||
467 | |||
468 | case 0: |
||
469 | if (state != 0) Error(1); |
||
470 | printf("EVT:Log starts at [%12llu]\n",tsc); |
||
471 | last_tsc = tsc; |
||
472 | log_start_tsc = tsc; |
||
1495 | giacomo | 473 | exec_list[current_exec].start = tsc; |
1494 | giacomo | 474 | state = 1; |
475 | break; |
||
476 | |||
477 | case 1: |
||
478 | printf("EVT:Log ends at [%12llu]\n",tsc); |
||
1495 | giacomo | 479 | exec_list[current_exec].dtsc = tsc - last_tsc; |
480 | exec_list[current_exec].ctx = current_context; |
||
481 | current_exec++; |
||
1494 | giacomo | 482 | last_tsc = tsc; |
483 | log_end_tsc = tsc; |
||
484 | state = 10; |
||
485 | break; |
||
486 | |||
487 | /* Int start */ |
||
488 | case 2: |
||
489 | if (state == 0) Error(2); |
||
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 | current_context = INT_CTX; |
||
1495 | giacomo | 495 | exec_list[current_exec].start = tsc; |
1494 | giacomo | 496 | state = 2; |
497 | break; |
||
498 | |||
499 | /* Int end */ |
||
500 | case 3: |
||
501 | if (state != 2) Error(3); |
||
1495 | giacomo | 502 | exec_list[current_exec].dtsc = tsc - last_tsc; |
503 | exec_list[current_exec].ctx = current_context; |
||
504 | current_exec++; |
||
1494 | giacomo | 505 | last_tsc = tsc; |
506 | current_context = par1; |
||
507 | |||
1495 | giacomo | 508 | for (i=0;i<context_total;i++) |
1494 | giacomo | 509 | if (par1 == context_list[i].ctx) break; |
1495 | giacomo | 510 | if (i == context_total) { |
511 | context_list[context_total].ctx = par1; |
||
512 | context_total++; |
||
1494 | giacomo | 513 | } |
514 | |||
1495 | giacomo | 515 | exec_list[current_exec].start = tsc; |
1494 | giacomo | 516 | state = 1; |
517 | break; |
||
518 | |||
519 | /* Change ctx */ |
||
520 | case 4: |
||
521 | |||
1495 | giacomo | 522 | exec_list[current_exec].dtsc = tsc - last_tsc; |
523 | exec_list[current_exec].ctx = current_context; |
||
524 | current_exec++; |
||
1494 | giacomo | 525 | last_tsc = tsc; |
526 | current_context = par1; |
||
527 | |||
1495 | giacomo | 528 | for (i=0;i<context_total;i++) |
1494 | giacomo | 529 | if (par1 == context_list[i].ctx) break; |
1495 | giacomo | 530 | if (i == context_total) { |
531 | context_list[context_total].ctx = par1; |
||
532 | context_total++; |
||
1494 | giacomo | 533 | } |
534 | |||
1495 | giacomo | 535 | exec_list[current_exec].start = tsc; |
1494 | giacomo | 536 | state = 1; |
537 | break; |
||
538 | |||
539 | /* Task create */ |
||
540 | case 5: |
||
541 | |||
1495 | giacomo | 542 | for (i=0;i<context_total;i++) |
1494 | giacomo | 543 | if (par1 == context_list[i].ctx) break; |
1495 | giacomo | 544 | if (i == context_total) { |
545 | context_list[context_total].ctx = par1; |
||
546 | context_list[context_total].pid = par2; |
||
547 | context_total++; |
||
1494 | giacomo | 548 | } |
549 | |||
550 | break; |
||
551 | |||
552 | /* Task endcycle */ |
||
553 | case 8: |
||
554 | |||
1495 | giacomo | 555 | for (i=0;i<context_total;i++) |
1494 | giacomo | 556 | if (par1 == context_list[i].ctx) break; |
1495 | giacomo | 557 | if (i == context_total) Error(4); |
1494 | giacomo | 558 | |
559 | endcycle_list[current_endcycle].ctx = par1; |
||
560 | endcycle_list[current_endcycle].tsc = tsc; |
||
561 | current_endcycle++; |
||
562 | |||
563 | break; |
||
564 | |||
565 | } |
||
566 | |||
1495 | giacomo | 567 | if (current_exec == MAXJOB-1) { |
568 | printf("Too many execs...\n"); |
||
1494 | giacomo | 569 | exit(3); |
570 | } |
||
571 | |||
572 | if (current_endcycle == MAXJOB-1) { |
||
573 | printf("Too many endcycle...\n"); |
||
574 | exit(4); |
||
575 | } |
||
576 | |||
577 | if (state == 10) break; |
||
578 | |||
579 | } |
||
580 | |||
1495 | giacomo | 581 | endcycle_total = current_endcycle; |
582 | exec_total = current_exec; |
||
1494 | giacomo | 583 | |
1495 | giacomo | 584 | return k; |
1494 | giacomo | 585 | |
1495 | giacomo | 586 | } |
1494 | giacomo | 587 | |
1495 | giacomo | 588 | int create_job_list() { |
1494 | giacomo | 589 | |
1495 | giacomo | 590 | int current_job = 0, h, i, k; |
591 | int temp_ctx; |
||
592 | unsigned long long temp_tsc, endcycle_start_tsc; |
||
593 | unsigned long long endcycle_end_tsc; |
||
1494 | giacomo | 594 | |
1495 | giacomo | 595 | job_list = malloc(sizeof(struct ctx_exec) * MAXJOB); |
1494 | giacomo | 596 | |
1495 | giacomo | 597 | for (k=0;k<context_total;k++) { |
1494 | giacomo | 598 | |
1495 | giacomo | 599 | temp_ctx = context_list[k].ctx; |
600 | endcycle_start_tsc = 0; |
||
1494 | giacomo | 601 | |
1495 | giacomo | 602 | for (h=0;h<endcycle_total;h++) { |
1494 | giacomo | 603 | |
1495 | giacomo | 604 | if (endcycle_list[h].ctx == temp_ctx) { |
1494 | giacomo | 605 | |
1495 | giacomo | 606 | if (endcycle_start_tsc == 0) |
607 | endcycle_start_tsc = log_start_tsc; |
||
1494 | giacomo | 608 | |
609 | endcycle_end_tsc = endcycle_list[h].tsc; |
||
610 | temp_tsc = 0; |
||
611 | |||
1495 | giacomo | 612 | job_list[current_job].start = 0; |
1494 | giacomo | 613 | |
1495 | giacomo | 614 | for(i=0;i<exec_total;i++) |
615 | if (exec_list[i].ctx == temp_ctx) { |
||
616 | if (exec_list[i].start < endcycle_end_tsc && |
||
617 | exec_list[i].start >= endcycle_start_tsc) { |
||
618 | if (job_list[current_job].start == 0) |
||
619 | job_list[current_job].start = exec_list[i].start; |
||
620 | temp_tsc += exec_list[i].dtsc; |
||
1494 | giacomo | 621 | } |
622 | } |
||
623 | |||
1495 | giacomo | 624 | job_list[current_job].dtsc = temp_tsc; |
625 | job_list[current_job].ctx = temp_ctx; |
||
626 | current_job++; |
||
1494 | giacomo | 627 | |
628 | endcycle_start_tsc = endcycle_end_tsc; |
||
629 | |||
1495 | giacomo | 630 | } |
1494 | giacomo | 631 | |
1495 | giacomo | 632 | } |
1494 | giacomo | 633 | |
1495 | giacomo | 634 | } |
635 | |||
636 | job_total = current_job; |
||
637 | |||
1494 | giacomo | 638 | return 0; |
639 | |||
640 | } |
||
641 | |||
1495 | giacomo | 642 | int elaborate_statistics(int num, int task_type) { |
643 | |||
1501 | giacomo | 644 | char pidstr[10]; |
645 | unsigned long long tot_tsc,mean_tsc,max_tsc,min_tsc,first_tsc; |
||
646 | int number; |
||
1495 | giacomo | 647 | |
648 | switch (context_list[num].pid) { |
||
649 | case PID_NO_DEF: |
||
650 | sprintf(pidstr,"NODEF"); |
||
651 | break; |
||
652 | case INT_PID: |
||
653 | sprintf(pidstr," INT"); |
||
654 | break; |
||
655 | default: |
||
656 | sprintf(pidstr,"%5d",context_list[num].pid); |
||
657 | break; |
||
658 | } |
||
659 | |||
660 | if (task_type == BACKGROUND) { |
||
661 | |||
662 | printf("Background Task CTX [%5d] PID [%s]\n",context_list[num].ctx,pidstr); |
||
663 | |||
1501 | giacomo | 664 | stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number); |
665 | |||
666 | printf(" Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec); |
||
667 | printf(" Mean CPU Bandwidth [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%'); |
||
668 | printf(" after first exec [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%'); |
||
669 | printf(" Execs Number [%12d]\n",number); |
||
1499 | giacomo | 670 | printf(" Min Exec dTSC [%12llu] us [%12llu]\n",min_tsc, min_tsc*1000/clk_per_msec); |
1501 | giacomo | 671 | printf(" Mean Exec dTSC [%12llu] us [%12llu]\n",mean_tsc, mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 672 | printf(" Max Exec dTSC [%12llu] us [%12llu]\n\n",max_tsc, max_tsc*1000/clk_per_msec); |
1495 | giacomo | 673 | |
1501 | giacomo | 674 | plot_exec_demand_function(num,pidstr); |
1500 | giacomo | 675 | |
1495 | giacomo | 676 | } |
677 | |||
678 | if (task_type == INTERRUPT) { |
||
679 | |||
680 | printf("Interrupts\n"); |
||
681 | |||
1501 | giacomo | 682 | stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number); |
1499 | giacomo | 683 | |
1501 | giacomo | 684 | printf(" Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec); |
685 | printf(" Mean CPU Bandwidth [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%'); |
||
686 | printf(" after first int [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%'); |
||
687 | printf(" Interrupts Number [%12d]\n",number); |
||
1499 | giacomo | 688 | printf(" Min Interrupt dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
1501 | giacomo | 689 | printf(" Mean Interrupt dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 690 | printf(" Max Interrupt dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
1495 | giacomo | 691 | |
1501 | giacomo | 692 | plot_exec_c_distrib(num,max_tsc,pidstr); |
1500 | giacomo | 693 | |
1501 | giacomo | 694 | arr_stats_from_execs(num,&min_tsc,&mean_tsc,&max_tsc); |
1499 | giacomo | 695 | |
696 | printf(" Min Arr. Delta dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
||
1501 | giacomo | 697 | printf(" Mean Arr. Delta dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 698 | printf(" Max Arr. Delta dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
1496 | giacomo | 699 | |
1501 | giacomo | 700 | plot_exec_arr_distrib(num,max_tsc,pidstr); |
1499 | giacomo | 701 | |
1495 | giacomo | 702 | } |
703 | |||
704 | if (task_type == PERIODICAL) { |
||
705 | |||
706 | printf("Periodical Task CTX [%5d] PID [%s]\n",context_list[num].ctx,pidstr); |
||
707 | |||
1501 | giacomo | 708 | stats_from_execs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number); |
709 | |||
710 | printf(" Total Execution dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec); |
||
711 | printf(" Mean CPU Bandwidth [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc)*100.0,'%'); |
||
712 | printf(" after first exec [%11f%c]\n",(double)(tot_tsc)/(double)(total_dtsc-first_tsc)*100.0,'%'); |
||
713 | printf(" Execs Number [%12d]\n",number); |
||
1499 | giacomo | 714 | printf(" Min Exec dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
1501 | giacomo | 715 | printf(" Mean Exec dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 716 | printf(" Max Exec dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
1495 | giacomo | 717 | |
1501 | giacomo | 718 | plot_exec_demand_function(num,pidstr); |
1500 | giacomo | 719 | |
1501 | giacomo | 720 | stats_from_jobs(num,&tot_tsc,&min_tsc,&mean_tsc,&max_tsc,&first_tsc,&number); |
721 | |||
722 | printf(" Total Job Exec dTSC [%12llu] us [%12llu]\n",tot_tsc,tot_tsc*1000/clk_per_msec); |
||
723 | printf(" Jobs Number [%12d]\n",number); |
||
1499 | giacomo | 724 | printf(" Min Job dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
1501 | giacomo | 725 | printf(" Mean Job dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 726 | printf(" Max Job dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
1496 | giacomo | 727 | |
1501 | giacomo | 728 | plot_job_c_distrib(num,max_tsc,pidstr); |
1499 | giacomo | 729 | |
1501 | giacomo | 730 | arr_stats_from_jobs(num,&min_tsc,&mean_tsc,&max_tsc); |
1499 | giacomo | 731 | |
1500 | giacomo | 732 | printf(" Min Arr. Delta dTSC [%12llu] us [%12llu]\n",min_tsc,min_tsc*1000/clk_per_msec); |
1501 | giacomo | 733 | printf(" Mean Arr. Delta dTSC [%12llu] us [%12llu]\n",mean_tsc,mean_tsc*1000/clk_per_msec); |
1497 | giacomo | 734 | printf(" Max Arr. Delta dTSC [%12llu] us [%12llu]\n\n",max_tsc,max_tsc*1000/clk_per_msec); |
1495 | giacomo | 735 | |
1501 | giacomo | 736 | plot_job_arr_distrib(num,max_tsc,pidstr); |
1499 | giacomo | 737 | |
1495 | giacomo | 738 | } |
739 | |||
740 | return 0; |
||
741 | |||
742 | } |
||
743 | |||
744 | int main(int argc, char *argv[]) { |
||
745 | |||
746 | int events_total,k,i; |
||
747 | int task_type; |
||
748 | unsigned long long total_tsc; |
||
749 | |||
1500 | giacomo | 750 | srand(getpid()); |
751 | |||
1497 | giacomo | 752 | if (argc < 3) { |
753 | printf("%s: Enter the input file name and clk_per_msec [%s filename clk_per_msec]\n",argv[0],argv[0]); |
||
1495 | giacomo | 754 | exit(1); |
755 | } |
||
756 | |||
757 | printf("\n"); |
||
1497 | giacomo | 758 | |
759 | clk_per_msec = atoi(argv[2]); |
||
760 | |||
761 | printf("Clk/msec = %u\n\n",clk_per_msec); |
||
762 | |||
1495 | giacomo | 763 | events_total = create_lists(argv[1]); |
764 | |||
1499 | giacomo | 765 | total_dtsc = log_end_tsc - log_start_tsc; |
1495 | giacomo | 766 | |
1499 | giacomo | 767 | printf("\nTotal dTSC [%12llu] us [%12llu]\n", total_dtsc, total_dtsc*1000/clk_per_msec); |
768 | printf("Events [%12d]\n",events_total); |
||
769 | printf("Execs [%12d]\n",exec_total); |
||
770 | printf("EndCycles [%12d]\n",endcycle_total); |
||
771 | |||
1495 | giacomo | 772 | total_tsc = 0; |
773 | for (i=0;i<exec_total;i++) |
||
774 | total_tsc += exec_list[i].dtsc; |
||
775 | |||
776 | /* Exec total execution check */ |
||
777 | printf("\nExec TSC sum = %llu (%2.2f)\n",total_tsc,(float)total_tsc/((float)(log_end_tsc - log_start_tsc))*100.0); |
||
778 | |||
779 | printf("\nPreemption Removing.... \n"); |
||
780 | |||
781 | /* Remove preemption from the computation time */ |
||
782 | create_job_list(); |
||
1500 | giacomo | 783 | /* |
1495 | giacomo | 784 | for (k=0;k<job_total;k++) |
785 | printf("Job CTX [%5d] Start [%12llu] dTSC [%12llu]\n", |
||
786 | job_list[k].ctx,job_list[k].start,job_list[k].dtsc); |
||
1500 | giacomo | 787 | */ |
1495 | giacomo | 788 | printf("\nCompute Task Statistics.... \n\n"); |
789 | |||
790 | for (i=0;i<context_total;i++) { |
||
791 | |||
792 | task_type = BACKGROUND; |
||
793 | |||
794 | if (context_list[i].ctx == INT_CTX) task_type = INTERRUPT; |
||
795 | |||
796 | for (k=0;k<job_total;k++) |
||
797 | if (job_list[k].ctx == context_list[i].ctx) { |
||
798 | task_type = PERIODICAL; |
||
799 | break; |
||
800 | } |
||
801 | |||
802 | elaborate_statistics(i,task_type); |
||
803 | |||
804 | } |
||
1500 | giacomo | 805 | |
1495 | giacomo | 806 | return 0; |
807 | |||
808 | } |
||
809 |