Subversion Repositories shark

Rev

Rev 1302 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1301 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *    Giacomo Guidi      <giacomo@gandalf.sssup.it>
10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
#include <stdio.h>
19
#include <unistd.h>
20
#include <stdlib.h>
21
#include <string.h>
22
 
23
#define READ_BUFFER 2000
24
#define DELTA_BUFFER 100
25
 
26
struct event_type {
27
  int type;
28
  unsigned long long tsc;
29
  int par[10];
30
};
31
 
32
struct ctx_time_type {
33
  int ctx;
34
  unsigned long long start_time;
35
  unsigned long long total_time;
36
};
37
 
38
struct ctx_time_type ctx_time[256];
1302 giacomo 39
struct ctx_time_type int_time;
1301 giacomo 40
unsigned long long last_time;
41
int total_ctx = 0;
42
int last_ctx = -1;
43
 
44
void analyze_event(struct event_type *e) {
45
 
46
  int i;
47
 
1302 giacomo 48
  // Start interrupt
49
  if (e->type == 0x2b || e->type == 0x03) {
50
 
51
    if (int_time.start_time == 0) int_time.start_time = e->tsc;
52
 
53
    if (last_ctx != -1) {
1301 giacomo 54
 
1302 giacomo 55
      if (e->tsc < last_time) {
56
        printf("Error events sequence\n");
57
        exit(2);
58
      }
59
 
60
      ctx_time[last_ctx].total_time += (e->tsc - last_time);
61
      last_time = e->tsc;
62
 
63
    } else {
64
 
65
      last_time = e->tsc;
66
 
67
    }
68
 
69
  }
70
 
71
  //End Interrupt
72
  if (e->type == 0x3b || e->type == 0x13) {
73
 
74
    if (int_time.start_time == 0) int_time.start_time = e->tsc;
75
 
76
    if (last_time != 0) {
77
 
78
      if (e->tsc < last_time) {
79
        printf("Error events sequence\n");
80
        exit(2);
81
      }
82
 
83
      int_time.total_time += (e->tsc - last_time);
84
      last_time = e->tsc;
85
 
86
    } else {
87
 
88
      last_time = e->tsc;
89
 
90
    }
91
 
1301 giacomo 92
    i = 0;
93
    while (ctx_time[i].ctx != e->par[0] && i < total_ctx) {
94
      i++;
95
    }
96
 
97
    if (ctx_time[i].start_time == 0) {
1302 giacomo 98
      ctx_time[i].start_time = e->tsc;
99
      ctx_time[i].total_time = 0;
1301 giacomo 100
      ctx_time[i].ctx = e->par[0];
1302 giacomo 101
      last_ctx = i;
102
      total_ctx++;
103
    } else {
104
      last_ctx = i;
105
    }
106
 
107
  }
108
 
1304 giacomo 109
  if (e->type == 0x25) {
110
    printf("Inheritance S %d E %d A %d\n",e->par[0],e->par[1],e->par[2]);
111
  }
112
 
1302 giacomo 113
  //Context Switch
114
  if (e->type == 0x15) {
115
 
116
    i = 0;
117
    while (ctx_time[i].ctx != e->par[0] && i < total_ctx) {
118
      i++;
119
    }
120
 
121
    if (ctx_time[i].start_time == 0) {
122
      ctx_time[i].ctx = e->par[0];
1301 giacomo 123
      ctx_time[i].start_time = e->tsc;
124
      ctx_time[i].total_time = 0;
125
 
126
      if (e->tsc < last_time) {
127
        printf("Error events sequence\n");
128
        exit(2);
129
      }
130
 
131
      if (last_ctx != -1) ctx_time[last_ctx].total_time += (e->tsc - last_time);  
132
 
133
      last_time = e->tsc;
134
      last_ctx = i;
135
      total_ctx++;
136
 
137
    } else {
138
 
139
      if (e->tsc < last_time) {
140
        printf("Error events sequence\n");
141
        exit(2);
142
      }
143
 
1302 giacomo 144
      if (last_ctx != -1) ctx_time[last_ctx].total_time += (e->tsc - last_time);
1301 giacomo 145
      last_time = e->tsc;
146
      last_ctx = i;
147
 
148
    }
149
 
150
  }
151
 
152
}
153
 
154
int main(int argc, char *argv[])
155
{
156
 
157
  char buffer[READ_BUFFER+DELTA_BUFFER];
158
  void *p, *last;
159
  int n,i,delta,size;
160
  struct event_type evt;
161
 
162
  unsigned long long ev = 0,start,stop;
163
  unsigned int total_simulation = 0;
164
 
165
  FILE *input_file;
166
 
167
  if (argc < 2) {
168
    printf("%s: Enter the input file name [%s filename]\n",argv[0],argv[0]);
169
    exit(1);
170
  }
171
 
172
  memset(ctx_time,0,sizeof(ctx_time));
1302 giacomo 173
  memset(&int_time,0,sizeof(int_time));
1301 giacomo 174
  total_ctx = 0;
175
 
176
  input_file = fopen(argv[1],"rb");
177
 
178
  last = buffer + READ_BUFFER;
179
 
180
  while(!feof(input_file)) {
181
 
182
    //move remaining byte
183
    delta = (unsigned int)(buffer) + READ_BUFFER - (unsigned int)(last);
184
    if (delta > 0) memcpy(buffer,last,delta);    
185
 
186
    n = fread(buffer+delta,1,READ_BUFFER+10,input_file);
187
 
188
    fseek(input_file,-(delta+10),SEEK_CUR);
189
 
190
    p = buffer;
191
 
192
    while ((unsigned int)(p) + *(unsigned char *)(p+9) <= (unsigned int)(buffer + READ_BUFFER) &&
193
           (unsigned int)(p) + *(unsigned char *)(p+9) <= (unsigned int)(buffer + n + delta)) {
194
 
195
      evt.type = (int)(*(unsigned char *)(p));
196
      evt.tsc = (unsigned long long)(*(unsigned int *)(p+1));
197
      evt.tsc <<= 32;
198
      evt.tsc += (unsigned long long)(*(unsigned int *)(p+5));
199
 
200
      size = *(unsigned char *)(p+9);
201
 
202
      if (evt.type == 0x20) {
203
         printf("Start Simulation\n");
204
         start = evt.tsc;
205
      }
206
 
207
      if (evt.type == 0x30) {
208
         printf("Stop Simulation\n");
209
         stop = evt.tsc;
210
      }
211
 
212
      size -= 10;
213
      i = 0;
214
      while (size > 0) {
215
        evt.par[i] = (int)(*(unsigned int *)(p+10+i*4));
216
        i++;
217
        size -= 4;
218
      }
219
 
220
      ev++;
221
 
222
      analyze_event(&evt);
223
 
224
      p += *(unsigned char *)(p+9);
225
 
226
      if ((unsigned int)p + 10 > (unsigned int)(buffer + n + delta)) break;
227
 
228
      last = p;
229
 
230
    }
231
 
232
    if ((unsigned int)p + 10 > (unsigned int)(buffer + n + delta)) break;
233
 
234
  }
235
 
236
  fclose(input_file);
237
 
238
  printf("Total Time %d\n",(unsigned int)((stop-start) * 1000 / 501162));
239
 
1302 giacomo 240
  printf("Total Ctx = %d\n",total_ctx);
1301 giacomo 241
 
1302 giacomo 242
  printf("Total Interrupt = %d\n",(unsigned int)(int_time.total_time * 1000 / 501162));
243
 
1301 giacomo 244
  total_simulation = 0;
245
  for (i=0;i<total_ctx;i++) {
246
    printf("Total Time Ctx %d => %d\n",ctx_time[i].ctx,(unsigned int)(ctx_time[i].total_time * 1000 / 501162));
247
    total_simulation += (unsigned int)(ctx_time[i].total_time * 1000 / 501162);
248
  }
249
 
250
  printf ("Total Simulation %d\n",total_simulation);
251
 
252
  return 0;
253
 
254
}
255