perf_event_uncore_multiple.c File Reference

Include dependency graph for perf_event_uncore_multiple.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 16 of file perf_event_uncore_multiple.c.

00016                                   {
00017 
00018    int retval;
00019    int EventSet = PAPI_NULL;
00020    int EventSet2 = PAPI_NULL;
00021    long long values[1],values2[1];
00022    char *uncore_event=NULL;
00023    char event_name[BUFSIZ];
00024    int uncore_cidx=-1;
00025    const PAPI_component_info_t *info;
00026 
00027    /* Set TESTS_QUIET variable */
00028    tests_quiet( argc, argv );
00029 
00030    /* Init the PAPI library */
00031    retval = PAPI_library_init( PAPI_VER_CURRENT );
00032    if ( retval != PAPI_VER_CURRENT ) {
00033       test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00034    }
00035 
00036    /* Find the uncore PMU */
00037    uncore_cidx=PAPI_get_component_index("perf_event_uncore");
00038    if (uncore_cidx<0) {
00039       test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
00040    }
00041 
00042    /* Check if component disabled */
00043    info=PAPI_get_component_info(uncore_cidx);
00044    if (info->disabled) {
00045       test_skip(__FILE__,__LINE__,"uncore component disabled",0);
00046    }
00047 
00048    /* Get a relevant event name */
00049    uncore_event=get_uncore_event(event_name, BUFSIZ);
00050    if (uncore_event==NULL) {
00051       test_skip( __FILE__, __LINE__,
00052             "PAPI does not support uncore on this processor", PAPI_ENOSUPP );
00053    }
00054 
00055    /* Create an eventset */
00056    retval = PAPI_create_eventset(&EventSet);
00057    if (retval != PAPI_OK) {
00058       test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
00059    }
00060 
00061    /* Create another eventset */
00062    retval = PAPI_create_eventset(&EventSet2);
00063    if (retval != PAPI_OK) {
00064       test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
00065    }
00066 
00067    /* Set a component for the EventSet */
00068    retval = PAPI_assign_eventset_component(EventSet, uncore_cidx);
00069 
00070    /* we need to set to a certain cpu for uncore to work */
00071 
00072    PAPI_cpu_option_t cpu_opt;
00073 
00074    cpu_opt.eventset=EventSet;
00075    cpu_opt.cpu_num=0;
00076 
00077    retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
00078    if (retval != PAPI_OK) {
00079       test_skip( __FILE__, __LINE__,
00080               "this test; trying to PAPI_CPU_ATTACH; need to run as root",
00081               retval);
00082    }
00083 
00084    /* we need to set the granularity to system-wide for uncore to work */
00085 
00086    PAPI_granularity_option_t gran_opt;
00087 
00088    gran_opt.def_cidx=0;
00089    gran_opt.eventset=EventSet;
00090    gran_opt.granularity=PAPI_GRN_SYS;
00091 
00092    retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
00093    if (retval != PAPI_OK) {
00094       test_skip( __FILE__, __LINE__,
00095               "this test; trying to set PAPI_GRN_SYS",
00096               retval);
00097    }
00098 
00099    /* we need to set domain to be as inclusive as possible */
00100 
00101    PAPI_domain_option_t domain_opt;
00102 
00103    domain_opt.def_cidx=0;
00104    domain_opt.eventset=EventSet;
00105    domain_opt.domain=PAPI_DOM_ALL;
00106 
00107    retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
00108    if (retval != PAPI_OK) {
00109       test_skip( __FILE__, __LINE__,
00110               "this test; trying to set PAPI_DOM_ALL; need to run as root",
00111               retval);
00112    }
00113 
00114    /* Add our uncore event */
00115    retval = PAPI_add_named_event(EventSet, uncore_event);
00116    if (retval != PAPI_OK) {
00117       if ( !TESTS_QUIET ) {
00118          fprintf(stderr,"Error trying to use event %s\n", uncore_event);
00119       }
00120       test_fail(__FILE__, __LINE__, "adding uncore event ",retval);
00121    }
00122 
00123    /* Add PAPI_TOT_CYC */
00124    retval = PAPI_add_named_event(EventSet2, "PAPI_TOT_CYC");
00125    if (retval != PAPI_OK) {
00126       if ( !TESTS_QUIET ) {
00127          fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n");
00128       }
00129       test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
00130    }
00131 
00132 
00133    /* Start PAPI */
00134    retval = PAPI_start( EventSet );
00135    if ( retval != PAPI_OK ) {
00136       test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00137    }
00138 
00139    retval = PAPI_start( EventSet2 );
00140    if ( retval != PAPI_OK ) {
00141       test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00142    }
00143 
00144    /* our work code */
00145    do_flops( NUM_FLOPS );
00146 
00147    /* Stop PAPI */
00148    retval = PAPI_stop( EventSet, values );
00149    if ( retval != PAPI_OK ) {
00150       test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00151    }
00152    retval = PAPI_stop( EventSet2, values2 );
00153    if ( retval != PAPI_OK ) {
00154       test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00155    }
00156 
00157    if ( !TESTS_QUIET ) {
00158       printf("Uncore and regular event test:\n");
00159       printf("Using uncore event %s\n",uncore_event);
00160       printf("\t%s: %lld\n",uncore_event,values[0]);
00161       printf("\t%s: %lld\n","PAPI_TOT_CYC",values2[0]);
00162    }
00163 
00164    test_pass( __FILE__, NULL, 0 );
00165 
00166    return 0;
00167 }

Here is the call graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1