|
PAPI
5.1.0.2
|
00001 /* This file tests uncore events on perf_event kernels 00002 */ 00003 00004 #include "papi_test.h" 00005 00006 #define MAX_CYCLE_ERROR 30 00007 00008 char uncore_event[]="snbep_unc_imc0::UNC_M_CLOCKTICKS"; 00009 00010 int 00011 main( int argc, char **argv ) 00012 { 00013 int retval; 00014 int EventSet = PAPI_NULL; 00015 long long values[1]; 00016 const PAPI_hw_info_t *hwinfo; 00017 00018 /* Set TESTS_QUIET variable */ 00019 tests_quiet( argc, argv ); 00020 00021 /* Init the PAPI library */ 00022 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00023 if ( retval != PAPI_VER_CURRENT ) { 00024 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00025 } 00026 00027 hwinfo = PAPI_get_hardware_info(); 00028 if ( hwinfo == NULL ) { 00029 test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info failed, THIS should not happen.", PAPI_ESYS); 00030 } 00031 if ( hwinfo->vendor != PAPI_VENDOR_INTEL ) { 00032 test_skip( __FILE__, __LINE__, "This test is only for Intel Processors, for now.", PAPI_OK ); 00033 } 00034 if (( hwinfo->cpuid_family != 6) || (hwinfo->cpuid_model != 45) ) { 00035 test_skip( __FILE__, __LINE__, "This test is only implemented for SandyBridge-EP series processors for now.", PAPI_OK ); 00036 } 00037 00038 retval = PAPI_create_eventset(&EventSet); 00039 if (retval != PAPI_OK) { 00040 test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval); 00041 } 00042 00043 /* we need to set a component for the EventSet */ 00044 00045 retval = PAPI_assign_eventset_component(EventSet, 0); 00046 00047 /* we need to set to a certain cpu for uncore to work */ 00048 00049 PAPI_cpu_option_t cpu_opt; 00050 00051 cpu_opt.eventset=EventSet; 00052 cpu_opt.cpu_num=0; 00053 00054 retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt); 00055 if (retval != PAPI_OK) { 00056 test_fail(__FILE__, __LINE__, "PAPI_CPU_ATTACH",retval); 00057 } 00058 00059 /* we need to set the granularity to system-wide for uncore to work */ 00060 00061 PAPI_granularity_option_t gran_opt; 00062 00063 gran_opt.def_cidx=0; 00064 gran_opt.eventset=EventSet; 00065 gran_opt.granularity=PAPI_GRN_SYS; 00066 00067 retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt); 00068 if (retval != PAPI_OK) { 00069 test_fail(__FILE__, __LINE__, "PAPI_GRANUL",retval); 00070 } 00071 00072 /* we need to set domain to be as inclusive as possible */ 00073 00074 PAPI_domain_option_t domain_opt; 00075 00076 domain_opt.def_cidx=0; 00077 domain_opt.eventset=EventSet; 00078 domain_opt.domain=PAPI_DOM_ALL; 00079 00080 retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt); 00081 if (retval != PAPI_OK) { 00082 test_fail(__FILE__, __LINE__, "PAPI_DOMAIN",retval); 00083 } 00084 00085 /* Add our uncore event */ 00086 00087 retval = PAPI_add_named_event(EventSet, uncore_event); 00088 00089 if (retval != PAPI_OK) { 00090 test_fail(__FILE__, __LINE__, "Error with event \n",retval); 00091 } 00092 00093 /* Start PAPI */ 00094 retval = PAPI_start( EventSet ); 00095 if ( retval != PAPI_OK ) { 00096 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00097 } 00098 00099 /* our work code */ 00100 do_flops( NUM_FLOPS ); 00101 00102 /* Stop PAPI */ 00103 retval = PAPI_stop( EventSet, values ); 00104 if ( retval != PAPI_OK ) { 00105 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00106 } 00107 00108 if ( !TESTS_QUIET ) { 00109 printf("Uncore test:\n"); 00110 printf("\t%s: %lld\n",uncore_event,values[0]); 00111 } 00112 00113 test_pass( __FILE__, NULL, 0 ); 00114 00115 return 0; 00116 }