Subversion Repositories shark

Rev

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