PAPI  5.0.1.0
overflow_values.c
Go to the documentation of this file.
00001 /* 
00002 * File:    overflow_values.c
00003 * CVS:     $Id$
00004 * Author:  Harald Servat
00005 *          harald@cepba.upc.edu
00006 * Mods:    <your name here>
00007 *          <your email address>
00008 */
00009 
00010 /* This file performs the following test: overflow values check
00011 
00012      The Eventset contains:
00013      + PAPI_TOT_INS (overflow monitor)
00014      + PAPI_TOT_CYC
00015      + PAPI_L1_DCM
00016 
00017    - Start eventset
00018    - Read and report event counts mod 1000
00019    - report overflow event counts
00020    - visually inspect for consistency
00021    - Stop eventset
00022 */
00023 
00024 #include "papi_test.h"
00025 
00026 #define OVRFLOW 5000000
00027 #define LOWERFLOW (OVRFLOW - (OVRFLOW/100))
00028 #define UPPERFLOW (OVRFLOW/100)
00029 #define ERRORFLOW (UPPERFLOW/5)
00030 static long long ovrflow = 0;
00031 
00032 void
00033 handler( int EventSet, void *address, long long overflow_vector, void *context )
00034 {
00035     int ret;
00036     int i;
00037     long long vals[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
00038 
00039     printf( "\nOverflow at %p! bit=0x%llx \n", address, overflow_vector );
00040     ret = PAPI_read( EventSet, vals );
00041     printf( "Overflow read vals :" );
00042     for ( i = 0; i < 3 /* 8 */ ; i++ )
00043         printf( "%lld ", vals[i] );
00044     printf( "\n\n" );
00045     ovrflow = vals[0];
00046 }
00047 
00048 int
00049 main( int argc, char *argv[] )
00050 {
00051     int EventSet = PAPI_NULL;
00052     int retval, i, dash = 0, evt3 = PAPI_L1_DCM;
00053     PAPI_option_t options;
00054     PAPI_option_t options2;
00055     const PAPI_hw_info_t *hwinfo;
00056     long long lwrflow = 0, error, max_error = 0;
00057     long long vals[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
00058 
00059     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00060 
00061     retval = PAPI_library_init( PAPI_VER_CURRENT );
00062     if ( retval != PAPI_VER_CURRENT && retval > 0 )
00063         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00064 
00065     retval = PAPI_get_opt( PAPI_HWINFO, &options );
00066     if ( retval < 0 )
00067         test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval );
00068     printf( "ovf_info = %d (%x)\n", options.ovf_info.type,
00069             options.ovf_info.type );
00070 
00071     retval = PAPI_get_opt( PAPI_SUBSTRATEINFO, &options2 );
00072     if ( retval < 0 )
00073         test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval );
00074     printf( "sub_info->hardware_intr = %d\n\n",
00075             options2.sub_info->hardware_intr );
00076 
00077     if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
00078         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EMISC );
00079 
00080     printf( "Architecture %s, %d\n", hwinfo->model_string, hwinfo->model );
00081 
00082 /* processing exceptions is a pain */
00083 #if ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) )
00084     if ( !strncmp( hwinfo->model_string, "Intel Pentium 4", 15 ) ) {
00085         evt3 = PAPI_L2_TCM;
00086     } else if ( !strncmp( hwinfo->model_string, "AMD K7", 6 ) ) {
00087         /* do nothing */
00088     } else if ( !strncmp( hwinfo->model_string, "AMD K8", 6 ) ) {
00089         /* do nothing */
00090     } else if ( !strncmp( hwinfo->model_string, "Intel Core", 10 ) ) {
00091         evt3 = 0;
00092     } else
00093         evt3 = 0;            /* for default PIII */
00094 #endif
00095 
00096     retval = PAPI_create_eventset( &EventSet );
00097     if ( retval < 0 )
00098         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00099 
00100     retval = PAPI_add_event( EventSet, PAPI_TOT_INS );
00101     if ( retval < 0 )
00102         test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_INS", retval );
00103     retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
00104     if ( retval < 0 )
00105         test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_CYC", retval );
00106     if ( evt3 ) {
00107         retval = PAPI_add_event( EventSet, evt3 );
00108         if ( retval < 0 )
00109             test_fail( __FILE__, __LINE__, "PAPI_add_event:evt3", retval );
00110     }
00111     retval = PAPI_overflow( EventSet, PAPI_TOT_INS, OVRFLOW, 0, handler );
00112     if ( retval < 0 )
00113         test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
00114 
00115     retval = PAPI_start( EventSet );
00116     if ( retval < 0 )
00117         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00118 
00119     for ( i = 0; i < 1000000; i++ ) {
00120         if ( i % 1000 == 0 ) {
00121             int i;
00122 
00123             PAPI_read( EventSet, vals );
00124             if ( vals[0] % OVRFLOW > LOWERFLOW ||
00125                  vals[0] % OVRFLOW < UPPERFLOW ) {
00126                 dash = 0;
00127                 printf( "Main loop read vals :" );
00128                 for ( i = 0; i < 3 /* 8 */ ; i++ )
00129                     printf( "%lld ", vals[i] );
00130                 printf( "\n" );
00131                 if ( ovrflow ) {
00132                     error = ovrflow - ( lwrflow + vals[0] ) / 2;
00133                     printf( "Difference: %lld\n", error );
00134                     ovrflow = 0;
00135                     if ( abs( error ) > max_error )
00136                         max_error = abs( error );
00137                 }
00138                 lwrflow = vals[0];
00139             } else if ( vals[0] % OVRFLOW > UPPERFLOW && !dash ) {
00140                 dash = 1;
00141                 printf( "---------------------\n" );
00142             }
00143         }
00144     }
00145 
00146     retval = PAPI_stop( EventSet, vals );
00147     if ( retval != PAPI_OK )
00148         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00149 
00150     retval = PAPI_cleanup_eventset( EventSet );
00151     if ( retval != PAPI_OK )
00152         test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
00153 
00154     retval = PAPI_destroy_eventset( &EventSet );
00155     if ( retval != PAPI_OK )
00156         test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
00157 
00158     printf( "Verification:\n" );
00159     printf
00160         ( "Maximum absolute difference between overflow value\nand adjacent measured values is: %lld\n",
00161           max_error );
00162     if ( max_error >= ERRORFLOW ) {
00163         printf( "This exceeds the error limit: %d\n", ERRORFLOW );
00164         test_fail( __FILE__, __LINE__, "Overflows", 1 );
00165     }
00166     printf( "This is within the error limit: %d\n", ERRORFLOW );
00167     test_pass( __FILE__, NULL, 0 );
00168     exit( 1 );
00169 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines