perf_event_amd_northbridge.c File Reference

Include dependency graph for perf_event_amd_northbridge.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 11 of file perf_event_amd_northbridge.c.

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

Here is the call graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1