Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1495 → Rev 1494

/demos/trunk/newtrace/utils/extract.c
8,62 → 8,64
#define INT_PID 9999
#define PID_NO_DEF -1
 
#define BACKGROUND 0
#define PERIODICAL 1
#define INTERRUPT 2
 
struct ctx_exec {
struct single_job_exec {
int ctx;
unsigned long long dtsc;
unsigned long long start;
};
 
struct ctx_to_pid {
struct single_ctx {
int ctx;
int pid;
};
 
struct endcycle {
struct single_endcycle {
int ctx;
unsigned long long tsc;
};
 
void Error(int num) {
printf("Finite-State machine error: %d\n",num);
printf("Finite State machine error: %d\n",num);
exit(2);
}
 
int context_total = 0,endcycle_total = 0,job_total = 0,exec_total = 0;
struct ctx_exec *exec_list;
struct ctx_to_pid *context_list;
struct endcycle *endcycle_list;
struct ctx_exec *job_list;
int main(int argc, char *argv[]) {
 
unsigned long long log_start_tsc = 0;
unsigned long long log_end_tsc = 0;
 
int create_lists(char *filename) {
 
FILE *input_file;
int type,par1,par2,k,i,h,temp_ctx;
unsigned long long tsc,endcycle_start_tsc,endcycle_end_tsc;
 
int type,par1,par2,k,i,state;
int context_number = 0;
int current_context = 0;
int current_cycle = 0;
int current_job = 0;
struct single_ctx context_list[MAXCONTEXT];
unsigned long long temp_tsc,last_tsc,log_start_tsc,log_end_tsc,total_tsc;
int state;
char pidstr[10];
 
int current_context = 0;
int current_exec = 0;
int current_endcycle = 0;
 
unsigned long long last_tsc, tsc;
struct single_job_exec *job_list;
struct single_endcycle *endcycle_list;
struct single_job_exec *cycle_list;
 
input_file = fopen(filename,"r");
if (argc < 2) {
printf("%s: Enter the input file name [%s filename]\n",argv[0],argv[0]);
exit(1);
}
input_file = fopen(argv[1],"r");
 
/* Memory alloc */
exec_list = malloc(sizeof(struct ctx_exec) * MAXJOB);
context_list = malloc(sizeof(struct ctx_to_pid) * MAXCONTEXT);
endcycle_list = malloc(sizeof(struct endcycle) * MAXJOB);
/* Alloc mem */
job_list = malloc(sizeof(struct single_job_exec) * MAXJOB);
endcycle_list = malloc(sizeof(struct single_endcycle) * MAXJOB);
cycle_list = malloc(sizeof(struct single_job_exec) * MAXJOB);
 
/* Finite-State machine
*
* FS-Machine states:
/* Finite-State machine */
 
/* FS-Machine states:
0 - Start
1 - Context running
71,15 → 73,15
10 - End
*/
*/
 
for(i=0;i<MAXCONTEXT;i++) {
context_list[i].ctx = 0;
context_list[i].pid = PID_NO_DEF;
context_list[i].ctx = 0;
context_list[i].pid = PID_NO_DEF;
}
 
/* The start context + interrupt context */
context_total = 2;
context_number = 2;
current_context = 0;
last_tsc = 0;
context_list[0].ctx = 0;
128,15 → 130,15
printf("EVT:Log starts at [%12llu]\n",tsc);
last_tsc = tsc;
log_start_tsc = tsc;
exec_list[current_exec].start = tsc;
job_list[current_job].start = tsc;
state = 1;
break;
 
case 1:
printf("EVT:Log ends at [%12llu]\n",tsc);
exec_list[current_exec].dtsc = tsc - last_tsc;
exec_list[current_exec].ctx = current_context;
current_exec++;
job_list[current_job].dtsc = tsc - last_tsc;
job_list[current_job].ctx = current_context;
current_job++;
last_tsc = tsc;
log_end_tsc = tsc;
state = 10;
145,12 → 147,12
/* Int start */
case 2:
if (state == 0) Error(2);
exec_list[current_exec].dtsc = tsc - last_tsc;
exec_list[current_exec].ctx = current_context;
current_exec++;
job_list[current_job].dtsc = tsc - last_tsc;
job_list[current_job].ctx = current_context;
current_job++;
last_tsc = tsc;
current_context = INT_CTX;
exec_list[current_exec].start = tsc;
job_list[current_job].start = tsc;
state = 2;
break;
 
157,20 → 159,20
/* Int end */
case 3:
if (state != 2) Error(3);
exec_list[current_exec].dtsc = tsc - last_tsc;
exec_list[current_exec].ctx = current_context;
current_exec++;
job_list[current_job].dtsc = tsc - last_tsc;
job_list[current_job].ctx = current_context;
current_job++;
last_tsc = tsc;
current_context = par1;
 
for (i=0;i<context_total;i++)
for (i=0;i<context_number;i++)
if (par1 == context_list[i].ctx) break;
if (i == context_total) {
context_list[context_total].ctx = par1;
context_total++;
if (i == context_number) {
context_list[context_number].ctx = par1;
context_number++;
}
 
exec_list[current_exec].start = tsc;
job_list[current_job].start = tsc;
state = 1;
break;
 
177,20 → 179,20
/* Change ctx */
case 4:
 
exec_list[current_exec].dtsc = tsc - last_tsc;
exec_list[current_exec].ctx = current_context;
current_exec++;
job_list[current_job].dtsc = tsc - last_tsc;
job_list[current_job].ctx = current_context;
current_job++;
last_tsc = tsc;
current_context = par1;
 
for (i=0;i<context_total;i++)
for (i=0;i<context_number;i++)
if (par1 == context_list[i].ctx) break;
if (i == context_total) {
context_list[context_total].ctx = par1;
context_total++;
if (i == context_number) {
context_list[context_number].ctx = par1;
context_number++;
}
 
exec_list[current_exec].start = tsc;
job_list[current_job].start = tsc;
state = 1;
break;
 
197,12 → 199,12
/* Task create */
case 5:
 
for (i=0;i<context_total;i++)
for (i=0;i<context_number;i++)
if (par1 == context_list[i].ctx) break;
if (i == context_total) {
context_list[context_total].ctx = par1;
context_list[context_total].pid = par2;
context_total++;
if (i == context_number) {
context_list[context_number].ctx = par1;
context_list[context_number].pid = par2;
context_number++;
}
 
break;
210,9 → 212,9
/* Task endcycle */
case 8:
 
for (i=0;i<context_total;i++)
for (i=0;i<context_number;i++)
if (par1 == context_list[i].ctx) break;
if (i == context_total) Error(4);
if (i == context_number) Error(4);
endcycle_list[current_endcycle].ctx = par1;
endcycle_list[current_endcycle].tsc = tsc;
222,8 → 224,8
 
}
 
if (current_exec == MAXJOB-1) {
printf("Too many execs...\n");
if (current_job == MAXJOB-1) {
printf("Too many jobs...\n");
exit(3);
}
 
236,218 → 238,80
 
}
 
endcycle_total = current_endcycle;
exec_total = current_exec;
printf("\nDelta TSC = %llu\n",log_end_tsc - log_start_tsc);
printf("Events [%8d]\n",k);
printf("Jobs [%8d]\n",current_job);
printf("EndCycles [%8d]\n",current_endcycle);
 
return k;
total_tsc = 0;
for (i=0;i<current_job;i++)
total_tsc += job_list[i].dtsc;
/* Jobs total execution check */
printf("\nJob TSC sum = %llu (%2.4f)\n",total_tsc,(float)total_tsc/((float)(log_end_tsc - log_start_tsc))*100.0);
 
}
/* Singel context total execution time */
 
int create_job_list() {
for (k=0;k<context_number;k++) {
 
int current_job = 0, h, i, k;
int temp_ctx;
unsigned long long temp_tsc, endcycle_start_tsc;
unsigned long long endcycle_end_tsc;
temp_tsc = 0;
 
job_list = malloc(sizeof(struct ctx_exec) * MAXJOB);
for (i=0;i<current_job;i++)
if (job_list[i].ctx == context_list[k].ctx) temp_tsc += job_list[i].dtsc;
 
for (k=0;k<context_total;k++) {
switch (context_list[k].pid) {
case PID_NO_DEF:
sprintf(pidstr,"NODEF");
break;
case INT_PID:
sprintf(pidstr," INT");
break;
default:
sprintf(pidstr,"%5d",context_list[k].pid);
break;
}
printf("Context [%5d:%s] total dTSC [%12llu]\n",context_list[k].ctx,pidstr,temp_tsc);
 
temp_ctx = context_list[k].ctx;
endcycle_start_tsc = 0;
}
 
for (h=0;h<endcycle_total;h++) {
printf("\nPreemption Removing.... \n");
 
if (endcycle_list[h].ctx == temp_ctx) {
/* Remove preemption from the computation time */
 
if (endcycle_start_tsc == 0)
endcycle_start_tsc = log_start_tsc;
current_cycle = 0;
endcycle_start_tsc = log_start_tsc;
 
for (h=0;h<current_endcycle;h++) {
 
endcycle_end_tsc = endcycle_list[h].tsc;
temp_ctx = endcycle_list[h].ctx;
temp_tsc = 0;
 
job_list[current_job].start = 0;
cycle_list[current_cycle].start = 0;
 
for(i=0;i<exec_total;i++)
if (exec_list[i].ctx == temp_ctx) {
if (exec_list[i].start < endcycle_end_tsc &&
exec_list[i].start >= endcycle_start_tsc) {
if (job_list[current_job].start == 0)
job_list[current_job].start = exec_list[i].start;
temp_tsc += exec_list[i].dtsc;
for(i=0;i<current_job;i++)
if (job_list[i].ctx == temp_ctx) {
if (job_list[i].start < endcycle_end_tsc &&
job_list[i].start >= endcycle_start_tsc) {
if (cycle_list[current_cycle].start == 0)
cycle_list[current_cycle].start = job_list[i].start;
temp_tsc += job_list[i].dtsc;
}
}
 
job_list[current_job].dtsc = temp_tsc;
job_list[current_job].ctx = temp_ctx;
current_job++;
cycle_list[current_cycle].dtsc = temp_tsc;
cycle_list[current_cycle].ctx = temp_ctx;
current_cycle++;
 
endcycle_start_tsc = endcycle_end_tsc;
 
}
}
 
}
for (k=0;k<current_cycle;k++)
printf("Cycle CTX [%5d] Start [%12llu] dTSC [%12llu]\n",cycle_list[k].ctx,cycle_list[k].start,cycle_list[k].dtsc);
 
}
 
job_total = current_job;
 
return 0;
 
}
 
int elaborate_statistics(int num, int task_type) {
 
int i,k;
char pidstr[10];
unsigned long long temp_tsc,max_tsc;
 
switch (context_list[num].pid) {
case PID_NO_DEF:
sprintf(pidstr,"NODEF");
break;
case INT_PID:
sprintf(pidstr," INT");
break;
default:
sprintf(pidstr,"%5d",context_list[num].pid);
break;
}
 
if (task_type == BACKGROUND) {
 
printf("Background Task CTX [%5d] PID [%s]\n",context_list[num].ctx,pidstr);
 
temp_tsc = 0;
max_tsc = 0;
k = 0;
for (i=0;i<exec_total;i++)
if (exec_list[i].ctx == context_list[num].ctx) {
if (exec_list[i].dtsc > max_tsc) max_tsc = exec_list[i].dtsc;
temp_tsc += exec_list[i].dtsc;
k++;
}
printf(" Total Execution dTSC [%12llu]\n",temp_tsc);
printf(" Execs Number [%12d]\n",k);
printf(" Mean Exec dTSC [%12llu]\n",temp_tsc / k);
printf(" Max Exec dTSC [%12llu]\n\n",max_tsc);
 
}
 
if (task_type == INTERRUPT) {
 
printf("Interrupts\n");
 
temp_tsc = 0;
max_tsc = 0;
k = 0;
for (i=0;i<exec_total;i++)
if (exec_list[i].ctx == context_list[num].ctx) {
if (exec_list[i].dtsc > max_tsc) max_tsc = exec_list[i].dtsc;
temp_tsc += exec_list[i].dtsc;
k++;
}
printf(" Total Execution dTSC [%12llu]\n",temp_tsc);
printf(" Interrupts Number [%12d]\n",k);
printf(" Mean Interrupt dTSC [%12llu]\n",temp_tsc / k);
printf(" Max Interrupt dTSC [%12llu]\n\n",max_tsc);
 
}
 
if (task_type == PERIODICAL) {
 
printf("Periodical Task CTX [%5d] PID [%s]\n",context_list[num].ctx,pidstr);
 
temp_tsc = 0;
max_tsc = 0;
k = 0;
for (i=0;i<exec_total;i++)
if (exec_list[i].ctx == context_list[num].ctx) {
if (exec_list[i].dtsc > max_tsc) max_tsc = exec_list[i].dtsc;
temp_tsc += exec_list[i].dtsc;
k++;
}
printf(" Total Execution dTSC [%12llu]\n",temp_tsc);
printf(" Execs Number [%12d]\n",k);
printf(" Mean Exec dTSC [%12llu]\n",temp_tsc / k);
printf(" Max Exec dTSC [%12llu]\n\n",max_tsc);
 
temp_tsc = 0;
max_tsc = 0;
k = 0;
for (i=0;i<job_total;i++)
if (job_list[i].ctx == context_list[num].ctx) {
if (job_list[i].dtsc > max_tsc) max_tsc = job_list[i].dtsc;
temp_tsc += job_list[i].dtsc;
k++;
}
printf(" Total Job Exec dTSC [%12llu]\n",temp_tsc);
printf(" Jobs Number [%12d]\n",k);
printf(" Mean Job dTSC [%12llu]\n",temp_tsc / k);
printf(" Max Job dTSC [%12llu]\n\n",max_tsc);
}
 
return 0;
 
}
 
int main(int argc, char *argv[]) {
 
int events_total,k,i;
int task_type;
unsigned long long total_tsc;
 
if (argc < 2) {
printf("%s: Enter the input file name [%s filename]\n",argv[0],argv[0]);
exit(1);
}
 
printf("\n");
events_total = create_lists(argv[1]);
 
printf("\nDelta TSC = %llu\n",log_end_tsc - log_start_tsc);
printf("Events [%8d]\n",events_total);
printf("Execs [%8d]\n",exec_total);
printf("EndCycles [%8d]\n",endcycle_total);
 
total_tsc = 0;
for (i=0;i<exec_total;i++)
total_tsc += exec_list[i].dtsc;
/* Exec total execution check */
printf("\nExec TSC sum = %llu (%2.2f)\n",total_tsc,(float)total_tsc/((float)(log_end_tsc - log_start_tsc))*100.0);
 
printf("\nPreemption Removing.... \n");
 
/* Remove preemption from the computation time */
create_job_list();
 
for (k=0;k<job_total;k++)
printf("Job CTX [%5d] Start [%12llu] dTSC [%12llu]\n",
job_list[k].ctx,job_list[k].start,job_list[k].dtsc);
 
printf("\nCompute Task Statistics.... \n\n");
 
for (i=0;i<context_total;i++) {
 
task_type = BACKGROUND;
 
if (context_list[i].ctx == INT_CTX) task_type = INTERRUPT;
 
for (k=0;k<job_total;k++)
if (job_list[k].ctx == context_list[i].ctx) {
task_type = PERIODICAL;
break;
}
 
elaborate_statistics(i,task_type);
 
}
 
return 0;
 
}