locks_pthreads.c File Reference

Include dependency graph for ctests/locks_pthreads.c:

Go to the source code of this file.

Functions

void lockloop (int iters, volatile long long *mycount)
void * Slave (void *arg)
int main (int argc, char **argv)

Variables

volatile long long count = 0
volatile long long tmpcount = 0
volatile int num_iters = 0

Function Documentation

void lockloop ( int  iters,
volatile long long *  mycount 
)

Definition at line 14 of file ctests/locks_pthreads.c.

00015 {
00016     int i;
00017     for ( i = 0; i < iters; i++ ) {
00018         PAPI_lock( PAPI_USR1_LOCK );
00019         *mycount = *mycount + 1;
00020         PAPI_unlock( PAPI_USR1_LOCK );
00021     }
00022 }

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file ctests/locks_pthreads.c.

00052 {
00053     pthread_t slaves[MAX_THREADS];
00054     int rc, i, nthr;
00055     int retval;
00056     const PAPI_hw_info_t *hwinfo = NULL;
00057 
00058     /* Set TESTS_QUIET variable */
00059     tests_quiet( argc, argv );  
00060 
00061     if ( ( retval =
00062            PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
00063         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00064 
00065     if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
00066         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
00067 
00068     retval =
00069         PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
00070     if ( retval != PAPI_OK ) {
00071         if ( retval == PAPI_ECMP )
00072             test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
00073         else
00074             test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
00075     }
00076 
00077     if ( hwinfo->ncpu > MAX_THREADS )
00078         nthr = MAX_THREADS;
00079     else
00080         nthr = hwinfo->ncpu;
00081 
00082     printf( "Creating %d threads\n", nthr );
00083 
00084     for ( i = 0; i < nthr; i++ ) {
00085         rc = pthread_create( &slaves[i], NULL, Slave, NULL );
00086         if ( rc ) {
00087             retval = PAPI_ESYS;
00088             test_fail( __FILE__, __LINE__, "pthread_create", retval );
00089         }
00090     }
00091 
00092     for ( i = 0; i < nthr; i++ ) {
00093         pthread_join( slaves[i], NULL );
00094     }
00095 
00096     printf( "Expected: %lld Received: %lld\n", ( long long ) nthr * num_iters,
00097             count );
00098     if ( nthr * num_iters != count )
00099         test_fail( __FILE__, __LINE__, "Thread Locks", 1 );
00100 
00101     test_pass( __FILE__, NULL, 0 );
00102     exit( 1 );
00103 }

Here is the call graph for this function:

void* Slave ( void *  arg  ) 

Definition at line 25 of file ctests/locks_pthreads.c.

00026 {
00027     long long duration;
00028 
00029     ( void ) arg;
00030 
00031     sleep( 1 );
00032     duration = PAPI_get_real_usec(  );
00033     lockloop( 10000, &tmpcount );
00034     duration = PAPI_get_real_usec(  ) - duration;
00035 
00036     /* First one here set's the number */
00037     PAPI_lock( PAPI_USR2_LOCK );
00038     if ( num_iters == 0 ) {
00039         printf( "10000 iterations took %lld us.\n", duration );
00040         num_iters = ( int ) ( 10 * ( TIME_LIMIT_IN_US / duration ) );
00041         printf( "Running %d iterations\n", num_iters );
00042     }
00043     PAPI_unlock( PAPI_USR2_LOCK );
00044 
00045     lockloop( num_iters, &count );
00046     pthread_exit( NULL );
00047 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

volatile long long count = 0

Definition at line 9 of file ctests/locks_pthreads.c.

volatile int num_iters = 0

Definition at line 11 of file ctests/locks_pthreads.c.

volatile long long tmpcount = 0

Definition at line 10 of file ctests/locks_pthreads.c.


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1