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