int main(int argc, char** argv) { int ret,quiet,i,matches=0; struct perf_event_attr pe; struct sigaction sa; void *our_mmap; char test_string[]="Testing simultaneous one-shot group overflow..."; /* Initialize overflow counts */ for(i=0;i<NUM_EVENTS;i++) { events[i].fd=-1; events[i].overflows=0; } quiet=test_quiet(); /*********************************************************************/ if (!quiet) { printf("This tests simultaneous overflow within " "group in one-shot mode.\n"); } /*********************************************************************/ /*****************************/ /* set up our signal handler */ /*****************************/ memset(&sa, 0, sizeof(struct sigaction)); sa.sa_sigaction = our_handler; sa.sa_flags = SA_SIGINFO; if (sigaction( SIGRTMIN+2, &sa, NULL) < 0) { fprintf(stderr,"Error setting up signal handler\n"); test_fail(test_string); } /***********************/ /* get expected counts */ /***********************/ if (!quiet) { printf("*** Testing running one at a time\n"); } for(i=0;i<NUM_EVENTS;i++) { memset(&pe,0,sizeof(struct perf_event_attr)); pe.type=event_values[i].type; pe.size=sizeof(struct perf_event_attr); pe.config=event_values[i].config; pe.sample_period=event_values[i].period; pe.sample_type=0; pe.read_format=PERF_FORMAT_GROUP; pe.disabled=1; pe.pinned=0; pe.exclude_kernel=1; pe.exclude_hv=1; pe.wakeup_events=1; arch_adjust_domain(&pe,quiet); events[i].fd=perf_event_open(&pe,0,-1,-1,0); if (events[i].fd<0) { fprintf(stderr,"Error opening leader %llx\n",pe.config); test_fail(test_string); } /* on older kernels you need this even if you don't use it */ our_mmap=mmap(NULL, (1+MMAP_PAGES)*getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, events[i].fd, 0); fcntl(events[i].fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC); fcntl(events[i].fd, F_SETSIG, SIGRTMIN+2); fcntl(events[i].fd, F_SETOWN,getpid()); ioctl(events[i].fd, PERF_EVENT_IOC_RESET, 0); if (!quiet) { //printf("Testing matrix matrix multiply\n"); printf("\tEvent %s with period %d\n", event_values[i].name, event_values[i].period); } ret=ioctl(events[i].fd, PERF_EVENT_IOC_REFRESH,1); if (!quiet) printf("\t\t"); naive_matrix_multiply(quiet); ret=ioctl(events[i].fd, PERF_EVENT_IOC_DISABLE,0); if (!quiet) { printf("\t\tfd %d overflows: %d (%s/%d)\n", events[i].fd,events[i].overflows, event_values[i].name, event_values[i].period); } if (events[i].overflows==0) { if (!quiet) printf("No overflow events generated.\n"); test_fail(test_string); } close(events[i].fd); events[i].individual_overflow=events[i].overflows; events[i].overflows=0; events[i].fd=-1; } /************************************************/ /* test when both events enabled in group */ /************************************************/ if (!quiet) { printf("*** Testing with multiple events at once\n"); for(i=0;i<NUM_EVENTS;i++) { printf("\tEvent %s with period %d\n", event_values[i].name, event_values[i].period); } } for(i=0;i<NUM_EVENTS;i++) { memset(&pe,0,sizeof(struct perf_event_attr)); pe.type=event_values[i].type; pe.size=sizeof(struct perf_event_attr); pe.config=event_values[i].config; pe.sample_period=event_values[i].period; pe.sample_type=0; pe.read_format=PERF_FORMAT_GROUP; pe.disabled=(i==0)?1:0; /* Note: pinning the group leader is what */ /* caused the bug in 4.11-rc1 */ pe.pinned=(i==0)?1:0; pe.exclude_kernel=1; pe.exclude_hv=1; pe.wakeup_events=1; arch_adjust_domain(&pe,quiet); events[i].fd=perf_event_open(&pe,0,-1,(i==0)?-1:events[0].fd,0); if (events[i].fd<0) { fprintf(stderr,"Error opening leader %llx\n",pe.config); test_fail(test_string); } /* on older kernels you need this even if you don't use it */ our_mmap=mmap(NULL, (1+MMAP_PAGES)*getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, events[i].fd, 0); fcntl(events[i].fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC); fcntl(events[i].fd, F_SETSIG, SIGRTMIN+2); fcntl(events[i].fd, F_SETOWN,getpid()); ioctl(events[i].fd, PERF_EVENT_IOC_RESET, 0); } ret=ioctl(events[0].fd, PERF_EVENT_IOC_REFRESH,1); if (ret<0) { if (!quiet) { fprintf(stderr,"Error with PERF_EVENT_IOC_REFRESH " "of group leader: %d %s\n", errno,strerror(errno)); } test_fail(test_string); } if (!quiet) printf("\t\t"); naive_matrix_multiply(quiet); ret=ioctl(events[0].fd, PERF_EVENT_IOC_DISABLE,0); for(i=0;i<NUM_EVENTS;i++) { if (!quiet) { printf("\t\tfd %d overflows: %d (%s/%d)\n", events[i].fd,events[i].overflows, event_values[i].name,event_values[i].period); } } int result; long long values[1+1*NUM_EVENTS],counts[NUM_EVENTS]; /* Read the results, complain if too few bytes read */ result=read(events[0].fd,&values,8*(1+1*NUM_EVENTS)); if (result!=8*(1+1*NUM_EVENTS)) { if (!quiet) printf("error reading\n"); test_fail(test_string); } /* Complain if the number of events field does not match expected */ if (values[0]!=NUM_EVENTS) { if (!quiet) printf("error reading\n"); test_fail(test_string); } if (!quiet) printf("\tEnding counts:\n"); for(i=0;i<NUM_EVENTS;i++) { counts[i]=values[i+1]; if (!quiet) printf("\t\tCount %d: %lld\n",i,counts[i]); } /* Complain if no overflows at all */ for(i=0;i<NUM_EVENTS;i++) { if (events[i].overflows==0) { if (!quiet) printf("No overflow events generated.\n"); test_fail(test_string); } } for(i=0;i<NUM_EVENTS;i++) { close(events[i].fd); } /* test validity */ for(i=0;i<NUM_EVENTS;i++) { if (!quiet) { printf("Event %s/%d Expected %lld Got %d\n", event_values[i].name, event_values[i].period, counts[i]/event_values[i].period, events[i].overflows); } if (counts[i]/event_values[i].period!=events[i].overflows) { /* Problem! */ } else { matches++; } } /* Counts will be slightly different because they will count */ /* while signal handler running. */ double error; error=(double)counts[0]-(double)counts[1]; error/=(double)counts[0]; error*=100.0; if ((error > 1.0) || (error < -1.0)) { if (!quiet) { fprintf(stderr,"Counts should be roughly the same " "but found %lf%% error\n",error); } test_fail(test_string); } if (matches!=NUM_EVENTS) { if (!quiet) fprintf(stderr,"Unexpected event count!\n"); test_fail(test_string); } test_pass(test_string); (void)our_mmap; return 0; }
int main(int argc, char **argv) { int ret; int fd; int result,precise_ip; int mmap_pages=1+MMAP_DATA_SIZE; struct perf_event_attr pe; struct sigaction sa; char test_string[]="Testing PERF_SAMPLE_WEIGHT..."; char event_name[BUFSIZ]; quiet=test_quiet(); if (!quiet) printf("This tests PERF_SAMPLE_WEIGHT samples\n"); memset(&sa, 0, sizeof(struct sigaction)); sa.sa_sigaction = our_handler; sa.sa_flags = SA_SIGINFO; if (sigaction( SIGIO, &sa, NULL) < 0) { fprintf(stderr,"Error setting up signal handler\n"); exit(1); } /* Set up Proper Event */ memset(&pe,0,sizeof(struct perf_event_attr)); result=get_latency_load_event(&pe.config,&pe.config1, &precise_ip,event_name); if (result<0) { if (!quiet) fprintf(stderr,"No load latency event available, trying instructions (probably will return 0)\n"); pe.type=PERF_TYPE_HARDWARE; pe.config=PERF_COUNT_HW_INSTRUCTIONS; } else { pe.type=PERF_TYPE_RAW; if (!quiet) printf("Using event %s\n",event_name); } pe.size=sizeof(struct perf_event_attr); pe.precise_ip=precise_ip; pe.sample_period=SAMPLE_FREQUENCY; pe.sample_type=PERF_SAMPLE_IP | PERF_SAMPLE_WEIGHT; global_sample_type=pe.sample_type; pe.read_format=0; pe.disabled=1; pe.pinned=1; pe.exclude_kernel=1; pe.exclude_hv=1; pe.wakeup_events=1; arch_adjust_domain(&pe,quiet); fd=perf_event_open(&pe,0,-1,-1,0); if (fd<0) { if (!quiet) { fprintf(stderr,"Problem opening leader %s\n", strerror(errno)); test_fail(test_string); } } our_mmap=mmap(NULL, mmap_pages*4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); fcntl(fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC); fcntl(fd, F_SETSIG, SIGIO); fcntl(fd, F_SETOWN,getpid()); ioctl(fd, PERF_EVENT_IOC_RESET, 0); ret=ioctl(fd, 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); } } naive_matrix_multiply(quiet); // instructions_million(); ret=ioctl(fd, PERF_EVENT_IOC_REFRESH,0); if (!quiet) { printf("Counts %d, using mmap buffer %p\n",count_total,our_mmap); } if (count_total==0) { if (!quiet) printf("No overflow events generated.\n"); test_fail(test_string); } munmap(our_mmap,mmap_pages*4096); close(fd); test_pass(test_string); return 0; }
int main(int argc, char **argv) { double error; int i,fd_insts,fd_cycles,read_result; long long cycles_count, insts_count; float IPC; struct timespec before,after; long long nsecs; struct perf_event_attr pe; int ppr; if (argc < 2) ppr = 4; else ppr = atoi(argv[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_CPU_CYCLES; pe.disabled=1; pe.exclude_kernel=1; pe.exclude_hv=1; fd_cycles=perf_event_open(&pe,0,-1,-1,0); if (fd_cycles<0) { fprintf(stderr,"Error opening leader %llx\n",pe.config); } pe.type=PERF_TYPE_HW_CACHE; pe.config=PERF_COUNT_HW_CACHE_L1D; //pe.config=PERF_COUNT_HW_INSTRUCTIONS; fd_insts=perf_event_open(&pe,0,-1,fd_cycles,0); if (fd_cycles<0) { fprintf(stderr,"Error opening event %llx\n",pe.config); } ioctl(fd_cycles, PERF_EVENT_IOC_ENABLE,0); ioctl(fd_insts, PERF_EVENT_IOC_ENABLE,0); for(i=0;i<SLEEP_RUNS;i++) { ioctl(fd_cycles, PERF_EVENT_IOC_RESET, 0); ioctl(fd_insts, PERF_EVENT_IOC_RESET, 0); set_ppr(ppr); //sleep(1); clock_gettime(CLOCK_REALTIME,&before); naive_matrix_multiply(1); clock_gettime(CLOCK_REALTIME,&after); //ioctl(fd_cycles, PERF_EVENT_IOC_DISABLE,0); //ioctl(fd_insts, PERF_EVENT_IOC_DISABLE,0); read_result=read(fd_cycles,&cycles_count,sizeof(long long)); read_result=read(fd_insts,&insts_count,sizeof(long long)); IPC = (float) insts_count / cycles_count; nsecs=convert_to_ns(&before,&after); printf("[Run %d] CYL: %lld INS: %lld IPC: %f PPR: %d Time: %lld\n", i, cycles_count, insts_count, IPC, get_ppr(), nsecs); } return 0; }
int main(int argc, char **argv) { int ret; int fd; int mmap_pages=1+MMAP_DATA_SIZE; struct perf_event_attr pe; struct sigaction sa; char test_string[]="Testing Intel Branch Trace Store..."; quiet=test_quiet(); if (!quiet) printf("This tests the intel BTS driver.\n"); memset(&sa, 0, sizeof(struct sigaction)); sa.sa_sigaction = our_handler; sa.sa_flags = SA_SIGINFO; if (sigaction( SIGIO, &sa, NULL) < 0) { fprintf(stderr,"Error setting up signal handler\n"); exit(1); } /* Find the BTS driver */ FILE *fff; int bts_type=0; fff=fopen("/sys/devices/intel_bts/type","r"); if (fff==NULL) { if (!quiet) { fprintf(stderr,"Intel BTS driver not found\n"); } test_skip(test_string); } fscanf(fff,"%d",&bts_type); fclose(fff); if (!quiet) { fprintf(stdout,"Found Intel BTS as type %d\n",bts_type); } /* Set up BTS Event */ memset(&pe,0,sizeof(struct perf_event_attr)); pe.size=sizeof(struct perf_event_attr); pe.type=bts_type; pe.disabled=1; // pe.exclude_kernel=1; // pe.exclude_user=1; /* pe.config not necessary? */ // sample_type=PERF_SAMPLE_IP|PERF_SAMPLE_WEIGHT|PERF_SAMPLE_ADDR; // read_format=0; // pe.sample_period=SAMPLE_FREQUENCY; // pe.sample_type=sample_type; // pe.read_format=read_format; // pe.pinned=1; // pe.exclude_hv=1; // pe.wakeup_events=1; // pe.precise_ip=1; arch_adjust_domain(&pe,quiet); fd=perf_event_open(&pe,0,-1,-1,0); if (fd<0) { if (!quiet) { fprintf(stderr,"Problem opening leader %s\n", strerror(errno)); test_fail(test_string); } } /* Setup normal mmap page */ our_mmap=mmap(NULL, mmap_pages*4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); struct perf_event_mmap_page *mmap_control; mmap_control = (struct perf_event_mmap_page *)our_mmap; mmap_control->aux_offset=mmap_pages*4096; mmap_control->aux_size=AUX_DATA_SIZE*4096; /* Setup aux mmap page */ our_aux=mmap(NULL, mmap_control->aux_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, mmap_control->aux_offset); fcntl(fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC); fcntl(fd, F_SETSIG, SIGIO); fcntl(fd, F_SETOWN,getpid()); ioctl(fd, PERF_EVENT_IOC_RESET, 0); ret=ioctl(fd, 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); } } naive_matrix_multiply(quiet); ret=ioctl(fd, PERF_EVENT_IOC_DISABLE,0); printf("After, aux_head=%llx aux_tail=%llx\n", mmap_control->aux_head,mmap_control->aux_tail); /* Attempt to parse */ memcpy(bts_buffer,our_aux,mmap_control->aux_head); int i; for(i=0;i< (mmap_control->aux_head/sizeof(struct bts_record));i++) { printf("From: %llx To: %llx Predicted: %d\n", bts_buffer[i].branch_from, bts_buffer[i].branch_to, !!(bts_buffer[i].predicted&0x10)); } printf("\n"); /* Clean up */ munmap(our_aux,AUX_DATA_SIZE*4096); munmap(our_mmap,mmap_pages*4096); close(fd); test_pass(test_string); return 0; }
int main(int argc, char **argv) { struct perf_event_attr pe; int i, group_fd = -1, fd[2]; for (i = 0; i < 2; i++) { memset(&pe, 0, sizeof(struct perf_event_attr)); pe.type = PMU_PERF_TYPE; pe.size = sizeof(struct perf_event_attr); pe.config = PMU_COUNETERS_LIST[i]; pe.disabled = 1; pe.exclude_kernel = 1; pe.exclude_hv = 1; fd[i] = perf_event_open(&pe, 0, -1, group_fd, 0); if (fd < 0) { fprintf(stderr, "Error opening %llu\n", (long long unsigned) pe.config); exit(1); } ioctl(fd[i], PERF_EVENT_IOC_ENABLE, 0); if (group_fd == -1) group_fd = fd[i]; } //pmu_ppr_open(fd[0], fd[1], 2000); printf("syscall %d\n", __NR_pmu_ppr_open); naive_matrix_multiply(1); sleep(1); __u64 counts[2]; read(fd[0], &counts[0], sizeof(__u64)); read(fd[1], &counts[1], sizeof(__u64)); printf("%ld %ld\n", counts[0], counts[1]); /* printf("char %ld\n", sizeof(char) ); printf("int %ld\n", sizeof(int) ); printf("long %ld\n", sizeof(long) ); printf("long long %ld\n", sizeof(long long) ); printf("long int %ld\n", sizeof(long int) ); printf("char * %ld\n", sizeof(char *) ); printf("int * %ld\n", sizeof(int *) ); printf("long * %ld\n", sizeof(long *) ); printf("long long * %ld\n", sizeof(long long*) ); printf("long int * %ld\n", sizeof(long int*) ); printf("void * %ld\n", sizeof(void *) ); */ return 0; }
int main(int argc, char **argv) { int retval,quiet; const PAPI_hw_info_t *info; int events[2]; long long counts[2]; double error; long long expected; char test_string[]="Testing core2_constraints..."; quiet=test_quiet(); retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { if (!quiet) printf("ERROR: PAPI_library_init %d\n", retval); test_fail(test_string); } if ( (info=PAPI_get_hardware_info())==NULL) { if (!quiet) printf("cannot obtain hardware info %d\n",retval); test_fail(test_string); } if ((info->vendor==PAPI_VENDOR_INTEL) && (info->cpuid_family==6) && ((info->cpuid_model==15) || (info->cpuid_model==23) || (info->cpuid_model==29))) { if (!quiet) printf("Found core2!\n"); } else { if (!quiet) printf("Not a core2.\n"); test_skip(test_string); } expected=naive_matrix_multiply_estimated_flops(quiet); retval=PAPI_event_name_to_code("FP_COMP_OPS_EXE",&events[0]); if (retval!=PAPI_OK) { if (!quiet) printf("PAPI_event_name_to_code %d\n", retval); test_fail(test_string); } events[1]=PAPI_TOT_INS; PAPI_start_counters(events,2); naive_matrix_multiply(quiet); PAPI_stop_counters(counts,2); error=(((double)counts[0]-(double)expected)/(double)expected)*100.0; if (!quiet) printf(" Expected: %lld Actual: %lld Error: %.2lf\n", expected, counts[0],error); if (error > 1.0) { if (!quiet) printf("FP error higher than expected\n"); test_fail(test_string); } /* set FP_COMP_OPS_EXE to be in slot 2 */ retval=PAPI_event_name_to_code("FP_COMP_OPS_EXE",&events[1]); if (retval!=PAPI_OK) { if (!quiet) printf("PAPI_event_name_to_code %d\n",retval); test_fail(test_string); } events[0]=events[1]; PAPI_start_counters(events,2); naive_matrix_multiply(quiet); PAPI_stop_counters(counts,2); error=(((double)counts[1]-(double)expected)/(double)expected)*100.0; if (!quiet) printf(" Expected: %lld Actual: %lld Error: %.2lf\n", expected, counts[1],error); if (error > 1.0) { if (!quiet) printf("FP error higher than expected\n"); test_fail(test_string); } PAPI_shutdown(); test_pass(test_string); return 0; }
int main(int argc, char **argv) { int ret,quiet,cpu; struct perf_event_attr pe; int fd1,fd2; long long counts[2]; long long events[2]; events[0]=0; events[1]=0; quiet=test_quiet(); cpu=detect_processor(); if (cpu==PROCESSOR_NEHALEM) { if (!quiet) printf("Found Nehalem!\n"); /* try OFFCORE_RESPONSE_0:DMND_DATA_RD:LOCAL_DRAM */ /* libpfm4 reports 0x5301b7 0x4001 */ events[0]=0x5301b7; events[1]=0x4001; } else if (cpu==PROCESSOR_WESTMERE) { if (!quiet) printf("Found Westmere!\n"); /* try OFFCORE_RESPONSE_0:DMND_DATA_RD:LOCAL_DRAM */ /* libpfm4 reports 0x5301b7 0x4001 */ events[0]=0x5301b7; events[1]=0x4001; } else if (cpu==PROCESSOR_SANDYBRIDGE) { if (!quiet) printf("Found Sandybridge!\n"); /* try OFFCORE_RESPONSE_0:DMND_DATA_RD:ANY_RESPONSE */ /* libpfm4 reports 0x5301b7 0x10001 */ events[0]=0x5301b7; events[1]=0x10001; } else if (cpu==PROCESSOR_SANDYBRIDGE_EP) { if (!quiet) printf("Found Sandybridge EP!\n"); /* try OFFCORE_RESPONSE_0:DMND_DATA_RD:ANY_RESPONSE */ /* libpfm4 reports 0x5301b7 0x10001 */ events[0]=0x5301b7; events[1]=0x10001; } else if (cpu==PROCESSOR_IVYBRIDGE) { if (!quiet) printf("Found IvyBridge!\n"); /* try OFFCORE_RESPONSE_0:DMND_DATA_RD:ANY_RESPONSE */ /* libpfm4 reports 0x5301b7 0x10001 */ events[0]=0x5301b7; events[1]=0x10001; } else if (cpu==PROCESSOR_NEHALEM_EX) { if (!quiet) printf("Found Nehalem EX!\n"); /* try OFFCORE_RESPONSE_0:DMND_DATA_RD:LOCAL_DRAM */ /* libpfm4 reports 0x5301b7 0x4001 */ events[0]=0x5301b7; events[1]=0x4001; } else if (cpu==PROCESSOR_WESTMERE_EX) { if (!quiet) printf("Found Westmere EX!\n"); /* try OFFCORE_RESPONSE_0:DMND_DATA_RD:LOCAL_DRAM */ /* libpfm4 reports 0x5301b7 0x4001 */ events[0]=0x5301b7; events[1]=0x4001; } else if (cpu==PROCESSOR_HASWELL) { if (!quiet) printf("Found Haswell!\n"); /* try OFFCORE_RESPONSE_0:DMND_DATA_RD:ANY_RESPONSE */ /* libpfm4 reports 0x5301b7 0x10001 */ events[0]=0x5301b7; events[1]=0x10001; } else { if (!quiet) printf("No known offcore response hardware\n"); test_skip(test_string); } /* Try to measure */ /* a cpu-specific offcore event */ /* as well as PAPI_TOT_INS; */ 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.disabled=1; pe.exclude_kernel=1; pe.exclude_hv=1; fd1=perf_event_open(&pe,0,-1,-1,0); if (fd1<0) { fprintf(stderr,"Error opening leader %llx\n",pe.config); test_fail(test_string); } memset(&pe,0,sizeof(struct perf_event_attr)); pe.size=sizeof(struct perf_event_attr); pe.type=PERF_TYPE_RAW; pe.config=events[0]; pe.config1=events[1]; pe.exclude_kernel=1; pe.exclude_hv=1; fd2=perf_event_open(&pe,0,-1,fd1,0); if (fd2<0) { fprintf(stderr,"Error opening %llx\n",pe.config); test_fail(test_string); } ioctl(fd1, PERF_EVENT_IOC_RESET, 0); ioctl(fd2, PERF_EVENT_IOC_RESET, 0); ret=ioctl(fd1, PERF_EVENT_IOC_ENABLE,0); if (ret<0) { if (!quiet) fprintf(stderr,"Error enabling events\n"); test_fail(test_string); } naive_matrix_multiply(quiet); ret=ioctl(fd1, PERF_EVENT_IOC_DISABLE,0); if (ret<0) { if (!quiet) fprintf(stderr,"Error disabling events\n"); test_fail(test_string); } if (!quiet) printf("Config1 after: %llx\n",pe.config1); ret=read(fd1,&counts[0],sizeof(long long)); if (ret!=sizeof(long long)) { if (!quiet) fprintf(stderr,"Unepxected result from read fd1: %d\n",ret); test_fail(test_string); } ret=read(fd2,&counts[1],sizeof(long long)); if (ret!=sizeof(long long)) { if (!quiet) fprintf(stderr,"Unepxected result from read fd2: %d\n",ret); test_fail(test_string); } if (!quiet) { printf("Retired instructions: %lld\n",counts[0]); } if (counts[0]<1) { fprintf(stderr,"Retired instruction count too low\n"); test_fail(test_string); } if (!quiet) { printf("Offcore response count: %lld\n",counts[1]); } if (counts[1]<1) { if (!quiet) fprintf(stderr,"Offcore response count too low\n"); test_fail(test_string); } test_pass( test_string ); return 0; }
int main(int argc, char **argv) { int ret; int fd; int mmap_pages=1+MMAP_DATA_SIZE; FILE *fff; struct perf_event_attr pe; struct sigaction sa; char test_string[]="Testing AMD IBS fetch samples..."; quiet=test_quiet(); if (!quiet) printf("This tests AMD IBS...\n"); /* TODO: detect we have AMD CPU */ /* Set up signal handler */ memset(&sa, 0, sizeof(struct sigaction)); sa.sa_sigaction = our_handler; sa.sa_flags = SA_SIGINFO; if (sigaction( SIGIO, &sa, NULL) < 0) { fprintf(stderr,"Error setting up signal handler\n"); exit(1); } /* Set up Event */ memset(&pe,0,sizeof(struct perf_event_attr)); sample_type=PERF_SAMPLE_IP | PERF_SAMPLE_WEIGHT | PERF_SAMPLE_ADDR | PERF_SAMPLE_RAW; read_format=0; pe.size=sizeof(struct perf_event_attr); /* Use a proper event */ /* ./perf record -a -e ibs_fetch/rand_en=1/GH /bin/ls */ fff=fopen("/sys/devices/ibs_fetch/type","r"); if (fff==NULL) { fprintf(stderr,"Could not open ibs_fetch PMU\n"); exit(1); } fscanf(fff,"%d",&pe.type); fclose(fff); /************************************************/ /* Set up the event */ /************************************************/ /* See BKDG MSRC001_1030 IBS Fetch Control (IC_IBS_CTL) */ /* Writable fields */ /* 57 = IbsRandEn */ /* 48 = IbsFetchEn */ /* 31:16 = IbsFetchCnt (updated by hardware) */ /* 15:0 = IbsFetchMaxCnt. Shifted left by 4 */ /* ibs_fetch/rand_en=1 */ pe.config = 0x200000000000000ULL; 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; // pe.precise_ip=1; arch_adjust_domain(&pe,quiet); fd=perf_event_open(&pe,-1,0,-1,0); if (fd<0) { if (!quiet) { fprintf(stderr,"Problem opening leader %s\n", strerror(errno)); test_fail(test_string); } } our_mmap=mmap(NULL, mmap_pages*4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); fcntl(fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC); fcntl(fd, F_SETSIG, SIGIO); fcntl(fd, F_SETOWN,getpid()); ioctl(fd, PERF_EVENT_IOC_RESET, 0); ret=ioctl(fd, 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); } } naive_matrix_multiply(quiet); ret=ioctl(fd, PERF_EVENT_IOC_REFRESH,0); if (!quiet) { printf("Counts %d, using mmap buffer %p\n",count_total,our_mmap); } if (count_total==0) { if (!quiet) printf("No overflow events generated.\n"); test_fail(test_string); } munmap(our_mmap,mmap_pages*4096); close(fd); test_pass(test_string); return 0; }
int main(int argc, char **argv) { int retval,quiet; double mhz,mmm_mhz; const PAPI_hw_info_t *info; double error; int i; int events[1]; long long counts[1],high=0,low=0,total=0,average=0; long long total_usecs,usecs,usec_start,usec_end; long long mmm_count; long long expected; char test_string[]="Testing PAPI_TOT_CYC predefined event..."; quiet=test_quiet(); retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) { if (!quiet) printf("PAPI_library_init %d\n", retval); test_fail(test_string); } retval = PAPI_query_event(PAPI_TOT_CYC); if (retval != PAPI_OK) { if (!quiet) printf("PAPI_TOT_CYC not supported\n"); test_skip(test_string); } if (!quiet) printf("\n"); if ( (info=PAPI_get_hardware_info())==NULL) { if (!quiet) printf("Error! cannot obtain hardware info\n"); test_fail(test_string); } mhz=info->mhz; if (!quiet) printf("System MHZ reported by PAPI = %f\n\n",mhz); events[0]=PAPI_TOT_CYC; if (!quiet) printf("Testing a sleep of 1 second (%d times):\n", SLEEP_RUNS); for(i=0;i<SLEEP_RUNS;i++) { PAPI_start_counters(events,1); sleep(1); PAPI_stop_counters(counts,1); if (counts[0]>high) high=counts[0]; if ((low==0) || (counts[0]<low)) low=counts[0]; total+=counts[0]; } average=total/SLEEP_RUNS; if (!quiet) { printf("\tAverage should be low, as no user cycles when sleeping\n"); printf("\tMeasured average: %lld\n",average); } if (average>1000000) { if (!quiet) printf("Average cycle count too high!\n"); test_fail(test_string); } /*****************************/ /* testing Matrix Matrix MHz */ /*****************************/ if (!quiet) printf("\nTesting MHz with matrix matrix multiply\n"); total_usecs=0; usec_start=PAPI_get_real_usec(); PAPI_start_counters(events,1); naive_matrix_multiply(quiet); PAPI_stop_counters(counts,1); usec_end=PAPI_get_real_usec(); usecs=usec_end-usec_start; expected=(long long)(mhz*usecs); if (!quiet) { printf("\tExpected cycles = %.2lfMHz * %lld usecs = %lld\n", mhz,usecs,expected); printf("\tActual measured cycles = %lld\n",counts[0]); printf("\tEstimated actual MHz = %.2lfMHz\n", (double)counts[0]/(double)usecs); } error= 100.0 * (double)(counts[0]-expected) / (double)expected; if ((error>10.0) || (error<-10.0)) { if (!quiet) printf("\tWarning: Error %.2lf%% too high!\n",error); } if (!quiet) printf("\n"); mmm_mhz=(double)counts[0]/(double)usecs; mmm_count=counts[0]; /* Linear Speedup */ if (!quiet) printf("Testing for a linear cycle increase\n"); #define REPITITIONS 2 usec_start=PAPI_get_real_usec(); PAPI_start_counters(events,1); for(i=0;i<REPITITIONS;i++) { naive_matrix_multiply(quiet); } PAPI_stop_counters(counts,1); usec_end=PAPI_get_real_usec(); usecs=usec_end-usec_start; expected=mmm_count*REPITITIONS; error= 100.0 * (double)(counts[0]-expected) / (double)expected; if (!quiet) { printf("\tExpected %lld, got %lld\n",expected,counts[0]); } if ((error>10.0) || (error<-10.0)) { if (!quiet) printf("Error too high!\n"); test_fail(test_string); } if (!quiet) printf("\n"); PAPI_shutdown(); test_pass(test_string); return 0; }