Skip to content

Commit

Permalink
Add multiple_mmap_sizes test
Browse files Browse the repository at this point in the history
  • Loading branch information
deater committed Mar 13, 2013
1 parent bec1faa commit 3bd2df3
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 89 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

13 March 2013
+ Add multiple_mmap_sizes test
+ Add hw_sw_mix test

29 January 2013
Expand Down
20 changes: 20 additions & 0 deletions record_sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LFLAGS =

all: \
lost_record_sample \
multiple_mmap_sizes \
print_record_sample \
validate_record_sample

Expand Down Expand Up @@ -46,6 +47,24 @@ lost_record_sample: lost_record_sample.o \
lost_record_sample.o: lost_record_sample.c
$(CC) $(CFLAGS) -c lost_record_sample.c


###

multiple_mmap_sizes: multiple_mmap_sizes.o \
parse_record.o \
../lib/test_utils.o \
../lib/perf_helpers.o \
../lib/instructions_testcode.o
$(CC) $(LFLAGS) -o multiple_mmap_sizes \
multiple_mmap_sizes.o \
parse_record.o \
../lib/test_utils.o \
../lib/perf_helpers.o \
../lib/instructions_testcode.o

multiple_mmap_sizes.o: multiple_mmap_sizes.c
$(CC) $(CFLAGS) -c multiple_mmap_sizes.c

###

print_record_sample: print_record_sample.o \
Expand Down Expand Up @@ -86,6 +105,7 @@ validate_record_sample.o: validate_record_sample.c
clean:
rm -f *~ *.o \
lost_record_sample \
multiple_mmap_sizes \
print_record_sample \
validate_record_sample

193 changes: 108 additions & 85 deletions record_sample/multiple_mmap_sizes.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* lost_record_sample.c */
/* multiple_mmap_sizes.c */
/* by Vince Weaver vincent.weaver _at_ maine.edu */

/* Try to overflow so that we get lost records */
/* Try to overflow a variety of mmap sizes */

/* There's been discussion of a possible kernel bug in the */
/* pages=1 case? */

#define _GNU_SOURCE 1

Expand Down Expand Up @@ -30,7 +33,8 @@
#include "parse_record.h"

#define SAMPLE_FREQUENCY 10000
#define MMAP_DATA_SIZE 1

int mmap_data_size;

int sample_type=PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_TIME |
PERF_SAMPLE_ADDR | PERF_SAMPLE_READ | PERF_SAMPLE_CALLCHAIN |
Expand Down Expand Up @@ -65,10 +69,10 @@ static void our_handler(int signum,siginfo_t *oh, void *blah) {

ret=ioctl(fd1, PERF_EVENT_IOC_DISABLE, 0);

if (num_oflos%100==0)
prev_head=perf_mmap_read(our_mmap,MMAP_DATA_SIZE,prev_head,
sample_type,read_format,NULL,0);

if (num_oflos%100==0) {
prev_head=perf_mmap_read(our_mmap,mmap_data_size,prev_head,
sample_type,read_format,NULL,0);
}
num_oflos++;

switch(oh->si_code) {
Expand All @@ -86,115 +90,134 @@ static void our_handler(int signum,siginfo_t *oh, void *blah) {
ret=ioctl(fd1, PERF_EVENT_IOC_REFRESH, 1);

(void) ret;

}


int main(int argc, char** argv) {

int ret,quiet;
int mmap_pages=1+MMAP_DATA_SIZE;
int mmap_pages;

struct perf_event_attr pe;

struct sigaction sa;
char test_string[]="Checking behavior on mmap overflow...";
char test_string[]="Checking behavior of various mmap sizes...";

quiet=test_quiet();

if (!quiet) printf("This checks behavior on mmap buffer being full.\n");
if (!quiet) printf("This checks a variety of mmap buffer sizes.\n");

/* set up validation */
validate.pid=getpid();
validate.tid=mygettid();
validate.events=2;

memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction = our_handler;
sa.sa_flags = SA_SIGINFO;
for(mmap_pages=0;mmap_pages<18;mmap_pages++) {

if (sigaction( SIGIO, &sa, NULL) < 0) {
fprintf(stderr,"Error setting up signal handler\n");
exit(1);
}

memset(&pe,0,sizeof(struct perf_event_attr));

pe.type=PERF_TYPE_HARDWARE;
pe.size=sizeof(struct perf_event_attr);
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.sample_period=SAMPLE_FREQUENCY;
pe.sample_type=sample_type;

pe.read_format=read_format;
pe.disabled=1;
pe.pinned=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;
pe.wakeup_events=1;

arch_adjust_domain(&pe,quiet);

fd1=perf_event_open(&pe,0,-1,-1,0);
if (fd1<0) {
if (!quiet) fprintf(stderr,"Error opening leader %llx\n",pe.config);
test_fail(test_string);
}
if (!quiet) {
printf("Testing with %d mmap pages\n",mmap_pages);
}

memset(&pe,0,sizeof(struct perf_event_attr));
if (mmap_pages>0) {
mmap_data_size=mmap_pages-1;
}
else {
mmap_data_size=0;
}

pe.type=PERF_TYPE_HARDWARE;
pe.size=sizeof(struct perf_event_attr);
pe.config=PERF_COUNT_HW_CPU_CYCLES;
pe.sample_type=PERF_SAMPLE_IP;
pe.read_format=PERF_FORMAT_GROUP|PERF_FORMAT_ID;
pe.disabled=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction = our_handler;
sa.sa_flags = SA_SIGINFO;

arch_adjust_domain(&pe,quiet);
if (sigaction( SIGIO, &sa, NULL) < 0) {
fprintf(stderr,"Error setting up signal handler\n");
exit(1);
}

fd2=perf_event_open(&pe,0,-1,fd1,0);
if (fd2<0) {
if (!quiet) fprintf(stderr,"Error opening %llx\n",pe.config);
test_fail(test_string);
}
memset(&pe,0,sizeof(struct perf_event_attr));

our_mmap=mmap(NULL, mmap_pages*4096,
PROT_READ|PROT_WRITE, MAP_SHARED, fd1, 0);
pe.type=PERF_TYPE_HARDWARE;
pe.size=sizeof(struct perf_event_attr);
pe.config=PERF_COUNT_HW_INSTRUCTIONS;
pe.sample_period=SAMPLE_FREQUENCY;
pe.sample_type=sample_type;


fcntl(fd1, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC);
fcntl(fd1, F_SETSIG, SIGIO);
fcntl(fd1, F_SETOWN,getpid());

ioctl(fd1, PERF_EVENT_IOC_RESET, 0);
pe.read_format=read_format;
pe.disabled=1;
pe.pinned=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;
pe.wakeup_events=1;

ret=ioctl(fd1, PERF_EVENT_IOC_ENABLE,0);
arch_adjust_domain(&pe,quiet);

if (ret<0) {
if (!quiet) {
fprintf(stderr,"Error with PERF_EVENT_IOC_ENABLE of group leader: "
"%d %s\n",errno,strerror(errno));
}
exit(1);
}
fd1=perf_event_open(&pe,0,-1,-1,0);
if (fd1<0) {
if (!quiet) fprintf(stderr,"Error opening leader %llx\n",pe.config);
test_fail(test_string);
}

instructions_million();

ret=ioctl(fd1, PERF_EVENT_IOC_REFRESH,0);
memset(&pe,0,sizeof(struct perf_event_attr));

if (count.total==0) {
if (!quiet) printf("No overflow events generated.\n");
test_fail(test_string);
}
pe.type=PERF_TYPE_HARDWARE;
pe.size=sizeof(struct perf_event_attr);
pe.config=PERF_COUNT_HW_CPU_CYCLES;
pe.sample_type=PERF_SAMPLE_IP;
pe.read_format=PERF_FORMAT_GROUP|PERF_FORMAT_ID;
pe.disabled=0;
pe.exclude_kernel=1;
pe.exclude_hv=1;

arch_adjust_domain(&pe,quiet);

munmap(our_mmap,mmap_pages*4096);
fd2=perf_event_open(&pe,0,-1,fd1,0);
if (fd2<0) {
if (!quiet) fprintf(stderr,"Error opening %llx\n",pe.config);
test_fail(test_string);
}

close(fd2);
close(fd1);
our_mmap=mmap(NULL, mmap_pages*4096,
PROT_READ|PROT_WRITE, MAP_SHARED, fd1, 0);

if (our_mmap == MAP_FAILED) {
if (!quiet) printf("\tmmap failed: %d %s\n",errno,strerror(errno));
continue;
}

fcntl(fd1, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC);
fcntl(fd1, F_SETSIG, SIGIO);
fcntl(fd1, F_SETOWN,getpid());

ioctl(fd1, PERF_EVENT_IOC_RESET, 0);

ret=ioctl(fd1, PERF_EVENT_IOC_ENABLE,0);

if (ret<0) {
if (!quiet) {
fprintf(stderr,
"Error with PERF_EVENT_IOC_ENABLE of group leader: "
"%d %s\n",errno,strerror(errno));
}
exit(1);
}

instructions_million();

ret=ioctl(fd1, PERF_EVENT_IOC_REFRESH,0);

if (count.total==0) {
if (!quiet) printf("No overflow events generated.\n");
test_fail(test_string);
}

munmap(our_mmap,mmap_pages*4096);

close(fd2);
close(fd1);
}

test_pass(test_string);

return 0;
}
11 changes: 7 additions & 4 deletions record_sample/parse_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ static int handle_struct_read_format(unsigned char *sample,
return offset;
}

long long perf_mmap_read( void *our_mmap, int mmap_size, long long prev_head,
int sample_type, int read_format,
long long perf_mmap_read( void *our_mmap, int mmap_size,
long long prev_head,
int sample_type, int read_format,
struct validate_values *validate,
int quiet ) {

Expand All @@ -118,18 +119,20 @@ long long perf_mmap_read( void *our_mmap, int mmap_size, long long prev_head,

void *data_mmap=our_mmap+getpagesize();

if (mmap_size==0) return 0;

if (control_page==NULL) {
fprintf(stderr,"ERROR mmap page NULL\n");
return -1;
}

head=control_page->data_head;
rmb(); /* Must always follow read of data_head */

size=head-prev_head;

//printf("Head: %lld Prev_head=%lld\n",head,prev_head);
//printf("%d new bytes\n",size);
//printf("%d new bytes\n",size);

bytesize=mmap_size*getpagesize();

Expand Down

0 comments on commit 3bd2df3

Please sign in to comment.