PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
multiplex3_pthreads.c File Reference
Include dependency graph for multiplex3_pthreads.c:

Go to the source code of this file.

Macros

#define MAX_TO_ADD   5
 

Functions

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

Macro Definition 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.

184 {
185  int i, rc, retval;
187  pthread_attr_t attr;
188 
189  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
190 
191  printf( "%s: Using %d threads\n\n", argv[0], NUM_THREADS );
192  printf
193  ( "Does non-threaded multiplexing work with extraneous threads present?\n" );
194 
195  /* Create a bunch of unused pthreads, to simulate threads created
196  * by the system that the user doesn't know about.
197  */
198  pthread_attr_init( &attr );
199 #ifdef PTHREAD_CREATE_UNDETACHED
200  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
201 #endif
202 #ifdef PTHREAD_SCOPE_SYSTEM
203  retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
204  if ( retval != 0 )
205  test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
206 #endif
207 
208 #ifdef PPC64
209  sigset_t sigprof;
210  sigemptyset( &sigprof );
211  sigaddset( &sigprof, SIGPROF );
212  retval = sigprocmask( SIG_BLOCK, &sigprof, NULL );
213  if ( retval != 0 )
214  test_fail( __FILE__, __LINE__, "sigprocmask SIG_BLOCK", retval );
215 #endif
216 
217  for ( i = 0; i < NUM_THREADS; i++ ) {
218  rc = pthread_create( &id[i], &attr, thread_fn, NULL );
219  if ( rc )
220  test_fail( __FILE__, __LINE__, "pthread_create", rc );
221  }
222  pthread_attr_destroy( &attr );
223 
224 #ifdef PPC64
225  retval = sigprocmask( SIG_UNBLOCK, &sigprof, NULL );
226  if ( retval != 0 )
227  test_fail( __FILE__, __LINE__, "sigprocmask SIG_UNBLOCK", retval );
228 #endif
229 
230  mainloop( NUM_ITERS );
231 
232  test_pass( __FILE__, NULL, 0 );
233  exit( 0 );
234 }
void mainloop(int arg)
#define NUM_ITERS
Definition: multiplex.c:19
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
void * thread_fn(void *dummy)
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int i
Definition: fileop.c:140
#define NUM_THREADS
Definition: test_utils.h:8
pthread_t
Definition: iozone.c:18557
int rc
Definition: iozone.c:20281
ssize_t retval
Definition: libasync.c:338
void exit()
pthread_attr_t attr
Definition: iozone.c:18466

Here is the call graph for this function:

void mainloop ( int  arg)

Definition at line 35 of file multiplex3_pthreads.c.

36 {
37  int allvalid;
38  long long *values;
39  int EventSet = PAPI_NULL;
40  int retval, i, j = 2, skipped_counters=0;
41  PAPI_event_info_t pset;
42 
43  ( void ) arg;
44 
45  /* Initialize the library */
46 
48  if ( retval != PAPI_VER_CURRENT )
49  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
50 
51  init_multiplex( );
52 
53  retval = PAPI_create_eventset( &EventSet );
54  if ( retval != PAPI_OK )
55  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
56 
57  /* In Component PAPI, EventSets must be assigned a component index
58  before you can fiddle with their internals.
59  0 is always the cpu component */
60  retval = PAPI_assign_eventset_component( EventSet, 0 );
61  if ( retval != PAPI_OK )
62  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
63  retval );
64 
65  retval = PAPI_set_multiplex( EventSet );
66  if ( retval == PAPI_ENOSUPP) {
67  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
68  } else if ( retval != PAPI_OK )
69  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
70 
71  if ( ( retval =
72  PAPI_thread_init( ( unsigned
73  long ( * )( void ) ) ( pthread_self ) ) ) !=
74  PAPI_OK ) {
75  if ( retval == PAPI_ECMP )
76  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
77  else
78  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
79  }
80 
81  retval = PAPI_add_event( EventSet, PAPI_TOT_INS );
82  if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
83  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
84  if ( !TESTS_QUIET ) {
85  printf( "Added %s\n", "PAPI_TOT_INS" );
86  }
87 
88  retval = PAPI_add_event( EventSet, PAPI_TOT_CYC );
89  if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
90  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
91  if ( !TESTS_QUIET ) {
92  printf( "Added %s\n", "PAPI_TOT_CYC" );
93  }
94 
95  values = ( long long * ) malloc( MAX_TO_ADD * sizeof ( long long ) );
96  if ( values == NULL )
97  test_fail( __FILE__, __LINE__, "malloc", 0 );
98 
99  for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
100  retval = PAPI_get_event_info( i | PAPI_PRESET_MASK, &pset );
101  if ( retval != PAPI_OK )
102  test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
103 
104  if ( pset.count ) {
105  printf( "Adding %s\n", pset.symbol );
106 
107  retval = PAPI_add_event( EventSet, ( int ) pset.event_code );
108  if ( ( retval != PAPI_OK ) && ( retval != PAPI_ECNFLCT ) )
109  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
110 
111  if ( retval == PAPI_OK ) {
112  printf( "Added %s\n", pset.symbol );
113  } else {
114  printf( "Could not add %s\n", pset.symbol );
115  }
116 
117  do_stuff( );
118 
119  if ( retval == PAPI_OK ) {
120  retval = PAPI_start( EventSet );
121  if ( retval != PAPI_OK )
122  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
123 
124  do_stuff( );
125 
126  retval = PAPI_stop( EventSet, values );
127  if ( retval != PAPI_OK )
128  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
129 
130  if ( values[j] ) {
131  if ( ++j >= MAX_TO_ADD )
132  break;
133  } else {
134  retval =
135  PAPI_remove_event( EventSet, ( int ) pset.event_code );
136  if ( retval == PAPI_OK )
137  printf( "Removed %s\n", pset.symbol );
138  /* This added because the test */
139  /* can take a long time if mplexing */
140  /* is broken and all values are 0 */
141  skipped_counters++;
142  if (skipped_counters>MAX_TO_ADD) break;
143 
144  }
145  }
146  }
147  }
148 
149  retval = PAPI_start( EventSet );
150  if ( retval != PAPI_OK )
151  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
152 
153  do_stuff( );
154 
155  retval = PAPI_stop( EventSet, values );
156  if ( retval != PAPI_OK )
157  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
158 
159  test_print_event_header( "multiplex3_pthreads:\n", EventSet );
160  allvalid = 0;
161  for ( i = 0; i < MAX_TO_ADD; i++ ) {
162  printf( ONENUM, values[i] );
163  if ( values[i] != 0 )
164  allvalid++;
165  }
166  printf( "\n" );
167  if ( !allvalid )
168  test_fail( __FILE__, __LINE__, "all counter registered no counts", 1 );
169 
170  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
171  if ( retval != PAPI_OK )
172  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
173 
174  retval = PAPI_destroy_eventset( &EventSet );
175  if ( retval != PAPI_OK )
176  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
177 
178  free( values );
179  PAPI_shutdown( );
180 }
unsigned int count
Definition: papi.h:982
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1692
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_TOT_INS
Definition: fpapi.h:185
void do_stuff(void)
Definition: do_loops.c:249
#define ONENUM
Definition: papi_test.h:111
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_PRESET_MASK
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
void init_multiplex(void)
Definition: test_utils.c:888
#define PAPI_ECNFLCT
Definition: fpapi.h:113
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:841
int TESTS_QUIET
Definition: test_utils.c:11
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:118
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_ENOSUPP
Definition: fpapi.h:123
#define PAPI_TOT_CYC
Definition: fpapi.h:194
void PAPI_shutdown(void)
Definition: papi.c:4344
free(dummyfile[xx])
#define PAPI_ECMP
Definition: fpapi.h:109
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1460
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int EventSet
#define PAPI_MAX_PRESET_EVENTS
Definition: fpapi.h:16
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3230
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
void test_print_event_header(char *call, int evset)
Definition: test_utils.c:645
int PAPI_start(int EventSet)
Definition: papi.c:2019
#define MAX_TO_ADD
long j
Definition: iozone.c:19135
unsigned int event_code
Definition: papi.h:959
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338

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.

24 {
25  ( void ) dummy;
26  while ( 1 ) {
27  do_stuff( );
28  }
29  return ( NULL );
30 }
void do_stuff(void)
Definition: do_loops.c:249
void
Definition: iozone.c:18627
int dummy
Definition: iozone.c:19741

Here is the call graph for this function:

Here is the caller graph for this function: