perf_event_uncore.c File Reference

Include dependency graph for tests/perf_event_uncore.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 9 of file tests/perf_event_uncore.c.

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

Here is the call graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1