perf_event_uncore_cbox.c File Reference

Include dependency graph for perf_event_uncore_cbox.c:

Go to the source code of this file.

Defines

#define EVENTS_TO_TRY   16
#define MAX_PACKAGES   4

Functions

int main (int argc, char **argv)

Define Documentation

#define EVENTS_TO_TRY   16

Definition at line 9 of file perf_event_uncore_cbox.c.

#define MAX_PACKAGES   4

Definition at line 10 of file perf_event_uncore_cbox.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 12 of file perf_event_uncore_cbox.c.

00012                                   {
00013 
00014    int retval,i,j;
00015    int EventSet[EVENTS_TO_TRY][MAX_PACKAGES];
00016    long long values[EVENTS_TO_TRY][MAX_PACKAGES];
00017    char event_name[BUFSIZ];
00018    char uncore_base[BUFSIZ];
00019    char uncore_event[BUFSIZ];
00020    int uncore_cidx=-1;
00021    int max_cbox=0;
00022    int core_to_use=0;
00023 
00024    const PAPI_hw_info_t *hwinfo;
00025 
00026    /* Set TESTS_QUIET variable */
00027    tests_quiet( argc, argv );
00028 
00029    /* Init the PAPI library */
00030    retval = PAPI_library_init( PAPI_VER_CURRENT );
00031    if ( retval != PAPI_VER_CURRENT ) {
00032       test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00033    }
00034 
00035    /* Find the uncore PMU */
00036    uncore_cidx=PAPI_get_component_index("perf_event_uncore");
00037    if (uncore_cidx<0) {
00038       test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
00039    }
00040 
00041    /* Get hardware info */
00042    hwinfo = PAPI_get_hardware_info();
00043    if ( hwinfo == NULL ) {
00044         test_fail(__FILE__,__LINE__,"PAPI_get_hardware_info()",retval);
00045    }
00046 
00047    /* Get event to use */
00048    if (hwinfo->vendor == PAPI_VENDOR_INTEL) {
00049 
00050       if ( hwinfo->cpuid_family == 6) {
00051          switch(hwinfo->cpuid_model) {
00052            case 45: /* SandyBridge EP */
00053                     strncpy(event_name,"UNC_C_TOR_OCCUPANCY:ALL",BUFSIZ);
00054                     strncpy(uncore_base,"snbep_unc_cbo",BUFSIZ);
00055                     break;
00056            case 58: /* IvyBridge */
00057                     strncpy(event_name,"UNC_CBO_CACHE_LOOKUP:STATE_I:ANY_FILTER",BUFSIZ);
00058                     strncpy(uncore_base,"ivb_unc_cbo",BUFSIZ);
00059                     break;
00060            
00061            case 63: /* Haswell EP */
00062                     strncpy(event_name,"hswep_unc_cbo0::UNC_C_COUNTER0_OCCUPANCY",BUFSIZ);
00063                     strncpy(uncore_base,"hswep_unc_cbo0",BUFSIZ);
00064                     break;
00065       default:
00066                     test_skip( __FILE__, __LINE__,
00067                 "We only support IVB and SNB-EP for now", PAPI_ENOSUPP );
00068         }
00069       }
00070       else {
00071           test_skip( __FILE__, __LINE__,
00072                 "We only support IVB and SNB-EP for now", PAPI_ENOSUPP );
00073       }
00074    }
00075    else {
00076       test_skip( __FILE__, __LINE__,
00077                 "This test only supported Intel chips", PAPI_ENOSUPP );
00078 
00079    }
00080 
00081    if (!TESTS_QUIET) {
00082       printf("Trying for %d sockets\n",hwinfo->sockets);
00083       printf("threads %d cores %d ncpus %d\n", hwinfo->threads,hwinfo->cores,
00084           hwinfo->ncpu);
00085    }
00086 
00087    for(i=0;i < hwinfo->sockets; i++) {
00088 
00089       /* perf_event provides which to use in "cpumask"    */
00090       /* but libpfm4 doesn't report this back to us (yet) */
00091       core_to_use=i*hwinfo->threads*hwinfo->cores;
00092       if (!TESTS_QUIET) {
00093          printf("Using core %d for socket %d\n",core_to_use,i);
00094       }
00095 
00096       for(j=0;j<EVENTS_TO_TRY;j++) {
00097 
00098          /* Create an eventset */
00099          EventSet[j][i]=PAPI_NULL;
00100          retval = PAPI_create_eventset(&EventSet[j][i]);
00101          if (retval != PAPI_OK) {
00102             test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
00103          }
00104 
00105          /* Set a component for the EventSet */
00106          retval = PAPI_assign_eventset_component(EventSet[j][i], uncore_cidx);
00107          if (retval!=PAPI_OK) {
00108             test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component",retval);
00109          }
00110 
00111          /* we need to set to a certain cpu for uncore to work */
00112 
00113          PAPI_cpu_option_t cpu_opt;
00114 
00115          cpu_opt.eventset=EventSet[j][i];
00116          cpu_opt.cpu_num=core_to_use;
00117 
00118          retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
00119          if (retval != PAPI_OK) {
00120             test_skip( __FILE__, __LINE__,
00121               "this test; trying to PAPI_CPU_ATTACH; need to run as root",
00122               retval);
00123          }
00124 
00125          /* Default Granularity should work */
00126 
00127          /* Default domain should work */
00128 
00129          /* Add our uncore event */
00130      sprintf(uncore_event,"%s%d::%s",uncore_base,j,event_name);
00131          retval = PAPI_add_named_event(EventSet[j][i], uncore_event);
00132          if (retval != PAPI_OK) {
00133             max_cbox=j;
00134         break;
00135          }
00136      if (!TESTS_QUIET) printf("Added %s for socket %d\n",uncore_event,i);
00137 
00138      }
00139    }
00140 
00141 
00142    for(i=0;i < hwinfo->sockets; i++) {
00143       for(j=0;j<max_cbox;j++) {
00144          if (!TESTS_QUIET) printf("Starting EventSet %d\n",EventSet[j][i]);
00145          /* Start PAPI */
00146          retval = PAPI_start( EventSet[j][i] );
00147          if ( retval != PAPI_OK ) {
00148         printf("Error starting socket %d cbox %d\n",i,j);
00149             test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00150          }
00151      }
00152    }
00153 
00154    /* our work code */
00155    do_flops( NUM_FLOPS );
00156 
00157    /* Stop PAPI */
00158    for(i=0;i < hwinfo->sockets; i++) {
00159       for(j=0;j<max_cbox;j++) {
00160          retval = PAPI_stop( EventSet[j][i],&values[j][i] );
00161          if ( retval != PAPI_OK ) {
00162         printf("Error stopping socket %d cbox %d\n",i,j);
00163             test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00164          }
00165      }
00166    }
00167 
00168    /* Print Results */
00169    if ( !TESTS_QUIET ) {
00170       for(i=0;i < hwinfo->sockets; i++) {
00171          printf("Socket %d\n",i);
00172          for(j=0;j<max_cbox;j++) {
00173             printf("\t%s%d::%s %lld\n",uncore_base,j,event_name,values[j][i]);
00174          }
00175       }
00176    }
00177 
00178    PAPI_shutdown();
00179 
00180    test_pass( __FILE__, NULL, 0 );
00181 
00182 
00183    return 0;
00184 }

Here is the call graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1