PAPI  5.3.0.0
perf_event_uncore_cbox.c
Go to the documentation of this file.
00001 /*
00002  * This file tests cbox uncore events on IVB and SNB-EP
00003  */
00004 
00005 #include "papi_test.h"
00006 
00007 #include "perf_event_uncore_lib.h"
00008 
00009 #define EVENTS_TO_TRY 16
00010 #define MAX_PACKAGES  4
00011 
00012 int main( int argc, char **argv ) {
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            default:
00061                     test_skip( __FILE__, __LINE__,
00062                 "We only support IVB and SNB-EP for now", PAPI_ENOSUPP );
00063         }
00064       }
00065       else {
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                 "This test only supported Intel chips", PAPI_ENOSUPP );
00073 
00074    }
00075 
00076    if (!TESTS_QUIET) {
00077       printf("Trying for %d sockets\n",hwinfo->sockets);
00078       printf("threads %d cores %d ncpus %d\n", hwinfo->threads,hwinfo->cores,
00079           hwinfo->ncpu);
00080    }
00081 
00082    for(i=0;i < hwinfo->sockets; i++) {
00083 
00084       /* perf_event provides which to use in "cpumask"    */
00085       /* but libpfm4 doesn't report this back to us (yet) */
00086       core_to_use=i*hwinfo->threads*hwinfo->cores;
00087       if (!TESTS_QUIET) {
00088          printf("Using core %d for socket %d\n",core_to_use,i);
00089       }
00090 
00091       for(j=0;j<EVENTS_TO_TRY;j++) {
00092 
00093          /* Create an eventset */
00094          EventSet[j][i]=PAPI_NULL;
00095          retval = PAPI_create_eventset(&EventSet[j][i]);
00096          if (retval != PAPI_OK) {
00097             test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
00098          }
00099 
00100          /* Set a component for the EventSet */
00101          retval = PAPI_assign_eventset_component(EventSet[j][i], uncore_cidx);
00102          if (retval!=PAPI_OK) {
00103             test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component",retval);
00104          }
00105 
00106          /* we need to set to a certain cpu for uncore to work */
00107 
00108          PAPI_cpu_option_t cpu_opt;
00109 
00110          cpu_opt.eventset=EventSet[j][i];
00111          cpu_opt.cpu_num=core_to_use;
00112 
00113          retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
00114          if (retval != PAPI_OK) {
00115             test_skip( __FILE__, __LINE__,
00116               "this test; trying to PAPI_CPU_ATTACH; need to run as root",
00117               retval);
00118          }
00119 
00120          /* Default Granularity should work */
00121 
00122          /* Default domain should work */
00123 
00124          /* Add our uncore event */
00125      sprintf(uncore_event,"%s%d::%s",uncore_base,j,event_name);
00126          retval = PAPI_add_named_event(EventSet[j][i], uncore_event);
00127          if (retval != PAPI_OK) {
00128             max_cbox=j;
00129         break;
00130          }
00131      if (!TESTS_QUIET) printf("Added %s for socket %d\n",uncore_event,i);
00132 
00133      }
00134    }
00135 
00136 
00137    for(i=0;i < hwinfo->sockets; i++) {
00138       for(j=0;j<max_cbox;j++) {
00139          if (!TESTS_QUIET) printf("Starting EventSet %d\n",EventSet[j][i]);
00140          /* Start PAPI */
00141          retval = PAPI_start( EventSet[j][i] );
00142          if ( retval != PAPI_OK ) {
00143         printf("Error starting socket %d cbox %d\n",i,j);
00144             test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00145          }
00146      }
00147    }
00148 
00149    /* our work code */
00150    do_flops( NUM_FLOPS );
00151 
00152    /* Stop PAPI */
00153    for(i=0;i < hwinfo->sockets; i++) {
00154       for(j=0;j<max_cbox;j++) {
00155          retval = PAPI_stop( EventSet[j][i],&values[j][i] );
00156          if ( retval != PAPI_OK ) {
00157         printf("Error stopping socket %d cbox %d\n",i,j);
00158             test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00159          }
00160      }
00161    }
00162 
00163    /* Print Results */
00164    if ( !TESTS_QUIET ) {
00165       for(i=0;i < hwinfo->sockets; i++) {
00166          printf("Socket %d\n",i);
00167          for(j=0;j<max_cbox;j++) {
00168             printf("\t%s%d::%s %lld\n",uncore_base,j,event_name,values[j][i]);
00169          }
00170       }
00171    }
00172 
00173    PAPI_shutdown();
00174 
00175    test_pass( __FILE__, NULL, 0 );
00176 
00177 
00178    return 0;
00179 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines