Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 13 additions & 60 deletions src/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,6 @@ void getProcedureOverhead(std::vector<double> &overhead){
}

double getSystemCallOverhead() {
uint64_t start, end;
int SUC_TIMES = 0;
pid_t pid;
double sum = 0;
for (int i=0; i<LOOP_TIMES; ++i) {
switch (pid = fork()) {
case -1:
exit(-1);
break;
case 0:
start = rdtsc();
getpid();
end = rdtsc();
sum += (end - start);
SUC_TIMES++;
exit(0);
default:
}
}
return sum / (double)SUC_TIMES;
}

// Test for cache of system call
double getSystemCallOverhead2() {
uint64_t start, end;
double sum = 0;
for (int i=0; i<LOOP_TIMES; ++i) {
Expand All @@ -153,28 +129,12 @@ double getThreadCreationOverhead() {
for (int i=0; i<LOOP_TIMES; ++i) {
start = rdtsc();
pthread_create(&threadId, NULL, newThread, NULL);
pthread_join(threadId, NULL);
end = rdtsc();
sum += (end - start);
}
return sum / (double)LOOP_TIMES;
}
// Test for succeed create
double getThreadCreationOverhead2() {
uint64_t start, end;
pthread_t threadId;
int SUC_TIMES = 0, res;
double sum = 0;
for (int i=0; i<LOOP_TIMES; ++i) {
start = rdtsc();
res = pthread_create(&threadId, NULL, newThread, NULL);
end = rdtsc();
if (res==0) {
sum += (end - start);
SUC_TIMES++;
}
}
return sum / (double)SUC_TIMES;
}

double getProcessCreationOverhead() {
uint64_t start, end;
Expand All @@ -184,13 +144,16 @@ double getProcessCreationOverhead() {
for (int i=0; i<LOOP_TIMES; ++i) {
start = rdtsc();
switch (pid = fork()) {
case 0:
exit(1);
case 1:
wait(NULL);
end = rdtsc();
sum += (end - start);
SUC_TIMES++;
case -1:
exit(-1);
break;
case 0:
exit(0);
default:
wait(NULL);
end = rdtsc();
sum += (end - start);
SUC_TIMES++;
}
}
return sum / (double)SUC_TIMES;
Expand All @@ -208,29 +171,19 @@ int main() {
std::vector<double> procedureOverhead;
getProcedureOverhead(procedureOverhead);
for (int i=0; i<8; ++i) {
printf("The average ovehead of a function with %d integer arguments is %f\n", i, procedureOverhead[i]);
printf("The average overhead of a function with %d integer arguments is %f\n", i, procedureOverhead[i]);
}

for (int i=0; i<REPEAT_TIMES; ++i) {
printf("system call overhead for %d times is %f\n", i, getSystemCallOverhead());
}

for (int i=0; i<REPEAT_TIMES; ++i) {
printf("system call overhead2 for %d times is %f\n", i, getSystemCallOverhead2());
printf("system call overhead for %d times is %f\n", i, getSystemCallOverhead()));
}

for (int i=0; i<REPEAT_TIMES; ++i) {
printf("thread creation overhead for %d times is %f\n", i, getThreadCreationOverhead());
}

for (int i=0; i<REPEAT_TIMES; ++i) {
printf("thread creation overhead2 for %d times is %f\n", i, getThreadCreationOverhead2());
}

for (int i=0; i<REPEAT_TIMES; ++i) {
printf("process creation overhead for %d times is %f\n", i, getProcessCreationOverhead());
}


return 0;
}