multiplex3_pthreads.c File Reference

Include dependency graph for multiplex3_pthreads.c:

Go to the source code of this file.

Defines

#define MAX_TO_ADD   5

Functions

void * thread_fn (void *dummy)
void mainloop (int arg)
int main (int argc, char **argv)

Define Documentation

#define MAX_TO_ADD   5

Definition at line 17 of file multiplex3_pthreads.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 183 of file multiplex3_pthreads.c.

00184 {
00185     int i, rc, retval;
00186     pthread_t id[NUM_THREADS];
00187     pthread_attr_t attr;
00188 
00189     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00190 
00191     printf( "%s: Using %d threads\n\n", argv[0], NUM_THREADS );
00192     printf
00193         ( "Does non-threaded multiplexing work with extraneous threads present?\n" );
00194 
00195     /* Create a bunch of unused pthreads, to simulate threads created
00196      * by the system that the user doesn't know about.
00197      */
00198     pthread_attr_init( &attr );
00199 #ifdef PTHREAD_CREATE_UNDETACHED
00200     pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
00201 #endif
00202 #ifdef PTHREAD_SCOPE_SYSTEM
00203     retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
00204     if ( retval != 0 )
00205         test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
00206 #endif
00207 
00208 #ifdef PPC64
00209     sigset_t sigprof;
00210     sigemptyset( &sigprof );
00211     sigaddset( &sigprof, SIGPROF );
00212     retval = sigprocmask( SIG_BLOCK, &sigprof, NULL );
00213     if ( retval != 0 )
00214         test_fail( __FILE__, __LINE__, "sigprocmask SIG_BLOCK", retval );
00215 #endif
00216 
00217     for ( i = 0; i < NUM_THREADS; i++ ) {
00218         rc = pthread_create( &id[i], &attr, thread_fn, NULL );
00219         if ( rc )
00220             test_fail( __FILE__, __LINE__, "pthread_create", rc );
00221     }
00222     pthread_attr_destroy( &attr );
00223 
00224 #ifdef PPC64
00225     retval = sigprocmask( SIG_UNBLOCK, &sigprof, NULL );
00226     if ( retval != 0 )
00227         test_fail( __FILE__, __LINE__, "sigprocmask SIG_UNBLOCK", retval );
00228 #endif
00229 
00230     mainloop( NUM_ITERS );
00231 
00232     test_pass( __FILE__, NULL, 0 );
00233     exit( 0 );
00234 }

Here is the call graph for this function:

void mainloop ( int  arg  ) 

Definition at line 35 of file multiplex3_pthreads.c.

00036 {
00037     int allvalid;
00038     long long *values;
00039     int EventSet = PAPI_NULL;
00040     int retval, i, j = 2, skipped_counters=0;
00041     PAPI_event_info_t pset;
00042 
00043     ( void ) arg;
00044 
00045     /* Initialize the library */
00046 
00047     retval = PAPI_library_init( PAPI_VER_CURRENT );
00048     if ( retval != PAPI_VER_CURRENT )
00049         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00050 
00051     init_multiplex(  );
00052 
00053     retval = PAPI_create_eventset( &EventSet );
00054     if ( retval != PAPI_OK )
00055         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00056 
00057     /* In Component PAPI, EventSets must be assigned a component index
00058        before you can fiddle with their internals.
00059        0 is always the cpu component */
00060     retval = PAPI_assign_eventset_component( EventSet, 0 );
00061     if ( retval != PAPI_OK )
00062         test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
00063                    retval );
00064 
00065     retval = PAPI_set_multiplex( EventSet );
00066         if ( retval == PAPI_ENOSUPP) {
00067        test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
00068     } else if ( retval != PAPI_OK )
00069         test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
00070 
00071     if ( ( retval =
00072            PAPI_thread_init( ( unsigned
00073                                long ( * )( void ) ) ( pthread_self ) ) ) !=
00074          PAPI_OK ) {
00075         if ( retval == PAPI_ECMP )
00076             test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
00077         else
00078             test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
00079     }
00080 
00081     retval = PAPI_add_event( EventSet, PAPI_TOT_INS );
00082     if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
00083         test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00084     if ( !TESTS_QUIET ) {
00085         printf( "Added %s\n", "PAPI_TOT_INS" );
00086     }
00087 
00088     retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
00089     if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
00090         test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00091     if ( !TESTS_QUIET ) {
00092         printf( "Added %s\n", "PAPI_TOT_CYC" );
00093     }
00094 
00095     values = ( long long * ) malloc( MAX_TO_ADD * sizeof ( long long ) );
00096     if ( values == NULL )
00097         test_fail( __FILE__, __LINE__, "malloc", 0 );
00098 
00099     for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
00100         retval = PAPI_get_event_info( i | PAPI_PRESET_MASK, &pset );
00101         if ( retval != PAPI_OK )
00102             test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
00103 
00104         if ( pset.count ) {
00105             printf( "Adding %s\n", pset.symbol );
00106 
00107             retval = PAPI_add_event( EventSet, ( int ) pset.event_code );
00108             if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
00109                 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00110 
00111             if ( retval == PAPI_OK ) {
00112                 printf( "Added %s\n", pset.symbol );
00113             } else {
00114                 printf( "Could not add %s\n", pset.symbol );
00115             }
00116 
00117             do_stuff(  );
00118 
00119             if ( retval == PAPI_OK ) {
00120                 retval = PAPI_start( EventSet );
00121                 if ( retval != PAPI_OK )
00122                     test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00123 
00124                 do_stuff(  );
00125 
00126                 retval = PAPI_stop( EventSet, values );
00127                 if ( retval != PAPI_OK )
00128                     test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00129 
00130                 if ( values[j] ) {
00131                     if ( ++j >= MAX_TO_ADD )
00132                         break;
00133                 } else {
00134                     retval =
00135                         PAPI_remove_event( EventSet, ( int ) pset.event_code );
00136                     if ( retval == PAPI_OK )
00137                         printf( "Removed %s\n", pset.symbol );
00138                         /* This added because the test */
00139                         /* can take a long time if mplexing */
00140                         /* is broken and all values are 0   */
00141                         skipped_counters++;
00142                         if (skipped_counters>MAX_TO_ADD) break;
00143 
00144                 }
00145             }
00146         }
00147     }
00148 
00149     retval = PAPI_start( EventSet );
00150     if ( retval != PAPI_OK )
00151         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00152 
00153     do_stuff(  );
00154 
00155     retval = PAPI_stop( EventSet, values );
00156     if ( retval != PAPI_OK )
00157         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00158 
00159     test_print_event_header( "multiplex3_pthreads:\n", EventSet );
00160     allvalid = 0;
00161     for ( i = 0; i < MAX_TO_ADD; i++ ) {
00162         printf( ONENUM, values[i] );
00163         if ( values[i] != 0 )
00164             allvalid++;
00165     }
00166     printf( "\n" );
00167     if ( !allvalid )
00168         test_fail( __FILE__, __LINE__, "all counter registered no counts", 1 );
00169 
00170     retval = PAPI_cleanup_eventset( EventSet ); /* JT */
00171     if ( retval != PAPI_OK )
00172         test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
00173 
00174     retval = PAPI_destroy_eventset( &EventSet );
00175     if ( retval != PAPI_OK )
00176         test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
00177 
00178     free( values );
00179     PAPI_shutdown(  );
00180 }

Here is the call graph for this function:

Here is the caller graph for this function:

void* thread_fn ( void *  dummy  ) 

Definition at line 23 of file multiplex3_pthreads.c.

00024 {
00025     ( void ) dummy;
00026     while ( 1 ) {
00027         do_stuff(  );
00028     }
00029     return ( NULL );
00030 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1