Subversion Repositories shark

Rev

Rev 1495 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1494 giacomo 1
#include <stdio.h>
2
#include <stdlib.h>
3
 
4
#define MAXCONTEXT 100
5
#define MAXJOB 100000
6
 
7
#define INT_CTX 1
8
#define INT_PID 9999
9
#define PID_NO_DEF -1
10
 
11
struct single_job_exec {
12
	int ctx;
13
	unsigned long long dtsc;
14
	unsigned long long start;
15
};
16
 
17
struct single_ctx {
18
	int ctx;
19
	int pid;
20
};
21
 
22
struct single_endcycle {
23
	int ctx;
24
	unsigned long long tsc;
25
};
26
 
27
void Error(int num) {
28
	printf("Finite State machine error: %d\n",num);
29
	exit(2);
30
}
31
 
32
int main(int argc, char *argv[]) {
33
 
34
  FILE *input_file;
35
  int type,par1,par2,k,i,h,temp_ctx;
36
  unsigned long long tsc,endcycle_start_tsc,endcycle_end_tsc;
37
 
38
  int context_number = 0;
39
  int current_context = 0;
40
  int current_cycle = 0;
41
  int current_job = 0;
42
  struct single_ctx context_list[MAXCONTEXT];
43
  unsigned long long temp_tsc,last_tsc,log_start_tsc,log_end_tsc,total_tsc;
44
  int state;
45
 
46
  char pidstr[10];
47
 
48
  int current_endcycle = 0;
49
 
50
  struct single_job_exec *job_list;
51
  struct single_endcycle *endcycle_list;
52
  struct single_job_exec *cycle_list;
53
 
54
  if (argc < 2) {
55
    printf("%s: Enter the input file name [%s filename]\n",argv[0],argv[0]);
56
    exit(1);
57
  }
58
 
59
  input_file = fopen(argv[1],"r");
60
 
61
  /* Alloc mem */
62
  job_list = malloc(sizeof(struct single_job_exec) * MAXJOB);
63
  endcycle_list = malloc(sizeof(struct single_endcycle) * MAXJOB);
64
  cycle_list = malloc(sizeof(struct single_job_exec) * MAXJOB);
65
 
66
  /* Finite-State machine */
67
 
68
  /*  FS-Machine states:
69
 
70
 
71
        1 - Context running
72
        2 - Interrupt running
73
 
74
        10 - End
75
 
76
  */
77
 
78
  for(i=0;i<MAXCONTEXT;i++) {
79
	context_list[i].ctx = 0;
80
	context_list[i].pid = PID_NO_DEF;
81
  }
82
 
83
  /* The start context + interrupt context */
84
  context_number = 2;
85
  current_context = 0;
86
  last_tsc = 0;
87
  context_list[0].ctx = 0;
88
  context_list[0].pid = PID_NO_DEF;
89
  context_list[1].ctx = INT_CTX;
90
  context_list[1].pid = INT_PID;
91
 
92
  state = 0;
93
 
94
  k = 0;
95
  while(!feof(input_file)) {
96
 
97
    fscanf(input_file,"%d %llu",&type,&tsc);
98
    k++;
99
 
100
    switch (type) {
101
 
102
	case 0:
103
	case 1:
104
 
105
		/* No par */
106
		break;
107
 
108
	case 2:
109
	case 3:
110
	case 4:
111
	case 6:
112
	case 7:
113
	case 8:
114
 
115
		/* 1 par */
116
		fscanf(input_file,"%d",&par1);
117
		break;
118
 
119
	case 5:
120
		/* 2 par */
121
		fscanf(input_file,"%d %d",&par1,&par2);
122
		break;
123
 
124
    }
125
 
126
    switch (type) {
127
 
128
	case 0:
129
		if (state != 0) Error(1);
130
		printf("EVT:Log starts at [%12llu]\n",tsc);
131
		last_tsc = tsc;
132
		log_start_tsc = tsc;
133
		job_list[current_job].start = tsc;
134
		state = 1;
135
		break;
136
 
137
	case 1:
138
		printf("EVT:Log   ends at [%12llu]\n",tsc);
139
		job_list[current_job].dtsc = tsc - last_tsc;
140
                job_list[current_job].ctx = current_context;
141
                current_job++;
142
		last_tsc = tsc;
143
		log_end_tsc = tsc;
144
		state = 10;
145
		break;
146
 
147
	/* Int start */
148
	case 2:
149
		if (state == 0) Error(2);
150
		job_list[current_job].dtsc = tsc - last_tsc;
151
		job_list[current_job].ctx = current_context;
152
		current_job++;
153
		last_tsc = tsc;
154
		current_context = INT_CTX;
155
		job_list[current_job].start = tsc;
156
		state = 2;
157
		break;
158
 
159
	/* Int end */
160
	case 3:
161
		if (state != 2) Error(3);
162
		job_list[current_job].dtsc = tsc - last_tsc;
163
		job_list[current_job].ctx = current_context;
164
		current_job++;
165
		last_tsc = tsc;
166
		current_context = par1;
167
 
168
		for (i=0;i<context_number;i++)
169
			if (par1 == context_list[i].ctx) break;
170
		if (i == context_number) {
171
			context_list[context_number].ctx = par1;
172
			context_number++;
173
		}
174
 
175
		job_list[current_job].start = tsc;
176
		state = 1;
177
		break;
178
 
179
	/* Change ctx */
180
	case 4:
181
 
182
		job_list[current_job].dtsc = tsc - last_tsc;
183
		job_list[current_job].ctx = current_context;
184
		current_job++;
185
		last_tsc = tsc;
186
		current_context = par1;
187
 
188
                for (i=0;i<context_number;i++)
189
                        if (par1 == context_list[i].ctx) break;
190
                if (i == context_number) {
191
                        context_list[context_number].ctx = par1;
192
                        context_number++;
193
                }
194
 
195
		job_list[current_job].start = tsc;
196
		state = 1;
197
		break;
198
 
199
	/* Task create */
200
	case 5:
201
 
202
		for (i=0;i<context_number;i++)
203
                        if (par1 == context_list[i].ctx) break;
204
                if (i == context_number) {
205
                        context_list[context_number].ctx = par1;
206
			context_list[context_number].pid = par2;
207
                        context_number++;
208
                }
209
 
210
		break;
211
 
212
	/* Task endcycle */
213
	case 8:
214
 
215
		for (i=0;i<context_number;i++)
216
			if (par1 == context_list[i].ctx) break;
217
		if (i == context_number) Error(4);
218
 
219
		endcycle_list[current_endcycle].ctx = par1;
220
		endcycle_list[current_endcycle].tsc = tsc;
221
		current_endcycle++;
222
 
223
		break;
224
 
225
    }
226
 
227
    if (current_job == MAXJOB-1) {
228
	printf("Too many jobs...\n");
229
	exit(3);
230
    }
231
 
232
    if (current_endcycle == MAXJOB-1) {
233
        printf("Too many endcycle...\n");
234
        exit(4);
235
    }
236
 
237
    if (state == 10) break;
238
 
239
  }
240
 
241
  printf("\nDelta TSC = %llu\n",log_end_tsc - log_start_tsc);
242
  printf("Events    [%8d]\n",k);
243
  printf("Jobs      [%8d]\n",current_job);
244
  printf("EndCycles [%8d]\n",current_endcycle);
245
 
246
  total_tsc = 0;
247
  for (i=0;i<current_job;i++)
248
	total_tsc += job_list[i].dtsc;
249
 
250
  /* Jobs total execution check */
251
  printf("\nJob TSC sum = %llu (%2.4f)\n",total_tsc,(float)total_tsc/((float)(log_end_tsc - log_start_tsc))*100.0);
252
 
253
  /* Singel context total execution time */
254
 
255
  for (k=0;k<context_number;k++) {
256
 
257
	temp_tsc = 0;
258
 
259
  	for (i=0;i<current_job;i++)
260
		if (job_list[i].ctx == context_list[k].ctx) temp_tsc += job_list[i].dtsc;
261
 
262
	switch (context_list[k].pid) {
263
		case PID_NO_DEF:
264
			sprintf(pidstr,"NODEF");
265
			break;
266
		case INT_PID:
267
			sprintf(pidstr,"  INT");
268
			break;
269
		default:
270
			sprintf(pidstr,"%5d",context_list[k].pid);
271
			break;
272
	}
273
 
274
	printf("Context [%5d:%s] total dTSC [%12llu]\n",context_list[k].ctx,pidstr,temp_tsc);
275
 
276
  }
277
 
278
  printf("\nPreemption Removing.... \n");
279
 
280
  /* Remove preemption from the computation time */
281
 
282
  current_cycle = 0;
283
  endcycle_start_tsc = log_start_tsc;
284
 
285
    for (h=0;h<current_endcycle;h++) {
286
 
287
	endcycle_end_tsc = endcycle_list[h].tsc;
288
	temp_ctx = endcycle_list[h].ctx;
289
	temp_tsc = 0;
290
 
291
	cycle_list[current_cycle].start = 0;
292
 
293
	for(i=0;i<current_job;i++)
294
		if (job_list[i].ctx == temp_ctx) {
295
			if (job_list[i].start < endcycle_end_tsc &&
296
				job_list[i].start >= endcycle_start_tsc) {
297
				if (cycle_list[current_cycle].start == 0)
298
				  cycle_list[current_cycle].start = job_list[i].start;
299
				temp_tsc += job_list[i].dtsc;
300
			}
301
		}
302
 
303
	cycle_list[current_cycle].dtsc = temp_tsc;
304
	cycle_list[current_cycle].ctx = temp_ctx;
305
	current_cycle++;
306
 
307
	endcycle_start_tsc = endcycle_end_tsc;
308
 
309
    }
310
 
311
  for (k=0;k<current_cycle;k++)
312
	printf("Cycle CTX [%5d] Start [%12llu] dTSC [%12llu]\n",cycle_list[k].ctx,cycle_list[k].start,cycle_list[k].dtsc);
313
 
314
  return 0;
315
 
316
}
317