void vt_metric_thread_fini() { if ( nmetrics == 0 ) return; /* ignore return value */ (void)PAPI_unregister_thread(); }
void * Thread( void *arg ) { int retval; void *arg2; retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); printf( "Thread %#x started, specific data is at %p\n", ( int ) pthread_self( ), arg ); retval = PAPI_set_thr_specific( PAPI_USR1_TLS, arg ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_thr_specific", retval ); retval = PAPI_get_thr_specific( PAPI_USR1_TLS, &arg2 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_thr_specific", retval ); if ( arg != arg2 ) test_fail( __FILE__, __LINE__, "set vs get specific", 0 ); while ( processing ) { if ( *( ( int * ) arg ) == 500000 ) { sleep( 1 ); int i; PAPI_all_thr_spec_t data; data.num = 10; data.id = ( unsigned long * ) malloc( ( size_t ) data.num * sizeof ( unsigned long ) ); data.data = ( void ** ) malloc( ( size_t ) data.num * sizeof ( void * ) ); retval = PAPI_get_thr_specific( PAPI_USR1_TLS | PAPI_TLS_ALL_THREADS, ( void ** ) &data ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_thr_specific", retval ); if ( data.num != 5 ) test_fail( __FILE__, __LINE__, "data.num != 5", 0 ); for ( i = 0; i < data.num; i++ ) printf( "Entry %d, Thread 0x%lx, Data Pointer %p, Value %d\n", i, data.id[i], data.data[i], *( int * ) data.data[i] ); processing = 0; } } retval = PAPI_unregister_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval ); return ( NULL ); }
void Thread( int t, int n ) { int retval, num_tests = 1; int EventSet1 = PAPI_NULL; int PAPI_event, mask1; int num_events1; long long **values; long long elapsed_us, elapsed_cyc; char event_name[PAPI_MAX_STR_LEN]; /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, depending on the availability of the event on the platform */ EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 ); retval = PAPI_event_code_to_name( PAPI_event, event_name ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); values = allocate_test_space( num_tests, num_events1 ); retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); do_flops( n ); elapsed_us = PAPI_get_real_usec( ) - elapsed_us; elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; retval = PAPI_stop( EventSet1, values[0] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); remove_test_events( &EventSet1, mask1 ); if ( !TESTS_QUIET ) { printf( "Thread %#x %-12s : \t%lld\n", t, event_name, values[0][1] ); printf( "Thread %#x PAPI_TOT_CYC : \t%lld\n", t, values[0][0] ); } free_test_space( values, num_tests ); if ( !TESTS_QUIET ) { printf( "Thread %#x Real usec : \t%lld\n", t, elapsed_us ); printf( "Thread %#x Real cycles : \t%lld\n", t, elapsed_cyc ); } PAPI_unregister_thread( ); }
void vt_metric_thread_fini() { int retval; if ( nmetrics == 0 ) return; retval = PAPI_unregister_thread(); if ( retval != PAPI_OK) vt_metric_error(retval, "PAPI_unregister_thread"); /* vt_cntl_msg("PAPI thread finalized"); */ }
void * my_thread( void *v ) { long num = ( long ) v; int n; int EventSet = PAPI_NULL; long long value; int retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); pthread_setspecific( key, v ); count[num] = 0; iter[num] = 0; last[num] = start; if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 ); if ( PAPI_add_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 ); if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 ); if ( PAPI_start( EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 ); printf( "launched timer in thread %ld\n", num ); for ( n = 1; n <= program_time; n++ ) { do_cycles( num, 1 ); print_rate( num ); } PAPI_stop( EventSet, &value ); retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval ); if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 ); if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 ); if ( PAPI_unregister_thread( ) != PAPI_OK != retval ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 ); return ( NULL ); }
void Thread( int n ){ int retval, num_tests = 1; int EventSet1 = PAPI_NULL; int PAPI_event, mask1; int num_events1; long long **values; long long elapsed_us, elapsed_cyc, L1_DCM; char event_name[PAPI_MAX_STR_LEN]; printf( "Thread %#x started\n", omp_get_thread_num( ) ); num_events1 = 2; EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 ); retval = PAPI_event_code_to_name( PAPI_event, event_name ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); values = allocate_test_space( num_tests, num_events1 ); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); retval = PAPI_start( EventSet1 ); do_flops( n ); retval = PAPI_stop( EventSet1, values[0] ); elapsed_us = PAPI_get_real_usec( ) - elapsed_us; elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; remove_test_events( &EventSet1, mask1 ); if ( !TESTS_QUIET ) { printf( "Thread %#x %-12s : \t%lld\n", omp_get_thread_num( ), event_name, values[0][1] ); printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", omp_get_thread_num( ), values[0][0] ); printf( "Thread %#x Real usec : \t%lld\n", omp_get_thread_num( ), elapsed_us ); printf( "Thread %#x Real cycles : \t%lld\n", omp_get_thread_num( ), elapsed_cyc ); } free_test_space( values, num_tests ); PAPI_unregister_thread( ); printf( "Thread %#x finished\n", omp_get_thread_num( ) ); }
void * pthread_main( void *arg ) { ( void ) arg; int retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); } clockcore( ); retval = PAPI_unregister_thread( ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval ); } return NULL; }
void *our_thread( void *arg ) { int retval,i; printf("Entering thread\n"); retval = PAPI_register_thread( ); for(i=0;i<num_events;i++) { PAPI_event_name_to_code (event_names[i], &event_codes[i]); } printf("Done thread\n"); retval = PAPI_unregister_thread( ); return NULL; }
void * thread( void *arg ) { ( void ) arg; /*unused */ int eventset = PAPI_NULL; long long values[PAPI_MPX_DEF_DEG]; int ret = PAPI_register_thread( ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", ret ); ret = PAPI_create_eventset( &eventset ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret ); printf( "Event set %d created\n", eventset ); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ ret = PAPI_assign_eventset_component( eventset, 0 ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", ret ); } ret = PAPI_set_multiplex( eventset ); if ( ret == PAPI_ENOSUPP) { test_skip( __FILE__, __LINE__, "Multiplexing not supported", 1 ); } else if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", ret ); } ret = PAPI_add_events( eventset, events, numevents ); if ( ret < PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events", ret ); } ret = PAPI_start( eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", ret ); } do_stuff( ); ret = PAPI_stop( eventset, values ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", ret ); } ret = PAPI_cleanup_eventset( eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", ret ); } ret = PAPI_destroy_eventset( &eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret ); } ret = PAPI_unregister_thread( ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret ); return ( NULL ); }
void * Thread( void *arg ) { int retval, num_tests = 1, i; int EventSet1 = PAPI_NULL, mask1, PAPI_event; int num_events1; long long **values; long long elapsed_us, elapsed_cyc; unsigned short *profbuf; char event_name[PAPI_MAX_STR_LEN]; retval = PAPI_register_thread( ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); profbuf = ( unsigned short * ) malloc( length * sizeof ( unsigned short ) ); if ( profbuf == NULL ) exit( 1 ); memset( profbuf, 0x00, length * sizeof ( unsigned short ) ); /* 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 ); values = allocate_test_space( num_tests, num_events1 ); if ( ( retval = PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); retval = PAPI_profil( profbuf, length, my_start, 65536, EventSet1, PAPI_event, THR, PAPI_PROFIL_POSIX ); if ( retval ) test_fail( __FILE__, __LINE__, "PAPI_profil", retval ); if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_flops( *( int * ) arg ); 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; /* to remove the profile flag */ retval = PAPI_profil( profbuf, length, my_start, 65536, EventSet1, PAPI_event, 0, PAPI_PROFIL_POSIX ); if ( retval ) test_fail( __FILE__, __LINE__, "PAPI_profil", retval ); remove_test_events( &EventSet1, mask1 ); if ( !TESTS_QUIET ) { if ( mask1 == 0x3 ) { printf( "Thread 0x%x PAPI_TOT_INS : \t%lld\n", ( int ) pthread_self( ), ( values[0] )[0] ); } else { printf( "Thread 0x%x PAPI_FP_INS : \t%lld\n", ( int ) pthread_self( ), ( 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 ); printf( "Test case: PAPI_profil() for pthreads\n" ); printf( "----Profile buffer for Thread 0x%x---\n", ( int ) pthread_self( ) ); for ( i = 0; i < ( int ) length; i++ ) { if ( profbuf[i] ) printf( "0x%lx\t%d\n", ( unsigned long ) ( my_start + 2 * i ), profbuf[i] ); } } for ( i = 0; i < ( int ) length; i++ ) if ( profbuf[i] ) break; if ( i >= ( int ) length ) test_fail( __FILE__, __LINE__, "No information in buffers", 1 ); 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 PAPI_get_info (char *event_name, int finish, int type) { int retval,i; PAPI_Event Event_papi; Event_papi.event_name = event_name; Event_papi.finish = finish; Event_papi.time = gettime(); long long values [PAPI_MAX_EVENT_NUM]; if (type == PAPI_PROCESS) { if ( (retval=PAPI_start(EventSet)) != PAPI_OK) ERROR_RETURN(retval); if ((retval=PAPI_stop(EventSet,values)) != PAPI_OK) ERROR_RETURN(retval); // printf_d ("%s\n", Event_papi.event_name); for (i = 0; i < NUM_EVENT; i++) { Event_papi.papi_event = PAPI_EVENT[i]; Event_papi.data = values[i]; if ((PAPI_info_record (Event_papi)) == -1) printf_d ("[PAPI]GET stream error!!\n"); } return 0; } else if (type == PAPI_THREAD) { int EventSet1 = PAPI_NULL; int *event_codes; event_codes = (int *)calloc (sizeof (int *), NUM_EVENT); for (i = 0; i < NUM_EVENT; ++i) { retval = PAPI_event_name_to_code (PAPI_EVENT[i], &event_codes[i]); if( retval != PAPI_OK ) printf_d("[PAPI]PAPI_event_name_to_code failed, retval = %d\n", retval ); } if ((retval = PAPI_register_thread ()) != PAPI_OK) ERROR_RETURN (retval); if ((retval=PAPI_create_eventset(&EventSet1)) != PAPI_OK) ERROR_RETURN(retval); if ((retval=PAPI_add_events(EventSet1, event_codes, NUM_EVENT)) != PAPI_OK) ERROR_RETURN(retval); if ((retval=PAPI_start(EventSet1)) != PAPI_OK) ERROR_RETURN(retval); if ((retval=PAPI_stop(EventSet1,values)) != PAPI_OK) ERROR_RETURN(retval); for (i = 0; i < NUM_EVENT; i++) { Event_papi.papi_event = PAPI_EVENT[i]; Event_papi.data = values[i]; PAPI_info_record (Event_papi); } if ((PAPI_unregister_thread()) != PAPI_OK) ERROR_RETURN(retval); return 0; } return 1; }
void perf_unregister_thread() { PAPI_unregister_thread(); }