コード例 #1
0
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);
}
コード例 #2
0
void initTimers() {
#if USING_PERFCTR == 0
	int retval;
	fprintf(stderr, "1\n");

	if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) {
		printf("PAPI Library initialization error! \n");
		exit(1);
	}

	fprintf(stderr, "2\n");
	if ((retval = PAPI_set_debug(PAPI_VERB_ESTOP)) != PAPI_OK) {
		printf("PAPI set debug error! \n");
		exit(1);
	}
	fprintf(stderr, "3\n");
	if (PAPI_thread_init(pthread_self) != PAPI_OK) {
		printf("PAPI thread Library initialisation error! \n");
		exit(1);
	}
	fprintf(stderr, "4\n");
	PAPI_thread_init(gettid);
	PAPI_register_thread();
#else
	PERFCTR_initialize();
	PERFCTR_register_thread();
#endif

	gettimeofday(&program_start, NULL);
}
コード例 #3
0
ファイル: thrspecific.c プロジェクト: FMCalisto/SMP
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 );
}
コード例 #4
0
ファイル: krentel_pthreads.c プロジェクト: arm-hpc/papi
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 );
}
コード例 #5
0
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;
}
コード例 #6
0
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;
}
コード例 #7
0
ファイル: eventLib.c プロジェクト: ManuelSelva/orcc
void event_create_eventList(int *eventSet, int eventCodeSetSize, int *eventCodeSet, int threadID) {

    int retval, i, maxNumberHwCounters, eventCodeSetMaxSize;
    PAPI_event_info_t info;

    maxNumberHwCounters = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL );
    printf("Max number of hardware counters = %d \n", maxNumberHwCounters);

    eventCodeSetMaxSize = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL );
    printf("Max number of multiplexed counters = %d \n", eventCodeSetMaxSize);

    if ( eventCodeSetMaxSize < eventCodeSetSize)
        test_fail( __FILE__, __LINE__, "eventCodeSetMaxSize < eventCodeSetSize, too many performance events defined! ", retval );

    retval = PAPI_register_thread();
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );

    retval = PAPI_create_eventset( eventSet );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

    retval = PAPI_assign_eventset_component( *eventSet, 0 );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );

    retval = PAPI_set_multiplex( *eventSet );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );

    for (i = 0; i < eventCodeSetSize; i++) {
        retval = PAPI_get_event_info(eventCodeSet[i], &info);
        if ( retval != PAPI_OK )
            test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );

        retval = PAPI_add_event( *eventSet, info.event_code);
        if ( retval != PAPI_OK )
            test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
        else
            printf("Adding %s \n", info.symbol);

    }

    printf("event_create_eventList done \n");
}
コード例 #8
0
ファイル: kufrin.c プロジェクト: pyrovski/papi-rapl
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 );
}
コード例 #9
0
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 );
}
コード例 #10
0
ファイル: Init.c プロジェクト: xiaodao90/wrapper
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;
}
コード例 #11
0
ファイル: perf.c プロジェクト: jiachengy/numa-db
void
perf_register_thread()
{
  PAPI_register_thread();
}