Exemple #1
0
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 *Master(void *arg)
{
   int i, retval, tmp;
   int *pointer, * pointer2;

   tmp = 20;
   pointer = &tmp;

   /* register the thread */
   if ( (retval=PAPI_register_thread())!= PAPI_OK )
      ERROR_RETURN(retval);
   
   /* save the pointer for late use */
   if ( (retval=PAPI_set_thr_specific(1,pointer))!= PAPI_OK )
      ERROR_RETURN(retval);
   /* change the value of tmp */
   tmp = 15;

   usleep(SLEEP_VALUE);
   PAPI_lock(PAPI_USR1_LOCK);
   /* Make sure Slaves are not sleeping */
   for (i = 0; i < LOOPS; i++) {
      count = 2 * count - i;
   }
   PAPI_unlock(PAPI_USR1_LOCK);

   /* retrieve the pointer saved by PAPI_set_thr_specific */
   if ( (retval=PAPI_get_thr_specific(1, (void *)&pointer2)) != PAPI_OK )
      ERROR_RETURN(retval);

   /* the output value should be 15 */
   printf("Thread specific data is %d \n", *pointer2);
   
   pthread_exit(NULL);
}
void _papi_hwi_shutdown_highlevel(){
   HighLevelInfo *state = NULL;

   if ( PAPI_get_thr_specific(PAPI_HIGH_LEVEL_TLS, (void *) &state)==PAPI_OK){
      if ( state ) papi_free(state);
   }
}
Exemple #4
0
/** @internal
 * This function is called to determine the state of the system.
 * We may as well set the HighLevelInfo so you don't have to look it
 * up again.
 */
int
_internal_check_state( HighLevelInfo ** outgoing )
{
    int retval;
    HighLevelInfo *state = NULL;

    /* Only allow one thread at a time in here */
    if ( init_level == PAPI_NOT_INITED ) {
        retval = PAPI_library_init( PAPI_VER_CURRENT );
        if ( retval != PAPI_VER_CURRENT ) {
            return ( retval );
        } else {
            _papi_hwi_lock( HIGHLEVEL_LOCK );
            init_level = PAPI_HIGH_LEVEL_INITED;
            _papi_hwi_unlock( HIGHLEVEL_LOCK );
        }
    }

    /*
     * Do we have the thread specific data setup yet?
     */
    if ( ( retval =
                PAPI_get_thr_specific( PAPI_HIGH_LEVEL_TLS, ( void * ) &state ) )
            != PAPI_OK || state == NULL ) {
        state = ( HighLevelInfo * ) papi_malloc( sizeof ( HighLevelInfo ) );
        if ( state == NULL )
            return ( PAPI_ENOMEM );

        memset( state, 0, sizeof ( HighLevelInfo ) );
        state->EventSet = -1;

        if ( ( retval = PAPI_create_eventset( &state->EventSet ) ) != PAPI_OK )
            return ( retval );

        if ( ( retval =
                    PAPI_set_thr_specific( PAPI_HIGH_LEVEL_TLS,
                                           state ) ) != PAPI_OK )
            return ( retval );
    }
    *outgoing = state;
    return ( PAPI_OK );
}