|
PAPI
5.0.1.0
|

Go to the source code of this file.
Functions | |
| void | handler (int EventSet, void *address, long long overflow_vector, void *context) |
| void * | Thread (void *arg) |
| int | main (int argc, char **argv) |
Variables | |
| static const PAPI_hw_info_t * | hw_info = NULL |
| static int | total [NUM_THREADS] |
| static int | expected [NUM_THREADS] |
| static pthread_t | myid [NUM_THREADS] |
| long long | mythreshold = 0 |
| void handler | ( | int | EventSet, |
| void * | address, | ||
| long long | overflow_vector, | ||
| void * | context | ||
| ) |
Definition at line 27 of file ctests/overflow_pthreads.c.
{
#if 0
printf( "handler(%d,0x%lx,%llx) Overflow %d in thread %lx\n",
EventSet, ( unsigned long ) address, overflow_vector,
total[EventSet], PAPI_thread_id( ) );
printf( "%lx vs %lx\n", myid[EventSet], PAPI_thread_id( ) );
#else /* eliminate unused parameter warning message */
( void ) address;
( void ) overflow_vector;
( void ) context;
#endif
total[EventSet]++;
}

| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Definition at line 124 of file ctests/overflow_pthreads.c.
{
pthread_t id[NUM_THREADS];
int flops[NUM_THREADS];
int i, rc, retval;
pthread_attr_t attr;
float ratio;
memset( total, 0x0, NUM_THREADS * sizeof ( *total ) );
memset( expected, 0x0, NUM_THREADS * sizeof ( *expected ) );
memset( myid, 0x0, NUM_THREADS * sizeof ( *myid ) );
tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
if ( ( retval =
PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
hw_info = PAPI_get_hardware_info( );
if ( hw_info == NULL )
test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
if ( ( retval =
PAPI_thread_init( ( unsigned
long ( * )( void ) ) ( pthread_self ) ) ) !=
PAPI_OK ) {
if ( retval == PAPI_ECMP )
test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
else
test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
}
#if defined(linux)
mythreshold = hw_info->cpu_max_mhz * 10000 * 2;
#else
mythreshold = THRESHOLD * 2;
#endif
pthread_attr_init( &attr );
#ifdef PTHREAD_CREATE_UNDETACHED
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
#endif
#ifdef PTHREAD_SCOPE_SYSTEM
retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
if ( retval != 0 )
test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
#endif
for ( i = 0; i < NUM_THREADS; i++ ) {
flops[i] = NUM_FLOPS * ( i + 1 );
rc = pthread_create( &id[i], &attr, Thread, ( void * ) &flops[i] );
if ( rc )
test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
}
for ( i = 0; i < NUM_THREADS; i++ )
pthread_join( id[i], NULL );
pthread_attr_destroy( &attr );
{
long long t = 0, r = 0;
for ( i = 0; i < NUM_THREADS; i++ ) {
t += ( NUM_FLOPS * ( i + 1 ) ) / mythreshold;
r += total[i];
}
printf( "Expected total overflows: %lld\n", t );
printf( "Received total overflows: %lld\n", r );
}
/* ratio = (float)total[0] / (float)expected[0]; */
/* printf("Ratio of total to expected: %f\n",ratio); */
ratio = 1.0;
for ( i = 0; i < NUM_THREADS; i++ ) {
printf( "Overflows thread %d: %d, expected %d\n",
i, total[i], ( int ) ( ratio * ( float ) expected[i] ) );
}
for ( i = 0; i < NUM_THREADS; i++ ) {
if ( total[i] < ( int ) ( ( ratio * ( float ) expected[i] ) / 2.0 ) )
test_fail( __FILE__, __LINE__, "not enough overflows", PAPI_EMISC );
}
test_pass( __FILE__, NULL, 0 );
pthread_exit( NULL );
exit( 1 );
}

| void* Thread | ( | void * | arg | ) |
Definition at line 45 of file ctests/overflow_pthreads.c.
{
int retval, num_tests = 1;
int EventSet1 = PAPI_NULL;
int mask1, papi_event;
int num_events1;
long long **values;
long long elapsed_us, elapsed_cyc;
char event_name[PAPI_MAX_STR_LEN];
retval = PAPI_register_thread( );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
/* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
PAPI_TOT_INS, depends on the availability of the event on the
platform */
EventSet1 =
add_two_nonderived_events( &num_events1, &papi_event, &mask1 );
if (EventSet1 < 0) return NULL;
/* Wait, we're indexing a per-thread array with the EventSet number? */
/* does that make any sense at all???? -- vmw */
expected[EventSet1] = *( int * ) arg / mythreshold;
myid[EventSet1] = PAPI_thread_id( );
values = allocate_test_space( num_tests, num_events1 );
elapsed_us = PAPI_get_real_usec( );
elapsed_cyc = PAPI_get_real_cyc( );
if ((retval = PAPI_overflow( EventSet1, papi_event,
mythreshold, 0, handler ) ) != PAPI_OK ) {
test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
}
/* start_timer(1); */
if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_start", retval );
do_stuff( );
if ( ( retval = PAPI_stop( EventSet1, values[0] ) ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
if ( ( retval =
PAPI_overflow( EventSet1, papi_event, 0, 0, NULL ) ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_overflow", retval );
remove_test_events( &EventSet1, mask1 );
if ( ( retval =
PAPI_event_code_to_name( papi_event, event_name ) ) != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
if ( !TESTS_QUIET ) {
printf( "Thread 0x%x %s : \t%lld\n", ( int ) pthread_self( ),
event_name, ( values[0] )[0] );
printf( "Thread 0x%x PAPI_TOT_CYC: \t%lld\n", ( int ) pthread_self( ),
( values[0] )[1] );
printf( "Thread 0x%x Real usec : \t%lld\n", ( int ) pthread_self( ),
elapsed_us );
printf( "Thread 0x%x Real cycles : \t%lld\n", ( int ) pthread_self( ),
elapsed_cyc );
}
free_test_space( values, num_tests );
retval = PAPI_unregister_thread( );
if ( retval != PAPI_OK )
test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
return ( NULL );
}


int expected[NUM_THREADS] [static] |
Definition at line 23 of file ctests/overflow_pthreads.c.
const PAPI_hw_info_t* hw_info = NULL [static] |
Definition at line 21 of file ctests/overflow_pthreads.c.
pthread_t myid[NUM_THREADS] [static] |
Definition at line 24 of file ctests/overflow_pthreads.c.
| long long mythreshold = 0 |
Definition at line 42 of file ctests/overflow_pthreads.c.
int total[NUM_THREADS] [static] |
Definition at line 22 of file ctests/overflow_pthreads.c.