forked from deater/perf_event_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some inherit and inherit_stat tests
Fairly simple for now, and still not sure how inherit_stat really differs.
- Loading branch information
Showing
5 changed files
with
329 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* inherit.c */ | ||
/* simple test of the inherit flag */ | ||
|
||
/* by Vince Weaver vweaver1 _at_ eecs.utk.edu */ | ||
|
||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <pthread.h> | ||
|
||
#include <unistd.h> | ||
#include <asm/unistd.h> | ||
#include <sys/ioctl.h> | ||
|
||
#include "perf_event.h" | ||
#include "perf_helpers.h" | ||
#include "test_utils.h" | ||
|
||
int fd; | ||
|
||
|
||
void *thread_work(void *blah) { | ||
|
||
return NULL; | ||
} | ||
|
||
|
||
char test_string[]="Testing inherit..."; | ||
|
||
int main(int argc, char** argv) { | ||
|
||
int j; | ||
int quiet; | ||
pthread_t our_thread[8]; | ||
int read_result; | ||
long long inherit_count,count; | ||
|
||
struct perf_event_attr pe; | ||
|
||
quiet=test_quiet(); | ||
|
||
if (!quiet) { | ||
printf("This test checks inherit functionality.\n"); | ||
printf("Starting and stopping 8 threads\n"); | ||
} | ||
|
||
/*************************/ | ||
/* With inherit set */ | ||
/*************************/ | ||
|
||
memset(&pe,0,sizeof(struct perf_event_attr)); | ||
|
||
pe.type=PERF_TYPE_HARDWARE; | ||
pe.config=PERF_COUNT_HW_INSTRUCTIONS; | ||
pe.disabled=1; | ||
pe.inherit=1; | ||
pe.exclude_kernel=1; | ||
pe.exclude_hv=1; | ||
|
||
fd=perf_event_open(&pe,0,-1,-1,0); | ||
if (fd<0) { | ||
fprintf(stderr,"Error opening\n"); | ||
exit(1); | ||
} | ||
|
||
ioctl(fd, PERF_EVENT_IOC_RESET, 0); | ||
ioctl(fd, PERF_EVENT_IOC_ENABLE,0); | ||
|
||
|
||
for(j=0;j<8;j++) { | ||
pthread_create(&our_thread[j],NULL,thread_work,0); | ||
} | ||
|
||
for(j=0;j<8;j++) { | ||
pthread_join(our_thread[j],NULL); | ||
} | ||
|
||
ioctl(fd, PERF_EVENT_IOC_DISABLE,0); | ||
|
||
read_result=read(fd,&inherit_count,sizeof(long long)); | ||
|
||
if (read_result!=sizeof(long long)) { | ||
fprintf(stderr,"\tImproper return from read: %d\n",read_result); | ||
test_fail(test_string); | ||
} | ||
|
||
close(fd); | ||
|
||
/****************************/ | ||
/* Without inherit set */ | ||
/****************************/ | ||
|
||
memset(&pe,0,sizeof(struct perf_event_attr)); | ||
|
||
pe.type=PERF_TYPE_HARDWARE; | ||
pe.config=PERF_COUNT_HW_INSTRUCTIONS; | ||
pe.disabled=1; | ||
pe.inherit=0; | ||
pe.exclude_kernel=1; | ||
pe.exclude_hv=1; | ||
|
||
fd=perf_event_open(&pe,0,-1,-1,0); | ||
if (fd<0) { | ||
fprintf(stderr,"Error opening\n"); | ||
exit(1); | ||
} | ||
|
||
ioctl(fd, PERF_EVENT_IOC_RESET, 0); | ||
ioctl(fd, PERF_EVENT_IOC_ENABLE,0); | ||
|
||
|
||
for(j=0;j<8;j++) { | ||
pthread_create(&our_thread[j],NULL,thread_work,0); | ||
} | ||
|
||
for(j=0;j<8;j++) { | ||
pthread_join(our_thread[j],NULL); | ||
} | ||
|
||
ioctl(fd, PERF_EVENT_IOC_DISABLE,0); | ||
|
||
read_result=read(fd,&count,sizeof(long long)); | ||
|
||
if (read_result!=sizeof(long long)) { | ||
fprintf(stderr,"\tImproper return from read: %d\n",read_result); | ||
test_fail(test_string); | ||
} | ||
|
||
close(fd); | ||
|
||
if (!quiet) { | ||
|
||
printf("\tFound %lld instructions with inherit enabled\n", | ||
inherit_count); | ||
printf("\tFound %lld instructions with inherit disabled\n", | ||
count); | ||
|
||
} | ||
|
||
if ((inherit_count < 6*count) || (inherit_count > 9*count)) { | ||
fprintf(stderr,"\tInherit count unexpected.\n"); | ||
test_fail(test_string); | ||
} | ||
|
||
test_pass(test_string); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* inherit_stat.c */ | ||
/* Find out what the inherit_stat flag does */ | ||
|
||
/* by Vince Weaver vweaver1 _at_ eecs.utk.edu */ | ||
|
||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <pthread.h> | ||
|
||
#include <unistd.h> | ||
#include <asm/unistd.h> | ||
#include <sys/ioctl.h> | ||
|
||
#include "perf_event.h" | ||
#include "perf_helpers.h" | ||
#include "test_utils.h" | ||
|
||
int fd; | ||
|
||
|
||
void *thread_work(void *blah) { | ||
|
||
return NULL; | ||
} | ||
|
||
|
||
char test_string[]="Testing inherit_stat..."; | ||
|
||
int main(int argc, char** argv) { | ||
|
||
int j; | ||
int quiet; | ||
pthread_t our_thread[8]; | ||
int read_result; | ||
long long inherit_count,count; | ||
|
||
struct perf_event_attr pe; | ||
|
||
quiet=test_quiet(); | ||
|
||
if (!quiet) { | ||
printf("This test checks inherit_stat functionality.\n"); | ||
printf("Starting and stopping 8 threads\n"); | ||
} | ||
|
||
/*************************/ | ||
/* With inherit_stat set */ | ||
/*************************/ | ||
|
||
memset(&pe,0,sizeof(struct perf_event_attr)); | ||
|
||
pe.type=PERF_TYPE_HARDWARE; | ||
pe.config=PERF_COUNT_HW_INSTRUCTIONS; | ||
pe.disabled=1; | ||
pe.inherit_stat=1; | ||
pe.exclude_kernel=1; | ||
pe.exclude_hv=1; | ||
|
||
fd=perf_event_open(&pe,0,-1,-1,0); | ||
if (fd<0) { | ||
fprintf(stderr,"Error opening\n"); | ||
exit(1); | ||
} | ||
|
||
ioctl(fd, PERF_EVENT_IOC_RESET, 0); | ||
ioctl(fd, PERF_EVENT_IOC_ENABLE,0); | ||
|
||
|
||
for(j=0;j<8;j++) { | ||
pthread_create(&our_thread[j],NULL,thread_work,0); | ||
} | ||
|
||
for(j=0;j<8;j++) { | ||
pthread_join(our_thread[j],NULL); | ||
} | ||
|
||
ioctl(fd, PERF_EVENT_IOC_DISABLE,0); | ||
|
||
read_result=read(fd,&inherit_count,sizeof(long long)); | ||
|
||
if (read_result!=sizeof(long long)) { | ||
fprintf(stderr,"\tImproper return from read: %d\n",read_result); | ||
test_fail(test_string); | ||
} | ||
|
||
close(fd); | ||
|
||
/****************************/ | ||
/* Without inherit_stat set */ | ||
/****************************/ | ||
|
||
memset(&pe,0,sizeof(struct perf_event_attr)); | ||
|
||
pe.type=PERF_TYPE_HARDWARE; | ||
pe.config=PERF_COUNT_HW_INSTRUCTIONS; | ||
pe.disabled=1; | ||
pe.inherit_stat=0; | ||
pe.exclude_kernel=1; | ||
pe.exclude_hv=1; | ||
|
||
fd=perf_event_open(&pe,0,-1,-1,0); | ||
if (fd<0) { | ||
fprintf(stderr,"Error opening\n"); | ||
exit(1); | ||
} | ||
|
||
ioctl(fd, PERF_EVENT_IOC_RESET, 0); | ||
ioctl(fd, PERF_EVENT_IOC_ENABLE,0); | ||
|
||
|
||
for(j=0;j<8;j++) { | ||
pthread_create(&our_thread[j],NULL,thread_work,0); | ||
} | ||
|
||
for(j=0;j<8;j++) { | ||
pthread_join(our_thread[j],NULL); | ||
} | ||
|
||
ioctl(fd, PERF_EVENT_IOC_DISABLE,0); | ||
|
||
read_result=read(fd,&count,sizeof(long long)); | ||
|
||
if (read_result!=sizeof(long long)) { | ||
fprintf(stderr,"\tImproper return from read: %d\n",read_result); | ||
test_fail(test_string); | ||
} | ||
|
||
close(fd); | ||
|
||
if (!quiet) { | ||
|
||
printf("\tFound %lld instructions with inherit_stat enabled\n", | ||
inherit_count); | ||
printf("\tFound %lld instructions with inherit_stat disabled\n", | ||
count); | ||
|
||
} | ||
|
||
if ((inherit_count < 6*count) || (inherit_count > 9*count)) { | ||
fprintf(stderr,"\tInherit count unexpected.\n"); | ||
test_fail(test_string); | ||
} | ||
|
||
test_pass(test_string); | ||
|
||
return 0; | ||
} |